Added fix for issue #1472 (#1473)

Avoid crash caused by power management suspension where fog fails to translate domain state pmsuspended.

Changed the driver.state() function so that it does not crash on undefined domain state. Just return nil :unknown instead.

Added unittests and made existing more general.

Closes #1472
This commit is contained in:
ebaklund
2022-04-04 10:58:10 +02:00
committed by GitHub
parent 55a220f1c8
commit 008e910856
2 changed files with 19 additions and 8 deletions

View File

@@ -135,7 +135,9 @@ module VagrantPlugins
end end
# TODO: terminated no longer appears to be a valid fog state, remove? # TODO: terminated no longer appears to be a valid fog state, remove?
return :not_created if domain.nil? || domain.state.to_sym == :terminated return :not_created if domain.nil?
return :unknown if domain.state.nil?
return :not_created if domain.state.to_sym == :terminated
state = domain.state.tr('-', '_').to_sym state = domain.state.tr('-', '_').to_sym
if state == :running if state == :running

View File

@@ -35,10 +35,10 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
# name for the test machines above. # name for the test machines above.
let(:machine) { iso_env.machine(:test1, :libvirt) } let(:machine) { iso_env.machine(:test1, :libvirt) }
let(:machine2) { iso_env.machine(:test2, :libvirt) } let(:machine2) { iso_env.machine(:test2, :libvirt) }
let(:connection1) { double("connection 1") } let(:connection1) { double("connection 1") }
let(:connection2) { double("connection 2") } let(:connection2) { double("connection 2") }
let(:system_connection1) { double("system connection 1") } let(:system_connection1) { double("system connection 1") }
let(:system_connection2) { double("system connection 2") } let(:system_connection2) { double("system connection 2") }
# make it easier for distros that want to switch the default value for # make it easier for distros that want to switch the default value for
# qemu_use_session to true by ensuring it is explicitly false for tests. # qemu_use_session to true by ensuring it is explicitly false for tests.
@@ -245,12 +245,21 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
end, end,
} }
], ],
[
nil,
:unknown,
{
:setup => ProcWithBinding.new do
expect(domain).to receive(:state).and_return('unknown').at_least(:once)
end,
}
],
[ [
'terminated', 'terminated',
:not_created, :not_created,
{ {
:setup => ProcWithBinding.new do :setup => ProcWithBinding.new do
expect(domain).to receive(:state).and_return('terminated') expect(domain).to receive(:state).and_return('terminated').at_least(:once)
end, end,
} }
], ],
@@ -259,7 +268,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
:inaccessible, :inaccessible,
{ {
:setup => ProcWithBinding.new do :setup => ProcWithBinding.new do
expect(domain).to receive(:state).and_return('running').twice() expect(domain).to receive(:state).and_return('running').at_least(:once)
expect(subject).to receive(:get_domain_ipaddress).and_raise(Fog::Errors::TimeoutError) expect(subject).to receive(:get_domain_ipaddress).and_raise(Fog::Errors::TimeoutError)
end, end,
} }
@@ -269,7 +278,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
:running, :running,
{ {
:setup => ProcWithBinding.new do :setup => ProcWithBinding.new do
expect(domain).to receive(:state).and_return('running').twice() expect(domain).to receive(:state).and_return('running').at_least(:once)
expect(subject).to receive(:get_domain_ipaddress).and_return('192.168.121.2') expect(subject).to receive(:get_domain_ipaddress).and_return('192.168.121.2')
end, end,
} }