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