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