blob: c1a8e24dd9bd6c9de4e223f9f3d444e4268b92cd [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/lbs"
10 "github.com/rackspace/gophercloud/rackspace/lb/v1/monitors"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func TestMonitors(t *testing.T) {
Jamie Hannaford07cf0ea2014-11-06 10:42:49 +010015 client := setup(t)
16
17 ids := createLB(t, client, 1)
18 lbID := ids[0]
19
20 getMonitor(t, client, lbID)
21
22 updateMonitor(t, client, lbID)
23
24 deleteMonitor(t, client, lbID)
25
26 deleteLB(t, client, lbID)
27}
28
29func getMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
30 hm, err := monitors.Get(client, lbID).Extract()
31 th.AssertNoErr(t, err)
32 t.Logf("Health monitor for LB %d: Type [%s] Delay [%d] Timeout [%d] AttemptLimit [%d]",
33 lbID, hm.Type, hm.Delay, hm.Timeout, hm.AttemptLimit)
34}
35
36func updateMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
37 opts := monitors.UpdateHTTPMonitorOpts{
38 AttemptLimit: 3,
39 Delay: 10,
40 Timeout: 10,
41 BodyRegex: "hello is it me you're looking for",
42 Path: "/foo",
43 StatusRegex: "200",
44 Type: monitors.HTTP,
45 }
46
47 err := monitors.Update(client, lbID, opts).ExtractErr()
48 th.AssertNoErr(t, err)
49
50 waitForLB(client, lbID, lbs.ACTIVE)
51 t.Logf("Updated monitor for LB %d", lbID)
52}
53
54func deleteMonitor(t *testing.T, client *gophercloud.ServiceClient, lbID int) {
55 err := monitors.Delete(client, lbID).ExtractErr()
56 th.AssertNoErr(t, err)
57
58 waitForLB(client, lbID, lbs.ACTIVE)
59 t.Logf("Deleted monitor for LB %d", lbID)
60}