blob: bc0c2a89f2a8c2b045d7e629124066d15d336560 [file] [log] [blame]
Jamie Hannafordc9da4b42014-11-05 16:34:56 +01001// +build acceptance lbs
2
3package v1
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/pagination"
10 "github.com/rackspace/gophercloud/rackspace/lb/v1/lbs"
11 "github.com/rackspace/gophercloud/rackspace/lb/v1/vips"
12 th "github.com/rackspace/gophercloud/testhelper"
13)
14
15func TestVIPs(t *testing.T) {
Jamie Hannafordc9da4b42014-11-05 16:34:56 +010016 client := setup(t)
17
18 ids := createLB(t, client, 1)
19 lbID := ids[0]
20
21 listVIPs(t, client, lbID)
22
23 vipIDs := addVIPs(t, client, lbID, 3)
24
25 deleteVIP(t, client, lbID, vipIDs[0])
26
27 bulkDeleteVIPs(t, client, lbID, vipIDs[1:])
Jamie Hannafordb514bfd2014-11-10 15:39:15 +010028
29 waitForLB(client, lbID, lbs.ACTIVE)
30 deleteLB(t, client, lbID)
Jamie Hannafordc9da4b42014-11-05 16:34:56 +010031}
32
33func listVIPs(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
34 err := vips.List(client, lbID).EachPage(func(page pagination.Page) (bool, error) {
35 vipList, err := vips.ExtractVIPs(page)
36 th.AssertNoErr(t, err)
37
38 for _, vip := range vipList {
39 t.Logf("Listing VIP: ID [%s] Address [%s] Type [%s] Version [%s]",
40 vip.ID, vip.Address, vip.Type, vip.Version)
41 }
42
43 return true, nil
44 })
45 th.AssertNoErr(t, err)
46}
47
48func addVIPs(t *testing.T, client *gophercloud.ServiceClient, lbID, count int) []int {
49 ids := []int{}
50
51 for i := 0; i < count; i++ {
52 opts := vips.CreateOpts{
53 Type: vips.PUBLIC,
54 Version: vips.IPV6,
55 }
56
57 vip, err := vips.Create(client, lbID, opts).Extract()
58 th.AssertNoErr(t, err)
59
60 t.Logf("Created VIP %d", vip.ID)
61
62 waitForLB(client, lbID, lbs.ACTIVE)
63
64 ids = append(ids, vip.ID)
65 }
66
67 return ids
68}
69
70func deleteVIP(t *testing.T, client *gophercloud.ServiceClient, lbID, vipID int) {
71 err := vips.Delete(client, lbID, vipID).ExtractErr()
72 th.AssertNoErr(t, err)
73
74 t.Logf("Deleted VIP %d", vipID)
75
76 waitForLB(client, lbID, lbs.ACTIVE)
77}
78
79func bulkDeleteVIPs(t *testing.T, client *gophercloud.ServiceClient, lbID int, ids []int) {
80 err := vips.BulkDelete(client, lbID, ids).ExtractErr()
81 th.AssertNoErr(t, err)
82 t.Logf("Deleted VIPs %s", intsToStr(ids))
83}