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