vagrant-cosmic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +8 -0
- data/Docker/.dockerignore +2 -0
- data/Docker/Dockerfile +48 -0
- data/Docker/Dockerfile.chefdk_0_17 +49 -0
- data/Docker/Dockerfile.latest_dependencies +49 -0
- data/Docker/README.md +95 -0
- data/Docker/vac.ps1 +29 -0
- data/Docker/vac.sh +30 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +187 -0
- data/LICENSE +8 -0
- data/README.md +409 -0
- data/Rakefile +106 -0
- data/build_rpm.sh +7 -0
- data/functional-tests/basic/Vagrantfile.basic_networking +34 -0
- data/functional-tests/basic/basic_spec.rb +15 -0
- data/functional-tests/networking/Vagrantfile.advanced_networking +106 -0
- data/functional-tests/networking/networking_spec.rb +14 -0
- data/functional-tests/rsync/Vagrantfile.advanced_networking +40 -0
- data/functional-tests/rsync/rsync_spec.rb +9 -0
- data/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +64 -0
- data/functional-tests/vmlifecycle/vmlifecycle_spec.rb +25 -0
- data/lib/vagrant-cosmic/action/connect_cosmic.rb +47 -0
- data/lib/vagrant-cosmic/action/is_created.rb +18 -0
- data/lib/vagrant-cosmic/action/is_stopped.rb +18 -0
- data/lib/vagrant-cosmic/action/message_already_created.rb +16 -0
- data/lib/vagrant-cosmic/action/message_not_created.rb +16 -0
- data/lib/vagrant-cosmic/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-cosmic/action/read_rdp_info.rb +42 -0
- data/lib/vagrant-cosmic/action/read_ssh_info.rb +70 -0
- data/lib/vagrant-cosmic/action/read_state.rb +38 -0
- data/lib/vagrant-cosmic/action/read_transport_info.rb +59 -0
- data/lib/vagrant-cosmic/action/read_winrm_info.rb +69 -0
- data/lib/vagrant-cosmic/action/run_instance.rb +819 -0
- data/lib/vagrant-cosmic/action/start_instance.rb +81 -0
- data/lib/vagrant-cosmic/action/stop_instance.rb +28 -0
- data/lib/vagrant-cosmic/action/terminate_instance.rb +208 -0
- data/lib/vagrant-cosmic/action/timed_provision.rb +21 -0
- data/lib/vagrant-cosmic/action/wait_for_state.rb +41 -0
- data/lib/vagrant-cosmic/action/warn_networks.rb +19 -0
- data/lib/vagrant-cosmic/action.rb +210 -0
- data/lib/vagrant-cosmic/capabilities/rdp.rb +12 -0
- data/lib/vagrant-cosmic/capabilities/winrm.rb +12 -0
- data/lib/vagrant-cosmic/config.rb +422 -0
- data/lib/vagrant-cosmic/errors.rb +27 -0
- data/lib/vagrant-cosmic/exceptions/exceptions.rb +15 -0
- data/lib/vagrant-cosmic/model/cosmic_resource.rb +51 -0
- data/lib/vagrant-cosmic/plugin.rb +82 -0
- data/lib/vagrant-cosmic/provider.rb +58 -0
- data/lib/vagrant-cosmic/service/cosmic_resource_service.rb +76 -0
- data/lib/vagrant-cosmic/util/timer.rb +17 -0
- data/lib/vagrant-cosmic/version.rb +5 -0
- data/lib/vagrant-cosmic.rb +17 -0
- data/locales/en.yml +131 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/vagrant-cosmic/action/read_ssh_info_spec.rb +80 -0
- data/spec/vagrant-cosmic/action/retrieve_public_ip_port_spec.rb +94 -0
- data/spec/vagrant-cosmic/action/run_instance_spec.rb +573 -0
- data/spec/vagrant-cosmic/action/terminate_instance_spec.rb +207 -0
- data/spec/vagrant-cosmic/config_spec.rb +340 -0
- data/spec/vagrant-cosmic/model/cosmic_resource_spec.rb +95 -0
- data/spec/vagrant-cosmic/service/cosmic_resource_service_spec.rb +43 -0
- data/spec/vagrant-cosmic/support/be_a_resource.rb +6 -0
- data/vagrant-cosmic.gemspec +59 -0
- data/vagrant-cosmic.spec +42 -0
- metadata +218 -0
@@ -0,0 +1,573 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vagrant-cosmic/action/run_instance'
|
3
|
+
require 'vagrant-cosmic/config'
|
4
|
+
|
5
|
+
require 'vagrant'
|
6
|
+
require 'fog/cosmic'
|
7
|
+
|
8
|
+
describe VagrantPlugins::Cosmic::Action::RunInstance do
|
9
|
+
let(:action) { VagrantPlugins::Cosmic::Action::RunInstance.new(app, env) }
|
10
|
+
|
11
|
+
let(:create_servers_parameters) do
|
12
|
+
{
|
13
|
+
:display_name => DISPLAY_NAME,
|
14
|
+
:group => nil,
|
15
|
+
:zone_id => ZONE_ID,
|
16
|
+
:flavor_id => SERVICE_OFFERING_ID,
|
17
|
+
:image_id => TEMPLATE_ID,
|
18
|
+
'network_ids' => NETWORK_ID
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:fake_job_result) do
|
23
|
+
{
|
24
|
+
'queryasyncjobresultresponse' => {
|
25
|
+
'jobstatus' => 1,
|
26
|
+
'jobresult' => {
|
27
|
+
'portforwardingrule' => {
|
28
|
+
'id' => PORT_FORWARDING_RULE_ID
|
29
|
+
},
|
30
|
+
'networkacl' => {
|
31
|
+
'id' => ACL_ID
|
32
|
+
},
|
33
|
+
'virtualmachine' => {
|
34
|
+
'password' => GENERATED_PASSWORD
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:list_public_ip_addresses_response) do
|
42
|
+
{
|
43
|
+
'listpublicipaddressesresponse' => {
|
44
|
+
'count' => 1,
|
45
|
+
'publicipaddress' =>
|
46
|
+
[
|
47
|
+
{
|
48
|
+
'id' => PF_IP_ADDRESS_ID,
|
49
|
+
'ipaddress' => PF_IP_ADDRESS,
|
50
|
+
'associatednetworkid' => NETWORK_ID,
|
51
|
+
'associatednetworkname' => NETWORK_NAME,
|
52
|
+
'vpcid' => VPC_ID
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
let(:network_type) { NETWORK_TYPE_ADVANCED }
|
60
|
+
let(:list_zones_response) do
|
61
|
+
{
|
62
|
+
'listzonesresponse' => {
|
63
|
+
'count' => 1,
|
64
|
+
'zone' =>
|
65
|
+
[
|
66
|
+
{
|
67
|
+
'tags' => [],
|
68
|
+
'id' => ZONE_ID,
|
69
|
+
'name' => ZONE_NAME,
|
70
|
+
'networktype' => network_type,
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
let(:list_service_offerings_response) do
|
78
|
+
{
|
79
|
+
'listserviceofferingsresponse' => {
|
80
|
+
'count' => 1,
|
81
|
+
'serviceoffering' => [
|
82
|
+
{
|
83
|
+
'id' => SERVICE_OFFERING_ID,
|
84
|
+
'name' => SERVICE_OFFERING_NAME,
|
85
|
+
'displaytext' => "Display version of #{SERVICE_OFFERING_NAME}"
|
86
|
+
}
|
87
|
+
]
|
88
|
+
}
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
let(:list_templates_response) do
|
93
|
+
{
|
94
|
+
'listtemplatesresponse' => {
|
95
|
+
'count' => 1,
|
96
|
+
'template' => [
|
97
|
+
{
|
98
|
+
'id' => TEMPLATE_ID,
|
99
|
+
'name' => TEMPLATE_NAME
|
100
|
+
}
|
101
|
+
]
|
102
|
+
}
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
let(:list_networks_response) do
|
107
|
+
{
|
108
|
+
'listnetworksresponse' => {
|
109
|
+
'count' => 1,
|
110
|
+
'network' => [
|
111
|
+
{
|
112
|
+
'id' => NETWORK_ID,
|
113
|
+
'name' => NETWORK_NAME,
|
114
|
+
'vpcid' => VPC_ID,
|
115
|
+
'aclid' => ACL_ID
|
116
|
+
}
|
117
|
+
]
|
118
|
+
}
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:list_network_acl_lists_response) do
|
123
|
+
{
|
124
|
+
'listnetworkacllistsresponse' => {
|
125
|
+
'count' => 3,
|
126
|
+
'networkacllist' => [
|
127
|
+
{
|
128
|
+
'id' => ACL_ID,
|
129
|
+
'name' => NETWORK_NAME,
|
130
|
+
'vpcid' => VPC_ID
|
131
|
+
},
|
132
|
+
{
|
133
|
+
'id' => '13fa8945-9248-13e5-4afa-525405b8977a', 'name' => 'default_allow',
|
134
|
+
'description' => 'Default Network ACL Allow All'
|
135
|
+
},
|
136
|
+
{
|
137
|
+
'id' => '13fa283b-9248-13e5-4afa-525405b8977a', 'name' => 'default_deny',
|
138
|
+
'description' => 'Default Network ACL Deny All'
|
139
|
+
}
|
140
|
+
]
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
let(:list_disk_offerings_response) do
|
145
|
+
{
|
146
|
+
'listdiskofferingsresponse' => {
|
147
|
+
'count' => 1,
|
148
|
+
'diskoffering' => [
|
149
|
+
{
|
150
|
+
'id' => DISK_OFFERING_ID,
|
151
|
+
'name' => DISK_OFFERING_NAME
|
152
|
+
}
|
153
|
+
]
|
154
|
+
}
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
158
|
+
let(:create_port_forwarding_rule_parameters) do
|
159
|
+
{
|
160
|
+
networkid: NETWORK_ID,
|
161
|
+
ipaddressid: PF_IP_ADDRESS_ID,
|
162
|
+
publicport: 49_152,
|
163
|
+
privateport: GUEST_PORT_SSH,
|
164
|
+
protocol: 'tcp',
|
165
|
+
virtualmachineid: SERVER_ID
|
166
|
+
}
|
167
|
+
end
|
168
|
+
|
169
|
+
let(:create_port_forwarding_rule_respones) do
|
170
|
+
{
|
171
|
+
'createportforwardingruleresponse' => {
|
172
|
+
'id' => PORT_FORWARDING_RULE_ID,
|
173
|
+
'jobid' => JOB_ID
|
174
|
+
}
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
178
|
+
let(:create_network_acl_request) do
|
179
|
+
{
|
180
|
+
command: 'createNetworkACL',
|
181
|
+
aclid: ACL_ID,
|
182
|
+
action: 'Allow',
|
183
|
+
protocol: 'tcp',
|
184
|
+
cidrlist: PF_TRUSTED_NETWORKS,
|
185
|
+
startport: GUEST_PORT_SSH,
|
186
|
+
endport: GUEST_PORT_SSH,
|
187
|
+
icmpcode: nil,
|
188
|
+
icmptype: nil,
|
189
|
+
traffictype: 'Ingress'
|
190
|
+
}
|
191
|
+
end
|
192
|
+
|
193
|
+
let(:createNetworkACL_response) do
|
194
|
+
{
|
195
|
+
'createnetworkaclresponse' => {
|
196
|
+
'id' => '5dcb96b5-7785-463d-9a11-d8388c98e4ee',
|
197
|
+
'jobid' => JOB_ID
|
198
|
+
}
|
199
|
+
}
|
200
|
+
end
|
201
|
+
|
202
|
+
let(:create_ssh_key_pair_response) do
|
203
|
+
{
|
204
|
+
'createsshkeypairresponse' => {
|
205
|
+
'keypair' => {
|
206
|
+
'privatekey' => "#{SSH_GENERATED_PRIVATE_KEY}\n",
|
207
|
+
'name' => SSH_GENERATED_KEY_NAME
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
end
|
212
|
+
|
213
|
+
describe 'run_instance' do
|
214
|
+
subject { action.call(env) }
|
215
|
+
let(:app) { double('Vagrant::Action::Warden') }
|
216
|
+
let(:ssh_key) { '/some/path' }
|
217
|
+
|
218
|
+
let(:template_name) { TEMPLATE_NAME }
|
219
|
+
let(:machine) { double('Vagrant::Machine') }
|
220
|
+
let(:data_dir) { double('Pathname') }
|
221
|
+
let(:a_path) { double('Pathname') }
|
222
|
+
let(:file) { double('File') }
|
223
|
+
let(:communicator) { double('VagrantPlugins::CommunicatorSSH::Communicator') }
|
224
|
+
let(:communicator_config) { double('VagrantPlugins::...::...Config') }
|
225
|
+
let(:cosmic_compute) { double('Fog::Cosmic::Compute') }
|
226
|
+
let(:servers) { double('Fog::Cosmic::Compute::Servers') }
|
227
|
+
let(:server) { double('Fog::Cosmic::Compute::Server') }
|
228
|
+
let(:ui) { double('Vagrant::UI::Prefixed') }
|
229
|
+
let(:root_path) { double('Pathname') }
|
230
|
+
let(:env) do
|
231
|
+
{
|
232
|
+
root_path: root_path,
|
233
|
+
ui: ui,
|
234
|
+
machine: machine,
|
235
|
+
cosmic_compute: cosmic_compute
|
236
|
+
}
|
237
|
+
end
|
238
|
+
|
239
|
+
let(:cosmic_zone) do
|
240
|
+
instance_double('Fog::Cosmic::Compute::Zone',
|
241
|
+
id: ZONE_ID,
|
242
|
+
name: ZONE_NAME,
|
243
|
+
network_type: network_type)
|
244
|
+
end
|
245
|
+
|
246
|
+
before(:each) do
|
247
|
+
allow(app).to receive(:call).and_return(true)
|
248
|
+
allow(ui).to receive(:info)
|
249
|
+
allow(ui).to receive(:detail)
|
250
|
+
|
251
|
+
allow(machine).to receive(:data_dir).and_return(data_dir)
|
252
|
+
allow(data_dir).to receive(:join).and_return(a_path)
|
253
|
+
allow(a_path).to receive(:open).and_yield(file)
|
254
|
+
|
255
|
+
allow(machine).to receive(:communicate).and_return(communicator)
|
256
|
+
allow(machine).to receive_message_chain(:communicate, :ready?).and_return(true)
|
257
|
+
|
258
|
+
allow(machine).to receive(:provider_config).and_return(provider_config)
|
259
|
+
expect(server).to receive(:wait_for).and_return(ready = true)
|
260
|
+
allow(server).to receive(:job_id).and_return(JOB_ID)
|
261
|
+
allow(server).to receive(:password_enabled).and_return(false)
|
262
|
+
expect(cosmic_compute).to receive(:servers).and_return(servers)
|
263
|
+
allow(cosmic_compute).to receive(:send).with(:list_zones, available: true, name: ZONE_NAME).and_return(list_zones_response)
|
264
|
+
allow(cosmic_compute).to receive(:send).with(:list_service_offerings, listall: true, name: SERVICE_OFFERING_NAME)
|
265
|
+
.and_return(list_service_offerings_response)
|
266
|
+
allow(cosmic_compute).to receive(:send)
|
267
|
+
.with(:list_templates, zoneid: ZONE_ID, templatefilter: 'executable', listall: true, name: TEMPLATE_NAME)
|
268
|
+
.and_return(list_templates_response)
|
269
|
+
allow(cosmic_compute).to receive(:zones).and_return([cosmic_zone])
|
270
|
+
allow(servers).to receive(:create).with(create_servers_parameters).and_return(server)
|
271
|
+
expect(server).to receive(:id).and_return(SERVER_ID)
|
272
|
+
expect(machine).to receive(:id=).with(SERVER_ID)
|
273
|
+
|
274
|
+
allow(cosmic_compute).to receive(:volumes).and_return([])
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'in basic zone' do
|
278
|
+
let(:network_name) { nil }
|
279
|
+
let(:provider_config) do
|
280
|
+
config = VagrantPlugins::Cosmic::Config.new
|
281
|
+
config.domain_config :cosmic do |cfg|
|
282
|
+
cfg.zone_name = ZONE_NAME
|
283
|
+
cfg.service_offering_name = SERVICE_OFFERING_NAME
|
284
|
+
cfg.template_name = template_name
|
285
|
+
cfg.display_name = DISPLAY_NAME
|
286
|
+
cfg.ssh_key = ssh_key
|
287
|
+
cfg.network_name = network_name
|
288
|
+
end
|
289
|
+
config.finalize!
|
290
|
+
config.get_domain_config(:cosmic)
|
291
|
+
end
|
292
|
+
let(:network_type) { NETWORK_TYPE_BASIC }
|
293
|
+
|
294
|
+
let(:create_servers_parameters) do
|
295
|
+
{
|
296
|
+
display_name: DISPLAY_NAME,
|
297
|
+
group: nil,
|
298
|
+
zone_id: ZONE_ID,
|
299
|
+
flavor_id: SERVICE_OFFERING_ID,
|
300
|
+
image_id: TEMPLATE_ID
|
301
|
+
}
|
302
|
+
end
|
303
|
+
|
304
|
+
context 'a basic configuration' do
|
305
|
+
it 'starts a vm' do
|
306
|
+
should eq true
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context 'with advanced zone parameters give warnings' do
|
311
|
+
let(:network_name) { NETWORK_NAME }
|
312
|
+
|
313
|
+
before(:each) do
|
314
|
+
expect(ui).to receive(:warn).with("Network name or id defined but zone Zone Name is of network type 'Basic'"\
|
315
|
+
"\nNetwork name or id will be ignored")
|
316
|
+
end
|
317
|
+
it 'starts a vm' do
|
318
|
+
should eq true
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context 'in advanced zone' do
|
324
|
+
let(:pf_ip_address) { nil }
|
325
|
+
let(:pf_trusted_networks) { nil }
|
326
|
+
let(:pf_public_port_randomrange) { { start: 49_152, end: 65_535 } }
|
327
|
+
let(:pf_open_firewall) { true }
|
328
|
+
let(:disk_offering_name) { nil }
|
329
|
+
|
330
|
+
let(:provider_config) do
|
331
|
+
config = VagrantPlugins::Cosmic::Config.new
|
332
|
+
config.domain_config :cosmic do |cfg|
|
333
|
+
cfg.zone_name = ZONE_NAME
|
334
|
+
cfg.network_name = NETWORK_NAME
|
335
|
+
cfg.service_offering_name = SERVICE_OFFERING_NAME
|
336
|
+
cfg.template_name = template_name
|
337
|
+
cfg.display_name = DISPLAY_NAME
|
338
|
+
cfg.pf_ip_address = pf_ip_address
|
339
|
+
cfg.pf_trusted_networks = pf_trusted_networks
|
340
|
+
cfg.pf_public_port_randomrange = pf_public_port_randomrange
|
341
|
+
cfg.pf_open_firewall = pf_open_firewall
|
342
|
+
cfg.ssh_key = ssh_key
|
343
|
+
cfg.disk_offering_name = disk_offering_name
|
344
|
+
end
|
345
|
+
config.finalize!
|
346
|
+
config.get_domain_config(:cosmic)
|
347
|
+
end
|
348
|
+
|
349
|
+
let(:winrm_config) { double('VagrantPlugins::VagrantWinRM::WinRMConfig') }
|
350
|
+
|
351
|
+
before(:each) do
|
352
|
+
allow(cosmic_compute).to receive(:query_async_job_result).with(jobid: JOB_ID).and_return(fake_job_result)
|
353
|
+
|
354
|
+
allow(cosmic_compute).to receive(:send).with(:list_networks, {}).and_return(list_networks_response)
|
355
|
+
end
|
356
|
+
|
357
|
+
context 'a basic configuration' do
|
358
|
+
it 'starts a vm' do
|
359
|
+
should eq true
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
context 'with template specified from Vagrant(file)' do
|
364
|
+
let(:template_name) { nil }
|
365
|
+
|
366
|
+
before(:each) do
|
367
|
+
expect(machine).to receive_message_chain(:config, :vm, :box).and_return(TEMPLATE_NAME)
|
368
|
+
end
|
369
|
+
it 'starts a vm' do
|
370
|
+
should eq true
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
context 'with additional data disk' do
|
375
|
+
let(:disk_offering_name) { DISK_OFFERING_NAME }
|
376
|
+
let(:create_servers_parameters) { super().merge('disk_offering_id' => DISK_OFFERING_ID) }
|
377
|
+
let(:volume) { double('Fog::Cosmic::Compute::Volume') }
|
378
|
+
|
379
|
+
before(:each) do
|
380
|
+
allow(cosmic_compute).to receive(:send).with(:list_disk_offerings, listall: true, name: DISK_OFFERING_NAME)
|
381
|
+
.and_return(list_disk_offerings_response)
|
382
|
+
expect(cosmic_compute).to receive(:volumes).and_return([volume])
|
383
|
+
allow(volume).to receive(:server_id).and_return(SERVER_ID)
|
384
|
+
allow(volume).to receive(:type).and_return('DATADISK')
|
385
|
+
allow(volume).to receive(:id).and_return(VOLUME_ID)
|
386
|
+
expect(file).to receive(:write).with("#{VOLUME_ID}\n")
|
387
|
+
allow(server).to receive(:id).and_return(SERVER_ID)
|
388
|
+
end
|
389
|
+
it 'starts a vm' do
|
390
|
+
should eq true
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
context 'with generated password' do
|
395
|
+
before(:each) do
|
396
|
+
expect(server).to receive(:password_enabled).and_return(true)
|
397
|
+
allow(server).to receive(:job_id).and_return(JOB_ID)
|
398
|
+
expect(file).to receive(:write).with(GENERATED_PASSWORD)
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'starts a vm' do
|
402
|
+
should eq true
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
context 'with SSH key generation' do
|
407
|
+
let(:ssh_key) { nil }
|
408
|
+
let(:create_servers_parameters) { super().merge('key_name' => SSH_GENERATED_KEY_NAME) }
|
409
|
+
|
410
|
+
before(:each) do
|
411
|
+
expect(ui).to receive(:warn)
|
412
|
+
.with('No keypair or ssh_key specified to launch your instance with.' \
|
413
|
+
"\n" + 'Generating a temporary keypair for this instance...')
|
414
|
+
expect(cosmic_compute).to receive(:create_ssh_key_pair).with(/vagacs_#{DISPLAY_NAME}/, nil, nil, nil)
|
415
|
+
.and_return(create_ssh_key_pair_response)
|
416
|
+
expect(file).to receive(:write).with("#{SSH_GENERATED_PRIVATE_KEY}\n")
|
417
|
+
expect(file).to receive(:write).with(SSH_GENERATED_KEY_NAME)
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'starts a vm' do
|
421
|
+
should eq true
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
context 'with autogenerated firewall and port forward' do
|
426
|
+
let(:pf_ip_address) { PF_IP_ADDRESS }
|
427
|
+
let(:pf_trusted_networks) { PF_TRUSTED_NETWORKS }
|
428
|
+
let(:pf_public_port_randomrange) { { start: PF_RANDOM_START, end: PF_RANDOM_START + 1 } }
|
429
|
+
let(:pf_open_firewall) { false }
|
430
|
+
|
431
|
+
before(:each) do
|
432
|
+
allow(cosmic_compute).to receive(:send).with(:list_public_ip_addresses, {})
|
433
|
+
.and_return(list_public_ip_addresses_response)
|
434
|
+
expect(communicator_config).to receive(:port).and_return(nil)
|
435
|
+
expect(communicator_config).to receive(:guest_port).and_return(nil)
|
436
|
+
|
437
|
+
allow(machine).to receive_message_chain(:config, :vm, :rdp, :port).and_return(3389)
|
438
|
+
allow(machine).to receive_message_chain(:config, :vm, :guest).and_return(nil)
|
439
|
+
allow(machine).to receive(:id).and_return(SERVER_ID)
|
440
|
+
|
441
|
+
allow(cosmic_compute).to receive(:send).with(:list_public_ip_addresses, 'id' => PF_IP_ADDRESS_ID)
|
442
|
+
.and_return(list_public_ip_addresses_response)
|
443
|
+
allow(cosmic_compute).to receive(:list_network_acl_lists).with(id: nil)
|
444
|
+
.and_return(list_network_acl_lists_response)
|
445
|
+
|
446
|
+
expect(file).to receive(:write).with(PORT_FORWARDING_RULE_ID + "\n")
|
447
|
+
expect(file).to receive(:write).with(PF_RANDOM_START.to_s)
|
448
|
+
expect(file).to receive(:write).with("#{ACL_ID},networkacl\n")
|
449
|
+
end
|
450
|
+
|
451
|
+
context 'for the SSH communicator' do
|
452
|
+
before(:each) do
|
453
|
+
allow(communicator).to receive_message_chain(:class, :name).and_return(COMMUNICATOR_SSH)
|
454
|
+
expect(machine).to receive_message_chain(:config, :ssh).and_return(communicator_config)
|
455
|
+
|
456
|
+
allow(communicator_config).to receive_message_chain(:default, :port).and_return(GUEST_PORT_SSH)
|
457
|
+
expect(cosmic_compute).to receive(:create_port_forwarding_rule)
|
458
|
+
.with(create_port_forwarding_rule_parameters)
|
459
|
+
.and_return(create_port_forwarding_rule_respones)
|
460
|
+
expect(cosmic_compute).to receive(:request)
|
461
|
+
.with(create_network_acl_request)
|
462
|
+
.and_return(createNetworkACL_response)
|
463
|
+
end
|
464
|
+
it 'starts a vm' do
|
465
|
+
should eq true
|
466
|
+
end
|
467
|
+
|
468
|
+
context 'with a port conflict' do
|
469
|
+
let(:pf_public_port_randomrange) { { start: PF_RANDOM_START - 1, end: PF_RANDOM_START + 1 } }
|
470
|
+
|
471
|
+
before(:each) do
|
472
|
+
allow(Kernel).to receive(:rand).with((PF_RANDOM_START - 1)...(PF_RANDOM_START + 1))
|
473
|
+
.and_return(PF_RANDOM_START - 1, PF_RANDOM_START)
|
474
|
+
expect(cosmic_compute).to receive(:create_port_forwarding_rule)
|
475
|
+
.with(create_port_forwarding_rule_parameters.merge(publicport: PF_RANDOM_START - 1))
|
476
|
+
.and_raise(
|
477
|
+
Fog::Cosmic::Compute::Error,
|
478
|
+
'The range specified, CONFLICTINGRANGE, conflicts with rule SOMERULE which has THESAME'
|
479
|
+
)
|
480
|
+
end
|
481
|
+
|
482
|
+
it 'starts a vm' do
|
483
|
+
should eq true
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context 'for the WinRM (and RDP) communicator' do
|
489
|
+
PF_RDP_RULE_ID = 'UUID RDP port forwarding rule'.freeze
|
490
|
+
PF_RDP_JOB_ID = 'UUID RDP Port Forward Job'.freeze
|
491
|
+
FW_RDP_JOB_ID = 'UUID RDP Port Firewall Job'.freeze
|
492
|
+
FW_RDP_ACL_ID = 'UUID of RDP ACL'.freeze
|
493
|
+
|
494
|
+
let(:pf_public_port_randomrange) { { start: PF_RANDOM_START, end: PF_RANDOM_START + 2 } }
|
495
|
+
|
496
|
+
let(:create_port_forwarding_rule_parameters) { super().merge(privateport: GUEST_PORT_WINRM) }
|
497
|
+
let(:create_port_forwarding_rule_rdp_parameters) do
|
498
|
+
create_port_forwarding_rule_parameters.merge(privateport: GUEST_PORT_RDP, publicport: PF_RANDOM_START + 1)
|
499
|
+
end
|
500
|
+
|
501
|
+
let(:create_network_acl_winrm_request) do
|
502
|
+
create_network_acl_request.merge(startport: GUEST_PORT_WINRM, endport: GUEST_PORT_WINRM)
|
503
|
+
end
|
504
|
+
let(:create_network_acl_rdp_request) do
|
505
|
+
create_network_acl_request.merge(startport: GUEST_PORT_RDP, endport: GUEST_PORT_RDP)
|
506
|
+
end
|
507
|
+
|
508
|
+
before(:each) do
|
509
|
+
allow(Kernel).to receive(:rand).with(PF_RANDOM_START...(PF_RANDOM_START + 2))
|
510
|
+
.and_return(PF_RANDOM_START, PF_RANDOM_START + 1)
|
511
|
+
|
512
|
+
allow(communicator).to receive_message_chain(:class, :name).and_return(COMMUNICATOR_WINRM)
|
513
|
+
expect(machine).to receive_message_chain(:config, :winrm).and_return(communicator_config)
|
514
|
+
|
515
|
+
allow(communicator_config).to receive_message_chain(:default, :port).and_return(GUEST_PORT_WINRM)
|
516
|
+
|
517
|
+
expect(cosmic_compute).to receive(:create_port_forwarding_rule)
|
518
|
+
.with(create_port_forwarding_rule_parameters)
|
519
|
+
.and_return(create_port_forwarding_rule_respones)
|
520
|
+
|
521
|
+
expect(cosmic_compute).to receive(:create_port_forwarding_rule)
|
522
|
+
.with(create_port_forwarding_rule_rdp_parameters).and_return(
|
523
|
+
'createportforwardingruleresponse' =>
|
524
|
+
{
|
525
|
+
'id' => PF_RDP_RULE_ID,
|
526
|
+
'jobid' => PF_RDP_JOB_ID
|
527
|
+
}
|
528
|
+
)
|
529
|
+
allow(cosmic_compute).to receive(:query_async_job_result).with(jobid: PF_RDP_JOB_ID)
|
530
|
+
.and_return(fake_job_result.merge(
|
531
|
+
'queryasyncjobresultresponse' => {
|
532
|
+
'jobresult' => {
|
533
|
+
'portforwardingrule' => {
|
534
|
+
'id' => PF_RDP_RULE_ID
|
535
|
+
}
|
536
|
+
}
|
537
|
+
}
|
538
|
+
))
|
539
|
+
expect(file).to receive(:write).with(PF_RDP_RULE_ID + "\n")
|
540
|
+
expect(file).to receive(:write).with((PF_RANDOM_START + 1).to_s)
|
541
|
+
expect(cosmic_compute).to receive(:request).with(create_network_acl_winrm_request)
|
542
|
+
.and_return(createNetworkACL_response)
|
543
|
+
|
544
|
+
expect(cosmic_compute).to receive(:request).with(create_network_acl_rdp_request)
|
545
|
+
.and_return(
|
546
|
+
'createnetworkaclresponse' => {
|
547
|
+
'id' => '5dcb96b5-7785-463d-9a11-d8388c98e4ee',
|
548
|
+
'jobid' => FW_RDP_JOB_ID
|
549
|
+
}
|
550
|
+
)
|
551
|
+
allow(cosmic_compute).to receive(:query_async_job_result).with(jobid: FW_RDP_JOB_ID)
|
552
|
+
.and_return(
|
553
|
+
fake_job_result.merge(
|
554
|
+
'queryasyncjobresultresponse' => {
|
555
|
+
'jobstatus' => 1,
|
556
|
+
'jobresult' => {
|
557
|
+
'networkacl' => {
|
558
|
+
'id' => FW_RDP_ACL_ID
|
559
|
+
}
|
560
|
+
}
|
561
|
+
}
|
562
|
+
)
|
563
|
+
)
|
564
|
+
expect(file).to receive(:write).with("#{FW_RDP_ACL_ID},networkacl\n")
|
565
|
+
end
|
566
|
+
it 'starts a vm' do
|
567
|
+
should eq true
|
568
|
+
end
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|
572
|
+
end
|
573
|
+
end
|