Jamie Hannaford | 2d48037 | 2014-10-22 10:47:09 +0200 | [diff] [blame] | 1 | // +build acceptance compute servers |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 6 | "strings" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 7 | "testing" |
| 8 | |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 9 | "github.com/gophercloud/gophercloud" |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 11 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 12 | "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 13 | th "github.com/gophercloud/gophercloud/testhelper" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 14 | ) |
| 15 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 16 | func TestServersList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 17 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 18 | if err != nil { |
| 19 | t.Fatalf("Unable to create a compute client: %v", err) |
| 20 | } |
| 21 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 22 | allPages, err := servers.List(client, servers.ListOpts{}).AllPages() |
| 23 | if err != nil { |
| 24 | t.Fatalf("Unable to retrieve servers: %v", err) |
| 25 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 26 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 27 | allServers, err := servers.ExtractServers(allPages) |
| 28 | if err != nil { |
| 29 | t.Fatalf("Unable to extract servers: %v", err) |
| 30 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 31 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 32 | for _, server := range allServers { |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 33 | tools.PrintResource(t, server) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 34 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 35 | } |
| 36 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 37 | func TestServersCreateDestroy(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 38 | client, err := clients.NewComputeV2Client() |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 39 | if err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 40 | t.Fatalf("Unable to create a compute client: %v", err) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 43 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 44 | if err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 48 | server, err := CreateServer(t, client) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 49 | if err != nil { |
| 50 | t.Fatalf("Unable to create server: %v", err) |
| 51 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 52 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 53 | defer DeleteServer(t, client, server) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 54 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 55 | newServer, err := servers.Get(client, server.ID).Extract() |
| 56 | if err != nil { |
| 57 | t.Errorf("Unable to retrieve server: %v", err) |
| 58 | } |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 59 | tools.PrintResource(t, newServer) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 60 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 61 | allAddressPages, err := servers.ListAddresses(client, server.ID).AllPages() |
| 62 | if err != nil { |
| 63 | t.Errorf("Unable to list server addresses: %v", err) |
| 64 | } |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 65 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 66 | allAddresses, err := servers.ExtractAddresses(allAddressPages) |
| 67 | if err != nil { |
| 68 | t.Errorf("Unable to extract server addresses: %v", err) |
| 69 | } |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 70 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 71 | for network, address := range allAddresses { |
| 72 | t.Logf("Addresses on %s: %+v", network, address) |
| 73 | } |
| 74 | |
| 75 | allNetworkAddressPages, err := servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName).AllPages() |
| 76 | if err != nil { |
| 77 | t.Errorf("Unable to list server addresses: %v", err) |
| 78 | } |
| 79 | |
| 80 | allNetworkAddresses, err := servers.ExtractNetworkAddresses(allNetworkAddressPages) |
| 81 | if err != nil { |
| 82 | t.Errorf("Unable to extract server addresses: %v", err) |
| 83 | } |
| 84 | |
| 85 | t.Logf("Addresses on %s:", choices.NetworkName) |
| 86 | for _, address := range allNetworkAddresses { |
| 87 | t.Logf("%+v", address) |
| 88 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 91 | func TestServersWithoutImageRef(t *testing.T) { |
| 92 | client, err := clients.NewComputeV2Client() |
| 93 | if err != nil { |
| 94 | t.Fatalf("Unable to create a compute client: %v", err) |
| 95 | } |
| 96 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 97 | server, err := CreateServerWithoutImageRef(t, client) |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 98 | if err != nil { |
| 99 | if err400, ok := err.(*gophercloud.ErrUnexpectedResponseCode); ok { |
| 100 | if !strings.Contains("Missing imageRef attribute", string(err400.Body)) { |
| 101 | defer DeleteServer(t, client, server) |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 107 | func TestServersUpdate(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 108 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 109 | if err != nil { |
| 110 | t.Fatalf("Unable to create a compute client: %v", err) |
| 111 | } |
| 112 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 113 | server, err := CreateServer(t, client) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 114 | if err != nil { |
| 115 | t.Fatal(err) |
| 116 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 117 | defer DeleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 118 | |
| 119 | alternateName := tools.RandomString("ACPTTEST", 16) |
| 120 | for alternateName == server.Name { |
| 121 | alternateName = tools.RandomString("ACPTTEST", 16) |
| 122 | } |
| 123 | |
| 124 | t.Logf("Attempting to rename the server to %s.", alternateName) |
| 125 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 126 | updateOpts := servers.UpdateOpts{ |
| 127 | Name: alternateName, |
| 128 | } |
| 129 | |
| 130 | updated, err := servers.Update(client, server.ID, updateOpts).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 131 | if err != nil { |
| 132 | t.Fatalf("Unable to rename server: %v", err) |
| 133 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 134 | |
| 135 | if updated.ID != server.ID { |
| 136 | t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID) |
| 137 | } |
| 138 | |
| 139 | err = tools.WaitFor(func() (bool, error) { |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 140 | latest, err := servers.Get(client, updated.ID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 141 | if err != nil { |
| 142 | return false, err |
| 143 | } |
| 144 | |
| 145 | return latest.Name == alternateName, nil |
| 146 | }) |
| 147 | } |
| 148 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 149 | func TestServersMetadata(t *testing.T) { |
| 150 | t.Parallel() |
| 151 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 152 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 153 | if err != nil { |
| 154 | t.Fatalf("Unable to create a compute client: %v", err) |
| 155 | } |
| 156 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 157 | server, err := CreateServer(t, client) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 158 | if err != nil { |
| 159 | t.Fatal(err) |
| 160 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 161 | defer DeleteServer(t, client, server) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 162 | |
| 163 | metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{ |
| 164 | "foo": "bar", |
| 165 | "this": "that", |
| 166 | }).Extract() |
| 167 | if err != nil { |
| 168 | t.Fatalf("Unable to update metadata: %v", err) |
| 169 | } |
| 170 | t.Logf("UpdateMetadata result: %+v\n", metadata) |
| 171 | |
| 172 | err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr() |
| 173 | if err != nil { |
| 174 | t.Fatalf("Unable to delete metadatum: %v", err) |
| 175 | } |
| 176 | |
| 177 | metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{ |
| 178 | "foo": "baz", |
| 179 | }).Extract() |
| 180 | if err != nil { |
| 181 | t.Fatalf("Unable to create metadatum: %v", err) |
| 182 | } |
| 183 | t.Logf("CreateMetadatum result: %+v\n", metadata) |
| 184 | |
| 185 | metadata, err = servers.Metadatum(client, server.ID, "foo").Extract() |
| 186 | if err != nil { |
| 187 | t.Fatalf("Unable to get metadatum: %v", err) |
| 188 | } |
| 189 | t.Logf("Metadatum result: %+v\n", metadata) |
| 190 | th.AssertEquals(t, "baz", metadata["foo"]) |
| 191 | |
| 192 | metadata, err = servers.Metadata(client, server.ID).Extract() |
| 193 | if err != nil { |
| 194 | t.Fatalf("Unable to get metadata: %v", err) |
| 195 | } |
| 196 | t.Logf("Metadata result: %+v\n", metadata) |
| 197 | |
| 198 | metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract() |
| 199 | if err != nil { |
| 200 | t.Fatalf("Unable to reset metadata: %v", err) |
| 201 | } |
| 202 | t.Logf("ResetMetadata result: %+v\n", metadata) |
| 203 | th.AssertDeepEquals(t, map[string]string{}, metadata) |
| 204 | } |
| 205 | |
| 206 | func TestServersActionChangeAdminPassword(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 207 | t.Parallel() |
| 208 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 209 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 210 | if err != nil { |
| 211 | t.Fatalf("Unable to create a compute client: %v", err) |
| 212 | } |
| 213 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 214 | server, err := CreateServer(t, client) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 215 | if err != nil { |
| 216 | t.Fatal(err) |
| 217 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 218 | defer DeleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 219 | |
| 220 | randomPassword := tools.MakeNewPassword(server.AdminPass) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 221 | res := servers.ChangeAdminPassword(client, server.ID, randomPassword) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 222 | if res.Err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 223 | t.Fatal(res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 226 | if err = WaitForComputeStatus(client, server, "PASSWORD"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 227 | t.Fatal(err) |
| 228 | } |
| 229 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 230 | if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 231 | t.Fatal(err) |
| 232 | } |
| 233 | } |
| 234 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 235 | func TestServersActionReboot(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 236 | t.Parallel() |
| 237 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 238 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 239 | if err != nil { |
| 240 | t.Fatalf("Unable to create a compute client: %v", err) |
| 241 | } |
| 242 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 243 | server, err := CreateServer(t, client) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 244 | if err != nil { |
| 245 | t.Fatal(err) |
| 246 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 247 | defer DeleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 248 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 249 | rebootOpts := &servers.RebootOpts{ |
| 250 | Type: servers.SoftReboot, |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | t.Logf("Attempting reboot of server %s", server.ID) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 254 | res := servers.Reboot(client, server.ID, rebootOpts) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 255 | if res.Err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 256 | t.Fatalf("Unable to reboot server: %v", res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 257 | } |
| 258 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 259 | if err = WaitForComputeStatus(client, server, "REBOOT"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 260 | t.Fatal(err) |
| 261 | } |
| 262 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 263 | if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 264 | t.Fatal(err) |
| 265 | } |
| 266 | } |
| 267 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 268 | func TestServersActionRebuild(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 269 | t.Parallel() |
| 270 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 271 | client, err := clients.NewComputeV2Client() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 272 | if err != nil { |
| 273 | t.Fatalf("Unable to create a compute client: %v", err) |
| 274 | } |
| 275 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 276 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 277 | if err != nil { |
| 278 | t.Fatal(err) |
| 279 | } |
| 280 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 281 | server, err := CreateServer(t, client) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 282 | if err != nil { |
| 283 | t.Fatal(err) |
| 284 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 285 | defer DeleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 286 | |
| 287 | t.Logf("Attempting to rebuild server %s", server.ID) |
| 288 | |
Jamie Hannaford | 5bfa2e8 | 2014-10-16 16:32:42 +0200 | [diff] [blame] | 289 | rebuildOpts := servers.RebuildOpts{ |
| 290 | Name: tools.RandomString("ACPTTEST", 16), |
| 291 | AdminPass: tools.MakeNewPassword(server.AdminPass), |
| 292 | ImageID: choices.ImageID, |
| 293 | } |
| 294 | |
| 295 | rebuilt, err := servers.Rebuild(client, server.ID, rebuildOpts).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 296 | if err != nil { |
| 297 | t.Fatal(err) |
| 298 | } |
| 299 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 300 | if rebuilt.ID != server.ID { |
| 301 | t.Errorf("Expected rebuilt server ID of [%s]; got [%s]", server.ID, rebuilt.ID) |
| 302 | } |
| 303 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 304 | if err = WaitForComputeStatus(client, rebuilt, "REBUILD"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 305 | t.Fatal(err) |
| 306 | } |
| 307 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 308 | if err = WaitForComputeStatus(client, rebuilt, "ACTIVE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 309 | t.Fatal(err) |
| 310 | } |
| 311 | } |
| 312 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 313 | func TestServersActionResizeConfirm(t *testing.T) { |
| 314 | t.Parallel() |
| 315 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 316 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 317 | if err != nil { |
| 318 | t.Fatalf("Unable to create a compute client: %v", err) |
| 319 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 320 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 321 | server, err := CreateServer(t, client) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 322 | if err != nil { |
| 323 | t.Fatal(err) |
| 324 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 325 | defer DeleteServer(t, client, server) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 326 | |
| 327 | t.Logf("Attempting to resize server %s", server.ID) |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 328 | ResizeServer(t, client, server) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 329 | |
| 330 | t.Logf("Attempting to confirm resize for server %s", server.ID) |
| 331 | if res := servers.ConfirmResize(client, server.ID); res.Err != nil { |
| 332 | t.Fatal(res.Err) |
| 333 | } |
| 334 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 335 | if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 336 | t.Fatal(err) |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | func TestServersActionResizeRevert(t *testing.T) { |
| 341 | t.Parallel() |
| 342 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 343 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 344 | if err != nil { |
| 345 | t.Fatalf("Unable to create a compute client: %v", err) |
| 346 | } |
| 347 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 348 | server, err := CreateServer(t, client) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 349 | if err != nil { |
| 350 | t.Fatal(err) |
| 351 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 352 | defer DeleteServer(t, client, server) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 353 | |
| 354 | t.Logf("Attempting to resize server %s", server.ID) |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 355 | ResizeServer(t, client, server) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 356 | |
| 357 | t.Logf("Attempting to revert resize for server %s", server.ID) |
| 358 | if res := servers.RevertResize(client, server.ID); res.Err != nil { |
| 359 | t.Fatal(res.Err) |
| 360 | } |
| 361 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 362 | if err = WaitForComputeStatus(client, server, "ACTIVE"); err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 363 | t.Fatal(err) |
| 364 | } |
| 365 | } |