mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
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:
@@ -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
|
||||
|
||||
@@ -35,10 +35,10 @@ describe VagrantPlugins::ProviderLibvirt::Driver do
|
||||
# name for the test machines above.
|
||||
let(:machine) { iso_env.machine(:test1, :libvirt) }
|
||||
let(:machine2) { iso_env.machine(:test2, :libvirt) }
|
||||
let(:connection1) { double("connection 1") }
|
||||
let(:connection2) { double("connection 2") }
|
||||
let(:system_connection1) { double("system connection 1") }
|
||||
let(:system_connection2) { double("system connection 2") }
|
||||
let(:connection1) { double("connection 1") }
|
||||
let(:connection2) { double("connection 2") }
|
||||
let(:system_connection1) { double("system connection 1") }
|
||||
let(:system_connection2) { double("system connection 2") }
|
||||
|
||||
# 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.
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user