blob: 1cc12356cafed410139af40b5814aad886bccb5c [file] [log] [blame]
Jamie Hannafordbde72602014-11-10 10:32:26 +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/throttle"
10 th "github.com/rackspace/gophercloud/testhelper"
11)
12
13func TestThrottle(t *testing.T) {
Jamie Hannafordbde72602014-11-10 10:32:26 +010014 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
30func 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
36func createThrottleConfig(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
Jamie Hannafordb514bfd2014-11-10 15:39:15 +010037 opts := throttle.CreateOpts{
38 MaxConnections: 200,
39 MaxConnectionRate: 100,
40 MinConnections: 0,
41 RateInterval: 10,
42 }
43
Jamie Hannafordbde72602014-11-10 10:32:26 +010044 err := throttle.Create(client, lbID, opts).ExtractErr()
45 th.AssertNoErr(t, err)
46 t.Logf("Enable throttling for %d", lbID)
47}
48
49func 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}