Jamie Hannaford | c9da4b4 | 2014-11-05 16:34:56 +0100 | [diff] [blame] | 1 | // +build acceptance lbs |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
| 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 | |
| 15 | func TestVIPs(t *testing.T) { |
Jamie Hannaford | c9da4b4 | 2014-11-05 16:34:56 +0100 | [diff] [blame] | 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:]) |
Jamie Hannaford | b514bfd | 2014-11-10 15:39:15 +0100 | [diff] [blame] | 28 | |
| 29 | waitForLB(client, lbID, lbs.ACTIVE) |
| 30 | deleteLB(t, client, lbID) |
Jamie Hannaford | c9da4b4 | 2014-11-05 16:34:56 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | func 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 | |
| 48 | func 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 | |
| 70 | func 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 | |
| 79 | func 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 | } |