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 ( |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 6 | "testing" |
| 7 | |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud" |
| 9 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 11 | th "github.com/gophercloud/gophercloud/testhelper" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 12 | ) |
| 13 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 14 | func TestServersList(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 15 | client, err := newClient() |
| 16 | if err != nil { |
| 17 | t.Fatalf("Unable to create a compute client: %v", err) |
| 18 | } |
| 19 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 20 | allPages, err := servers.List(client, servers.ListOpts{}).AllPages() |
| 21 | if err != nil { |
| 22 | t.Fatalf("Unable to retrieve servers: %v", err) |
| 23 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 24 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 25 | allServers, err := servers.ExtractServers(allPages) |
| 26 | if err != nil { |
| 27 | t.Fatalf("Unable to extract servers: %v", err) |
| 28 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 29 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 30 | for _, server := range allServers { |
| 31 | printServer(t, &server) |
| 32 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 33 | } |
| 34 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 35 | func TestServersCreateDestroy(t *testing.T) { |
| 36 | client, err := newClient() |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 37 | if err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 38 | t.Fatalf("Unable to create a compute client: %v", err) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 39 | } |
| 40 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 41 | choices, err := ComputeChoicesFromEnv() |
| 42 | if err != nil { |
| 43 | t.Fatal(err) |
| 44 | } |
| 45 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 46 | server, err := createServer(t, client, choices) |
| 47 | if err != nil { |
| 48 | t.Fatalf("Unable to create server: %v", err) |
| 49 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 50 | |
| 51 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 52 | t.Fatalf("Unable to wait for server: %v", err) |
| 53 | } |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [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 | } |
| 60 | printServer(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 | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 92 | func TestServersUpdate(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 93 | client, err := newClient() |
| 94 | if err != nil { |
| 95 | t.Fatalf("Unable to create a compute client: %v", err) |
| 96 | } |
| 97 | |
| 98 | choices, err := ComputeChoicesFromEnv() |
| 99 | if err != nil { |
| 100 | t.Fatal(err) |
| 101 | } |
| 102 | |
| 103 | server, err := createServer(t, client, choices) |
| 104 | if err != nil { |
| 105 | t.Fatal(err) |
| 106 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 107 | |
| 108 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 109 | t.Fatal(err) |
| 110 | } |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 111 | defer deleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 112 | |
| 113 | alternateName := tools.RandomString("ACPTTEST", 16) |
| 114 | for alternateName == server.Name { |
| 115 | alternateName = tools.RandomString("ACPTTEST", 16) |
| 116 | } |
| 117 | |
| 118 | t.Logf("Attempting to rename the server to %s.", alternateName) |
| 119 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 120 | updateOpts := servers.UpdateOpts{ |
| 121 | Name: alternateName, |
| 122 | } |
| 123 | |
| 124 | updated, err := servers.Update(client, server.ID, updateOpts).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 125 | if err != nil { |
| 126 | t.Fatalf("Unable to rename server: %v", err) |
| 127 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 128 | |
| 129 | if updated.ID != server.ID { |
| 130 | t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID) |
| 131 | } |
| 132 | |
| 133 | err = tools.WaitFor(func() (bool, error) { |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 134 | latest, err := servers.Get(client, updated.ID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 135 | if err != nil { |
| 136 | return false, err |
| 137 | } |
| 138 | |
| 139 | return latest.Name == alternateName, nil |
| 140 | }) |
| 141 | } |
| 142 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 143 | func TestServersMetadata(t *testing.T) { |
| 144 | t.Parallel() |
| 145 | |
| 146 | choices, err := ComputeChoicesFromEnv() |
| 147 | if err != nil { |
| 148 | t.Fatal(err) |
| 149 | } |
| 150 | |
| 151 | client, err := newClient() |
| 152 | if err != nil { |
| 153 | t.Fatalf("Unable to create a compute client: %v", err) |
| 154 | } |
| 155 | |
| 156 | server, err := createServer(t, client, choices) |
| 157 | if err != nil { |
| 158 | t.Fatal(err) |
| 159 | } |
| 160 | |
| 161 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 162 | t.Fatal(err) |
| 163 | } |
| 164 | defer deleteServer(t, client, server) |
| 165 | |
| 166 | metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{ |
| 167 | "foo": "bar", |
| 168 | "this": "that", |
| 169 | }).Extract() |
| 170 | if err != nil { |
| 171 | t.Fatalf("Unable to update metadata: %v", err) |
| 172 | } |
| 173 | t.Logf("UpdateMetadata result: %+v\n", metadata) |
| 174 | |
| 175 | err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr() |
| 176 | if err != nil { |
| 177 | t.Fatalf("Unable to delete metadatum: %v", err) |
| 178 | } |
| 179 | |
| 180 | metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{ |
| 181 | "foo": "baz", |
| 182 | }).Extract() |
| 183 | if err != nil { |
| 184 | t.Fatalf("Unable to create metadatum: %v", err) |
| 185 | } |
| 186 | t.Logf("CreateMetadatum result: %+v\n", metadata) |
| 187 | |
| 188 | metadata, err = servers.Metadatum(client, server.ID, "foo").Extract() |
| 189 | if err != nil { |
| 190 | t.Fatalf("Unable to get metadatum: %v", err) |
| 191 | } |
| 192 | t.Logf("Metadatum result: %+v\n", metadata) |
| 193 | th.AssertEquals(t, "baz", metadata["foo"]) |
| 194 | |
| 195 | metadata, err = servers.Metadata(client, server.ID).Extract() |
| 196 | if err != nil { |
| 197 | t.Fatalf("Unable to get metadata: %v", err) |
| 198 | } |
| 199 | t.Logf("Metadata result: %+v\n", metadata) |
| 200 | |
| 201 | metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract() |
| 202 | if err != nil { |
| 203 | t.Fatalf("Unable to reset metadata: %v", err) |
| 204 | } |
| 205 | t.Logf("ResetMetadata result: %+v\n", metadata) |
| 206 | th.AssertDeepEquals(t, map[string]string{}, metadata) |
| 207 | } |
| 208 | |
| 209 | func TestServersActionChangeAdminPassword(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 210 | t.Parallel() |
| 211 | |
| 212 | client, err := newClient() |
| 213 | if err != nil { |
| 214 | t.Fatalf("Unable to create a compute client: %v", err) |
| 215 | } |
| 216 | |
| 217 | choices, err := ComputeChoicesFromEnv() |
| 218 | if err != nil { |
| 219 | t.Fatal(err) |
| 220 | } |
| 221 | |
| 222 | server, err := createServer(t, client, choices) |
| 223 | if err != nil { |
| 224 | t.Fatal(err) |
| 225 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 226 | |
| 227 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 228 | t.Fatal(err) |
| 229 | } |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 230 | defer deleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 231 | |
| 232 | randomPassword := tools.MakeNewPassword(server.AdminPass) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 233 | res := servers.ChangeAdminPassword(client, server.ID, randomPassword) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 234 | if res.Err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 235 | t.Fatal(res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | if err = waitForStatus(client, server, "PASSWORD"); err != nil { |
| 239 | t.Fatal(err) |
| 240 | } |
| 241 | |
| 242 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 243 | t.Fatal(err) |
| 244 | } |
| 245 | } |
| 246 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 247 | func TestServersActionReboot(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 248 | t.Parallel() |
| 249 | |
| 250 | client, err := newClient() |
| 251 | if err != nil { |
| 252 | t.Fatalf("Unable to create a compute client: %v", err) |
| 253 | } |
| 254 | |
| 255 | choices, err := ComputeChoicesFromEnv() |
| 256 | if err != nil { |
| 257 | t.Fatal(err) |
| 258 | } |
| 259 | |
| 260 | server, err := createServer(t, client, choices) |
| 261 | if err != nil { |
| 262 | t.Fatal(err) |
| 263 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 264 | |
| 265 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 266 | t.Fatal(err) |
| 267 | } |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 268 | defer deleteServer(t, client, server) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 269 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 270 | rebootOpts := &servers.RebootOpts{ |
| 271 | Type: servers.SoftReboot, |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | t.Logf("Attempting reboot of server %s", server.ID) |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 275 | res := servers.Reboot(client, server.ID, rebootOpts) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 276 | if res.Err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 277 | t.Fatalf("Unable to reboot server: %v", res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | if err = waitForStatus(client, server, "REBOOT"); err != nil { |
| 281 | t.Fatal(err) |
| 282 | } |
| 283 | |
| 284 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 285 | t.Fatal(err) |
| 286 | } |
| 287 | } |
| 288 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 289 | func TestServersActionRebuild(t *testing.T) { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 290 | t.Parallel() |
| 291 | |
| 292 | client, err := newClient() |
| 293 | if err != nil { |
| 294 | t.Fatalf("Unable to create a compute client: %v", err) |
| 295 | } |
| 296 | |
| 297 | choices, err := ComputeChoicesFromEnv() |
| 298 | if err != nil { |
| 299 | t.Fatal(err) |
| 300 | } |
| 301 | |
| 302 | server, err := createServer(t, client, choices) |
| 303 | if err != nil { |
| 304 | t.Fatal(err) |
| 305 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 306 | |
| 307 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 308 | t.Fatal(err) |
| 309 | } |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [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 | |
| 329 | if err = waitForStatus(client, rebuilt, "REBUILD"); err != nil { |
| 330 | t.Fatal(err) |
| 331 | } |
| 332 | |
| 333 | if err = waitForStatus(client, rebuilt, "ACTIVE"); err != nil { |
| 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 | |
| 341 | choices, err := ComputeChoicesFromEnv() |
| 342 | if err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 343 | t.Fatal(err) |
| 344 | } |
| 345 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 346 | client, err := newClient() |
| 347 | if err != nil { |
| 348 | t.Fatalf("Unable to create a compute client: %v", err) |
| 349 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 350 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 351 | server, err := createServer(t, client, choices) |
| 352 | if err != nil { |
| 353 | t.Fatal(err) |
| 354 | } |
| 355 | |
| 356 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 357 | t.Fatal(err) |
| 358 | } |
| 359 | defer deleteServer(t, client, server) |
| 360 | |
| 361 | t.Logf("Attempting to resize server %s", server.ID) |
| 362 | resizeServer(t, client, server, choices) |
| 363 | |
| 364 | t.Logf("Attempting to confirm resize for server %s", server.ID) |
| 365 | if res := servers.ConfirmResize(client, server.ID); res.Err != nil { |
| 366 | t.Fatal(res.Err) |
| 367 | } |
| 368 | |
| 369 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 370 | t.Fatal(err) |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | func TestServersActionResizeRevert(t *testing.T) { |
| 375 | t.Parallel() |
| 376 | |
| 377 | choices, err := ComputeChoicesFromEnv() |
| 378 | if err != nil { |
| 379 | t.Fatal(err) |
| 380 | } |
| 381 | |
| 382 | client, err := newClient() |
| 383 | if err != nil { |
| 384 | t.Fatalf("Unable to create a compute client: %v", err) |
| 385 | } |
| 386 | |
| 387 | server, err := createServer(t, client, choices) |
| 388 | if err != nil { |
| 389 | t.Fatal(err) |
| 390 | } |
| 391 | |
| 392 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 393 | t.Fatal(err) |
| 394 | } |
| 395 | defer deleteServer(t, client, server) |
| 396 | |
| 397 | t.Logf("Attempting to resize server %s", server.ID) |
| 398 | resizeServer(t, client, server, choices) |
| 399 | |
| 400 | t.Logf("Attempting to revert resize for server %s", server.ID) |
| 401 | if res := servers.RevertResize(client, server.ID); res.Err != nil { |
| 402 | t.Fatal(res.Err) |
| 403 | } |
| 404 | |
| 405 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 406 | t.Fatal(err) |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices) (*servers.Server, error) { |
| 411 | if testing.Short() { |
| 412 | t.Skip("Skipping test that requires server creation in short mode.") |
| 413 | } |
| 414 | |
| 415 | networkID, err := getNetworkIDFromTenantNetworks(t, client, choices.NetworkName) |
| 416 | if err != nil { |
| 417 | t.Fatalf("Failed to obtain network ID: %v", err) |
| 418 | } |
| 419 | |
| 420 | name := tools.RandomString("ACPTTEST", 16) |
| 421 | t.Logf("Attempting to create server: %s", name) |
| 422 | |
| 423 | pwd := tools.MakeNewPassword("") |
| 424 | |
| 425 | server, err := servers.Create(client, servers.CreateOpts{ |
| 426 | Name: name, |
| 427 | FlavorRef: choices.FlavorID, |
| 428 | ImageRef: choices.ImageID, |
| 429 | AdminPass: pwd, |
| 430 | Networks: []servers.Network{ |
| 431 | servers.Network{UUID: networkID}, |
| 432 | }, |
| 433 | Personality: servers.Personality{ |
| 434 | &servers.File{ |
| 435 | Path: "/etc/test", |
| 436 | Contents: []byte("hello world"), |
| 437 | }, |
| 438 | }, |
| 439 | }).Extract() |
| 440 | if err != nil { |
| 441 | t.Fatalf("Unable to create server: %v", err) |
| 442 | } |
| 443 | |
| 444 | th.AssertEquals(t, pwd, server.AdminPass) |
| 445 | |
| 446 | return server, err |
| 447 | } |
| 448 | |
| 449 | func resizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server, choices *ComputeChoices) { |
Ash Wilson | 14c3741 | 2014-10-24 14:45:27 -0400 | [diff] [blame] | 450 | opts := &servers.ResizeOpts{ |
| 451 | FlavorRef: choices.FlavorIDResize, |
| 452 | } |
| 453 | if res := servers.Resize(client, server.ID, opts); res.Err != nil { |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 454 | t.Fatal(res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 457 | if err := waitForStatus(client, server, "VERIFY_RESIZE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 458 | t.Fatal(err) |
| 459 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 460 | } |
| 461 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 462 | func deleteServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server) { |
| 463 | err := servers.Delete(client, server.ID).ExtractErr() |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 464 | if err != nil { |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 465 | t.Fatalf("Unable to delete server %s: %s", server.ID, err) |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 466 | } |
| 467 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 468 | t.Logf("Deleted server: %s", server.ID) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 469 | } |
| 470 | |
Joe Topjian | 34368bd | 2016-07-24 06:00:07 +0000 | [diff] [blame] | 471 | func printServer(t *testing.T, server *servers.Server) { |
| 472 | t.Logf("ID: %s", server.ID) |
| 473 | t.Logf("TenantID: %s", server.TenantID) |
| 474 | t.Logf("UserID: %s", server.UserID) |
| 475 | t.Logf("Name: %s", server.Name) |
| 476 | t.Logf("Updated: %s", server.Updated) |
| 477 | t.Logf("Created: %s", server.Created) |
| 478 | t.Logf("HostID: %s", server.HostID) |
| 479 | t.Logf("Status: %s", server.Status) |
| 480 | t.Logf("Progress: %d", server.Progress) |
| 481 | t.Logf("AccessIPv4: %s", server.AccessIPv4) |
| 482 | t.Logf("AccessIPv6: %s", server.AccessIPv6) |
| 483 | t.Logf("Image: %s", server.Image) |
| 484 | t.Logf("Flavor: %s", server.Flavor) |
| 485 | t.Logf("Addresses: %#v", server.Addresses) |
| 486 | t.Logf("Metadata: %#v", server.Metadata) |
| 487 | t.Logf("Links: %#v", server.Links) |
| 488 | t.Logf("KeyName: %s", server.KeyName) |
| 489 | t.Logf("AdminPass: %s", server.AdminPass) |
| 490 | t.Logf("SecurityGroups: %#v", server.SecurityGroups) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 491 | } |