blob: 54719d091ecf400838da0744518bd328109ebbd8 [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"
Jon Perritt27249f42016-02-18 10:35:59 -060010 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
Jon Perritt0b09d1d2014-10-24 13:26:18 -050011)
12
Joe Topjianf1f40412016-10-13 17:42:25 -060013func TestBootFromImage(t *testing.T) {
Jon Perritt0b09d1d2014-10-24 13:26:18 -050014 if testing.Short() {
15 t.Skip("Skipping test that requires server creation in short mode.")
16 }
17
Joe Topjian1c15e3f2016-08-08 10:48:38 -060018 client, err := clients.NewComputeV2Client()
Joe Topjianaa8e5e32016-07-25 20:09:52 +000019 if err != nil {
20 t.Fatalf("Unable to create a compute client: %v", err)
21 }
22
Joe Topjian1c15e3f2016-08-08 10:48:38 -060023 choices, err := clients.AcceptanceTestChoicesFromEnv()
Jon Perritt0b09d1d2014-10-24 13:26:18 -050024 if err != nil {
25 t.Fatal(err)
26 }
27
Joe Topjianaa8e5e32016-07-25 20:09:52 +000028 blockDevices := []bootfromvolume.BlockDevice{
Jon Perritt01686cd2014-10-24 14:10:16 -050029 bootfromvolume.BlockDevice{
Joe Topjianf1f40412016-10-13 17:42:25 -060030 BootIndex: 0,
Joe Topjian50cdddf2016-09-16 10:56:09 -060031 DeleteOnTermination: true,
Joe Topjianf1f40412016-10-13 17:42:25 -060032 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
47func 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 Topjian50cdddf2016-09-16 10:56:09 -060068 VolumeSize: 2,
Jon Perritt01686cd2014-10-24 14:10:16 -050069 },
Jon Perritt0b09d1d2014-10-24 13:26:18 -050070 }
71
Joe Topjian1c15e3f2016-08-08 10:48:38 -060072 server, err := CreateBootableVolumeServer(t, client, blockDevices, choices)
Joe Topjianaa8e5e32016-07-25 20:09:52 +000073 if err != nil {
Joe Topjian50cdddf2016-09-16 10:56:09 -060074 t.Fatalf("Unable to create server: %v", err)
Jon Perritt0b09d1d2014-10-24 13:26:18 -050075 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060076 defer DeleteServer(t, client, server)
Jon Perrittcf01b932014-11-18 13:49:26 -070077
Joe Topjian1c15e3f2016-08-08 10:48:38 -060078 PrintServer(t, server)
Jon Perritt0b09d1d2014-10-24 13:26:18 -050079}
Joe Topjianecf63dd2015-12-12 20:33:50 +000080
Joe Topjianf1f40412016-10-13 17:42:25 -060081func 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 Topjian50cdddf2016-09-16 10:56:09 -0600124func TestBootFromMultiEphemeralServer(t *testing.T) {
Joe Topjianecf63dd2015-12-12 20:33:50 +0000125 if testing.Short() {
126 t.Skip("Skipping test that requires server creation in short mode.")
127 }
128
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600129 client, err := clients.NewComputeV2Client()
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000130 if err != nil {
131 t.Fatalf("Unable to create a compute client: %v", err)
132 }
133
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600134 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjianecf63dd2015-12-12 20:33:50 +0000135 if err != nil {
136 t.Fatal(err)
137 }
138
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000139 blockDevices := []bootfromvolume.BlockDevice{
Joe Topjianecf63dd2015-12-12 20:33:50 +0000140 bootfromvolume.BlockDevice{
141 BootIndex: 0,
Joe Topjianf1f40412016-10-13 17:42:25 -0600142 DestinationType: bootfromvolume.DestinationLocal,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000143 DeleteOnTermination: true,
Joe Topjianf1f40412016-10-13 17:42:25 -0600144 SourceType: bootfromvolume.SourceImage,
145 UUID: choices.ImageID,
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000146 VolumeSize: 5,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000147 },
148 bootfromvolume.BlockDevice{
149 BootIndex: -1,
Joe Topjianf1f40412016-10-13 17:42:25 -0600150 DestinationType: bootfromvolume.DestinationLocal,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000151 DeleteOnTermination: true,
152 GuestFormat: "ext4",
Joe Topjianf1f40412016-10-13 17:42:25 -0600153 SourceType: bootfromvolume.SourceBlank,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000154 VolumeSize: 1,
155 },
156 bootfromvolume.BlockDevice{
157 BootIndex: -1,
Joe Topjianf1f40412016-10-13 17:42:25 -0600158 DestinationType: bootfromvolume.DestinationLocal,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000159 DeleteOnTermination: true,
160 GuestFormat: "ext4",
Joe Topjianf1f40412016-10-13 17:42:25 -0600161 SourceType: bootfromvolume.SourceBlank,
Joe Topjianecf63dd2015-12-12 20:33:50 +0000162 VolumeSize: 1,
163 },
164 }
165
Joe Topjian50cdddf2016-09-16 10:56:09 -0600166 server, err := CreateMultiEphemeralServer(t, client, blockDevices, choices)
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000167 if err != nil {
168 t.Fatalf("Unable to create server: %v", err)
169 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600170 defer DeleteServer(t, client, server)
Joe Topjianaa8e5e32016-07-25 20:09:52 +0000171
Joe Topjian1c15e3f2016-08-08 10:48:38 -0600172 PrintServer(t, server)
Joe Topjianecf63dd2015-12-12 20:33:50 +0000173}
Joe Topjianf1f40412016-10-13 17:42:25 -0600174
175func 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
216func 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}