blob: 92acb1a44a2b9e1402ae4079bcdc5527dba207e1 [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) {
16 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:])
28}
29
30func listVIPs(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
31 err := vips.List(client, lbID).EachPage(func(page pagination.Page) (bool, error) {
32 vipList, err := vips.ExtractVIPs(page)
33 th.AssertNoErr(t, err)
34
35 for _, vip := range vipList {
36 t.Logf("Listing VIP: ID [%s] Address [%s] Type [%s] Version [%s]",
37 vip.ID, vip.Address, vip.Type, vip.Version)
38 }
39
40 return true, nil
41 })
42 th.AssertNoErr(t, err)
43}
44
45func addVIPs(t *testing.T, client *gophercloud.ServiceClient, lbID, count int) []int {
46 ids := []int{}
47
48 for i := 0; i < count; i++ {
49 opts := vips.CreateOpts{
50 Type: vips.PUBLIC,
51 Version: vips.IPV6,
52 }
53
54 vip, err := vips.Create(client, lbID, opts).Extract()
55 th.AssertNoErr(t, err)
56
57 t.Logf("Created VIP %d", vip.ID)
58
59 waitForLB(client, lbID, lbs.ACTIVE)
60
61 ids = append(ids, vip.ID)
62 }
63
64 return ids
65}
66
67func deleteVIP(t *testing.T, client *gophercloud.ServiceClient, lbID, vipID int) {
68 err := vips.Delete(client, lbID, vipID).ExtractErr()
69 th.AssertNoErr(t, err)
70
71 t.Logf("Deleted VIP %d", vipID)
72
73 waitForLB(client, lbID, lbs.ACTIVE)
74}
75
76func bulkDeleteVIPs(t *testing.T, client *gophercloud.ServiceClient, lbID int, ids []int) {
77 err := vips.BulkDelete(client, lbID, ids).ExtractErr()
78 th.AssertNoErr(t, err)
79 t.Logf("Deleted VIPs %s", intsToStr(ids))
80}