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