bosh_vcloud_cpi 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +26 -0
- data/Rakefile +50 -0
- data/lib/cloud/vcloud/cloud.rb +633 -0
- data/lib/cloud/vcloud/const.rb +27 -0
- data/lib/cloud/vcloud/util.rb +21 -0
- data/lib/cloud/vcloud/version.rb +7 -0
- data/lib/cloud/vcloud.rb +30 -0
- data/spec/assets/test-deployment-manifest.yml +183 -0
- data/spec/assets/test-director-config.yml +73 -0
- data/spec/assets/valid_stemcell.tgz +0 -0
- data/spec/spec_helper.rb +135 -0
- data/spec/unit/cloud_spec.rb +506 -0
- metadata +131 -0
@@ -0,0 +1,506 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
module VCloudCloud
|
5
|
+
module UnitTest
|
6
|
+
AGENT_ENV = %q[{"vm":{"name":"vm-8715dc0d-0270-4679-8429-6b90090bab58","id":
|
7
|
+
"vm-793"},"agent_id":"1a8ad1aa-4b28-4483-be81-9c45f1d2f071","networks":{
|
8
|
+
"default":{"ip":"10.147.130.80","netmask":"255.255.255.192","cloud_properties":{
|
9
|
+
"name":"VC-10.47.24.204-vcd-external"},"default":["dns","gateway"],"dns":[
|
10
|
+
"10.147.115.1","10.147.115.2"],"gateway":"10.147.130.126","mac":
|
11
|
+
"00:50:56:9a:44:d8"}},"disks":{"system":0,"persistent":{}},"ntp":[
|
12
|
+
"ntp01.las01.emcatmos.com"],"blobstore":{"plugin":"simple","properties":{
|
13
|
+
"endpoint":"http://10.147.130.68:25250","user":"agent","password":"Ag3Nt"}},
|
14
|
+
"mbus":"nats://bosh:b0$H@10.147.130.68:4222","env":{}}]
|
15
|
+
AGENT_ENV_WITH_PERSITENT_DISK = %q[{"vm":{"name":
|
16
|
+
"vm-8715dc0d-0270-4679-8429-6b90090bab58","id":"vm-793"},"agent_id":
|
17
|
+
"1a8ad1aa-4b28-4483-be81-9c45f1d2f071","networks":{"default":{
|
18
|
+
"ip":"10.147.130.80","netmask":"255.255.255.192","cloud_properties":{"name":
|
19
|
+
"VC-10.47.24.204-vcd-external"},"default":["dns","gateway"],"dns":[
|
20
|
+
"10.147.115.1","10.147.115.2"],"gateway":"10.147.130.126","mac":
|
21
|
+
"00:50:56:9a:44:d8"}},"disks":{"system":0,"ephemeral":1, "persistent":{
|
22
|
+
"test_disk":1}},"ntp":["ntp01.las01.emcatmos.com"],"blobstore":{"plugin":
|
23
|
+
"simple","properties":{"endpoint":"http://10.147.130.68:25250","user":"agent",
|
24
|
+
"password":"Ag3Nt"}},"mbus":"nats://bosh:b0$H@10.147.130.68:4222","env":{}}]
|
25
|
+
|
26
|
+
class CatalogItem
|
27
|
+
def urn
|
28
|
+
"urn:vcloud:catalogitem:0bed5661-6fef-43e8-aaae-973783efc5cb"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class VApp
|
33
|
+
def vms
|
34
|
+
@vms
|
35
|
+
end
|
36
|
+
def name
|
37
|
+
"myTestVapp"
|
38
|
+
end
|
39
|
+
def initialize
|
40
|
+
@vms = Array[ Vm.new ]
|
41
|
+
end
|
42
|
+
def urn
|
43
|
+
"urn:vcloud:vapp:a1da3521-71aa-480b-97f4-2fdc2ce48569"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Network
|
48
|
+
def initialize(name)
|
49
|
+
@name = name
|
50
|
+
end
|
51
|
+
|
52
|
+
def [](p)
|
53
|
+
@name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Vdc
|
58
|
+
attr_accessor :name
|
59
|
+
|
60
|
+
def initialize(name)
|
61
|
+
@name = name
|
62
|
+
end
|
63
|
+
|
64
|
+
def available_networks
|
65
|
+
[Network.new("a"), Network.new("vcd-org-network")]
|
66
|
+
end
|
67
|
+
|
68
|
+
def storage_profiles
|
69
|
+
#[Network.new("a"), Network.new("vcd-org-network")]
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
class Vm
|
74
|
+
class Nic
|
75
|
+
def network
|
76
|
+
VCloudCloud::Test::test_deployment_manifest[
|
77
|
+
"network"]["default"]["cloud_properties"]["name"]
|
78
|
+
end
|
79
|
+
def mac_address
|
80
|
+
"00:50:56:de:ad:ff"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class HardDisk
|
85
|
+
attr_accessor :disk_id
|
86
|
+
|
87
|
+
def initialize(disk_id)
|
88
|
+
@disk_id = disk_id
|
89
|
+
end
|
90
|
+
|
91
|
+
def urn
|
92
|
+
"urn:vcloud:disk:a1da3521-71aa-480b-97f4-2fdc2ce48569"
|
93
|
+
end
|
94
|
+
|
95
|
+
def size_mb
|
96
|
+
1073741824.to_i/1024/1024
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class HwSec
|
101
|
+
def nics
|
102
|
+
Array[ Nic.new ]
|
103
|
+
end
|
104
|
+
def hard_disks
|
105
|
+
@disks
|
106
|
+
end
|
107
|
+
def initialize
|
108
|
+
@disks = [ HardDisk.new(0) ]
|
109
|
+
end
|
110
|
+
def add_hard_disk
|
111
|
+
disk = HardDisk.new(@disks.size)
|
112
|
+
@disks << disk
|
113
|
+
end
|
114
|
+
def del_hard_disk
|
115
|
+
disk = @disks.pop
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def hardware_section
|
120
|
+
@hw
|
121
|
+
end
|
122
|
+
|
123
|
+
def urn
|
124
|
+
"urn:vcloud:vm:a1da3521-71aa-480b-97f4-2fdc2ce48569"
|
125
|
+
end
|
126
|
+
|
127
|
+
def name
|
128
|
+
"myTestVm"
|
129
|
+
end
|
130
|
+
|
131
|
+
def name=(value)
|
132
|
+
"myTestVm"
|
133
|
+
end
|
134
|
+
|
135
|
+
def description=(value)
|
136
|
+
"myTestVm"
|
137
|
+
end
|
138
|
+
|
139
|
+
def initialize
|
140
|
+
@hw = HwSec.new
|
141
|
+
end
|
142
|
+
|
143
|
+
def add_hard_disk
|
144
|
+
@hw.add_hard_disk
|
145
|
+
end
|
146
|
+
|
147
|
+
def del_hard_disk
|
148
|
+
@hw.del_hard_disk
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
module VCloudCloud
|
156
|
+
vcd_settings = VCloudCloud::Test::vcd_settings
|
157
|
+
cloud_properties = VCloudCloud::Test::director_cloud_properties
|
158
|
+
test_manifest = VCloudCloud::Test::test_deployment_manifest
|
159
|
+
|
160
|
+
describe Cloud, :min, :all do
|
161
|
+
|
162
|
+
it "can upload a valid stemcell" do
|
163
|
+
mc = mock("client")
|
164
|
+
mc.should_receive(:upload_vapp_template).with(an_instance_of(String),
|
165
|
+
an_instance_of(String)).and_return { UnitTest::CatalogItem.new }
|
166
|
+
|
167
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
168
|
+
cloud.stub!(:client) { mc }
|
169
|
+
|
170
|
+
cloud.create_stemcell(Test::spec_asset("valid_stemcell.tgz"), {})
|
171
|
+
end
|
172
|
+
|
173
|
+
it "can delete a stemcell" do
|
174
|
+
mc = mock("client")
|
175
|
+
mc.should_receive(:delete_catalog_vapp).with(
|
176
|
+
an_instance_of(String)).and_return {}
|
177
|
+
|
178
|
+
cloud= VCloudCloud::Cloud.new(cloud_properties)
|
179
|
+
cloud.stub!(:client) { mc }
|
180
|
+
|
181
|
+
cloud.delete_stemcell("test_stemcell_name")
|
182
|
+
end
|
183
|
+
|
184
|
+
it "can create a vm" do
|
185
|
+
vapp = UnitTest::VApp.new
|
186
|
+
mc = mock("client")
|
187
|
+
mc.should_receive(:upload_vapp_template).with(an_instance_of(String),
|
188
|
+
an_instance_of(String)).and_return { UnitTest::CatalogItem.new }
|
189
|
+
mc.should_receive(:instantiate_vapp_template).with(an_instance_of(String),
|
190
|
+
an_instance_of(String), an_instance_of(String), anything).and_return {
|
191
|
+
vapp }
|
192
|
+
mc.should_receive(:power_on_vapp).with(anything).and_return {}
|
193
|
+
mc.should_receive(:get_ovdc).at_least(:once).with().and_return {
|
194
|
+
UnitTest::Vdc.new("myOvdc") }
|
195
|
+
mc.should_receive(:add_network).with(anything, anything).and_return {}
|
196
|
+
mc.should_receive(:delete_networks).with(anything, anything).and_return {}
|
197
|
+
mc.should_receive(:reconfigure_vm).with(anything).and_return {
|
198
|
+
vapp.vms[0].add_hard_disk }
|
199
|
+
mc.should_receive(:delete_catalog_media).with(
|
200
|
+
an_instance_of(String)).and_return { raise VCloudSdk::CatalogMediaNotFoundError,
|
201
|
+
"ISO by name not found" }
|
202
|
+
mc.should_receive(:upload_catalog_media).with(
|
203
|
+
an_instance_of(String), an_instance_of(String), anything).and_return {}
|
204
|
+
mc.should_receive(:insert_catalog_media).with(anything,
|
205
|
+
an_instance_of(String)).and_return {}
|
206
|
+
mc.should_receive(:eject_catalog_media).with(anything,
|
207
|
+
an_instance_of(String)).and_return {}
|
208
|
+
mc.should_receive(:get_vapp).at_least(:once).with(anything).and_return {
|
209
|
+
vapp }
|
210
|
+
mc.should_receive(:set_metadata).with(anything, an_instance_of(String),
|
211
|
+
an_instance_of(String)).and_return {}
|
212
|
+
|
213
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
214
|
+
cloud.stub!(:client) { mc }
|
215
|
+
|
216
|
+
stemcell = cloud.create_stemcell(Test::spec_asset("valid_stemcell.tgz"),
|
217
|
+
{})
|
218
|
+
cloud.create_vm(Test::generate_unique_name, stemcell,
|
219
|
+
test_manifest["resource_pools"][0]["cloud_properties"],
|
220
|
+
test_manifest["network"])
|
221
|
+
end
|
222
|
+
|
223
|
+
it "can create a vm with disk locality" do
|
224
|
+
vapp = UnitTest::VApp.new
|
225
|
+
mc = mock("client")
|
226
|
+
mc.should_receive(:upload_vapp_template).with(an_instance_of(String),
|
227
|
+
an_instance_of(String)).and_return { UnitTest::CatalogItem.new() }
|
228
|
+
mc.should_receive(:instantiate_vapp_template).with(an_instance_of(String),
|
229
|
+
an_instance_of(String), an_instance_of(String), anything).and_return {
|
230
|
+
vapp }
|
231
|
+
mc.should_receive(:reconfigure_vm).with(anything).and_return {
|
232
|
+
vapp.vms[0].add_hard_disk }
|
233
|
+
mc.should_receive(:power_on_vapp).with(anything).and_return {}
|
234
|
+
mc.should_receive(:get_ovdc).at_least(:once).with().and_return {
|
235
|
+
UnitTest::Vdc.new("myOvdc") }
|
236
|
+
mc.should_receive(:add_network).with(anything, anything).and_return {}
|
237
|
+
mc.should_receive(:delete_networks).with(anything, anything).and_return {}
|
238
|
+
mc.should_receive(:delete_catalog_media).with(
|
239
|
+
an_instance_of(String)).and_return { raise VCloudSdk::CatalogMediaNotFoundError,
|
240
|
+
"ISO by name not found" }
|
241
|
+
mc.should_receive(:upload_catalog_media).with(an_instance_of(String),
|
242
|
+
an_instance_of(String), anything).and_return {}
|
243
|
+
mc.should_receive(:insert_catalog_media).with(anything,
|
244
|
+
an_instance_of(String)).and_return {}
|
245
|
+
mc.should_receive(:eject_catalog_media).with(anything,
|
246
|
+
an_instance_of(String)).and_return {}
|
247
|
+
mc.should_receive(:get_vapp).at_least(:once).with(anything).and_return {
|
248
|
+
vapp }
|
249
|
+
mc.should_receive(:set_metadata).with(anything, an_instance_of(String),
|
250
|
+
an_instance_of(String)).and_return {}
|
251
|
+
mc.should_receive(:get_disk).twice.with(an_instance_of(
|
252
|
+
String)).and_return { vapp.vms[0].hardware_section.hard_disks.last }
|
253
|
+
|
254
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
255
|
+
cloud.stub!(:client) { mc }
|
256
|
+
|
257
|
+
disk_locality = []
|
258
|
+
disk_locality << "test_disk_id"
|
259
|
+
disk_locality << "test_disk_id_non_existent"
|
260
|
+
stemcell = cloud.create_stemcell(Test::spec_asset("valid_stemcell.tgz"),
|
261
|
+
{})
|
262
|
+
cloud.create_vm(Test::generate_unique_name, stemcell,
|
263
|
+
test_manifest["resource_pools"][0]["cloud_properties"],
|
264
|
+
test_manifest["network"], disk_locality)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "can delete a vm" do
|
268
|
+
vapp = UnitTest::VApp.new
|
269
|
+
mc = mock("client")
|
270
|
+
mc.should_receive(:get_vapp).with(anything).and_return { vapp }
|
271
|
+
mc.should_receive(:power_off_vapp).with(vapp).and_return {}
|
272
|
+
mc.should_receive(:delete_vapp).with(vapp).and_return {} if
|
273
|
+
vcd_settings['debug']['delete_vapp'] == true
|
274
|
+
mc.should_receive(:delete_catalog_media).with(
|
275
|
+
an_instance_of(String)).and_return {}
|
276
|
+
|
277
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
278
|
+
cloud.stub!(:client) { mc }
|
279
|
+
|
280
|
+
cloud.delete_vm(vapp.name)
|
281
|
+
end
|
282
|
+
|
283
|
+
it "can delete a suspended vm" do
|
284
|
+
vapp_power_state = "suspended"
|
285
|
+
vapp = UnitTest::VApp.new
|
286
|
+
mc = mock("client")
|
287
|
+
mc.should_receive(:get_vapp).with(anything).and_return { vapp }
|
288
|
+
mc.should_receive(:discard_suspended_state_vapp).with(
|
289
|
+
anything).and_return { vapp }
|
290
|
+
mc.should_receive(:power_off_vapp).at_least(:once).with(vapp).and_return {
|
291
|
+
if vapp_power_state == "suspended"
|
292
|
+
vapp_power_state = "off"
|
293
|
+
raise VCloudSdk::VappSuspendedError
|
294
|
+
end
|
295
|
+
}
|
296
|
+
mc.should_receive(:delete_vapp).with(vapp).and_return {} if
|
297
|
+
vcd_settings['debug']['delete_vapp'] == true
|
298
|
+
mc.should_receive(:delete_catalog_media).with(
|
299
|
+
an_instance_of(String)).and_return {}
|
300
|
+
|
301
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
302
|
+
cloud.stub!(:client) { mc }
|
303
|
+
|
304
|
+
cloud.delete_vm(vapp.name)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "can reboot a vm" do
|
308
|
+
vapp = UnitTest::VApp.new
|
309
|
+
mc = mock("client")
|
310
|
+
mc.should_receive(:get_vapp).with(anything).and_return { vapp }
|
311
|
+
mc.should_receive(:reboot_vapp).with(vapp).and_return {}
|
312
|
+
|
313
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
314
|
+
cloud.stub!(:client) { mc }
|
315
|
+
|
316
|
+
cloud.reboot_vm(vapp.name)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "can reboot a powered off vm" do
|
320
|
+
vapp_power_state = "off"
|
321
|
+
vapp = UnitTest::VApp.new
|
322
|
+
mc = mock("client")
|
323
|
+
mc.should_receive(:get_vapp).with(anything).and_return { vapp }
|
324
|
+
mc.should_receive(:power_on_vapp).with(vapp).and_return {}
|
325
|
+
mc.should_receive(:reboot_vapp).at_least(:once).with(vapp).and_return {
|
326
|
+
if vapp_power_state == "off"
|
327
|
+
vapp_power_state = "on"
|
328
|
+
raise VCloudSdk::VappPoweredOffError
|
329
|
+
end
|
330
|
+
}
|
331
|
+
|
332
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
333
|
+
cloud.stub!(:client) { mc }
|
334
|
+
|
335
|
+
cloud.reboot_vm(vapp.name)
|
336
|
+
end
|
337
|
+
|
338
|
+
it "can reboot a suspended vm" do
|
339
|
+
vapp_power_state = "suspended"
|
340
|
+
vapp = UnitTest::VApp.new
|
341
|
+
mc = mock("client")
|
342
|
+
mc.should_receive(:get_vapp).with(anything).and_return { vapp }
|
343
|
+
mc.should_receive(:discard_suspended_state_vapp).with(
|
344
|
+
anything).and_return { vapp }
|
345
|
+
mc.should_receive(:power_on_vapp).with(vapp).and_return {}
|
346
|
+
mc.should_receive(:reboot_vapp).at_least(:once).with(vapp).and_return {
|
347
|
+
if vapp_power_state == "suspended"
|
348
|
+
vapp_power_state = "on"
|
349
|
+
raise VCloudSdk::VappSuspendedError
|
350
|
+
end
|
351
|
+
}
|
352
|
+
|
353
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
354
|
+
cloud.stub!(:client) { mc }
|
355
|
+
|
356
|
+
cloud.reboot_vm(vapp.name)
|
357
|
+
end
|
358
|
+
|
359
|
+
it "can re-configure vm networks" do
|
360
|
+
vapp = UnitTest::VApp.new
|
361
|
+
mc = mock("client")
|
362
|
+
mc.should_receive(:get_vapp).at_least(:once).with(
|
363
|
+
anything).and_return { vapp }
|
364
|
+
mc.should_receive(:power_off_vapp).with(vapp).and_return {}
|
365
|
+
mc.should_receive(:power_on_vapp).with(anything).and_return {}
|
366
|
+
mc.should_receive(:reconfigure_vm).with(anything).and_return {}
|
367
|
+
mc.should_receive(:get_ovdc).at_least(:once).with().and_return {
|
368
|
+
UnitTest::Vdc.new("myOvdc") }
|
369
|
+
mc.should_receive(:delete_networks).with(anything, anything).and_return {}
|
370
|
+
mc.should_receive(:add_network).with(anything, anything).and_return {}
|
371
|
+
mc.should_receive(:delete_catalog_media).with(
|
372
|
+
an_instance_of(String)).and_return {}
|
373
|
+
mc.should_receive(:upload_catalog_media).with(an_instance_of(String),
|
374
|
+
an_instance_of(String), anything).and_return {}
|
375
|
+
mc.should_receive(:insert_catalog_media).with(anything,
|
376
|
+
an_instance_of(String)).and_return {}
|
377
|
+
mc.should_receive(:eject_catalog_media).with(anything,
|
378
|
+
an_instance_of(String)).and_return {}
|
379
|
+
mc.should_receive(:set_metadata).with(anything, an_instance_of(String),
|
380
|
+
an_instance_of(String)).and_return {}
|
381
|
+
mc.should_receive(:get_metadata).with(anything,
|
382
|
+
an_instance_of(String)).and_return { UnitTest::AGENT_ENV }
|
383
|
+
|
384
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
385
|
+
cloud.stub!(:client) { mc }
|
386
|
+
|
387
|
+
cloud.configure_networks(vapp.name, test_manifest["network"])
|
388
|
+
end
|
389
|
+
|
390
|
+
it "can create a disk without locality" do
|
391
|
+
vapp = UnitTest::VApp.new
|
392
|
+
mc = mock("client")
|
393
|
+
mc.should_receive(:create_disk).with(
|
394
|
+
an_instance_of(String), an_instance_of(Fixnum)).and_return {
|
395
|
+
vapp.vms[0].hardware_section.hard_disks.last }
|
396
|
+
|
397
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
398
|
+
cloud.stub!(:client) { mc }
|
399
|
+
|
400
|
+
cloud.create_disk(4096)
|
401
|
+
end
|
402
|
+
|
403
|
+
it "can create a disk with locality" do
|
404
|
+
vapp = UnitTest::VApp.new
|
405
|
+
mc = mock("client")
|
406
|
+
mc.should_receive(:get_vapp).with(anything).and_return { vapp }
|
407
|
+
mc.should_receive(:create_disk).with(
|
408
|
+
an_instance_of(String), an_instance_of(Fixnum), anything).and_return {
|
409
|
+
vapp.vms[0].hardware_section.hard_disks.last }
|
410
|
+
|
411
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
412
|
+
cloud.stub!(:client) { mc }
|
413
|
+
|
414
|
+
cloud.create_disk(4096, vapp.name)
|
415
|
+
end
|
416
|
+
|
417
|
+
it "can delete a disk" do
|
418
|
+
vapp = UnitTest::VApp.new
|
419
|
+
mc = mock("client")
|
420
|
+
mc.should_receive(:delete_disk).any_number_of_times.with(
|
421
|
+
anything).and_return {}
|
422
|
+
mc.should_receive(:get_disk).with(an_instance_of(String)).and_return {
|
423
|
+
vapp.vms[0].hardware_section.hard_disks.last }
|
424
|
+
|
425
|
+
cloud= VCloudCloud::Cloud.new(cloud_properties)
|
426
|
+
cloud.stub!(:client) { mc }
|
427
|
+
|
428
|
+
cloud.delete_disk("test_disk_id")
|
429
|
+
end
|
430
|
+
|
431
|
+
it "can attach a disk to a vm" do
|
432
|
+
vapp = UnitTest::VApp.new
|
433
|
+
mc = mock("client")
|
434
|
+
mc.should_receive(:get_vapp).at_least(:once).with(
|
435
|
+
anything).and_return { vapp }
|
436
|
+
mc.should_receive(:delete_catalog_media).with(
|
437
|
+
an_instance_of(String)).and_return {}
|
438
|
+
mc.should_receive(:upload_catalog_media).with(an_instance_of(String),
|
439
|
+
an_instance_of(String), anything).and_return {}
|
440
|
+
mc.should_receive(:insert_catalog_media).with(anything,
|
441
|
+
an_instance_of(String)).and_return {}
|
442
|
+
mc.should_receive(:eject_catalog_media).with(anything,
|
443
|
+
an_instance_of(String)).and_return {}
|
444
|
+
mc.should_receive(:set_metadata).with(anything, an_instance_of(String),
|
445
|
+
an_instance_of(String)).and_return {}
|
446
|
+
mc.should_receive(:get_metadata).with(anything,
|
447
|
+
an_instance_of(String)).and_return { UnitTest::AGENT_ENV }
|
448
|
+
mc.should_receive(:get_ovdc).at_least(:once).with().and_return {
|
449
|
+
UnitTest::Vdc.new("myOvdc") }
|
450
|
+
mc.should_receive(:attach_disk).with(
|
451
|
+
an_instance_of(UnitTest::Vm::HardDisk), anything).and_return {
|
452
|
+
vapp.vms[0].add_hard_disk }
|
453
|
+
mc.should_receive(:get_disk).with(an_instance_of(String)).and_return {
|
454
|
+
vapp.vms[0].hardware_section.hard_disks.last }
|
455
|
+
|
456
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
457
|
+
cloud.stub!(:client) { mc }
|
458
|
+
|
459
|
+
cloud.attach_disk(vapp.name, "test_disk_id")
|
460
|
+
end
|
461
|
+
|
462
|
+
it "can detach a disk from a vm" do
|
463
|
+
vapp = UnitTest::VApp.new
|
464
|
+
mc = mock("client")
|
465
|
+
mc.should_receive(:get_vapp).at_least(:once).with(
|
466
|
+
anything).and_return { vapp }
|
467
|
+
mc.should_receive(:delete_catalog_media).with(
|
468
|
+
an_instance_of(String)).and_return {}
|
469
|
+
mc.should_receive(:upload_catalog_media).with(an_instance_of(String),
|
470
|
+
an_instance_of(String), anything).and_return {}
|
471
|
+
mc.should_receive(:insert_catalog_media).with(anything,
|
472
|
+
an_instance_of(String)).and_return {}
|
473
|
+
mc.should_receive(:eject_catalog_media).with(anything,
|
474
|
+
an_instance_of(String)).and_return {}
|
475
|
+
mc.should_receive(:set_metadata).with(anything, an_instance_of(String),
|
476
|
+
an_instance_of(String)).and_return {}
|
477
|
+
mc.should_receive(:get_metadata).with(anything,
|
478
|
+
an_instance_of(String)).and_return { UnitTest::AGENT_ENV }
|
479
|
+
mc.should_receive(:get_ovdc).at_least(:once).with().and_return {
|
480
|
+
UnitTest::Vdc.new("myOvdc") }
|
481
|
+
mc.should_receive(:detach_disk).with(
|
482
|
+
an_instance_of(UnitTest::Vm::HardDisk), anything).and_return {
|
483
|
+
vapp.vms[0].del_hard_disk }
|
484
|
+
mc.should_receive(:get_disk).with(an_instance_of(String)).and_return {
|
485
|
+
vapp.vms[0].hardware_section.hard_disks.last }
|
486
|
+
|
487
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
488
|
+
cloud.stub!(:client) { mc }
|
489
|
+
|
490
|
+
cloud.detach_disk(vapp.name, "test_disk_id")
|
491
|
+
end
|
492
|
+
|
493
|
+
it "can get the size of a disk" do
|
494
|
+
vapp = UnitTest::VApp.new
|
495
|
+
mc = mock("client")
|
496
|
+
mc.should_receive(:get_disk).with(
|
497
|
+
an_instance_of(String)).and_return {
|
498
|
+
vapp.vms[0].hardware_section.hard_disks.last }
|
499
|
+
|
500
|
+
cloud = VCloudCloud::Cloud.new(cloud_properties)
|
501
|
+
cloud.stub!(:client) { mc }
|
502
|
+
|
503
|
+
cloud.get_disk_size_mb("test_disk_id").should equal(1024.to_i)
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bosh_vcloud_cpi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.4.8
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- VMware
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-11-12 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bosh_common
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bosh_cpi
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.4.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: ruby_vcloud_sdk
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: uuidtools
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: yajl-ruby
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.8.2
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
description: BOSH vCloud CPI
|
72
|
+
email: support@vmware.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
79
|
+
files:
|
80
|
+
- lib/cloud/vcloud.rb
|
81
|
+
- lib/cloud/vcloud/cloud.rb
|
82
|
+
- lib/cloud/vcloud/const.rb
|
83
|
+
- lib/cloud/vcloud/util.rb
|
84
|
+
- lib/cloud/vcloud/version.rb
|
85
|
+
- README
|
86
|
+
- Rakefile
|
87
|
+
- spec/assets/test-deployment-manifest.yml
|
88
|
+
- spec/assets/test-director-config.yml
|
89
|
+
- spec/assets/valid_stemcell.tgz
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/unit/cloud_spec.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: http://www.vmware.com
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: -157759317589376717
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: -157759317589376717
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 1.6.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: BOSH vCloud CPI
|
126
|
+
test_files:
|
127
|
+
- spec/assets/test-deployment-manifest.yml
|
128
|
+
- spec/assets/test-director-config.yml
|
129
|
+
- spec/assets/valid_stemcell.tgz
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/unit/cloud_spec.rb
|