Consolidate ip address retreival to single method (#1199)

Refactor WaitTillUp action to make use of the domain IP address
retrieval code in the driver to ensure a single place to maintain.

Remove references to machine option for driver where already should be
available as an instance variable.
This commit is contained in:
Darragh Bailey
2021-03-13 19:55:17 +00:00
committed by GitHub
parent e6ae883ec3
commit c8c590f586
4 changed files with 63 additions and 67 deletions

View File

@@ -12,18 +12,19 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
include_context 'libvirt'
include_context 'unit'
let (:driver) { double('driver') }
describe '#call' do
before do
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
.to receive(:get_domain).and_return(domain)
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver).to receive(:state)
.and_return(:running)
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Provider).to receive(:driver)
.and_return(driver)
allow(driver).to receive(:get_domain).and_return(domain)
allow(driver).to receive(:state).and_return(:running)
end
context 'when machine does not exist' do
before do
allow_any_instance_of(VagrantPlugins::ProviderLibvirt::Driver)
.to receive(:get_domain).and_return(nil)
allow(driver).to receive(:get_domain).and_return(nil)
end
it 'raises exception' do
@@ -51,7 +52,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
allow(domain).to receive(:wait_for).and_return(true)
allow(env).to receive(:[]).and_call_original
allow(env).to receive(:[]).with(:interrupted).and_return(false, true, true)
allow(env).to receive(:[]).with(:ip_address).and_return('192.168.121.2')
allow(driver).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
end
it 'should exit after getting IP' do
expect(app).to_not receive(:call)
@@ -71,7 +72,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
allow(domain).to receive(:wait_for).and_return(true)
allow(env).to receive(:[]).and_call_original
allow(env).to receive(:[]).with(:interrupted).and_return(false)
allow(env).to receive(:[]).with(:ip_address).and_return('192.168.121.2')
allow(driver).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
end
it 'should call the next hook' do
expect(app).to receive(:call)