Skip to content

Commit

Permalink
Testing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbertJanSW committed Sep 7, 2018
1 parent 3b307fe commit 3210266
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GEM
erubis (2.7.0)
excon (0.62.0)
ffi (1.9.23)
ffi (1.9.23-x64-mingw32)
fission (0.5.0)
CFPropertyList (~> 2.2)
fog (2.0.0)
Expand Down Expand Up @@ -230,6 +231,8 @@ GEM
net-ssh (4.2.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
nokogiri (1.8.2-x64-mingw32)
mini_portile2 (~> 2.3.0)
nori (2.6.0)
rake (10.5.0)
rb-fsevent (0.10.3)
Expand Down Expand Up @@ -291,6 +294,7 @@ GEM

PLATFORMS
ruby
x64-mingw32

DEPENDENCIES
coveralls
Expand Down
12 changes: 4 additions & 8 deletions lib/vagrant-cloudstack/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def get_communicator_connect_attempts(communicator)
'VagrantPlugins::CommunicatorSSH::Communicator' => 40,
'VagrantPlugins::CommunicatorWinRM::Communicator' => 1
}
communicator_connect_attempts[communicator.class.name]
return communicator_connect_attempts[communicator.class.name].nil? ? 1 : communicator_connect_attempts[communicator.class.name]
end

def evaluate_pf_private_port
Expand Down Expand Up @@ -498,9 +498,8 @@ def apply_port_forwarding_rule(rule)
if response['queryasyncjobresultresponse']['jobstatus'] != 0
port_forwarding_rule = response['queryasyncjobresultresponse']['jobresult']['portforwardingrule']
break
else
sleep 2
end
sleep 2
end
rescue Fog::Compute::Cloudstack::Error => e
raise Errors::FogError, :message => e.message
Expand Down Expand Up @@ -727,9 +726,8 @@ def apply_firewall_rule(acl_name, options, response_string, type_string)
if response['queryasyncjobresultresponse']['jobstatus'] != 0
firewall_rule = response['queryasyncjobresultresponse']['jobresult'][type_string]
break
else
sleep 2
end
sleep 2
end
rescue Fog::Compute::Cloudstack::Error => e
if e.message =~ /The range specified,.*conflicts with rule/
Expand Down Expand Up @@ -772,7 +770,6 @@ def wait_for_password
if @server.respond_to?('job_id')
server_job_result = @env[:cloudstack_compute].query_async_job_result({:jobid => @server.job_id})
if server_job_result.nil?
@env[:ui].warn(' -- Failed to retrieve job_result')
raise 'ERROR -- Failed to retrieve job_result'
end

Expand All @@ -781,9 +778,8 @@ def wait_for_password
if server_job_result['queryasyncjobresultresponse']['jobstatus'] != 0
password = server_job_result['queryasyncjobresultresponse']['jobresult']['virtualmachine']['password']
break
else
sleep 2
end
sleep 2
end

@env[:ui].info("Password of virtualmachine: #{password}")
Expand Down
22 changes: 12 additions & 10 deletions spec/vagrant-cloudstack/action/run_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@

allow(machine).to receive(:provider_config).and_return(provider_config)
expect(server).to receive(:wait_for).and_return(ready = true)
allow(server).to receive(:password_enabled).and_return(false)
allow(server).to receive(:password_enabled).and_return(true)
allow(server).to receive(:job_id).and_return(JOB_ID)

expect(file).to receive(:write).with(GENERATED_PASSWORD)
allow(cloudstack_compute).to receive(:query_async_job_result).with(jobid: JOB_ID).and_return(fake_job_result)
expect(cloudstack_compute).to receive(:servers).and_return(servers)
allow(cloudstack_compute).to receive(:send).with(:list_zones, available: true).and_return(list_zones_response)
allow(cloudstack_compute).to receive(:send).with(:list_service_offerings, listall: true)
Expand Down Expand Up @@ -289,6 +293,7 @@
cfg.ssh_key = ssh_key
cfg.security_groups = security_groups
cfg.network_name = network_name
cfg.vm_password = GENERATED_PASSWORD
end
config.finalize!
config.get_domain_config(:cloudstack)
Expand Down Expand Up @@ -354,8 +359,8 @@
should eq true
end
end
end

end
context 'in advanced zone' do
let(:pf_ip_address) { nil }
let(:pf_trusted_networks) { nil }
Expand All @@ -377,6 +382,7 @@
cfg.pf_open_firewall = pf_open_firewall
cfg.ssh_key = ssh_key
cfg.disk_offering_name = disk_offering_name
cfg.vm_password = GENERATED_PASSWORD
end
config.finalize!
config.get_domain_config(:cloudstack)
Expand All @@ -385,8 +391,6 @@
let(:winrm_config) { double('VagrantPlugins::VagrantWinRM::WinRMConfig') }

before(:each) do
allow(cloudstack_compute).to receive(:query_async_job_result).with(jobid: JOB_ID).and_return(fake_job_result)

allow(cloudstack_compute).to receive(:send).with(:list_networks, {}).and_return(list_networks_response)
end

Expand Down Expand Up @@ -427,11 +431,9 @@
end
end

context 'with generated password' do
context 'with static password' do
before(:each) do
expect(server).to receive(:password_enabled).and_return(true)
allow(server).to receive(:job_id).and_return(JOB_ID)
expect(file).to receive(:write).with(GENERATED_PASSWORD)
expect(server).to receive(:password_enabled).and_return(false)
end

it 'starts a vm' do
Expand Down Expand Up @@ -606,4 +608,4 @@
end
end
end
end
end

0 comments on commit 3210266

Please sign in to comment.