blob: 2ba8888bf26b2b370698e2ed575470d0a2575071 [file] [log] [blame]
Joe Topjianaa8e5e32016-07-25 20:09:52 +00001// +build acceptance compute bootfromvolume
Jon Perritt0b09d1d2014-10-24 13:26:18 -05002
3package v2
4
5import (
6 "testing"
7
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Joe Topjianf1f40412016-10-13 17:42:25 -06009 blockstorage "github.com/gophercloud/gophercloud/acceptance/openstack/blockstorage/v2"
Joe Topjian66a046c2017-01-19 22:07:26 -070010 "github.com/gophercloud/gophercloud/acceptance/tools"
Jon Perritt27249f42016-02-18 10:35:59 -060011 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
Jon Perritt0b09d1d2014-10-24 13:26:18 -050012)
13
Joe Topjianf1f40412016-10-13 17:42:25 -060014func TestBootFromImage(t *testing.T) {
Jon Perritt0b09d1d2014-10-24 13:26:18 -050015 if testing.Short() {
16 t.Skip("Skipping test that requires server creation in short mode.")
17 }
18
Joe Topjian1c15e3f2016-08-08 10:48:38 -060019 client, err := clients.NewComputeV2Client()
Joe Topjianaa8e5e32016-07-25 20:09:52 +000020 if err != nil {
21 t.Fatalf("Unable to create a compute client: %v", err)
22 }
23
Joe Topjian1c15e3f2016-08-08 10:48:38 -060024 choices, err := clients.AcceptanceTestChoicesFromEnv()
Jon Perritt0b09d1d2014-10-24 13:26:18 -050025 if err != nil {
26 t.Fatal(err)
27 }
28
Joe Topjianaa8e5e32016-07-25 20:09:52 +000029 blockDevices := []bootfromvolume.BlockDevice{
Jon Perritt01686cd2014-10-24 14:10:16 -050030 bootfromvolume.BlockDevice{
Joe Topjianf1f40412016-10-13 17:42:25 -060031 BootIndex: 0,
Joe Topjian50cdddf2016-09-16 10:56:09 -060032 DeleteOnTermination: true,
Joe Topjianf1f40412016-10-13 17:42:25 -060033 DestinationType: bootfromvolume.DestinationLocal,
34 SourceType: bootfromvolume.SourceImage,
35 UUID: choices.ImageID,
36 },
37 }
38
Joe Topjian66a046c2017-01-19 22:07:26 -070039 server, err := CreateBootableVolumeServer(t, client, blockDevices)
Joe Topjianf1f40412016-10-13 17:42:25 -060040 if err != nil {
41 t.Fatalf("Unable to create server: %v", err)
42 }
43 defer DeleteServer(t, client, server)
44
Joe Topjian66a046c2017-01-19 22:07:26 -070045 tools.PrintResource(t, server)
Joe Topjianf1f40412016-10-13 17:42:25 -060046}
47
48func 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 Topjian50cdddf2016-09-16 10:56:09 -060069 VolumeSize: 2,
Jon Perritt01686cd2014-10-24 14:10:16 -050070 },
Jon Perritt0b09d1d2014-10-24 13:26:18 -050071 }
72
Joe Topjian66a046c2017-01-19 22:07:26 -070073 server, err := CreateBootableVolumeServer(t, client, blockDevices)
Joe Topjianaa8e5e32016-07-25 20:09:52 +000074 if err != nil {
Joe Topjian50cdddf2016-09-16 10:56:09 -060075 t.Fatalf("Unable to create server: %v", err)
Jon Perritt0b09d1d2014-10-24 13:26:18 -050076 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060077 defer DeleteServer(t, client, server)
Jon Perrittcf01b932014-11-18 13:49:26 -070078
Joe Topjian66a046c2017-01-19 22:07:26 -070079 tools.PrintResource(t, server)
Jon Perritt0b09d1d2014-10-24 13:26:18 -050080}
Joe Topjianecf63dd2015-12-12 20:33:50 +000081
Joe Topjianf1f40412016-10-13 17:42:25 -060082func 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 Topjian66a046c2017-01-19 22:07:26 -070097 volume, err := blockstorage.CreateVolumeFromImage(t, blockStorageClient)
Joe Topjianf1f40412016-10-13 17:42:25 -060098 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 Topjian66a046c2017-01-19 22:07:26 -0700111 server, err := CreateBootableVolumeServer(t, computeClient, blockDevices)
Joe Topjianf1f40412016-10-13 17:42:25 -0600112 if err != nil {
113 t.Fatalf("Unable to create server: %v", err)
114 }
115 defer DeleteServer(t, computeClient, server)
116
Joe Topjian66a046c2017-01-19 22:07:26 -0700117 tools.PrintResource(t, server)
Joe Topjianf1f40412016-10-13 17:42:25 -0600118}
119
Joe Topjian50cdddf2016-09-16 10:56:09 -0600120func TestBootFromMultiEphemeralServer(t *testing.T) {
Joe Topjianecf63dd2015-12-12 20:33:50 +0000121 if testing.Short() {
122 t.Skip("Skipping test that requires server creation in short mode.")
123 }
124
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600125 client, err := clients.NewComputeV2Client()
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000126 if err != nil {
127 t.Fatalf("Unable to create a compute client: %v", err)
128 }
129
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600130 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjianecf63dd2015-12-12 20:33:50 +0000131 if err != nil {
132 t.Fatal(err)
133 }
134
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000135 blockDevices := []bootfromvolume.BlockDevice{
Joe Topjianecf63dd2015-12-12 20:33:50 +0000136 bootfromvolume.BlockDevice{
137 BootIndex: 0,
Joe Topjianf1f40412016-10-13 17:42:25 -0600138 DestinationType: bootfromvolume.DestinationLocal,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000139 DeleteOnTermination: true,
Joe Topjianf1f40412016-10-13 17:42:25 -0600140 SourceType: bootfromvolume.SourceImage,
141 UUID: choices.ImageID,
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000142 VolumeSize: 5,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000143 },
144 bootfromvolume.BlockDevice{
145 BootIndex: -1,
Joe Topjianf1f40412016-10-13 17:42:25 -0600146 DestinationType: bootfromvolume.DestinationLocal,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000147 DeleteOnTermination: true,
148 GuestFormat: "ext4",
Joe Topjianf1f40412016-10-13 17:42:25 -0600149 SourceType: bootfromvolume.SourceBlank,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000150 VolumeSize: 1,
151 },
152 bootfromvolume.BlockDevice{
153 BootIndex: -1,
Joe Topjianf1f40412016-10-13 17:42:25 -0600154 DestinationType: bootfromvolume.DestinationLocal,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000155 DeleteOnTermination: true,
156 GuestFormat: "ext4",
Joe Topjianf1f40412016-10-13 17:42:25 -0600157 SourceType: bootfromvolume.SourceBlank,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000158 VolumeSize: 1,
159 },
160 }
161
Joe Topjian66a046c2017-01-19 22:07:26 -0700162 server, err := CreateMultiEphemeralServer(t, client, blockDevices)
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000163 if err != nil {
164 t.Fatalf("Unable to create server: %v", err)
165 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600166 defer DeleteServer(t, client, server)
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000167
Joe Topjian66a046c2017-01-19 22:07:26 -0700168 tools.PrintResource(t, server)
Joe Topjianecf63dd2015-12-12 20:33:50 +0000169}
Joe Topjianf1f40412016-10-13 17:42:25 -0600170
171func 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 Topjian66a046c2017-01-19 22:07:26 -0700203 server, err := CreateBootableVolumeServer(t, client, blockDevices)
Joe Topjianf1f40412016-10-13 17:42:25 -0600204 if err != nil {
205 t.Fatalf("Unable to create server: %v", err)
206 }
207 defer DeleteServer(t, client, server)
208
Joe Topjian66a046c2017-01-19 22:07:26 -0700209 tools.PrintResource(t, server)
Joe Topjianf1f40412016-10-13 17:42:25 -0600210}
211
212func 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 Topjian66a046c2017-01-19 22:07:26 -0700254 server, err := CreateBootableVolumeServer(t, computeClient, blockDevices)
Joe Topjianf1f40412016-10-13 17:42:25 -0600255 if err != nil {
256 t.Fatalf("Unable to create server: %v", err)
257 }
258 defer DeleteServer(t, computeClient, server)
259
Joe Topjian66a046c2017-01-19 22:07:26 -0700260 tools.PrintResource(t, server)
Joe Topjianf1f40412016-10-13 17:42:25 -0600261}