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 ( |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 6 | "os" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 7 | "testing" |
| 8 | |
| 9 | "github.com/rackspace/gophercloud" |
| 10 | "github.com/rackspace/gophercloud/acceptance/tools" |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 11 | "github.com/rackspace/gophercloud/openstack" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 12 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 13 | "github.com/rackspace/gophercloud/openstack/networking/v2/networks" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 14 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | f3b2e14 | 2014-11-04 16:00:19 -0600 | [diff] [blame] | 15 | th "github.com/rackspace/gophercloud/testhelper" |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 16 | ) |
| 17 | |
| 18 | func TestListServers(t *testing.T) { |
| 19 | client, err := newClient() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to create a compute client: %v", err) |
| 22 | } |
| 23 | |
| 24 | t.Logf("ID\tRegion\tName\tStatus\tIPv4\tIPv6") |
| 25 | |
Jamie Hannaford | 1e7841b | 2014-10-16 12:45:49 +0200 | [diff] [blame] | 26 | pager := servers.List(client, servers.ListOpts{}) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 27 | count, pages := 0, 0 |
| 28 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 29 | pages++ |
| 30 | t.Logf("---") |
| 31 | |
| 32 | servers, err := servers.ExtractServers(page) |
| 33 | if err != nil { |
| 34 | return false, err |
| 35 | } |
| 36 | |
| 37 | for _, s := range servers { |
| 38 | t.Logf("%s\t%s\t%s\t%s\t%s\t\n", s.ID, s.Name, s.Status, s.AccessIPv4, s.AccessIPv6) |
| 39 | count++ |
| 40 | } |
| 41 | |
| 42 | return true, nil |
| 43 | }) |
| 44 | |
Ash Wilson | 9a9f5bc | 2014-10-24 14:55:40 -0400 | [diff] [blame] | 45 | t.Logf("--------\n%d servers listed on %d pages.\n", count, pages) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 46 | } |
| 47 | |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 48 | func networkingClient() (*gophercloud.ServiceClient, error) { |
Ash Wilson | 1904fce | 2014-10-22 15:50:48 -0400 | [diff] [blame] | 49 | opts, err := openstack.AuthOptionsFromEnv() |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 50 | if err != nil { |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | provider, err := openstack.AuthenticatedClient(opts) |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | |
| 59 | return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{ |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 60 | Region: os.Getenv("OS_REGION_NAME"), |
| 61 | }) |
| 62 | } |
| 63 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 64 | func createServer(t *testing.T, client *gophercloud.ServiceClient, choices *ComputeChoices) (*servers.Server, error) { |
Ash Wilson | 14c3741 | 2014-10-24 14:45:27 -0400 | [diff] [blame] | 65 | if testing.Short() { |
Jon Perritt | 8135c6f | 2014-10-23 12:29:14 -0500 | [diff] [blame] | 66 | t.Skip("Skipping test that requires server creation in short mode.") |
| 67 | } |
| 68 | |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 69 | var network networks.Network |
| 70 | |
| 71 | networkingClient, err := networkingClient() |
| 72 | if err != nil { |
| 73 | t.Fatalf("Unable to create a networking client: %v", err) |
| 74 | } |
| 75 | |
Joe Topjian | b4395c7 | 2015-02-24 02:47:23 +0000 | [diff] [blame] | 76 | pager := networks.List(networkingClient, networks.ListOpts{ |
| 77 | Name: choices.NetworkName, |
| 78 | Limit: 1, |
| 79 | }) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 80 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 81 | networks, err := networks.ExtractNetworks(page) |
| 82 | if err != nil { |
| 83 | t.Errorf("Failed to extract networks: %v", err) |
| 84 | return false, err |
| 85 | } |
| 86 | |
| 87 | if len(networks) == 0 { |
Jon Perritt | 3525c64 | 2014-10-21 17:12:06 -0500 | [diff] [blame] | 88 | t.Fatalf("No networks to attach to server") |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 89 | return false, err |
| 90 | } |
| 91 | |
| 92 | network = networks[0] |
| 93 | |
| 94 | return false, nil |
| 95 | }) |
| 96 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 97 | name := tools.RandomString("ACPTTEST", 16) |
| 98 | t.Logf("Attempting to create server: %s\n", name) |
| 99 | |
Jon Perritt | f3b2e14 | 2014-11-04 16:00:19 -0600 | [diff] [blame] | 100 | pwd := tools.MakeNewPassword("") |
| 101 | |
Ash Wilson | 488e730 | 2014-10-02 11:04:25 -0400 | [diff] [blame] | 102 | server, err := servers.Create(client, servers.CreateOpts{ |
Ash Wilson | e845851 | 2014-09-29 08:50:09 -0400 | [diff] [blame] | 103 | Name: name, |
| 104 | FlavorRef: choices.FlavorID, |
| 105 | ImageRef: choices.ImageID, |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 106 | Networks: []servers.Network{ |
| 107 | servers.Network{UUID: network.ID}, |
| 108 | }, |
Jon Perritt | f3b2e14 | 2014-11-04 16:00:19 -0600 | [diff] [blame] | 109 | AdminPass: pwd, |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 110 | }).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 111 | if err != nil { |
| 112 | t.Fatalf("Unable to create server: %v", err) |
| 113 | } |
| 114 | |
Jon Perritt | f3b2e14 | 2014-11-04 16:00:19 -0600 | [diff] [blame] | 115 | th.AssertEquals(t, pwd, server.AdminPass) |
| 116 | |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 117 | return server, err |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | func TestCreateDestroyServer(t *testing.T) { |
| 121 | choices, err := ComputeChoicesFromEnv() |
| 122 | if err != nil { |
| 123 | t.Fatal(err) |
| 124 | } |
| 125 | |
| 126 | client, err := newClient() |
| 127 | if err != nil { |
| 128 | t.Fatalf("Unable to create a compute client: %v", err) |
| 129 | } |
| 130 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 131 | server, err := createServer(t, client, choices) |
| 132 | if err != nil { |
| 133 | t.Fatalf("Unable to create server: %v", err) |
| 134 | } |
| 135 | defer func() { |
| 136 | servers.Delete(client, server.ID) |
| 137 | t.Logf("Server deleted.") |
| 138 | }() |
| 139 | |
| 140 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 141 | t.Fatalf("Unable to wait for server: %v", err) |
| 142 | } |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 143 | |
| 144 | pager := servers.ListAddresses(client, server.ID) |
| 145 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 146 | networks, err := servers.ExtractAddresses(page) |
| 147 | if err != nil { |
| 148 | return false, err |
| 149 | } |
| 150 | |
| 151 | for n, a := range networks { |
| 152 | t.Logf("%s: %+v\n", n, a) |
| 153 | } |
| 154 | return true, nil |
| 155 | }) |
| 156 | |
Joe Topjian | b4395c7 | 2015-02-24 02:47:23 +0000 | [diff] [blame] | 157 | pager = servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 158 | pager.EachPage(func(page pagination.Page) (bool, error) { |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 159 | addresses, err := servers.ExtractNetworkAddresses(page) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 160 | if err != nil { |
| 161 | return false, err |
| 162 | } |
| 163 | |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 164 | for _, a := range addresses { |
| 165 | t.Logf("%+v\n", a) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 166 | } |
| 167 | return true, nil |
| 168 | }) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | func TestUpdateServer(t *testing.T) { |
| 172 | client, err := newClient() |
| 173 | if err != nil { |
| 174 | t.Fatalf("Unable to create a compute client: %v", err) |
| 175 | } |
| 176 | |
| 177 | choices, err := ComputeChoicesFromEnv() |
| 178 | if err != nil { |
| 179 | t.Fatal(err) |
| 180 | } |
| 181 | |
| 182 | server, err := createServer(t, client, choices) |
| 183 | if err != nil { |
| 184 | t.Fatal(err) |
| 185 | } |
| 186 | defer servers.Delete(client, server.ID) |
| 187 | |
| 188 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 189 | t.Fatal(err) |
| 190 | } |
| 191 | |
| 192 | alternateName := tools.RandomString("ACPTTEST", 16) |
| 193 | for alternateName == server.Name { |
| 194 | alternateName = tools.RandomString("ACPTTEST", 16) |
| 195 | } |
| 196 | |
| 197 | t.Logf("Attempting to rename the server to %s.", alternateName) |
| 198 | |
Ash Wilson | dcbc8fb | 2014-09-29 09:05:44 -0400 | [diff] [blame] | 199 | updated, err := servers.Update(client, server.ID, servers.UpdateOpts{Name: alternateName}).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 200 | if err != nil { |
| 201 | t.Fatalf("Unable to rename server: %v", err) |
| 202 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 203 | |
| 204 | if updated.ID != server.ID { |
| 205 | t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID) |
| 206 | } |
| 207 | |
| 208 | err = tools.WaitFor(func() (bool, error) { |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 209 | latest, err := servers.Get(client, updated.ID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 210 | if err != nil { |
| 211 | return false, err |
| 212 | } |
| 213 | |
| 214 | return latest.Name == alternateName, nil |
| 215 | }) |
| 216 | } |
| 217 | |
| 218 | func TestActionChangeAdminPassword(t *testing.T) { |
| 219 | t.Parallel() |
| 220 | |
| 221 | client, err := newClient() |
| 222 | if err != nil { |
| 223 | t.Fatalf("Unable to create a compute client: %v", err) |
| 224 | } |
| 225 | |
| 226 | choices, err := ComputeChoicesFromEnv() |
| 227 | if err != nil { |
| 228 | t.Fatal(err) |
| 229 | } |
| 230 | |
| 231 | server, err := createServer(t, client, choices) |
| 232 | if err != nil { |
| 233 | t.Fatal(err) |
| 234 | } |
| 235 | defer servers.Delete(client, server.ID) |
| 236 | |
| 237 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 238 | t.Fatal(err) |
| 239 | } |
| 240 | |
| 241 | randomPassword := tools.MakeNewPassword(server.AdminPass) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 242 | res := servers.ChangeAdminPassword(client, server.ID, randomPassword) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 243 | if res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 244 | t.Fatal(err) |
| 245 | } |
| 246 | |
| 247 | if err = waitForStatus(client, server, "PASSWORD"); err != nil { |
| 248 | t.Fatal(err) |
| 249 | } |
| 250 | |
| 251 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 252 | t.Fatal(err) |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func TestActionReboot(t *testing.T) { |
| 257 | t.Parallel() |
| 258 | |
| 259 | client, err := newClient() |
| 260 | if err != nil { |
| 261 | t.Fatalf("Unable to create a compute client: %v", err) |
| 262 | } |
| 263 | |
| 264 | choices, err := ComputeChoicesFromEnv() |
| 265 | if err != nil { |
| 266 | t.Fatal(err) |
| 267 | } |
| 268 | |
| 269 | server, err := createServer(t, client, choices) |
| 270 | if err != nil { |
| 271 | t.Fatal(err) |
| 272 | } |
| 273 | defer servers.Delete(client, server.ID) |
| 274 | |
| 275 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 276 | t.Fatal(err) |
| 277 | } |
| 278 | |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 279 | res := servers.Reboot(client, server.ID, "aldhjflaskhjf") |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 280 | if res.Err == nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 281 | t.Fatal("Expected the SDK to provide an ArgumentError here") |
| 282 | } |
| 283 | |
| 284 | t.Logf("Attempting reboot of server %s", server.ID) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 285 | res = servers.Reboot(client, server.ID, servers.OSReboot) |
| 286 | if res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 287 | t.Fatalf("Unable to reboot server: %v", err) |
| 288 | } |
| 289 | |
| 290 | if err = waitForStatus(client, server, "REBOOT"); err != nil { |
| 291 | t.Fatal(err) |
| 292 | } |
| 293 | |
| 294 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 295 | t.Fatal(err) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | func TestActionRebuild(t *testing.T) { |
| 300 | t.Parallel() |
| 301 | |
| 302 | client, err := newClient() |
| 303 | if err != nil { |
| 304 | t.Fatalf("Unable to create a compute client: %v", err) |
| 305 | } |
| 306 | |
| 307 | choices, err := ComputeChoicesFromEnv() |
| 308 | if err != nil { |
| 309 | t.Fatal(err) |
| 310 | } |
| 311 | |
| 312 | server, err := createServer(t, client, choices) |
| 313 | if err != nil { |
| 314 | t.Fatal(err) |
| 315 | } |
| 316 | defer servers.Delete(client, server.ID) |
| 317 | |
| 318 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 319 | t.Fatal(err) |
| 320 | } |
| 321 | |
| 322 | t.Logf("Attempting to rebuild server %s", server.ID) |
| 323 | |
Jamie Hannaford | 5bfa2e8 | 2014-10-16 16:32:42 +0200 | [diff] [blame] | 324 | rebuildOpts := servers.RebuildOpts{ |
| 325 | Name: tools.RandomString("ACPTTEST", 16), |
| 326 | AdminPass: tools.MakeNewPassword(server.AdminPass), |
| 327 | ImageID: choices.ImageID, |
| 328 | } |
| 329 | |
| 330 | rebuilt, err := servers.Rebuild(client, server.ID, rebuildOpts).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 331 | if err != nil { |
| 332 | t.Fatal(err) |
| 333 | } |
| 334 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 335 | if rebuilt.ID != server.ID { |
| 336 | t.Errorf("Expected rebuilt server ID of [%s]; got [%s]", server.ID, rebuilt.ID) |
| 337 | } |
| 338 | |
| 339 | if err = waitForStatus(client, rebuilt, "REBUILD"); err != nil { |
| 340 | t.Fatal(err) |
| 341 | } |
| 342 | |
| 343 | if err = waitForStatus(client, rebuilt, "ACTIVE"); err != nil { |
| 344 | t.Fatal(err) |
| 345 | } |
| 346 | } |
| 347 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 348 | func resizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server, choices *ComputeChoices) { |
| 349 | if err := waitForStatus(client, server, "ACTIVE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 350 | t.Fatal(err) |
| 351 | } |
| 352 | |
| 353 | t.Logf("Attempting to resize server [%s]", server.ID) |
| 354 | |
Ash Wilson | 14c3741 | 2014-10-24 14:45:27 -0400 | [diff] [blame] | 355 | opts := &servers.ResizeOpts{ |
| 356 | FlavorRef: choices.FlavorIDResize, |
| 357 | } |
| 358 | if res := servers.Resize(client, server.ID, opts); res.Err != nil { |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 359 | t.Fatal(res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 360 | } |
| 361 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 362 | if err := waitForStatus(client, server, "VERIFY_RESIZE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 363 | t.Fatal(err) |
| 364 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | func TestActionResizeConfirm(t *testing.T) { |
| 368 | t.Parallel() |
| 369 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 370 | choices, err := ComputeChoicesFromEnv() |
| 371 | if err != nil { |
| 372 | t.Fatal(err) |
| 373 | } |
| 374 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 375 | client, err := newClient() |
| 376 | if err != nil { |
| 377 | t.Fatalf("Unable to create a compute client: %v", err) |
| 378 | } |
| 379 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 380 | server, err := createServer(t, client, choices) |
| 381 | if err != nil { |
| 382 | t.Fatal(err) |
| 383 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 384 | defer servers.Delete(client, server.ID) |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 385 | resizeServer(t, client, server, choices) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 386 | |
| 387 | t.Logf("Attempting to confirm resize for server %s", server.ID) |
| 388 | |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 389 | if res := servers.ConfirmResize(client, server.ID); res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 390 | t.Fatal(err) |
| 391 | } |
| 392 | |
| 393 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 394 | t.Fatal(err) |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | func TestActionResizeRevert(t *testing.T) { |
| 399 | t.Parallel() |
| 400 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 401 | choices, err := ComputeChoicesFromEnv() |
| 402 | if err != nil { |
| 403 | t.Fatal(err) |
| 404 | } |
| 405 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 406 | client, err := newClient() |
| 407 | if err != nil { |
| 408 | t.Fatalf("Unable to create a compute client: %v", err) |
| 409 | } |
| 410 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 411 | server, err := createServer(t, client, choices) |
| 412 | if err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 413 | t.Fatal(err) |
| 414 | } |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 415 | defer servers.Delete(client, server.ID) |
| 416 | resizeServer(t, client, server, choices) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 417 | |
| 418 | t.Logf("Attempting to revert resize for server %s", server.ID) |
| 419 | |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 420 | if res := servers.RevertResize(client, server.ID); res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 421 | t.Fatal(err) |
| 422 | } |
| 423 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 424 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 425 | t.Fatal(err) |
| 426 | } |
| 427 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 428 | |
| 429 | func TestServerMetadata(t *testing.T) { |
| 430 | t.Parallel() |
| 431 | |
| 432 | choices, err := ComputeChoicesFromEnv() |
Jon Perritt | d29c4af | 2014-11-20 08:47:56 -0700 | [diff] [blame] | 433 | th.AssertNoErr(t, err) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 434 | |
| 435 | client, err := newClient() |
| 436 | if err != nil { |
| 437 | t.Fatalf("Unable to create a compute client: %v", err) |
| 438 | } |
| 439 | |
| 440 | server, err := createServer(t, client, choices) |
| 441 | if err != nil { |
| 442 | t.Fatal(err) |
| 443 | } |
| 444 | defer servers.Delete(client, server.ID) |
| 445 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 446 | t.Fatal(err) |
| 447 | } |
| 448 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 449 | metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{ |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 450 | "foo": "bar", |
| 451 | "this": "that", |
| 452 | }).Extract() |
| 453 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 454 | t.Logf("UpdateMetadata result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 455 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 456 | err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 457 | th.AssertNoErr(t, err) |
| 458 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 459 | metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{ |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 460 | "foo": "baz", |
| 461 | }).Extract() |
| 462 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 463 | t.Logf("CreateMetadatum result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 464 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 465 | metadata, err = servers.Metadatum(client, server.ID, "foo").Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 466 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 467 | t.Logf("Metadatum result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 468 | th.AssertEquals(t, "baz", metadata["foo"]) |
| 469 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 470 | metadata, err = servers.Metadata(client, server.ID).Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 471 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 472 | t.Logf("Metadata result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 473 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 474 | metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 475 | th.AssertNoErr(t, err) |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 476 | t.Logf("ResetMetadata result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 477 | th.AssertDeepEquals(t, map[string]string{}, metadata) |
| 478 | } |