blob: c61f4620533c18991f489e587517e80f47d74092 [file] [log] [blame]
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +01001// +build acceptance lbs
2
3package v1
4
5import (
Jamie Hannafordbde72602014-11-10 10:32:26 +01006 "testing"
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +01007
Jamie Hannafordbde72602014-11-10 10:32:26 +01008 "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 Hannaford07cf0ea2014-11-06 10:42:49 +010013)
14
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010015func TestACL(t *testing.T) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010016 return
17 client := setup(t)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010018
Jamie Hannafordbde72602014-11-10 10:32:26 +010019 ids := createLB(t, client, 1)
20 lbID := ids[0]
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010021
Jamie Hannafordbde72602014-11-10 10:32:26 +010022 createACL(t, client, lbID)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010023
Jamie Hannafordbde72602014-11-10 10:32:26 +010024 waitForLB(client, lbID, lbs.ACTIVE)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010025
26 networkIDs := showACL(t, client, lbID)
27
Jamie Hannafordbde72602014-11-10 10:32:26 +010028 deleteNetworkItem(t, client, lbID, networkIDs[0])
29 waitForLB(client, lbID, lbs.ACTIVE)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010030
31 bulkDeleteACL(t, client, lbID, networkIDs[1:2])
Jamie Hannafordbde72602014-11-10 10:32:26 +010032 waitForLB(client, lbID, lbs.ACTIVE)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010033
Jamie Hannafordbde72602014-11-10 10:32:26 +010034 deleteACL(t, client, lbID)
35 waitForLB(client, lbID, lbs.ACTIVE)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010036
Jamie Hannafordbde72602014-11-10 10:32:26 +010037 deleteLB(t, client, lbID)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010038}
39
40func createACL(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010041 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 }
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010047
Jamie Hannafordbde72602014-11-10 10:32:26 +010048 err := acl.Create(client, lbID, opts).ExtractErr()
49 th.AssertNoErr(t, err)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010050
Jamie Hannafordbde72602014-11-10 10:32:26 +010051 t.Logf("Created ACL items for LB %d", lbID)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010052}
53
54func showACL(t *testing.T, client *gophercloud.ServiceClient, lbID int) []int {
55 ids := []int{}
56
Jamie Hannafordbde72602014-11-10 10:32:26 +010057 err := acl.List(client, lbID).EachPage(func(page pagination.Page) (bool, error) {
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010058 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)
Jamie Hannafordbde72602014-11-10 10:32:26 +010063 ids = append(ids, i.ID)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010064 }
65
66 return true, nil
67 })
Jamie Hannafordbde72602014-11-10 10:32:26 +010068 th.AssertNoErr(t, err)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010069
Jamie Hannafordbde72602014-11-10 10:32:26 +010070 return ids
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010071}
72
73func deleteNetworkItem(t *testing.T, client *gophercloud.ServiceClient, lbID, itemID int) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010074 err := acl.Delete(client, lbID, itemID).ExtractErr()
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010075
Jamie Hannafordbde72602014-11-10 10:32:26 +010076 th.AssertNoErr(t, err)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010077
Jamie Hannafordbde72602014-11-10 10:32:26 +010078 t.Logf("Deleted network item %d", itemID)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010079}
80
81func bulkDeleteACL(t *testing.T, client *gophercloud.ServiceClient, lbID int, items []int) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010082 err := acl.BulkDelete(client, lbID, items).ExtractErr()
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010083
Jamie Hannafordbde72602014-11-10 10:32:26 +010084 th.AssertNoErr(t, err)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010085
Jamie Hannafordbde72602014-11-10 10:32:26 +010086 t.Logf("Deleted network items %s", intsToStr(items))
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010087}
88
89func deleteACL(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010090 err := acl.DeleteAll(client, lbID).ExtractErr()
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010091
Jamie Hannafordbde72602014-11-10 10:32:26 +010092 th.AssertNoErr(t, err)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010093
Jamie Hannafordbde72602014-11-10 10:32:26 +010094 t.Logf("Deleted ACL from LB %d", lbID)
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010095}