Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 1 | // +build acceptance compute bootfromvolume |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 9 | blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2" |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 11 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume" |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 12 | ) |
| 13 | |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 14 | func TestBootFromImage(t *testing.T) { |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 15 | if testing.Short() { |
| 16 | t.Skip("Skipping test that requires server creation in short mode.") |
| 17 | } |
| 18 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 19 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 20 | if err != nil { |
| 21 | t.Fatalf("Unable to create a compute client: %v", err) |
| 22 | } |
| 23 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 24 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 29 | blockDevices := []bootfromvolume.BlockDevice{ |
Jon Perritt | 01686cd | 2014-10-24 14:10:16 -0500 | [diff] [blame] | 30 | bootfromvolume.BlockDevice{ |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 31 | BootIndex: 0, |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 32 | DeleteOnTermination: true, |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 33 | DestinationType: bootfromvolume.DestinationLocal, |
| 34 | SourceType: bootfromvolume.SourceImage, |
| 35 | UUID: choices.ImageID, |
| 36 | }, |
| 37 | } |
| 38 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 39 | server, err := CreateBootableVolumeServer(t, client, blockDevices) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 40 | if err != nil { |
| 41 | t.Fatalf("Unable to create server: %v", err) |
| 42 | } |
| 43 | defer DeleteServer(t, client, server) |
| 44 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 45 | tools.PrintResource(t, server) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | func TestBootFromNewVolume(t *testing.T) { |
| 49 | if testing.Short() { |
| 50 | t.Skip("Skipping test that requires server creation in short mode.") |
| 51 | } |
| 52 | |
| 53 | client, err := clients.NewComputeV2Client() |
| 54 | if err != nil { |
| 55 | t.Fatalf("Unable to create a compute client: %v", err) |
| 56 | } |
| 57 | |
| 58 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
| 59 | if err != nil { |
| 60 | t.Fatal(err) |
| 61 | } |
| 62 | |
| 63 | blockDevices := []bootfromvolume.BlockDevice{ |
| 64 | bootfromvolume.BlockDevice{ |
| 65 | DeleteOnTermination: true, |
| 66 | DestinationType: bootfromvolume.DestinationVolume, |
| 67 | SourceType: bootfromvolume.SourceImage, |
| 68 | UUID: choices.ImageID, |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 69 | VolumeSize: 2, |
Jon Perritt | 01686cd | 2014-10-24 14:10:16 -0500 | [diff] [blame] | 70 | }, |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 71 | } |
| 72 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 73 | server, err := CreateBootableVolumeServer(t, client, blockDevices) |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 74 | if err != nil { |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 75 | t.Fatalf("Unable to create server: %v", err) |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 76 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 77 | defer DeleteServer(t, client, server) |
Jon Perritt | cf01b93 | 2014-11-18 13:49:26 -0700 | [diff] [blame] | 78 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 79 | tools.PrintResource(t, server) |
Jon Perritt | 0b09d1d | 2014-10-24 13:26:18 -0500 | [diff] [blame] | 80 | } |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 81 | |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 82 | func TestBootFromExistingVolume(t *testing.T) { |
| 83 | if testing.Short() { |
| 84 | t.Skip("Skipping test that requires server creation in short mode.") |
| 85 | } |
| 86 | |
| 87 | computeClient, err := clients.NewComputeV2Client() |
| 88 | if err != nil { |
| 89 | t.Fatalf("Unable to create a compute client: %v", err) |
| 90 | } |
| 91 | |
| 92 | blockStorageClient, err := clients.NewBlockStorageV2Client() |
| 93 | if err != nil { |
| 94 | t.Fatalf("Unable to create a block storage client: %v", err) |
| 95 | } |
| 96 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 97 | volume, err := blockstorage.CreateVolumeFromImage(t, blockStorageClient) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 98 | if err != nil { |
| 99 | t.Fatal(err) |
| 100 | } |
| 101 | |
| 102 | blockDevices := []bootfromvolume.BlockDevice{ |
| 103 | bootfromvolume.BlockDevice{ |
| 104 | DeleteOnTermination: true, |
| 105 | DestinationType: bootfromvolume.DestinationVolume, |
| 106 | SourceType: bootfromvolume.SourceVolume, |
| 107 | UUID: volume.ID, |
| 108 | }, |
| 109 | } |
| 110 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 111 | server, err := CreateBootableVolumeServer(t, computeClient, blockDevices) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 112 | if err != nil { |
| 113 | t.Fatalf("Unable to create server: %v", err) |
| 114 | } |
| 115 | defer DeleteServer(t, computeClient, server) |
| 116 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 117 | tools.PrintResource(t, server) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 118 | } |
| 119 | |
Joe Topjian | 50cdddf | 2016-09-16 10:56:09 -0600 | [diff] [blame] | 120 | func TestBootFromMultiEphemeralServer(t *testing.T) { |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 121 | if testing.Short() { |
| 122 | t.Skip("Skipping test that requires server creation in short mode.") |
| 123 | } |
| 124 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 125 | client, err := clients.NewComputeV2Client() |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 126 | if err != nil { |
| 127 | t.Fatalf("Unable to create a compute client: %v", err) |
| 128 | } |
| 129 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 130 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 131 | if err != nil { |
| 132 | t.Fatal(err) |
| 133 | } |
| 134 | |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 135 | blockDevices := []bootfromvolume.BlockDevice{ |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 136 | bootfromvolume.BlockDevice{ |
| 137 | BootIndex: 0, |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 138 | DestinationType: bootfromvolume.DestinationLocal, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 139 | DeleteOnTermination: true, |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 140 | SourceType: bootfromvolume.SourceImage, |
| 141 | UUID: choices.ImageID, |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 142 | VolumeSize: 5, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 143 | }, |
| 144 | bootfromvolume.BlockDevice{ |
| 145 | BootIndex: -1, |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 146 | DestinationType: bootfromvolume.DestinationLocal, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 147 | DeleteOnTermination: true, |
| 148 | GuestFormat: "ext4", |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 149 | SourceType: bootfromvolume.SourceBlank, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 150 | VolumeSize: 1, |
| 151 | }, |
| 152 | bootfromvolume.BlockDevice{ |
| 153 | BootIndex: -1, |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 154 | DestinationType: bootfromvolume.DestinationLocal, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 155 | DeleteOnTermination: true, |
| 156 | GuestFormat: "ext4", |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 157 | SourceType: bootfromvolume.SourceBlank, |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 158 | VolumeSize: 1, |
| 159 | }, |
| 160 | } |
| 161 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 162 | server, err := CreateMultiEphemeralServer(t, client, blockDevices) |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 163 | if err != nil { |
| 164 | t.Fatalf("Unable to create server: %v", err) |
| 165 | } |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 166 | defer DeleteServer(t, client, server) |
Joe Topjian | aa8e5e3 | 2016-07-25 20:09:52 +0000 | [diff] [blame] | 167 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 168 | tools.PrintResource(t, server) |
Joe Topjian | ecf63dd | 2015-12-12 20:33:50 +0000 | [diff] [blame] | 169 | } |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 170 | |
| 171 | func TestAttachNewVolume(t *testing.T) { |
| 172 | if testing.Short() { |
| 173 | t.Skip("Skipping test that requires server creation in short mode.") |
| 174 | } |
| 175 | |
| 176 | client, err := clients.NewComputeV2Client() |
| 177 | if err != nil { |
| 178 | t.Fatalf("Unable to create a compute client: %v", err) |
| 179 | } |
| 180 | |
| 181 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
| 182 | if err != nil { |
| 183 | t.Fatal(err) |
| 184 | } |
| 185 | |
| 186 | blockDevices := []bootfromvolume.BlockDevice{ |
| 187 | bootfromvolume.BlockDevice{ |
| 188 | BootIndex: 0, |
| 189 | DeleteOnTermination: true, |
| 190 | DestinationType: bootfromvolume.DestinationLocal, |
| 191 | SourceType: bootfromvolume.SourceImage, |
| 192 | UUID: choices.ImageID, |
| 193 | }, |
| 194 | bootfromvolume.BlockDevice{ |
| 195 | BootIndex: 1, |
| 196 | DeleteOnTermination: true, |
| 197 | DestinationType: bootfromvolume.DestinationVolume, |
| 198 | SourceType: bootfromvolume.SourceBlank, |
| 199 | VolumeSize: 2, |
| 200 | }, |
| 201 | } |
| 202 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 203 | server, err := CreateBootableVolumeServer(t, client, blockDevices) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 204 | if err != nil { |
| 205 | t.Fatalf("Unable to create server: %v", err) |
| 206 | } |
| 207 | defer DeleteServer(t, client, server) |
| 208 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 209 | tools.PrintResource(t, server) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | func TestAttachExistingVolume(t *testing.T) { |
| 213 | if testing.Short() { |
| 214 | t.Skip("Skipping test that requires server creation in short mode.") |
| 215 | } |
| 216 | |
| 217 | computeClient, err := clients.NewComputeV2Client() |
| 218 | if err != nil { |
| 219 | t.Fatalf("Unable to create a compute client: %v", err) |
| 220 | } |
| 221 | |
| 222 | blockStorageClient, err := clients.NewBlockStorageV2Client() |
| 223 | if err != nil { |
| 224 | t.Fatalf("Unable to create a block storage client: %v", err) |
| 225 | } |
| 226 | |
| 227 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
| 228 | if err != nil { |
| 229 | t.Fatal(err) |
| 230 | } |
| 231 | |
| 232 | volume, err := blockstorage.CreateVolume(t, blockStorageClient) |
| 233 | if err != nil { |
| 234 | t.Fatal(err) |
| 235 | } |
| 236 | |
| 237 | blockDevices := []bootfromvolume.BlockDevice{ |
| 238 | bootfromvolume.BlockDevice{ |
| 239 | BootIndex: 0, |
| 240 | DeleteOnTermination: true, |
| 241 | DestinationType: bootfromvolume.DestinationLocal, |
| 242 | SourceType: bootfromvolume.SourceImage, |
| 243 | UUID: choices.ImageID, |
| 244 | }, |
| 245 | bootfromvolume.BlockDevice{ |
| 246 | BootIndex: 1, |
| 247 | DeleteOnTermination: true, |
| 248 | DestinationType: bootfromvolume.DestinationVolume, |
| 249 | SourceType: bootfromvolume.SourceVolume, |
| 250 | UUID: volume.ID, |
| 251 | }, |
| 252 | } |
| 253 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 254 | server, err := CreateBootableVolumeServer(t, computeClient, blockDevices) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 255 | if err != nil { |
| 256 | t.Fatalf("Unable to create server: %v", err) |
| 257 | } |
| 258 | defer DeleteServer(t, computeClient, server) |
| 259 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame] | 260 | tools.PrintResource(t, server) |
Joe Topjian | f1f4041 | 2016-10-13 17:42:25 -0600 | [diff] [blame] | 261 | } |