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