vagrant-proxmox 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sanity_checks.rb +1 -1
- data/lib/vagrant-proxmox.rb +1 -2
- data/lib/vagrant-proxmox/action.rb +133 -86
- data/lib/vagrant-proxmox/action/connect_proxmox.rb +10 -10
- data/lib/vagrant-proxmox/action/create_vm.rb +33 -28
- data/lib/vagrant-proxmox/action/destroy_vm.rb +10 -6
- data/lib/vagrant-proxmox/action/get_node_list.rb +8 -6
- data/lib/vagrant-proxmox/action/is_created.rb +1 -0
- data/lib/vagrant-proxmox/action/is_stopped.rb +1 -0
- data/lib/vagrant-proxmox/action/message_file_not_found.rb +21 -0
- data/lib/vagrant-proxmox/action/message_not_running.rb +20 -0
- data/lib/vagrant-proxmox/action/message_upload_server_error.rb +20 -0
- data/lib/vagrant-proxmox/action/proxmox_action.rb +6 -22
- data/lib/vagrant-proxmox/action/read_ssh_info.rb +1 -0
- data/lib/vagrant-proxmox/action/read_state.rb +11 -14
- data/lib/vagrant-proxmox/action/select_node.rb +23 -0
- data/lib/vagrant-proxmox/action/shutdown_vm.rb +8 -8
- data/lib/vagrant-proxmox/action/start_vm.rb +20 -12
- data/lib/vagrant-proxmox/action/stop_vm.rb +9 -8
- data/lib/vagrant-proxmox/action/sync_folders.rb +1 -1
- data/lib/vagrant-proxmox/action/upload_iso_file.rb +38 -0
- data/lib/vagrant-proxmox/action/upload_template_file.rb +38 -0
- data/lib/vagrant-proxmox/config.rb +85 -5
- data/lib/vagrant-proxmox/errors.rb +22 -2
- data/lib/vagrant-proxmox/plugin.rb +0 -14
- data/lib/vagrant-proxmox/proxmox/connection.rb +217 -0
- data/lib/vagrant-proxmox/proxmox/errors.rb +23 -0
- data/lib/vagrant-proxmox/version.rb +1 -1
- data/locales/en.yml +29 -2
- data/spec/actions/cleanup_after_destroy_action_spec.rb +2 -2
- data/spec/actions/connect_proxmox_action_spec.rb +32 -15
- data/spec/actions/create_vm_action_spec.rb +155 -130
- data/spec/actions/destroy_vm_action_spec.rb +50 -23
- data/spec/actions/get_node_list_action_spec.rb +25 -12
- data/spec/actions/is_created_action_spec.rb +8 -8
- data/spec/actions/is_stopped_action_spec.rb +8 -8
- data/spec/actions/message_already_running_action_spec.rb +2 -2
- data/spec/actions/message_already_stopped_action_spec.rb +2 -2
- data/spec/actions/message_file_not_found_spec.rb +23 -0
- data/spec/actions/message_not_created_action_spec.rb +2 -2
- data/spec/actions/message_not_running_action_spec.rb +23 -0
- data/spec/actions/message_upload_server_error_spec.rb +23 -0
- data/spec/actions/proxmox_action_shared.rb +0 -64
- data/spec/actions/proxmox_action_spec.rb +57 -0
- data/spec/actions/read_ssh_info_action_spec.rb +6 -6
- data/spec/actions/read_state_action_spec.rb +36 -34
- data/spec/actions/select_node_spec.rb +33 -0
- data/spec/actions/shutdown_vm_action_spec.rb +50 -22
- data/spec/actions/start_vm_action_spec.rb +87 -33
- data/spec/actions/stop_vm_action_spec.rb +50 -23
- data/spec/actions/sync_folders_action_spec.rb +9 -9
- data/spec/actions/upload_iso_file_action_spec.rb +70 -0
- data/spec/actions/upload_template_file_action_spec.rb +70 -0
- data/spec/commands/destroy_command_spec.rb +25 -25
- data/spec/commands/halt_command_spec.rb +17 -17
- data/spec/commands/provision_command_spec.rb +22 -9
- data/spec/commands/ssh_command_spec.rb +18 -5
- data/spec/commands/ssh_run_command_spec.rb +19 -6
- data/spec/commands/status_command_spec.rb +2 -2
- data/spec/commands/up_command_spec.rb +174 -34
- data/spec/config_spec.rb +325 -46
- data/spec/plugin_spec.rb +1 -8
- data/spec/provider_spec.rb +4 -4
- data/spec/proxmox/connection_spec.rb +662 -0
- data/spec/proxmox/rest_call_shared.rb +41 -0
- data/spec/sanity_checks_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -97
- data/spec/spec_helpers/common_helpers.rb +111 -0
- data/spec/spec_helpers/time_helpers.rb +90 -0
- metadata +161 -45
@@ -6,7 +6,7 @@ describe VagrantPlugins::Proxmox::Action::ReadSSHInfo do
|
|
6
6
|
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
7
7
|
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox)} }
|
8
8
|
|
9
|
-
subject { described_class.new(-> (_) {}, environment) }
|
9
|
+
subject(:action) { described_class.new(-> (_) {}, environment) }
|
10
10
|
|
11
11
|
describe '#call' do
|
12
12
|
|
@@ -14,16 +14,16 @@ describe VagrantPlugins::Proxmox::Action::ReadSSHInfo do
|
|
14
14
|
|
15
15
|
context 'when no ip address is configured' do
|
16
16
|
it 'should write no ssh info into env[:machine_ssh_info]' do
|
17
|
-
|
18
|
-
env[:machine_ssh_info].
|
17
|
+
action.call env
|
18
|
+
expect(env[:machine_ssh_info]).to eq(nil)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'when an ip address is configured' do
|
23
|
-
before { env[:machine].config.vm.
|
23
|
+
before { allow(env[:machine].config.vm).to receive(:networks) { [[:public_network, {ip: '127.0.0.1'}]] } }
|
24
24
|
it 'should write the ssh info into env[:machine_ssh_info]' do
|
25
|
-
|
26
|
-
env[:machine_ssh_info].
|
25
|
+
action.call env
|
26
|
+
expect(env[:machine_ssh_info]).to eq({host: '127.0.0.1', port: 22})
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -1,52 +1,54 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'actions/proxmox_action_shared'
|
3
3
|
|
4
|
-
|
4
|
+
module VagrantPlugins::Proxmox
|
5
5
|
|
6
|
-
|
7
|
-
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox)} }
|
6
|
+
describe VagrantPlugins::Proxmox::Action::ReadState do
|
8
7
|
|
9
|
-
|
8
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
9
|
+
let(:connection) { Connection.new 'https://proxmox.example.com/api2/json' }
|
10
|
+
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox), proxmox_connection: connection} }
|
11
|
+
let(:node) { 'localhost' }
|
12
|
+
let(:vm_id) { '100' }
|
13
|
+
let(:machine_id) { "#{node}/#{vm_id}" }
|
10
14
|
|
11
|
-
|
15
|
+
subject(:action) { described_class.new(-> (_) {}, environment) }
|
12
16
|
|
13
|
-
|
17
|
+
before do
|
18
|
+
allow(env[:machine]).to receive(:id) { machine_id }
|
19
|
+
allow(connection).to receive :get_vm_state
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#call' do
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
24
|
+
it_behaves_like 'a proxmox action call'
|
25
|
+
|
26
|
+
it 'should store the machine state in env[:machine_state_id]' do
|
27
|
+
expect(connection).to receive(:get_vm_state).and_return :running
|
28
|
+
action.call env
|
29
|
+
expect(env[:machine_state_id]).to eq(:running)
|
19
30
|
end
|
20
|
-
end
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
RestClient.should_receive(:get).with('https://your.proxmox.server/api2/json/nodes/localhost/openvz/100/status/current', anything).
|
26
|
-
and_raise(RestClient::InternalServerError)
|
27
|
-
subject.call env
|
28
|
-
env[:machine_state_id].should == :not_created
|
32
|
+
it 'should call get_vm_state with the node and vm_id' do
|
33
|
+
expect(connection).to receive(:get_vm_state).with vm_id
|
34
|
+
action.call env
|
29
35
|
end
|
30
|
-
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
env[:machine_state_id].should == :stopped
|
37
|
+
context 'when no machine id is defined' do
|
38
|
+
let(:machine_id) { nil }
|
39
|
+
it 'should [:machine_state_id] to :not_created' do
|
40
|
+
action.call env
|
41
|
+
expect(env[:machine_state_id]).to eq(:not_created)
|
42
|
+
end
|
39
43
|
end
|
40
|
-
end
|
41
44
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
subject.call env
|
48
|
-
env[:machine_state_id].should == :running
|
45
|
+
context 'when the server communication fails' do
|
46
|
+
before { allow(connection).to receive(:get_vm_state).and_raise ApiError::ConnectionError }
|
47
|
+
it 'should raise an error' do
|
48
|
+
expect { action.call env }.to raise_error Errors::CommunicationError
|
49
|
+
end
|
49
50
|
end
|
51
|
+
|
50
52
|
end
|
51
53
|
|
52
54
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'actions/proxmox_action_shared'
|
3
|
+
|
4
|
+
module VagrantPlugins::Proxmox
|
5
|
+
|
6
|
+
describe VagrantPlugins::Proxmox::Action::SelectNode do
|
7
|
+
|
8
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
9
|
+
let(:connection) { Connection.new 'https://proxmox.example.com/api2/json' }
|
10
|
+
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
11
|
+
proxmox_connection: connection, proxmox_nodes: nodes} }
|
12
|
+
let(:nodes) { ['node1', 'node2'] }
|
13
|
+
|
14
|
+
subject(:action) { described_class.new(-> (_) {}, environment) }
|
15
|
+
|
16
|
+
describe '#call' do
|
17
|
+
|
18
|
+
before do
|
19
|
+
allow(nodes).to receive(:sample).and_return 'node2'
|
20
|
+
end
|
21
|
+
|
22
|
+
it_behaves_like 'a proxmox action call'
|
23
|
+
|
24
|
+
it 'randomly selects a node from the list of available nodes' do
|
25
|
+
action.call env
|
26
|
+
expect(env[:proxmox_selected_node]).to eq('node2')
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -1,35 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'actions/proxmox_action_shared'
|
3
3
|
|
4
|
-
|
4
|
+
module VagrantPlugins::Proxmox
|
5
5
|
|
6
|
-
|
7
|
-
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
8
|
-
proxmox_nodes: [{node: 'localhost'}],
|
9
|
-
ui: double('ui').as_null_object} }
|
6
|
+
describe Action::ShutdownVm do
|
10
7
|
|
11
|
-
|
8
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
9
|
+
let(:connection) { Connection.new 'https://proxmox.example.com/api2/json' }
|
10
|
+
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
11
|
+
ui: double('ui').as_null_object,
|
12
|
+
proxmox_connection: connection} }
|
12
13
|
|
13
|
-
|
14
|
+
subject(:action) { described_class.new(-> (_) {}, environment) }
|
14
15
|
|
15
|
-
|
16
|
-
env[:machine].id = 'localhost/100'
|
17
|
-
allow(RestClient).to receive(:post).and_return({data: 'task_id'}.to_json)
|
18
|
-
allow(RestClient).to receive(:get).and_return({data: {exitstatus: 'OK'}}.to_json)
|
19
|
-
end
|
16
|
+
describe '#call' do
|
20
17
|
|
21
|
-
|
22
|
-
|
18
|
+
before do
|
19
|
+
env[:machine].id = 'localhost/100'
|
20
|
+
allow(connection).to receive_messages :shutdown_vm => 'OK'
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
it_behaves_like 'a proxmox action call'
|
24
|
+
|
25
|
+
it 'should call the shutdown_vm function of connection' do
|
26
|
+
expect(connection).to receive(:shutdown_vm).with '100'
|
27
|
+
action.call env
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should print a message to the user interface' do
|
31
|
+
expect(env[:ui]).to receive(:info).with 'Shutting down the virtual machine...'
|
32
|
+
expect(env[:ui]).to receive(:info).with 'Done!'
|
33
|
+
action.call env
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when the proxmox server responds with an error to the shutdown request' do
|
37
|
+
|
38
|
+
context 'when the proxmox server replies with an internal server error to the shutdown request' do
|
39
|
+
it 'should raise a VMShutdownError' do
|
40
|
+
allow(connection).to receive(:shutdown_vm).and_raise ApiError::ServerError
|
41
|
+
expect { action.send :call, env }.to raise_error Errors::VMShutdownError
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when the proxmox server replies with an internal server error to the task status request' do
|
46
|
+
it 'should raise a VMShutdownError' do
|
47
|
+
allow(connection).to receive(:shutdown_vm).and_raise ApiError::ServerError
|
48
|
+
expect { action.send :call, env }.to raise_error Errors::VMShutdownError
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when the proxmox server does not reply the task status request with OK' do
|
53
|
+
it 'should raise a VMShutdownError' do
|
54
|
+
allow(connection).to receive_messages :shutdown_vm => 'shutdown vm error'
|
55
|
+
expect { action.send :call, env }.to raise_error Errors::VMShutdownError, /shutdown vm error/
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
28
60
|
|
29
|
-
it 'should print a message to the user interface' do
|
30
|
-
env[:ui].should_receive(:info).with 'Shutting down the virtual machine...'
|
31
|
-
env[:ui].should_receive(:info).with 'Done!'
|
32
|
-
subject.call env
|
33
61
|
end
|
34
62
|
|
35
63
|
end
|
@@ -1,47 +1,101 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'actions/proxmox_action_shared'
|
3
3
|
|
4
|
-
|
4
|
+
module VagrantPlugins::Proxmox
|
5
5
|
|
6
|
-
|
7
|
-
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
8
|
-
proxmox_nodes: [{node: 'localhost'}],
|
9
|
-
ui: double('ui').as_null_object} }
|
6
|
+
describe Action::StartVm do
|
10
7
|
|
11
|
-
|
8
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
9
|
+
let(:connection) { Connection.new 'https://proxmox.example.com/api2/json' }
|
10
|
+
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
11
|
+
ui: double('ui').as_null_object,
|
12
|
+
proxmox_connection: connection} }
|
13
|
+
let(:ssh_reachable) { true }
|
14
|
+
let(:ssh_timeout) { 60 }
|
15
|
+
let(:ssh_status_check_interval) { 5 }
|
12
16
|
|
13
|
-
|
17
|
+
subject(:action) { described_class.new(-> (_) {}, environment) }
|
14
18
|
|
15
|
-
|
16
|
-
env[:machine].id = 'localhost/100'
|
17
|
-
allow(RestClient).to receive(:post).and_return({data: 'task_id'}.to_json)
|
18
|
-
allow(RestClient).to receive(:get).and_return({data: {exitstatus: 'OK'}}.to_json)
|
19
|
-
allow(env[:machine].communicate).to receive(:ready?).and_return true
|
20
|
-
end
|
19
|
+
describe '#call' do
|
21
20
|
|
22
|
-
|
23
|
-
|
21
|
+
before do
|
22
|
+
env[:machine].id = 'localhost/100'
|
23
|
+
allow(connection).to receive_messages :start_vm => 'OK'
|
24
|
+
allow(env[:machine].communicate).to receive_messages :ready? => ssh_reachable
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
RestClient.should_receive(:post).with('https://your.proxmox.server/api2/json/nodes/localhost/openvz/100/status/start', nil, anything)
|
27
|
-
subject.call env
|
28
|
-
end
|
27
|
+
it_behaves_like 'a proxmox action call'
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
env[:ui].should_receive(:info).with 'Done!'
|
35
|
-
subject.call env
|
36
|
-
end
|
29
|
+
it 'should call the start_vm function of connection' do
|
30
|
+
expect(connection).to receive(:start_vm).with '100'
|
31
|
+
action.call env
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
it 'should print a message to the user interface' do
|
35
|
+
expect(env[:ui]).to receive(:info).with 'Starting the virtual machine...'
|
36
|
+
expect(env[:ui]).to receive(:info).with 'Done!'
|
37
|
+
expect(env[:ui]).to receive(:info).with 'Waiting for SSH connection...'
|
38
|
+
expect(env[:ui]).to receive(:info).with 'Done!'
|
39
|
+
action.call env
|
40
|
+
end
|
44
41
|
|
45
|
-
|
42
|
+
it 'should periodically call env[:machine].communicate.ready? to check for ssh access' do
|
43
|
+
expect(env[:machine].communicate).to receive(:ready?).and_return false
|
44
|
+
expect(subject).to receive(:sleep).with ssh_status_check_interval
|
45
|
+
expect(env[:machine].communicate).to receive(:ready?).and_return true
|
46
|
+
action.call env
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when the proxmox server responds with an error to the start request' do
|
50
|
+
|
51
|
+
context 'when the proxmox server replies with an internal server error to the start request' do
|
52
|
+
it 'should raise a VMStartError' do
|
53
|
+
allow(connection).to receive(:start_vm).and_raise ApiError::ServerError
|
54
|
+
expect { action.send :call, env }.to raise_error Errors::VMStartError
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when the proxmox server replies with an internal server error to the task status request' do
|
59
|
+
it 'should raise a VMStartError' do
|
60
|
+
allow(connection).to receive(:start_vm).and_raise ApiError::ServerError
|
61
|
+
expect { action.send :call, env }.to raise_error Errors::VMStartError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'when the proxmox server does not reply the task status request with OK' do
|
66
|
+
it 'should raise a VMStartError' do
|
67
|
+
allow(connection).to receive_messages :start_vm => 'start vm error'
|
68
|
+
expect { action.send :call, env }.to raise_error Errors::VMStartError, /start vm error/
|
69
|
+
end
|
70
|
+
end
|
46
71
|
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when no ssh connection can be established after startup' do
|
75
|
+
|
76
|
+
let(:ssh_reachable) { false }
|
77
|
+
|
78
|
+
before do
|
79
|
+
allow(action).to receive(:sleep) { |duration| Timecop.travel(Time.now + duration) }
|
80
|
+
Timecop.freeze
|
81
|
+
end
|
82
|
+
|
83
|
+
after do
|
84
|
+
Timecop.return
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should wait the default timeout' do
|
88
|
+
begin
|
89
|
+
action.call env
|
90
|
+
rescue Errors::SSHError
|
91
|
+
end
|
92
|
+
expect(Time).to have_elapsed ssh_timeout.seconds
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should raise an ssh error' do
|
96
|
+
expect { action.send :call, env }.to raise_error Errors::SSHError, /Unable to establish an ssh connection/
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
47
101
|
end
|
@@ -1,37 +1,64 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'actions/proxmox_action_shared'
|
3
3
|
|
4
|
-
|
4
|
+
module VagrantPlugins::Proxmox
|
5
5
|
|
6
|
-
|
7
|
-
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
8
|
-
proxmox_nodes: [{node: 'localhost'}],
|
9
|
-
ui: double('ui').as_null_object} }
|
6
|
+
describe Action::StopVm do
|
10
7
|
|
11
|
-
|
8
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
9
|
+
let(:connection) { Connection.new 'https://proxmox.example.com/api2/json' }
|
10
|
+
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
|
11
|
+
ui: double('ui').as_null_object, proxmox_connection: connection} }
|
12
12
|
|
13
|
-
|
13
|
+
subject(:action) { described_class.new(-> (_) {}, environment) }
|
14
14
|
|
15
|
-
|
16
|
-
env[:machine].id = 'localhost/100'
|
17
|
-
allow(RestClient).to receive(:post).and_return({data: 'task_id'}.to_json)
|
18
|
-
allow(RestClient).to receive(:get).and_return({data: {exitstatus: 'OK'}}.to_json)
|
19
|
-
end
|
15
|
+
describe '#call' do
|
20
16
|
|
21
|
-
|
22
|
-
|
17
|
+
before do
|
18
|
+
env[:machine].id = 'localhost/100'
|
19
|
+
allow(connection).to receive_messages :stop_vm => 'OK'
|
20
|
+
end
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
it_behaves_like 'a proxmox action call'
|
23
|
+
|
24
|
+
it 'should call the stop_vm function of connection' do
|
25
|
+
expect(connection).to receive(:stop_vm).with '100'
|
26
|
+
action.call env
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should print a message to the user interface' do
|
30
|
+
expect(env[:ui]).to receive(:info).with 'Stopping the virtual machine...'
|
31
|
+
expect(env[:ui]).to receive(:info).with 'Done!'
|
32
|
+
action.call env
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when the proxmox server responds with an error to the stop request' do
|
36
|
+
|
37
|
+
context 'when the proxmox server replies with an internal server error to the stop request' do
|
38
|
+
it 'should raise a VMStopError' do
|
39
|
+
allow(connection).to receive(:stop_vm).and_raise ApiError::ServerError
|
40
|
+
expect { action.send :call, env }.to raise_error Errors::VMStopError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when the proxmox server replies with an internal server error to the task status request' do
|
45
|
+
it 'should raise a VMStopError' do
|
46
|
+
allow(connection).to receive(:stop_vm).and_raise ApiError::ServerError
|
47
|
+
expect { action.send :call, env }.to raise_error Errors::VMStopError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when the proxmox server does not reply the task status request with OK' do
|
52
|
+
it 'should raise a VMStopError' do
|
53
|
+
allow(connection).to receive_messages :stop_vm => 'stop vm error'
|
54
|
+
expect { action.send :call, env }.to raise_error Errors::VMStopError, /stop vm error/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
28
59
|
|
29
|
-
it 'should print a message to the user interface' do
|
30
|
-
env[:ui].should_receive(:info).with 'Stopping the virtual machine...'
|
31
|
-
env[:ui].should_receive(:info).with 'Done!'
|
32
|
-
subject.call env
|
33
60
|
end
|
34
61
|
|
35
62
|
end
|
36
63
|
|
37
|
-
end
|
64
|
+
end
|