Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 1 | // +build acceptance compute servers |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/rackspace/gophercloud" |
| 9 | "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/servergroups" |
| 10 | ) |
| 11 | |
| 12 | func createServerGroup(t *testing.T, computeClient *gophercloud.ServiceClient) (*servergroups.ServerGroup, error) { |
| 13 | sg, err := servergroups.Create(computeClient, &servergroups.CreateOpts{ |
| 14 | Name: "test", |
| 15 | Policies: []string{"affinity"}, |
| 16 | }).Extract() |
| 17 | |
| 18 | if err != nil { |
| 19 | t.Fatalf("Unable to create server group: %v", err) |
| 20 | } |
| 21 | |
| 22 | t.Logf("Created server group: %v", sg.ID) |
| 23 | t.Logf("It has policies: %v", sg.Policies) |
| 24 | |
| 25 | return sg, nil |
| 26 | } |
| 27 | |
| 28 | func getServerGroup(t *testing.T, computeClient *gophercloud.ServiceClient, sgID string) error { |
| 29 | sg, err := servergroups.Get(computeClient, sgID).Extract() |
| 30 | if err != nil { |
| 31 | t.Fatalf("Unable to get server group: %v", err) |
| 32 | } |
| 33 | |
| 34 | t.Logf("Got server group: %v", sg.Name) |
| 35 | |
| 36 | return nil |
| 37 | } |
| 38 | |
| 39 | func TestServerGroups(t *testing.T) { |
| 40 | computeClient, err := newClient() |
| 41 | if err != nil { |
| 42 | t.Fatalf("Unable to create a compute client: %v", err) |
| 43 | } |
| 44 | |
| 45 | sg, err := createServerGroup(t, computeClient) |
| 46 | if err != nil { |
| 47 | t.Fatalf("Unable to create server group: %v", err) |
| 48 | } |
| 49 | defer func() { |
| 50 | servergroups.Delete(computeClient, sg.ID) |
| 51 | t.Logf("ServerGroup deleted.") |
| 52 | }() |
| 53 | |
| 54 | err = getServerGroup(t, computeClient, sg.ID) |
| 55 | if err != nil { |
| 56 | t.Fatalf("Unable to get server group: %v", err) |
| 57 | } |
| 58 | } |