blob: 80015e143f5291ac334452ffa049a90859e2160b [file] [log] [blame]
Joe Topjianc9fb21b2015-02-22 05:55:48 +00001// +build acceptance compute servers
2
3package v2
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud"
9 "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/servergroups"
10)
11
12func 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
28func 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
39func 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}