Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +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/rackspace/lb/v1/throttle" |
| 10 | th "github.com/rackspace/gophercloud/testhelper" |
| 11 | ) |
| 12 | |
| 13 | func TestThrottle(t *testing.T) { |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 14 | client := setup(t) |
| 15 | |
| 16 | ids := createLB(t, client, 1) |
| 17 | lbID := ids[0] |
| 18 | |
| 19 | getThrottleConfig(t, client, lbID) |
| 20 | |
| 21 | createThrottleConfig(t, client, lbID) |
| 22 | waitForLB(client, lbID, "ACTIVE") |
| 23 | |
| 24 | deleteThrottleConfig(t, client, lbID) |
| 25 | waitForLB(client, lbID, "ACTIVE") |
| 26 | |
| 27 | deleteLB(t, client, lbID) |
| 28 | } |
| 29 | |
| 30 | func getThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 31 | sp, err := throttle.Get(client, lbID).Extract() |
| 32 | th.AssertNoErr(t, err) |
| 33 | t.Logf("Throttle config: MaxConns [%s]", sp.MaxConnections) |
| 34 | } |
| 35 | |
| 36 | func createThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
Jamie Hannaford | b514bfd | 2014-11-10 15:39:15 +0100 | [diff] [blame] | 37 | opts := throttle.CreateOpts{ |
| 38 | MaxConnections: 200, |
| 39 | MaxConnectionRate: 100, |
| 40 | MinConnections: 0, |
| 41 | RateInterval: 10, |
| 42 | } |
| 43 | |
Jamie Hannaford | bde7260 | 2014-11-10 10:32:26 +0100 | [diff] [blame] | 44 | err := throttle.Create(client, lbID, opts).ExtractErr() |
| 45 | th.AssertNoErr(t, err) |
| 46 | t.Logf("Enable throttling for %d", lbID) |
| 47 | } |
| 48 | |
| 49 | func deleteThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) { |
| 50 | err := throttle.Delete(client, lbID).ExtractErr() |
| 51 | th.AssertNoErr(t, err) |
| 52 | t.Logf("Disable throttling for %d", lbID) |
| 53 | } |