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
# 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
if state == :running

View File

@@ -245,12 +245,21 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
end,
}
],
[
nil,
:unknown,
{
:setup => ProcWithBinding.new do
expect(domain).to receive(:state).and_return('unknown').at_least(:once)
end,
}
],
[
'terminated',
:not_created,
{
:setup => ProcWithBinding.new do
expect(domain).to receive(:state).and_return('terminated')
expect(domain).to receive(:state).and_return('terminated').at_least(:once)
end,
}
],
@@ -259,7 +268,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
:inaccessible,
{
: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)
end,
}
@@ -269,7 +278,7 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
:running,
{
: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')
end,
}