blob: 5921014f5edd9ca99c7cc0df1124d1cce2bb8ec4 [file] [log] [blame]
Joe Topjian6aa8ba02016-07-24 16:12:30 +00001// +build acceptance compute servergroups
Joe Topjianc9fb21b2015-02-22 05:55:48 +00002
3package v2
4
5import (
6 "testing"
7
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Jon Perritt27249f42016-02-18 10:35:59 -06009 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
10 "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
Joe Topjianc9fb21b2015-02-22 05:55:48 +000011)
12
Joe Topjian6aa8ba02016-07-24 16:12:30 +000013func TestServergroupsList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060014 client, err := clients.NewComputeV2Client()
Joe Topjian6aa8ba02016-07-24 16:12:30 +000015 if err != nil {
16 t.Fatalf("Unable to create a compute client: %v", err)
17 }
18
19 allPages, err := servergroups.List(client).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to list server groups: %v", err)
22 }
23
24 allServerGroups, err := servergroups.ExtractServerGroups(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract server groups: %v", err)
27 }
28
29 for _, serverGroup := range allServerGroups {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060030 PrintServerGroup(t, &serverGroup)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000031 }
32}
33
34func TestServergroupsCreate(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060035 client, err := clients.NewComputeV2Client()
Joe Topjian6aa8ba02016-07-24 16:12:30 +000036 if err != nil {
37 t.Fatalf("Unable to create a compute client: %v", err)
38 }
39
Joe Topjian1c15e3f2016-08-08 10:48:38 -060040 serverGroup, err := CreateServerGroup(t, client, "anti-affinity")
Joe Topjian6aa8ba02016-07-24 16:12:30 +000041 if err != nil {
42 t.Fatalf("Unable to create server group: %v", err)
43 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060044 defer DeleteServerGroup(t, client, serverGroup)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000045
46 serverGroup, err = servergroups.Get(client, serverGroup.ID).Extract()
47 if err != nil {
48 t.Fatalf("Unable to get server group: %v", err)
49 }
50
Joe Topjian1c15e3f2016-08-08 10:48:38 -060051 PrintServerGroup(t, serverGroup)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000052}
53
54func TestServergroupsAffinityPolicy(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060055 client, err := clients.NewComputeV2Client()
Joe Topjian6aa8ba02016-07-24 16:12:30 +000056 if err != nil {
57 t.Fatalf("Unable to create a compute client: %v", err)
58 }
59
Joe Topjian1c15e3f2016-08-08 10:48:38 -060060 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjian6aa8ba02016-07-24 16:12:30 +000061 if err != nil {
62 t.Fatal(err)
63 }
64
Joe Topjian1c15e3f2016-08-08 10:48:38 -060065 serverGroup, err := CreateServerGroup(t, client, "affinity")
Joe Topjian6aa8ba02016-07-24 16:12:30 +000066 if err != nil {
67 t.Fatalf("Unable to create server group: %v", err)
68 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060069 defer DeleteServerGroup(t, client, serverGroup)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000070
Joe Topjian1c15e3f2016-08-08 10:48:38 -060071 firstServer, err := CreateServerInServerGroup(t, client, choices, serverGroup)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000072 if err != nil {
73 t.Fatalf("Unable to create server: %v", err)
74 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060075 defer DeleteServer(t, client, firstServer)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000076
77 firstServer, err = servers.Get(client, firstServer.ID).Extract()
78
Joe Topjian1c15e3f2016-08-08 10:48:38 -060079 secondServer, err := CreateServerInServerGroup(t, client, choices, serverGroup)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000080 if err != nil {
81 t.Fatalf("Unable to create server: %v", err)
82 }
83
Joe Topjian1c15e3f2016-08-08 10:48:38 -060084 if err = WaitForComputeStatus(client, secondServer, "ACTIVE"); err != nil {
Joe Topjian6aa8ba02016-07-24 16:12:30 +000085 t.Fatalf("Unable to wait for server: %v", err)
86 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060087 defer DeleteServer(t, client, secondServer)
Joe Topjian6aa8ba02016-07-24 16:12:30 +000088
89 secondServer, err = servers.Get(client, secondServer.ID).Extract()
90
91 if firstServer.HostID != secondServer.HostID {
92 t.Fatalf("%s and %s were not scheduled on the same host.", firstServer.ID, secondServer.ID)
93 }
94}