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