Reduce start domain unnecessary domain redefines (#1178)

Various checks in the start domain action were accidentally causing a
redefine right after initial create. Update to provide debug output when
the domain needs to be changed to allow capture of the redefines
occurring in the future and to make it easy for the tests to pick up
where the redefine was triggered by setting an expectation on the log
output.

Include a small fix to avoid running strip on what might be a nil object
returned for elements without any text attributes.

Fix a bug where changes to tpm settings made to the config after an
initial domain creation where there was previously no tpm defined, would
be ignored.

Adds a logger double and updates other tests that trigger log calls.

should fix #1176
This commit is contained in:
Darragh Bailey
2020-12-05 15:24:42 +00:00
committed by GitHub
parent c12b0de254
commit 21f7a796ff
8 changed files with 130 additions and 15 deletions

View File

@@ -26,6 +26,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::CreateDomain do
allow(connection).to receive(:servers).and_return(servers)
allow(connection).to receive(:volumes).and_return(volumes)
allow(logger).to receive(:info)
end
context 'default pool' do

View File

@@ -16,6 +16,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
let(:servers) { double('servers') }
let(:domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), test_file)) }
let(:updated_domain_xml) { File.read(File.join(File.dirname(__FILE__), File.basename(__FILE__, '.rb'), updated_test_file)) }
describe '#call' do
before do
@@ -26,6 +27,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
allow(connection).to receive(:servers).and_return(servers)
allow(servers).to receive(:get).and_return(domain)
expect(logger).to receive(:info)
end
context 'default config' do
@@ -38,12 +40,35 @@ describe VagrantPlugins::ProviderLibvirt::Action::StartDomain do
allow(libvirt_domain).to receive(:num_vcpus).and_return(1)
end
it 'should execute correctly' do
it 'should execute without changing' do
allow(libvirt_domain).to receive(:undefine)
expect(logger).to_not receive(:debug)
expect(libvirt_domain).to receive(:autostart=)
expect(domain).to receive(:start)
expect(subject.call(env)).to be_nil
end
context 'tpm_path added' do
let(:updated_test_file) { 'default_added_tpm_path.xml' }
let(:vagrantfile_providerconfig) do
<<-EOF
libvirt.tpm_path = '/dev/tpm0'
libvirt.tpm_type = 'passthrough'
libvirt.tpm_model = 'tpm-tis'
EOF
end
it 'should modify the domain tpm_path' do
expect(libvirt_domain).to receive(:undefine)
expect(logger).to receive(:debug).with('tpm created from previously not defined')
expect(servers).to receive(:create).with(xml: updated_domain_xml)
expect(libvirt_domain).to receive(:autostart=)
expect(domain).to receive(:start)
expect(subject.call(env)).to be_nil
end
end
end
end
end

View File

@@ -8,14 +8,14 @@
<cpu mode='host-model'>
<model fallback='allow'></model>
<model fallback='allow'/>
</cpu>
<os>
<type>hvm</type>
<kernel/>
<initrd></initrd>
<initrd/>
<cmdline/>
</os>
<features>

View File

@@ -0,0 +1,48 @@
<domain xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0' type=''>
<name/>
<title/>
<description/>
<uuid/>
<memory/>
<vcpu>1</vcpu>
<cpu mode='host-model'>
<model fallback='allow'/>
</cpu>
<os>
<type>hvm</type>
<kernel/>
<initrd/>
<cmdline/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<devices>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target port='0'/>
</console>
<input bus='ps2' type='mouse'/>
<graphics autoport='yes' keymap='en-us' listen='127.0.0.1' port='-1' type='vnc'/>
<video>
<model heads='1' type='cirrus' vram='9216'/>
</video>
<tpm model='tpm-tis'><backend type='passthrough'><device path='/dev/tpm0'/></backend></tpm></devices>
</domain>

View File

@@ -41,6 +41,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
it 'should exit' do
expect(app).to_not receive(:call)
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
expect(logger).to receive(:debug).with(/Searching for IP for MAC address: .*/)
expect(subject.call(env)).to be_nil
end
end
@@ -56,7 +57,6 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
expect(app).to_not receive(:call)
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
expect(ui).to receive(:info).with('Waiting for SSH to become available...')
logger = subject.instance_variable_get(:@logger)
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: .*/)
@@ -77,6 +77,10 @@ describe VagrantPlugins::ProviderLibvirt::Action::WaitTillUp do
expect(app).to receive(:call)
expect(ui).to receive(:info).with('Waiting for domain to get an IP address...')
expect(ui).to receive(:info).with('Waiting for SSH to become available...')
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: .*/)
expect(logger).to receive(:info).with(/Time for SSH ready: .*/)
expect(env[:machine].communicate).to receive(:ready?).and_return(true)
expect(subject.call(env)).to be_nil
end