Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 1 | // +build acceptance lbs |
| 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 6 | "testing" |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 7 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/pagination" |
| 10 | "github.com/rackspace/gophercloud/rackspace/lb/v1/acl" |
| 11 | "github.com/rackspace/gophercloud/rackspace/lb/v1/lbs" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 13 | ) |
| 14 | |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 15 | func TestACL(t *testing.T) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 16 | client := setup(t) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 17 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 18 | ids := createLB(t, client, 1) |
| 19 | lbID := ids[0] |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 20 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 21 | createACL(t, client, lbID) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 22 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 23 | waitForLB(client, lbID, lbs.ACTIVE) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 24 | |
| 25 | networkIDs := showACL(t, client, lbID) |
| 26 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 27 | deleteNetworkItem(t, client, lbID, networkIDs[0]) |
| 28 | waitForLB(client, lbID, lbs.ACTIVE) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 29 | |
| 30 | bulkDeleteACL(t, client, lbID, networkIDs[1:2]) |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 31 | waitForLB(client, lbID, lbs.ACTIVE) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 32 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 33 | deleteACL(t, client, lbID) |
| 34 | waitForLB(client, lbID, lbs.ACTIVE) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 35 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 36 | deleteLB(t, client, lbID) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | func createACL(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 40 | opts := acl.CreateOpts{ |
| 41 | acl.CreateOpt{Address: "206.160.163.21", Type: acl.DENY}, |
| 42 | acl.CreateOpt{Address: "206.160.165.11", Type: acl.DENY}, |
| 43 | acl.CreateOpt{Address: "206.160.165.12", Type: acl.DENY}, |
| 44 | acl.CreateOpt{Address: "206.160.165.13", Type: acl.ALLOW}, |
| 45 | } |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 46 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 47 | err := acl.Create(client, lbID, opts).ExtractErr() |
| 48 | th.AssertNoErr(t, err) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 49 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 50 | t.Logf("Created ACL items for LB %d", lbID) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func showACL(t *testing.T, client *gophercloud.ServiceClient, lbID int) []int { |
| 54 | ids := []int{} |
| 55 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 56 | err := acl.List(client, lbID).EachPage(func(page pagination.Page) (bool, error) { |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 57 | accessList, err := acl.ExtractAccessList(page) |
| 58 | th.AssertNoErr(t, err) |
| 59 | |
| 60 | for _, i := range accessList { |
| 61 | t.Logf("Listing network item: ID [%s] Address [%s] Type [%s]", i.ID, i.Address, i.Type) |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 62 | ids = append(ids, i.ID) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | return true, nil |
| 66 | }) |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 67 | th.AssertNoErr(t, err) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 68 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 69 | return ids |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | func deleteNetworkItem(t *testing.T, client *gophercloud.ServiceClient, lbID, itemID int) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 73 | err := acl.Delete(client, lbID, itemID).ExtractErr() |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 74 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 75 | th.AssertNoErr(t, err) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 76 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 77 | t.Logf("Deleted network item %d", itemID) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | func bulkDeleteACL(t *testing.T, client *gophercloud.ServiceClient, lbID int, items []int) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 81 | err := acl.BulkDelete(client, lbID, items).ExtractErr() |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 82 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 83 | th.AssertNoErr(t, err) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 84 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 85 | t.Logf("Deleted network items %s", intsToStr(items)) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | func deleteACL(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 89 | err := acl.DeleteAll(client, lbID).ExtractErr() |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 90 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 91 | th.AssertNoErr(t, err) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 92 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 93 | t.Logf("Deleted ACL from LB %d", lbID) |
Jamie Hannaford | 07cf0ea | 2014-11-06 10:42:49 +0100 | [diff] [blame] | 94 | } |