diff --git a/lib/vagrant-libvirt/driver.rb b/lib/vagrant-libvirt/driver.rb index b9beb39..663d38d 100644 --- a/lib/vagrant-libvirt/driver.rb +++ b/lib/vagrant-libvirt/driver.rb @@ -97,11 +97,13 @@ module VagrantPlugins return get_ipaddress_from_system domain.mac end - # Get IP address from arp table + # Get IP address from dhcp leases table begin ip_address = get_ipaddress_from_domain(domain) rescue Fog::Errors::TimeoutError @logger.info('Timeout at waiting for an ip address for machine %s' % machine.name) + + raise end unless ip_address diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb index 5d14445..f4b3e38 100644 --- a/lib/vagrant-libvirt/plugin.rb +++ b/lib/vagrant-libvirt/plugin.rb @@ -26,6 +26,7 @@ module VagrantPlugins end action_hook(:remove_libvirt_image) do |hook| + require_relative 'action' hook.after Vagrant::Action::Builtin::BoxRemove, Action.remove_libvirt_image end diff --git a/spec/unit/action/wait_till_up_spec.rb b/spec/unit/action/wait_till_up_spec.rb index 60f83f3..09a248d 100644 --- a/spec/unit/action/wait_till_up_spec.rb +++ b/spec/unit/action/wait_till_up_spec.rb @@ -12,7 +12,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do include_context 'libvirt' include_context 'unit' - let (:driver) { double('driver') } + let (:driver) { VagrantPlugins::ProviderLibvirt::Driver.new env[:machine] } describe '#call' do before do @@ -47,6 +47,24 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do end end + context 'multiple timeouts waiting for IP' do + before do + allow(env).to receive(:[]).and_call_original + allow(env).to receive(:[]).with(:interrupted).and_return(false) + allow(logger).to receive(:debug) + allow(logger).to receive(:info) + end + + it 'should abort after hitting limit' do + expect(domain).to receive(:wait_for).at_least(300).times.and_raise(::Fog::Errors::TimeoutError) + expect(app).to_not receive(:call) + expect(ui).to receive(:info).with('Waiting for domain to get an IP address...') + expect(ui).to_not receive(:info).with('Waiting for SSH to become available...') + expect(env[:machine].communicate).to_not receive(:ready?) + expect {subject.call(env) }.to raise_error(::Fog::Errors::TimeoutError) + end + end + context 'if interrupted waiting for SSH' do before do allow(domain).to receive(:wait_for).and_return(true)