2021-06-30 13:27:03 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
require 'vagrant-libvirt/action/wait_till_up'
|
|
|
|
|
require 'vagrant-libvirt/errors'
|
2016-01-25 19:07:14 +00:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
require 'support/sharedcontext'
|
|
|
|
|
require 'support/libvirt_context'
|
2016-01-25 19:07:14 +00:00
|
|
|
|
|
|
|
|
describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
|
|
|
|
|
subject { described_class.new(app, env) }
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
include_context 'vagrant-unit'
|
|
|
|
|
include_context 'libvirt'
|
|
|
|
|
include_context 'unit'
|
2016-01-25 19:07:14 +00:00
|
|
|
|
2021-04-03 14:57:31 +01:00
|
|
|
let (:driver) { VagrantPlugins::ProviderLibvirt::Driver.new env[:machine] }
|
2021-03-13 19:55:17 +00:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
describe '#call' do
|
2016-01-26 16:28:19 +00:00
|
|
|
before do
|
2021-03-13 19:55:17 +00:00
|
|
|
allow(driver).to receive(:get_domain).and_return(domain)
|
|
|
|
|
allow(driver).to receive(:state).and_return(:running)
|
2021-11-08 11:31:04 +00:00
|
|
|
# return some information for domain when needed
|
|
|
|
|
allow(domain).to receive(:mac).and_return('9C:D5:53:F1:5A:E7')
|
2021-12-11 14:58:59 +00:00
|
|
|
|
|
|
|
|
allow(machine.provider_config).to receive(:qemu_use_session).and_return(false)
|
2016-01-26 16:28:19 +00:00
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'when machine does not exist' do
|
2016-01-25 19:07:14 +00:00
|
|
|
before do
|
2021-03-13 19:55:17 +00:00
|
|
|
allow(driver).to receive(:get_domain).and_return(nil)
|
2016-01-25 19:07:14 +00:00
|
|
|
end
|
|
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
it 'raises exception' do
|
2016-01-25 19:07:14 +00:00
|
|
|
expect(app).to_not receive(:call)
|
2016-12-06 23:20:29 +01:00
|
|
|
expect { subject.call(env) }.to raise_error(::VagrantPlugins::ProviderLibvirt::Errors::NoDomainError,
|
|
|
|
|
/No domain found. Domain dummy-vagrant_dummy not found/)
|
2016-01-25 19:07:14 +00:00
|
|
|
end
|
|
|
|
|
end
|
2015-10-14 17:29:07 +01:00
|
|
|
|
2016-12-06 23:20:29 +01:00
|
|
|
context 'when machine is booting' do
|
|
|
|
|
context 'if interrupted looking for IP' do
|
2015-10-14 17:29:07 +01:00
|
|
|
before do
|
|
|
|
|
env[:interrupted] = true
|
|
|
|
|
end
|
2016-12-06 23:20:29 +01:00
|
|
|
it 'should exit' do
|
2015-10-14 17:29:07 +01:00
|
|
|
expect(app).to_not receive(:call)
|
2016-12-06 23:20:29 +01:00
|
|
|
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
|
2020-12-05 15:24:42 +00:00
|
|
|
expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
|
2015-10-14 17:29:07 +01:00
|
|
|
expect(subject.call(env)).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2021-04-03 14:57:31 +01:00
|
|
|
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 {subject.call(env) }.to raise_error(::Fog::Errors::TimeoutError)
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-10-14 17:29:07 +01:00
|
|
|
end
|
2016-01-26 16:28:19 +00:00
|
|
|
|
2021-05-20 13:36:23 +01:00
|
|
|
context 'when machine boots and ip available' do
|
2016-01-26 16:28:19 +00:00
|
|
|
before do
|
2016-01-26 16:58:17 +00:00
|
|
|
allow(domain).to receive(:wait_for).and_return(true)
|
2016-01-26 16:28:19 +00:00
|
|
|
allow(env).to receive(:[]).and_call_original
|
|
|
|
|
allow(env).to receive(:[]).with(:interrupted).and_return(false)
|
2022-09-28 18:40:32 +01:00
|
|
|
allow(driver).to receive(:get_ipaddress).and_return('192.168.121.2')
|
2016-01-26 16:28:19 +00:00
|
|
|
end
|
2016-12-06 23:20:29 +01:00
|
|
|
it 'should call the next hook' do
|
2016-01-26 16:28:19 +00:00
|
|
|
expect(app).to receive(:call)
|
2016-12-06 23:20:29 +01:00
|
|
|
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
|
2020-12-05 15:24:42 +00:00
|
|
|
expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
|
|
|
|
|
expect(logger).to receive(:info).with('Got IP address 192.168.121.2')
|
|
|
|
|
expect(logger).to receive(:info).with(/Time for getting IP: .*/)
|
2016-01-26 16:28:19 +00:00
|
|
|
expect(subject.call(env)).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-01-25 19:07:14 +00:00
|
|
|
end
|
|
|
|
|
end
|