mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Ensure ssh_run and ssh actions match vagrant (#1378)
Vagrant expects that providers raise specific errors if the machines are not available. Update to match the built-in providers. Fixes: #1376
This commit is contained in:
@@ -233,14 +233,12 @@ module VagrantPlugins
|
|||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use Call, IsCreated do |env, b2|
|
b.use Call, IsCreated do |env, b2|
|
||||||
unless env[:result]
|
unless env[:result]
|
||||||
b2.use MessageNotCreated
|
raise Vagrant::Errors::VMNotCreatedError
|
||||||
next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use Call, IsRunning do |env2, b3|
|
b2.use Call, IsRunning do |env2, b3|
|
||||||
unless env2[:result]
|
unless env2[:result]
|
||||||
b3.use MessageNotRunning
|
raise Vagrant::Errors::VMNotRunningError
|
||||||
next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
b3.use SSHExec
|
b3.use SSHExec
|
||||||
@@ -330,14 +328,12 @@ module VagrantPlugins
|
|||||||
b.use ConfigValidate
|
b.use ConfigValidate
|
||||||
b.use Call, IsCreated do |env, b2|
|
b.use Call, IsCreated do |env, b2|
|
||||||
unless env[:result]
|
unless env[:result]
|
||||||
b2.use MessageNotCreated
|
raise Vagrant::Errors::VMNotCreatedError
|
||||||
next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
b2.use Call, IsRunning do |env2, b3|
|
b2.use Call, IsRunning do |env2, b3|
|
||||||
unless env2[:result]
|
unless env2[:result]
|
||||||
b3.use MessageNotRunning
|
raise Vagrant::Errors::VMNotRunningError
|
||||||
next
|
|
||||||
end
|
end
|
||||||
|
|
||||||
b3.use SSHRun
|
b3.use SSHRun
|
||||||
|
|||||||
@@ -93,4 +93,82 @@ describe VagrantPlugins::ProviderLibvirt::Action do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#action_ssh' do
|
||||||
|
context 'when not created' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cause an error' do
|
||||||
|
expect{ machine.action(:ssh, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when created' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when not running' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cause an error' do
|
||||||
|
expect{ machine.action(:ssh, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotRunningError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when running' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should call SSHExec' do
|
||||||
|
expect_any_instance_of(Vagrant::Action::Builtin::SSHExec).to receive(:call).and_return(0)
|
||||||
|
expect(machine.action(:ssh, ssh_opts: {})).to match(hash_including({:action_name => :machine_action_ssh}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#action_ssh_run' do
|
||||||
|
context 'when not created' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cause an error' do
|
||||||
|
expect{ machine.action(:ssh_run, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotCreatedError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when created' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsCreated, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when not running' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cause an error' do
|
||||||
|
expect{ machine.action(:ssh_run, ssh_opts: {})}.to raise_error(Vagrant::Errors::VMNotRunningError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when running' do
|
||||||
|
before do
|
||||||
|
allow_action_env_result(VagrantPlugins::ProviderLibvirt::Action::IsRunning, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should call SSHRun' do
|
||||||
|
expect_any_instance_of(Vagrant::Action::Builtin::SSHRun).to receive(:call).and_return(0)
|
||||||
|
expect(machine.action(:ssh_run, ssh_opts: {})).to match(hash_including({:action_name => :machine_action_ssh_run}))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user