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