mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Update HaltDomain spec to cover updated implementation
This commit is contained in:
committed by
Darragh Bailey
parent
64d087d2f9
commit
44d7c5526d
@@ -20,72 +20,39 @@ describe VagrantPlugins::ProviderLibvirt::Action::HaltDomain do
|
||||
.to receive(:connection).and_return(connection)
|
||||
allow(connection).to receive(:servers).and_return(servers)
|
||||
allow(servers).to receive(:get).and_return(domain)
|
||||
# always see this at the start of #call
|
||||
expect(ui).to receive(:info).with('Halting domain...')
|
||||
allow(ui).to receive(:info).with('Halting domain...')
|
||||
end
|
||||
|
||||
context 'with graceful timeout' do
|
||||
it "should shutdown" do
|
||||
expect(guest).to receive(:capability).with(:halt).and_return(true)
|
||||
expect(domain).to receive(:wait_for).with(60).and_return(false)
|
||||
expect(subject.call(env)).to be_nil
|
||||
context "when state is not running" do
|
||||
before { expect(domain).to receive(:state).at_least(1).
|
||||
and_return('not_created') }
|
||||
|
||||
it "should not poweroff when state is not running" do
|
||||
expect(domain).not_to receive(:poweroff)
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
context 'when halt fails' do
|
||||
before do
|
||||
expect(logger).to receive(:info).with('Trying Libvirt graceful shutdown.')
|
||||
expect(guest).to receive(:capability).with(:halt).and_raise(IOError)
|
||||
expect(domain).to receive(:state).and_return('running')
|
||||
end
|
||||
|
||||
it "should call shutdown" do
|
||||
expect(domain).to receive(:shutdown)
|
||||
expect(domain).to receive(:wait_for).with(60).and_return(false)
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
|
||||
context 'when shutdown fails' do
|
||||
it "should call power off" do
|
||||
expect(logger).to receive(:error).with('Failed to shutdown cleanly. Calling force poweroff.')
|
||||
expect(domain).to receive(:shutdown).and_raise(IOError)
|
||||
expect(domain).to receive(:poweroff)
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when shutdown exceeds the timeout' do
|
||||
it "should call poweroff" do
|
||||
expect(logger).to receive(:info).with('VM is still running. Calling force poweroff.')
|
||||
expect(domain).to receive(:shutdown).and_raise(Timeout::Error)
|
||||
expect(domain).to receive(:poweroff)
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when halt exceeds the timeout' do
|
||||
before do
|
||||
expect(logger).to_not receive(:info).with('Trying Libvirt graceful shutdown.')
|
||||
expect(guest).to receive(:capability).with(:halt).and_raise(Timeout::Error)
|
||||
end
|
||||
|
||||
it "should call poweroff" do
|
||||
expect(logger).to receive(:info).with('VM is still running. Calling force poweroff.')
|
||||
expect(domain).to receive(:poweroff)
|
||||
expect(subject.call(env)).to be_nil
|
||||
end
|
||||
it "should not print halting message" do
|
||||
expect(ui).not_to receive(:info)
|
||||
subject.call(env)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with force halt enabled' do
|
||||
context "when state is running" do
|
||||
before do
|
||||
allow(env).to receive(:[]).and_call_original
|
||||
expect(env).to receive(:[]).with(:force_halt).and_return(true)
|
||||
expect(domain).to receive(:state).at_least(1).
|
||||
and_return('running')
|
||||
allow(domain).to receive(:poweroff)
|
||||
end
|
||||
|
||||
it "should just call poweroff" do
|
||||
it "should poweroff" do
|
||||
expect(domain).to receive(:poweroff)
|
||||
expect(subject.call(env)).to be_nil
|
||||
subject.call(env)
|
||||
end
|
||||
|
||||
it "should print halting message" do
|
||||
expect(ui).to receive(:info).with('Halting domain...')
|
||||
subject.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user