Skip to content

Commit 3210266

Browse files
committed
Testing improvements
1 parent 3b307fe commit 3210266

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ GEM
4646
erubis (2.7.0)
4747
excon (0.62.0)
4848
ffi (1.9.23)
49+
ffi (1.9.23-x64-mingw32)
4950
fission (0.5.0)
5051
CFPropertyList (~> 2.2)
5152
fog (2.0.0)
@@ -230,6 +231,8 @@ GEM
230231
net-ssh (4.2.0)
231232
nokogiri (1.8.2)
232233
mini_portile2 (~> 2.3.0)
234+
nokogiri (1.8.2-x64-mingw32)
235+
mini_portile2 (~> 2.3.0)
233236
nori (2.6.0)
234237
rake (10.5.0)
235238
rb-fsevent (0.10.3)
@@ -291,6 +294,7 @@ GEM
291294

292295
PLATFORMS
293296
ruby
297+
x64-mingw32
294298

295299
DEPENDENCIES
296300
coveralls

lib/vagrant-cloudstack/action/run_instance.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def get_communicator_connect_attempts(communicator)
388388
'VagrantPlugins::CommunicatorSSH::Communicator' => 40,
389389
'VagrantPlugins::CommunicatorWinRM::Communicator' => 1
390390
}
391-
communicator_connect_attempts[communicator.class.name]
391+
return communicator_connect_attempts[communicator.class.name].nil? ? 1 : communicator_connect_attempts[communicator.class.name]
392392
end
393393

394394
def evaluate_pf_private_port
@@ -498,9 +498,8 @@ def apply_port_forwarding_rule(rule)
498498
if response['queryasyncjobresultresponse']['jobstatus'] != 0
499499
port_forwarding_rule = response['queryasyncjobresultresponse']['jobresult']['portforwardingrule']
500500
break
501-
else
502-
sleep 2
503501
end
502+
sleep 2
504503
end
505504
rescue Fog::Compute::Cloudstack::Error => e
506505
raise Errors::FogError, :message => e.message
@@ -727,9 +726,8 @@ def apply_firewall_rule(acl_name, options, response_string, type_string)
727726
if response['queryasyncjobresultresponse']['jobstatus'] != 0
728727
firewall_rule = response['queryasyncjobresultresponse']['jobresult'][type_string]
729728
break
730-
else
731-
sleep 2
732729
end
730+
sleep 2
733731
end
734732
rescue Fog::Compute::Cloudstack::Error => e
735733
if e.message =~ /The range specified,.*conflicts with rule/
@@ -772,7 +770,6 @@ def wait_for_password
772770
if @server.respond_to?('job_id')
773771
server_job_result = @env[:cloudstack_compute].query_async_job_result({:jobid => @server.job_id})
774772
if server_job_result.nil?
775-
@env[:ui].warn(' -- Failed to retrieve job_result')
776773
raise 'ERROR -- Failed to retrieve job_result'
777774
end
778775

@@ -781,9 +778,8 @@ def wait_for_password
781778
if server_job_result['queryasyncjobresultresponse']['jobstatus'] != 0
782779
password = server_job_result['queryasyncjobresultresponse']['jobresult']['virtualmachine']['password']
783780
break
784-
else
785-
sleep 2
786781
end
782+
sleep 2
787783
end
788784

789785
@env[:ui].info("Password of virtualmachine: #{password}")

spec/vagrant-cloudstack/action/run_instance_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,11 @@
260260

261261
allow(machine).to receive(:provider_config).and_return(provider_config)
262262
expect(server).to receive(:wait_for).and_return(ready = true)
263-
allow(server).to receive(:password_enabled).and_return(false)
263+
allow(server).to receive(:password_enabled).and_return(true)
264+
allow(server).to receive(:job_id).and_return(JOB_ID)
265+
266+
expect(file).to receive(:write).with(GENERATED_PASSWORD)
267+
allow(cloudstack_compute).to receive(:query_async_job_result).with(jobid: JOB_ID).and_return(fake_job_result)
264268
expect(cloudstack_compute).to receive(:servers).and_return(servers)
265269
allow(cloudstack_compute).to receive(:send).with(:list_zones, available: true).and_return(list_zones_response)
266270
allow(cloudstack_compute).to receive(:send).with(:list_service_offerings, listall: true)
@@ -289,6 +293,7 @@
289293
cfg.ssh_key = ssh_key
290294
cfg.security_groups = security_groups
291295
cfg.network_name = network_name
296+
cfg.vm_password = GENERATED_PASSWORD
292297
end
293298
config.finalize!
294299
config.get_domain_config(:cloudstack)
@@ -354,8 +359,8 @@
354359
should eq true
355360
end
356361
end
357-
end
358-
362+
end
363+
359364
context 'in advanced zone' do
360365
let(:pf_ip_address) { nil }
361366
let(:pf_trusted_networks) { nil }
@@ -377,6 +382,7 @@
377382
cfg.pf_open_firewall = pf_open_firewall
378383
cfg.ssh_key = ssh_key
379384
cfg.disk_offering_name = disk_offering_name
385+
cfg.vm_password = GENERATED_PASSWORD
380386
end
381387
config.finalize!
382388
config.get_domain_config(:cloudstack)
@@ -385,8 +391,6 @@
385391
let(:winrm_config) { double('VagrantPlugins::VagrantWinRM::WinRMConfig') }
386392

387393
before(:each) do
388-
allow(cloudstack_compute).to receive(:query_async_job_result).with(jobid: JOB_ID).and_return(fake_job_result)
389-
390394
allow(cloudstack_compute).to receive(:send).with(:list_networks, {}).and_return(list_networks_response)
391395
end
392396

@@ -427,11 +431,9 @@
427431
end
428432
end
429433

430-
context 'with generated password' do
434+
context 'with static password' do
431435
before(:each) do
432-
expect(server).to receive(:password_enabled).and_return(true)
433-
allow(server).to receive(:job_id).and_return(JOB_ID)
434-
expect(file).to receive(:write).with(GENERATED_PASSWORD)
436+
expect(server).to receive(:password_enabled).and_return(false)
435437
end
436438

437439
it 'starts a vm' do
@@ -606,4 +608,4 @@
606608
end
607609
end
608610
end
609-
end
611+
end

0 commit comments

Comments
 (0)