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, |
Kevin Pike | 60c1e89 | 2015-05-05 07:35:02 -0700 | [diff] [blame] | 110 | Personality: servers.Personality{ |
| 111 | &servers.File{ |
| 112 | Path: "/etc/test", |
| 113 | Contents: []byte("hello world"), |
| 114 | }, |
| 115 | }, |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 116 | }).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 117 | if err != nil { |
| 118 | t.Fatalf("Unable to create server: %v", err) |
| 119 | } |
| 120 | |
Jon Perritt | f3b2e14 | 2014-11-04 16:00:19 -0600 | [diff] [blame] | 121 | th.AssertEquals(t, pwd, server.AdminPass) |
| 122 | |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 123 | return server, err |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | func TestCreateDestroyServer(t *testing.T) { |
| 127 | choices, err := ComputeChoicesFromEnv() |
| 128 | if err != nil { |
| 129 | t.Fatal(err) |
| 130 | } |
| 131 | |
| 132 | client, err := newClient() |
| 133 | if err != nil { |
| 134 | t.Fatalf("Unable to create a compute client: %v", err) |
| 135 | } |
| 136 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 137 | server, err := createServer(t, client, choices) |
| 138 | if err != nil { |
| 139 | t.Fatalf("Unable to create server: %v", err) |
| 140 | } |
| 141 | defer func() { |
| 142 | servers.Delete(client, server.ID) |
| 143 | t.Logf("Server deleted.") |
| 144 | }() |
| 145 | |
| 146 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 147 | t.Fatalf("Unable to wait for server: %v", err) |
| 148 | } |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 149 | |
| 150 | pager := servers.ListAddresses(client, server.ID) |
| 151 | pager.EachPage(func(page pagination.Page) (bool, error) { |
| 152 | networks, err := servers.ExtractAddresses(page) |
| 153 | if err != nil { |
| 154 | return false, err |
| 155 | } |
| 156 | |
| 157 | for n, a := range networks { |
| 158 | t.Logf("%s: %+v\n", n, a) |
| 159 | } |
| 160 | return true, nil |
| 161 | }) |
| 162 | |
Joe Topjian | b4395c7 | 2015-02-24 02:47:23 +0000 | [diff] [blame] | 163 | pager = servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 164 | pager.EachPage(func(page pagination.Page) (bool, error) { |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 165 | addresses, err := servers.ExtractNetworkAddresses(page) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 166 | if err != nil { |
| 167 | return false, err |
| 168 | } |
| 169 | |
Jon Perritt | b51ba9c | 2015-02-23 10:56:35 -0700 | [diff] [blame] | 170 | for _, a := range addresses { |
| 171 | t.Logf("%+v\n", a) |
Jon Perritt | 38cc052 | 2015-02-19 22:16:40 -0700 | [diff] [blame] | 172 | } |
| 173 | return true, nil |
| 174 | }) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | func TestUpdateServer(t *testing.T) { |
| 178 | client, err := newClient() |
| 179 | if err != nil { |
| 180 | t.Fatalf("Unable to create a compute client: %v", err) |
| 181 | } |
| 182 | |
| 183 | choices, err := ComputeChoicesFromEnv() |
| 184 | if err != nil { |
| 185 | t.Fatal(err) |
| 186 | } |
| 187 | |
| 188 | server, err := createServer(t, client, choices) |
| 189 | if err != nil { |
| 190 | t.Fatal(err) |
| 191 | } |
| 192 | defer servers.Delete(client, server.ID) |
| 193 | |
| 194 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 195 | t.Fatal(err) |
| 196 | } |
| 197 | |
| 198 | alternateName := tools.RandomString("ACPTTEST", 16) |
| 199 | for alternateName == server.Name { |
| 200 | alternateName = tools.RandomString("ACPTTEST", 16) |
| 201 | } |
| 202 | |
| 203 | t.Logf("Attempting to rename the server to %s.", alternateName) |
| 204 | |
Ash Wilson | dcbc8fb | 2014-09-29 09:05:44 -0400 | [diff] [blame] | 205 | updated, err := servers.Update(client, server.ID, servers.UpdateOpts{Name: alternateName}).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 206 | if err != nil { |
| 207 | t.Fatalf("Unable to rename server: %v", err) |
| 208 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 209 | |
| 210 | if updated.ID != server.ID { |
| 211 | t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID) |
| 212 | } |
| 213 | |
| 214 | err = tools.WaitFor(func() (bool, error) { |
Ash Wilson | 89734d0 | 2014-09-25 13:50:08 -0400 | [diff] [blame] | 215 | latest, err := servers.Get(client, updated.ID).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 216 | if err != nil { |
| 217 | return false, err |
| 218 | } |
| 219 | |
| 220 | return latest.Name == alternateName, nil |
| 221 | }) |
| 222 | } |
| 223 | |
| 224 | func TestActionChangeAdminPassword(t *testing.T) { |
| 225 | t.Parallel() |
| 226 | |
| 227 | client, err := newClient() |
| 228 | if err != nil { |
| 229 | t.Fatalf("Unable to create a compute client: %v", err) |
| 230 | } |
| 231 | |
| 232 | choices, err := ComputeChoicesFromEnv() |
| 233 | if err != nil { |
| 234 | t.Fatal(err) |
| 235 | } |
| 236 | |
| 237 | server, err := createServer(t, client, choices) |
| 238 | if err != nil { |
| 239 | t.Fatal(err) |
| 240 | } |
| 241 | defer servers.Delete(client, server.ID) |
| 242 | |
| 243 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 244 | t.Fatal(err) |
| 245 | } |
| 246 | |
| 247 | randomPassword := tools.MakeNewPassword(server.AdminPass) |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 248 | res := servers.ChangeAdminPassword(client, server.ID, randomPassword) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 249 | if res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 250 | t.Fatal(err) |
| 251 | } |
| 252 | |
| 253 | if err = waitForStatus(client, server, "PASSWORD"); err != nil { |
| 254 | t.Fatal(err) |
| 255 | } |
| 256 | |
| 257 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 258 | t.Fatal(err) |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | func TestActionReboot(t *testing.T) { |
| 263 | t.Parallel() |
| 264 | |
| 265 | client, err := newClient() |
| 266 | if err != nil { |
| 267 | t.Fatalf("Unable to create a compute client: %v", err) |
| 268 | } |
| 269 | |
| 270 | choices, err := ComputeChoicesFromEnv() |
| 271 | if err != nil { |
| 272 | t.Fatal(err) |
| 273 | } |
| 274 | |
| 275 | server, err := createServer(t, client, choices) |
| 276 | if err != nil { |
| 277 | t.Fatal(err) |
| 278 | } |
| 279 | defer servers.Delete(client, server.ID) |
| 280 | |
| 281 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 282 | t.Fatal(err) |
| 283 | } |
| 284 | |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 285 | res := servers.Reboot(client, server.ID, "aldhjflaskhjf") |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 286 | if res.Err == nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 287 | t.Fatal("Expected the SDK to provide an ArgumentError here") |
| 288 | } |
| 289 | |
| 290 | t.Logf("Attempting reboot of server %s", server.ID) |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 291 | res = servers.Reboot(client, server.ID, servers.OSReboot) |
| 292 | if res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 293 | t.Fatalf("Unable to reboot server: %v", err) |
| 294 | } |
| 295 | |
| 296 | if err = waitForStatus(client, server, "REBOOT"); err != nil { |
| 297 | t.Fatal(err) |
| 298 | } |
| 299 | |
| 300 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 301 | t.Fatal(err) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func TestActionRebuild(t *testing.T) { |
| 306 | t.Parallel() |
| 307 | |
| 308 | client, err := newClient() |
| 309 | if err != nil { |
| 310 | t.Fatalf("Unable to create a compute client: %v", err) |
| 311 | } |
| 312 | |
| 313 | choices, err := ComputeChoicesFromEnv() |
| 314 | if err != nil { |
| 315 | t.Fatal(err) |
| 316 | } |
| 317 | |
| 318 | server, err := createServer(t, client, choices) |
| 319 | if err != nil { |
| 320 | t.Fatal(err) |
| 321 | } |
| 322 | defer servers.Delete(client, server.ID) |
| 323 | |
| 324 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 325 | t.Fatal(err) |
| 326 | } |
| 327 | |
| 328 | t.Logf("Attempting to rebuild server %s", server.ID) |
| 329 | |
Jamie Hannaford | 5bfa2e8 | 2014-10-16 16:32:42 +0200 | [diff] [blame] | 330 | rebuildOpts := servers.RebuildOpts{ |
| 331 | Name: tools.RandomString("ACPTTEST", 16), |
| 332 | AdminPass: tools.MakeNewPassword(server.AdminPass), |
| 333 | ImageID: choices.ImageID, |
| 334 | } |
| 335 | |
| 336 | rebuilt, err := servers.Rebuild(client, server.ID, rebuildOpts).Extract() |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 337 | if err != nil { |
| 338 | t.Fatal(err) |
| 339 | } |
| 340 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 341 | if rebuilt.ID != server.ID { |
| 342 | t.Errorf("Expected rebuilt server ID of [%s]; got [%s]", server.ID, rebuilt.ID) |
| 343 | } |
| 344 | |
| 345 | if err = waitForStatus(client, rebuilt, "REBUILD"); err != nil { |
| 346 | t.Fatal(err) |
| 347 | } |
| 348 | |
| 349 | if err = waitForStatus(client, rebuilt, "ACTIVE"); err != nil { |
| 350 | t.Fatal(err) |
| 351 | } |
| 352 | } |
| 353 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 354 | func resizeServer(t *testing.T, client *gophercloud.ServiceClient, server *servers.Server, choices *ComputeChoices) { |
| 355 | if err := waitForStatus(client, server, "ACTIVE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 356 | t.Fatal(err) |
| 357 | } |
| 358 | |
| 359 | t.Logf("Attempting to resize server [%s]", server.ID) |
| 360 | |
Ash Wilson | 14c3741 | 2014-10-24 14:45:27 -0400 | [diff] [blame] | 361 | opts := &servers.ResizeOpts{ |
| 362 | FlavorRef: choices.FlavorIDResize, |
| 363 | } |
| 364 | if res := servers.Resize(client, server.ID, opts); res.Err != nil { |
Jon Perritt | 2a7797d | 2014-10-21 15:08:43 -0500 | [diff] [blame] | 365 | t.Fatal(res.Err) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 366 | } |
| 367 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 368 | if err := waitForStatus(client, server, "VERIFY_RESIZE"); err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 369 | t.Fatal(err) |
| 370 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | func TestActionResizeConfirm(t *testing.T) { |
| 374 | t.Parallel() |
| 375 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 376 | choices, err := ComputeChoicesFromEnv() |
| 377 | if err != nil { |
| 378 | t.Fatal(err) |
| 379 | } |
| 380 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 381 | client, err := newClient() |
| 382 | if err != nil { |
| 383 | t.Fatalf("Unable to create a compute client: %v", err) |
| 384 | } |
| 385 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 386 | server, err := createServer(t, client, choices) |
| 387 | if err != nil { |
| 388 | t.Fatal(err) |
| 389 | } |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 390 | defer servers.Delete(client, server.ID) |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 391 | resizeServer(t, client, server, choices) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 392 | |
| 393 | t.Logf("Attempting to confirm resize for server %s", server.ID) |
| 394 | |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 395 | if res := servers.ConfirmResize(client, server.ID); res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 396 | t.Fatal(err) |
| 397 | } |
| 398 | |
| 399 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 400 | t.Fatal(err) |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func TestActionResizeRevert(t *testing.T) { |
| 405 | t.Parallel() |
| 406 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 407 | choices, err := ComputeChoicesFromEnv() |
| 408 | if err != nil { |
| 409 | t.Fatal(err) |
| 410 | } |
| 411 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 412 | client, err := newClient() |
| 413 | if err != nil { |
| 414 | t.Fatalf("Unable to create a compute client: %v", err) |
| 415 | } |
| 416 | |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 417 | server, err := createServer(t, client, choices) |
| 418 | if err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 419 | t.Fatal(err) |
| 420 | } |
Ash Wilson | dc7daa8 | 2014-09-23 16:34:42 -0400 | [diff] [blame] | 421 | defer servers.Delete(client, server.ID) |
| 422 | resizeServer(t, client, server, choices) |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 423 | |
| 424 | t.Logf("Attempting to revert resize for server %s", server.ID) |
| 425 | |
Jamie Hannaford | a262174 | 2014-10-16 14:35:49 +0200 | [diff] [blame] | 426 | if res := servers.RevertResize(client, server.ID); res.Err != nil { |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 427 | t.Fatal(err) |
| 428 | } |
| 429 | |
Ash Wilson | fd56648 | 2014-09-23 15:47:35 -0400 | [diff] [blame] | 430 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 431 | t.Fatal(err) |
| 432 | } |
| 433 | } |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 434 | |
| 435 | func TestServerMetadata(t *testing.T) { |
| 436 | t.Parallel() |
| 437 | |
| 438 | choices, err := ComputeChoicesFromEnv() |
Jon Perritt | d29c4af | 2014-11-20 08:47:56 -0700 | [diff] [blame] | 439 | th.AssertNoErr(t, err) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 440 | |
| 441 | client, err := newClient() |
| 442 | if err != nil { |
| 443 | t.Fatalf("Unable to create a compute client: %v", err) |
| 444 | } |
| 445 | |
| 446 | server, err := createServer(t, client, choices) |
| 447 | if err != nil { |
| 448 | t.Fatal(err) |
| 449 | } |
| 450 | defer servers.Delete(client, server.ID) |
| 451 | if err = waitForStatus(client, server, "ACTIVE"); err != nil { |
| 452 | t.Fatal(err) |
| 453 | } |
| 454 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 455 | metadata, err := servers.UpdateMetadata(client, server.ID, servers.MetadataOpts{ |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 456 | "foo": "bar", |
| 457 | "this": "that", |
| 458 | }).Extract() |
| 459 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 460 | t.Logf("UpdateMetadata result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 461 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 462 | err = servers.DeleteMetadatum(client, server.ID, "foo").ExtractErr() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 463 | th.AssertNoErr(t, err) |
| 464 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 465 | metadata, err = servers.CreateMetadatum(client, server.ID, servers.MetadatumOpts{ |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 466 | "foo": "baz", |
| 467 | }).Extract() |
| 468 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 469 | t.Logf("CreateMetadatum result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 470 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 471 | metadata, err = servers.Metadatum(client, server.ID, "foo").Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 472 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 473 | t.Logf("Metadatum result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 474 | th.AssertEquals(t, "baz", metadata["foo"]) |
| 475 | |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 476 | metadata, err = servers.Metadata(client, server.ID).Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 477 | th.AssertNoErr(t, err) |
Jon Perritt | 78c57ce | 2014-11-20 11:07:18 -0700 | [diff] [blame] | 478 | t.Logf("Metadata result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 479 | |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 480 | metadata, err = servers.ResetMetadata(client, server.ID, servers.MetadataOpts{}).Extract() |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 481 | th.AssertNoErr(t, err) |
Jon Perritt | 789f832 | 2014-11-21 08:20:04 -0700 | [diff] [blame] | 482 | t.Logf("ResetMetadata result: %+v\n", metadata) |
Jon Perritt | cc77da6 | 2014-11-16 13:14:21 -0700 | [diff] [blame] | 483 | th.AssertDeepEquals(t, map[string]string{}, metadata) |
| 484 | } |