fog-brightbox 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe Fog::Brightbox::Compute::ImageSelector do
4
+ subject { Fog::Brightbox::Compute::ImageSelector }
5
+
6
+ describe "#latest_ubuntu" do
7
+ it do
8
+ image_list = [
9
+ {"id"=>"img-kppxh", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-kppxh", "name"=>"ubuntu-xenial-16.04-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:16.04:amd64/20211001/disk1.img, Release: release", "source"=>"tmp54tt71pg", "arch"=>"x86_64", "created_at"=>"2021-10-02T06:57:09.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>394, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
10
+ {"id"=>"img-bugr2", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-bugr2", "name"=>"ubuntu-xenial-16.04-i386-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:16.04:i386/20211001/disk1.img, Release: release", "source"=>"tmplj717rjf", "arch"=>"i686", "created_at"=>"2021-10-02T06:58:18.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>385, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
11
+ {"id"=>"img-6vfpp", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-6vfpp", "name"=>"ubuntu-xenial-daily-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:16.04:amd64/20211001/disk1.img, Release: daily", "source"=>"tmp3aj5trto", "arch"=>"x86_64", "created_at"=>"2021-10-02T06:58:57.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>394, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
12
+ {"id"=>"img-x08p6", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-x08p6", "name"=>"ubuntu-bionic-18.04-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:18.04:amd64/20220523/disk1.img, Release: release", "source"=>"tmpcyevpow5", "arch"=>"x86_64", "created_at"=>"2022-05-24T06:57:15.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>480, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
13
+ {"id"=>"img-jrbnn", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-jrbnn", "name"=>"ubuntu-bionic-18.04-i386-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:18.04:i386/20220523/disk1.img, Release: release", "source"=>"tmpw502837r", "arch"=>"i686", "created_at"=>"2022-05-24T06:57:44.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>450, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
14
+ {"id"=>"img-1cbbg", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-1cbbg", "name"=>"ubuntu-focal-daily-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:20.04:amd64/20220530/disk1.img, Release: daily", "source"=>"tmpa2iezlb7", "arch"=>"x86_64", "created_at"=>"2022-06-01T07:06:08.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>685, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
15
+ {"id"=>"img-cjc8m", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-cjc8m", "name"=>"ubuntu-focal-20.04-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:20.04:amd64/20220530/disk1.img, Release: release", "source"=>"tmppadp2ka9", "arch"=>"x86_64", "created_at"=>"2022-06-02T06:57:21.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>685, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
16
+ {"id"=>"img-yes2q", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-yes2q", "name"=>"ubuntu-bionic-daily-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:18.04:amd64/20220530/disk1.img, Release: daily", "source"=>"tmp7b0ty_cz", "arch"=>"x86_64", "created_at"=>"2022-06-02T06:59:06.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>480, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
17
+ {"id"=>"img-44xv2", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-44xv2", "name"=>"ubuntu-bionic-daily-i386-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:18.04:i386/20220530/disk1.img, Release: daily", "source"=>"tmpcsk_ejc9", "arch"=>"i686", "created_at"=>"2022-06-02T06:59:33.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>450, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
18
+ {"id"=>"img-axy3r", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-axy3r", "name"=>"ubuntu-impish-daily-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:21.10:amd64/20220604/disk1.img, Release: daily", "source"=>"tmpq4xcgkhd", "arch"=>"x86_64", "created_at"=>"2022-06-05T06:57:52.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>699, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
19
+ {"id"=>"img-5sf6z", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-5sf6z", "name"=>"ubuntu-jammy-daily-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:22.04:amd64/20220604/disk1.img, Release: daily", "source"=>"tmp6lwsv5cb", "arch"=>"x86_64", "created_at"=>"2022-06-05T06:58:33.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>709, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
20
+ {"id"=>"img-vuptu", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-vuptu", "name"=>"ubuntu-kinetic-daily-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:daily:download/com.ubuntu.cloud.daily:server:22.10:amd64/20220605/disk1.img, Release: daily", "source"=>"tmpj_k3e6u1", "arch"=>"x86_64", "created_at"=>"2022-06-06T06:57:58.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>752, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
21
+ {"id"=>"img-tqaxd", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-tqaxd", "name"=>"ubuntu-impish-21.10-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:21.10:amd64/20220604/disk1.img, Release: release", "source"=>"tmp_xphnxch", "arch"=>"x86_64", "created_at"=>"2022-06-07T06:57:33.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>699, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
22
+ {"id"=>"img-7d1e3", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-7d1e3", "name"=>"ubuntu-jammy-22.04-amd64-server", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:server:22.04:amd64/20220604/disk1.img, Release: release", "source"=>"tmp11_42l44", "arch"=>"x86_64", "created_at"=>"2022-06-07T06:58:16.000Z", "owner"=>"acc-kg71m", "official"=>true, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>709, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
23
+ {"id"=>"img-kg2oa", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-kg2oa", "name"=>"ubuntu-bionic-18.04-amd64-minimal", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:18.04:amd64/20220607/disk1.img, Release: minimal release", "source"=>"tmpd7d5lvyb", "arch"=>"x86_64", "created_at"=>"2022-06-08T07:01:21.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>258, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
24
+ {"id"=>"img-sdofr", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-sdofr", "name"=>"ubuntu-focal-20.04-amd64-minimal", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:20.04:amd64/20220607/disk1.img, Release: minimal release", "source"=>"tmpl6wvuqu9", "arch"=>"x86_64", "created_at"=>"2022-06-08T07:01:49.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>330, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
25
+ {"id"=>"img-7wwg7", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-7wwg7", "name"=>"ubuntu-impish-21.10-amd64-minimal", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:21.10:amd64/20220607/disk1.img, Release: minimal release", "source"=>"tmpfkqj3pjo", "arch"=>"x86_64", "created_at"=>"2022-06-08T07:02:13.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>328, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil},
26
+ {"id"=>"img-ielp9", "resource_type"=>"image", "url"=>"https://api.gb1s.brightbox.com/1.0/images/img-ielp9", "name"=>"ubuntu-jammy-22.04-amd64-minimal", "username"=>"ubuntu", "status"=>"available", "locked"=>false, "description"=>"ID: com.ubuntu.cloud:released:download/com.ubuntu.cloud:minimal:22.04:amd64/20220607/disk1.img, Release: minimal release", "source"=>"tmpd0ctsx1v", "arch"=>"x86_64", "created_at"=>"2022-06-08T07:02:38.000Z", "owner"=>"acc-yw7i0", "official"=>false, "public"=>true, "compatibility_mode"=>false, "source_type"=>"upload", "source_trigger"=>"manual", "disk_size"=>353, "virtual_size"=>2252, "min_ram"=>nil, "ancestor"=>nil}
27
+ ]
28
+
29
+ selector = subject.new(image_list)
30
+
31
+ assert_equal "img-7d1e3", selector.latest_ubuntu
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,348 @@
1
+ require "spec_helper"
2
+ require "fog/brightbox/models/compute/volume"
3
+
4
+ describe Fog::Brightbox::Compute::Volume do
5
+ include ModelSetup
6
+ include SupportsResourceLocking
7
+
8
+ subject { service.volumes.new }
9
+
10
+ describe "when state is 'creating'" do
11
+ it do
12
+ subject.state = "creating"
13
+
14
+ assert subject.creating?
15
+ refute subject.attached?
16
+ refute subject.detached?
17
+ refute subject.deleting?
18
+ refute subject.deleted?
19
+ refute subject.failed?
20
+
21
+ refute subject.ready?
22
+ refute subject.finished?
23
+ end
24
+ end
25
+
26
+ describe "when state is 'attached'" do
27
+ it do
28
+ subject.state = "attached"
29
+
30
+ refute subject.creating?
31
+ assert subject.attached?
32
+ refute subject.detached?
33
+ refute subject.deleting?
34
+ refute subject.deleted?
35
+ refute subject.failed?
36
+
37
+ assert subject.ready?
38
+ refute subject.finished?
39
+ end
40
+ end
41
+
42
+ describe "when state is 'detached'" do
43
+ it do
44
+ subject.state = "detached"
45
+
46
+ refute subject.creating?
47
+ refute subject.attached?
48
+ assert subject.detached?
49
+ refute subject.deleting?
50
+ refute subject.deleted?
51
+ refute subject.failed?
52
+
53
+ assert subject.ready?
54
+ refute subject.finished?
55
+ end
56
+ end
57
+
58
+ describe "when state is 'deleting'" do
59
+ it do
60
+ subject.state = "deleting"
61
+
62
+ refute subject.creating?
63
+ refute subject.attached?
64
+ refute subject.detached?
65
+ assert subject.deleting?
66
+ refute subject.deleted?
67
+ refute subject.failed?
68
+
69
+ refute subject.ready?
70
+ refute subject.finished?
71
+ end
72
+ end
73
+
74
+ describe "when state is 'deleted'" do
75
+ it do
76
+ subject.state = "deleted"
77
+
78
+ refute subject.creating?
79
+ refute subject.attached?
80
+ refute subject.detached?
81
+ refute subject.deleting?
82
+ assert subject.deleted?
83
+ refute subject.failed?
84
+
85
+ refute subject.ready?
86
+ assert subject.finished?
87
+ end
88
+ end
89
+
90
+ describe "when state is 'failed'" do
91
+ it do
92
+ subject.state = "failed"
93
+
94
+ refute subject.creating?
95
+ refute subject.attached?
96
+ refute subject.detached?
97
+ refute subject.deleting?
98
+ refute subject.deleted?
99
+ assert subject.failed?
100
+
101
+ refute subject.ready?
102
+ assert subject.finished?
103
+ end
104
+ end
105
+
106
+ describe "#attach" do
107
+ it do
108
+ subject.id = "vol-12345"
109
+ assert subject.persisted?
110
+
111
+ server = service.servers.new
112
+ server.id = "srv-12345"
113
+
114
+ stub_request(:post, "http://localhost/1.0/volumes/vol-12345/attach").
115
+ with(:query => hash_including(:account_id),
116
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
117
+ "Content-Type" => "application/json" },
118
+ :body => hash_including(:server => "srv-12345")).
119
+ to_return(:status => 202,
120
+ :body => %q({"id":"vol-12345","status":"attached"}),
121
+ :headers => {})
122
+
123
+ subject.attach(server)
124
+
125
+ assert subject.attached?
126
+ end
127
+ end
128
+
129
+ describe "#collection_name" do
130
+ it "responds 'volumes'" do
131
+ assert_equal "volumes", subject.collection_name
132
+ end
133
+ end
134
+
135
+ describe "#copy" do
136
+ it do
137
+ subject.id = "vol-12345"
138
+ subject.state = "attached"
139
+ subject.delete_with_server = false
140
+
141
+ refute subject.delete_with_server
142
+ assert subject.persisted?
143
+
144
+ stub_request(:post, "http://localhost/1.0/volumes/vol-12345/copy").
145
+ with(:query => hash_including(:account_id),
146
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
147
+ "Content-Type" => "application/json" },
148
+ :body => hash_including(:delete_with_server => true)).
149
+ to_return(:status => 202,
150
+ :body => %q({"id":"vol-abcde","delete_with_server":true,"name":"Copy of vol-12345 (Impish Image)","status":"detached"}),
151
+ :headers => {})
152
+
153
+ copy = subject.copy(delete_with_server: true)
154
+
155
+ assert copy.persisted?
156
+ assert_equal "vol-abcde", copy.id
157
+ assert copy.delete_with_server
158
+ assert copy.detached?
159
+ end
160
+ end
161
+
162
+ describe "#detach" do
163
+ it do
164
+ subject.id = "vol-12345"
165
+ subject.state = "attached"
166
+
167
+ assert subject.persisted?
168
+
169
+ stub_request(:post, "http://localhost/1.0/volumes/vol-12345/detach").
170
+ with(:query => hash_including(:account_id),
171
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
172
+ "Content-Type" => "application/json" }).
173
+ to_return(:status => 202,
174
+ :body => %q({"id":"vol-12345","status":"detached"}),
175
+ :headers => {})
176
+
177
+ subject.detach
178
+
179
+ assert subject.detached?
180
+ end
181
+ end
182
+
183
+ describe "#destroy" do
184
+ it do
185
+ subject.id = "vol-12345"
186
+ assert subject.persisted?
187
+
188
+ stub_request(:delete, "http://localhost/1.0/volumes/vol-12345").
189
+ with(:query => hash_including(:account_id),
190
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
191
+ "Content-Type" => "application/json" }).
192
+ to_return(:status => 202,
193
+ :body => %q({"id":"vol-12345","status":"deleting"}),
194
+ :headers => {})
195
+
196
+ subject.destroy
197
+ assert_equal "deleting", subject.state
198
+ end
199
+ end
200
+
201
+ describe "#ready?" do
202
+ describe "when state is 'creating'" do
203
+ it do
204
+ subject.state = "creating"
205
+
206
+ refute subject.ready?
207
+ end
208
+ end
209
+
210
+ describe "when state is 'attached'" do
211
+ it do
212
+ subject.state = "attached"
213
+
214
+ assert subject.ready?
215
+ end
216
+ end
217
+
218
+ describe "when state is 'detached'" do
219
+ it do
220
+ subject.state = "detached"
221
+
222
+ assert subject.ready?
223
+ end
224
+ end
225
+ end
226
+
227
+ describe "#resize" do
228
+ it do
229
+ subject.id = "vol-12345"
230
+ subject.size = 40_000
231
+
232
+ assert subject.persisted?
233
+
234
+ stub_request(:post, "http://localhost/1.0/volumes/vol-12345/resize").
235
+ with(:query => hash_including(:account_id),
236
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
237
+ "Content-Type" => "application/json" },
238
+ :body => hash_including(:from => 40_000, :to => 50_000)).
239
+ to_return(:status => 202,
240
+ :body => %q({"id":"vol-12345","size": 50000}),
241
+ :headers => {})
242
+
243
+ subject.resize(to: 50_000)
244
+
245
+ assert 50_000, subject.size
246
+ end
247
+ end
248
+
249
+ describe "#resource_name" do
250
+ it "responds 'volume'" do
251
+ assert_equal "volume", subject.resource_name
252
+ end
253
+ end
254
+
255
+ describe "#save" do
256
+ describe "when creating" do
257
+ describe "with mutually exclusive arguments" do
258
+ it "raises Fog::Errors::Error" do
259
+ options = {
260
+ filesystem_type: "ext4",
261
+ image_id: "img-12345"
262
+ }
263
+
264
+ @volume = Fog::Brightbox::Compute::Volume.new({ :service => service }.merge(options))
265
+
266
+ assert_raises Fog::Errors::Error do
267
+ @volume.save
268
+ end
269
+ end
270
+ end
271
+
272
+ describe "with filesytem type" do
273
+ it "sends correct JSON" do
274
+ options = {
275
+ description: "An ext4 volume",
276
+ filesystem_type: "ext4"
277
+ }
278
+
279
+ stub_request(:post, "http://localhost/1.0/volumes").
280
+ with(:query => hash_including(:account_id),
281
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
282
+ "Content-Type" => "application/json" },
283
+ :body => hash_including(:filesystem_type => "ext4")).
284
+ to_return(:status => 202,
285
+ :body => %q({"id":"vol-12345","image":{"id":"img-blank"}}),
286
+ :headers => {})
287
+
288
+ @volume = Fog::Brightbox::Compute::Volume.new({ :service => service }.merge(options))
289
+ assert @volume.save
290
+ assert_equal @volume.filesystem_type, "ext4"
291
+ assert_equal @volume.image_id, "img-blank"
292
+ assert_equal @volume.description, "An ext4 volume"
293
+ end
294
+ end
295
+
296
+ describe "with image" do
297
+ it "sends correct JSON" do
298
+ options = {
299
+ image_id: "img-12345",
300
+ name: "My Volume"
301
+ }
302
+
303
+ stub_request(:post, "http://localhost/1.0/volumes").
304
+ with(:query => hash_including(:account_id),
305
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
306
+ "Content-Type" => "application/json" },
307
+ :body => hash_including(:image => "img-12345")).
308
+ to_return(:status => 202,
309
+ :body => %q({"id":"vol-12345","image":{"id":"img-12345"}}),
310
+ :headers => {})
311
+
312
+
313
+ @volume = Fog::Brightbox::Compute::Volume.new({ :service => service }.merge(options))
314
+ assert @volume.save
315
+ assert_equal @volume.image_id, "img-12345"
316
+ assert_equal @volume.name, "My Volume"
317
+ end
318
+ end
319
+ end
320
+
321
+ describe "when updating" do
322
+ it do
323
+ subject.id = "vol-12345"
324
+
325
+ assert subject.persisted?
326
+
327
+ subject.delete_with_server = true
328
+ subject.description = "Updated description"
329
+ subject.name = "New name"
330
+ subject.serial = "NewSerial"
331
+
332
+ stub_request(:put, "http://localhost/1.0/volumes/vol-12345").
333
+ with(:query => hash_including(:account_id),
334
+ :headers => { "Authorization" => "Bearer FAKECACHEDTOKEN",
335
+ "Content-Type" => "application/json" },
336
+ :body => hash_including(:delete_with_server => true,
337
+ :description => "Updated description",
338
+ :name => "New name",
339
+ :serial => "NewSerial")).
340
+ to_return(:status => 202,
341
+ :body => %q({"id":"vol-12345"}),
342
+ :headers => {})
343
+
344
+ subject.save
345
+ end
346
+ end
347
+ end
348
+ end
@@ -252,6 +252,29 @@ class Brightbox
252
252
  "inviter" => Brightbox::Compute::Formats::Nested::USER
253
253
  }
254
254
 
255
+ VOLUME = {
256
+ "id" => String,
257
+ "resource_type" => String,
258
+ "url" => String,
259
+ "status" => String,
260
+ "name" => Fog::Nullable::String,
261
+ "delete_with_server" => Fog::Boolean,
262
+ "description" => Fog::Nullable::String,
263
+ "boot" => Fog::Boolean,
264
+ "encrypted" => Fog::Boolean,
265
+ "filesystem_label" => Fog::Nullable::String,
266
+ "filesystem_type" => Fog::Nullable::String,
267
+ "locked" => Fog::Boolean,
268
+ "serial" => String,
269
+ "size" => Integer,
270
+ "source" => Fog::Nullable::String,
271
+ "source_type" => String,
272
+ "storage_type" => String,
273
+ "created_at" => String,
274
+ "updated_at" => String,
275
+ "deleted_at" => Fog::Nullable::String
276
+ }
277
+
255
278
  ZONE = {
256
279
  "id" => String,
257
280
  "resource_type" => String,
@@ -482,6 +505,29 @@ class Brightbox
482
505
  "inviter" => Brightbox::Compute::Formats::Nested::USER
483
506
  }
484
507
 
508
+ VOLUME = {
509
+ "id" => String,
510
+ "resource_type" => String,
511
+ "url" => String,
512
+ "status" => String,
513
+ "name" => Fog::Nullable::String,
514
+ "delete_with_server" => Fog::Boolean,
515
+ "description" => Fog::Nullable::String,
516
+ "boot" => Fog::Boolean,
517
+ "encrypted" => Fog::Boolean,
518
+ "filesystem_label" => Fog::Nullable::String,
519
+ "filesystem_type" => Fog::Nullable::String,
520
+ "locked" => Fog::Boolean,
521
+ "serial" => String,
522
+ "size" => Integer,
523
+ "source" => Fog::Nullable::String,
524
+ "source_type" => String,
525
+ "storage_type" => String,
526
+ "created_at" => String,
527
+ "updated_at" => String,
528
+ "deleted_at" => Fog::Nullable::String
529
+ }
530
+
485
531
  ZONE = {
486
532
  "id" => String,
487
533
  "resource_type" => String,
@@ -706,6 +752,7 @@ class Brightbox
706
752
  "snapshots" => [Brightbox::Compute::Formats::Nested::IMAGE],
707
753
  "server_groups" => [Brightbox::Compute::Formats::Nested::SERVER_GROUP],
708
754
  "interfaces" => [Brightbox::Compute::Formats::Nested::INTERFACE],
755
+ "volumes" => [Brightbox::Compute::Formats::Nested::VOLUME],
709
756
  "zone" => Fog::Brightbox::Nullable::Zone,
710
757
  "licence_name" => Fog::Nullable::String,
711
758
  "username" => Fog::Nullable::String,
@@ -763,6 +810,32 @@ class Brightbox
763
810
  "inviter" => Brightbox::Compute::Formats::Nested::USER
764
811
  }
765
812
 
813
+ VOLUME = {
814
+ "id" => String,
815
+ "resource_type" => String,
816
+ "url" => String,
817
+ "status" => String,
818
+ "name" => Fog::Nullable::String,
819
+ "delete_with_server" => Fog::Boolean,
820
+ "description" => Fog::Nullable::String,
821
+ "boot" => Fog::Boolean,
822
+ "encrypted" => Fog::Boolean,
823
+ "filesystem_label" => Fog::Nullable::String,
824
+ "filesystem_type" => Fog::Nullable::String,
825
+ "locked" => Fog::Boolean,
826
+ "serial" => String,
827
+ "size" => Integer,
828
+ "source" => Fog::Nullable::String,
829
+ "source_type" => String,
830
+ "storage_type" => String,
831
+ "created_at" => String,
832
+ "updated_at" => String,
833
+ "deleted_at" => Fog::Nullable::String,
834
+ "account" => Brightbox::Compute::Formats::Nested::ACCOUNT,
835
+ "image" => Fog::Brightbox::Nullable::Image,
836
+ "server" => Fog::Brightbox::Nullable::Server
837
+ }
838
+
766
839
  ZONE = {
767
840
  "id" => String,
768
841
  "resource_type" => String,
@@ -787,6 +860,7 @@ class Brightbox
787
860
  SERVER_GROUPS = [Brightbox::Compute::Formats::Collected::SERVER_GROUP]
788
861
  SERVER_TYPES = [Brightbox::Compute::Formats::Collected::SERVER_TYPE]
789
862
  USERS = [Brightbox::Compute::Formats::Collected::USER]
863
+ VOLUMES = [Brightbox::Compute::Formats::Collected::VOLUME]
790
864
  ZONES = [Brightbox::Compute::Formats::Collected::ZONE]
791
865
  end
792
866
  end
@@ -0,0 +1,57 @@
1
+ Shindo.tests("Fog::Compute[:brightbox] | volume requests", ["brightbox"]) do
2
+ pending if Fog.mocking?
3
+ image_id = Brightbox::Compute::TestSupport.image_id
4
+
5
+ tests("success") do
6
+ create_options = { image: image_id }
7
+
8
+ tests("#create_volume(#{create_options.inspect})") do
9
+ result = Fog::Compute[:brightbox].create_volume(create_options)
10
+ @volume_id = result["id"]
11
+ data_matches_schema(Brightbox::Compute::Formats::Full::VOLUME, :allow_extra_keys => true) { result }
12
+ end
13
+
14
+ tests("#list_volumes") do
15
+ result = Fog::Compute[:brightbox].list_volumes
16
+ data_matches_schema(Brightbox::Compute::Formats::Collection::VOLUMES, :allow_extra_keys => true) { result }
17
+
18
+ test("#{@volume_id} is listed") do
19
+ result.any? do |volume|
20
+ volume["id"] == @volume_id
21
+ end
22
+ end
23
+ end
24
+
25
+ tests("#get_volume('#{@volume_id}')") do
26
+ result = Fog::Compute[:brightbox].get_volume(@volume_id)
27
+ data_matches_schema(Brightbox::Compute::Formats::Full::VOLUME, :allow_extra_keys => true) { result }
28
+ end
29
+
30
+ update_options = {
31
+ name: "New name"
32
+ }
33
+ tests("#update_volume('#{@volume_id}', ...)") do
34
+ result = Fog::Compute[:brightbox].update_volume(@volume_id, update_options)
35
+ data_matches_schema(Brightbox::Compute::Formats::Full::VOLUME, :allow_extra_keys => true) { result }
36
+
37
+ test("name has updated") { result["name"] == "New name" }
38
+ end
39
+
40
+ Fog::Compute[:brightbox].volumes.get(@volume_id).wait_for { ready? }
41
+
42
+ tests("#delete_volume('#{@volume_id}')") do
43
+ result = Fog::Compute[:brightbox].delete_volume(@volume_id)
44
+ data_matches_schema(Brightbox::Compute::Formats::Full::VOLUME, :allow_extra_keys => true) { result }
45
+ end
46
+ end
47
+
48
+ tests("failure") do
49
+ tests("create_volume without options").raises(ArgumentError) do
50
+ Fog::Compute[:brightbox].create_volume
51
+ end
52
+
53
+ tests("get_volume with invalid ID").raises(Excon::Errors::NotFound) do
54
+ Fog::Compute[:brightbox].get_volume("vol-00000")
55
+ end
56
+ end
57
+ end