vagrant-proxmox 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sanity_checks.rb +1 -1
  3. data/lib/vagrant-proxmox.rb +1 -2
  4. data/lib/vagrant-proxmox/action.rb +133 -86
  5. data/lib/vagrant-proxmox/action/connect_proxmox.rb +10 -10
  6. data/lib/vagrant-proxmox/action/create_vm.rb +33 -28
  7. data/lib/vagrant-proxmox/action/destroy_vm.rb +10 -6
  8. data/lib/vagrant-proxmox/action/get_node_list.rb +8 -6
  9. data/lib/vagrant-proxmox/action/is_created.rb +1 -0
  10. data/lib/vagrant-proxmox/action/is_stopped.rb +1 -0
  11. data/lib/vagrant-proxmox/action/message_file_not_found.rb +21 -0
  12. data/lib/vagrant-proxmox/action/message_not_running.rb +20 -0
  13. data/lib/vagrant-proxmox/action/message_upload_server_error.rb +20 -0
  14. data/lib/vagrant-proxmox/action/proxmox_action.rb +6 -22
  15. data/lib/vagrant-proxmox/action/read_ssh_info.rb +1 -0
  16. data/lib/vagrant-proxmox/action/read_state.rb +11 -14
  17. data/lib/vagrant-proxmox/action/select_node.rb +23 -0
  18. data/lib/vagrant-proxmox/action/shutdown_vm.rb +8 -8
  19. data/lib/vagrant-proxmox/action/start_vm.rb +20 -12
  20. data/lib/vagrant-proxmox/action/stop_vm.rb +9 -8
  21. data/lib/vagrant-proxmox/action/sync_folders.rb +1 -1
  22. data/lib/vagrant-proxmox/action/upload_iso_file.rb +38 -0
  23. data/lib/vagrant-proxmox/action/upload_template_file.rb +38 -0
  24. data/lib/vagrant-proxmox/config.rb +85 -5
  25. data/lib/vagrant-proxmox/errors.rb +22 -2
  26. data/lib/vagrant-proxmox/plugin.rb +0 -14
  27. data/lib/vagrant-proxmox/proxmox/connection.rb +217 -0
  28. data/lib/vagrant-proxmox/proxmox/errors.rb +23 -0
  29. data/lib/vagrant-proxmox/version.rb +1 -1
  30. data/locales/en.yml +29 -2
  31. data/spec/actions/cleanup_after_destroy_action_spec.rb +2 -2
  32. data/spec/actions/connect_proxmox_action_spec.rb +32 -15
  33. data/spec/actions/create_vm_action_spec.rb +155 -130
  34. data/spec/actions/destroy_vm_action_spec.rb +50 -23
  35. data/spec/actions/get_node_list_action_spec.rb +25 -12
  36. data/spec/actions/is_created_action_spec.rb +8 -8
  37. data/spec/actions/is_stopped_action_spec.rb +8 -8
  38. data/spec/actions/message_already_running_action_spec.rb +2 -2
  39. data/spec/actions/message_already_stopped_action_spec.rb +2 -2
  40. data/spec/actions/message_file_not_found_spec.rb +23 -0
  41. data/spec/actions/message_not_created_action_spec.rb +2 -2
  42. data/spec/actions/message_not_running_action_spec.rb +23 -0
  43. data/spec/actions/message_upload_server_error_spec.rb +23 -0
  44. data/spec/actions/proxmox_action_shared.rb +0 -64
  45. data/spec/actions/proxmox_action_spec.rb +57 -0
  46. data/spec/actions/read_ssh_info_action_spec.rb +6 -6
  47. data/spec/actions/read_state_action_spec.rb +36 -34
  48. data/spec/actions/select_node_spec.rb +33 -0
  49. data/spec/actions/shutdown_vm_action_spec.rb +50 -22
  50. data/spec/actions/start_vm_action_spec.rb +87 -33
  51. data/spec/actions/stop_vm_action_spec.rb +50 -23
  52. data/spec/actions/sync_folders_action_spec.rb +9 -9
  53. data/spec/actions/upload_iso_file_action_spec.rb +70 -0
  54. data/spec/actions/upload_template_file_action_spec.rb +70 -0
  55. data/spec/commands/destroy_command_spec.rb +25 -25
  56. data/spec/commands/halt_command_spec.rb +17 -17
  57. data/spec/commands/provision_command_spec.rb +22 -9
  58. data/spec/commands/ssh_command_spec.rb +18 -5
  59. data/spec/commands/ssh_run_command_spec.rb +19 -6
  60. data/spec/commands/status_command_spec.rb +2 -2
  61. data/spec/commands/up_command_spec.rb +174 -34
  62. data/spec/config_spec.rb +325 -46
  63. data/spec/plugin_spec.rb +1 -8
  64. data/spec/provider_spec.rb +4 -4
  65. data/spec/proxmox/connection_spec.rb +662 -0
  66. data/spec/proxmox/rest_call_shared.rb +41 -0
  67. data/spec/sanity_checks_spec.rb +1 -1
  68. data/spec/spec_helper.rb +15 -97
  69. data/spec/spec_helpers/common_helpers.rb +111 -0
  70. data/spec/spec_helpers/time_helpers.rb +90 -0
  71. metadata +161 -45
@@ -8,27 +8,27 @@ module VagrantPlugins::Proxmox
8
8
  let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
9
9
  let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox), ui: double('ui').as_null_object} }
10
10
 
11
- subject { described_class.new(-> (_) {}, environment) }
11
+ subject(:action) { described_class.new(-> (_) {}, environment) }
12
12
 
13
13
  describe '#call' do
14
14
 
15
15
  before do
16
- env[:machine].stub(:ssh_info) { {host: '127.0.0.1', port: 22, username: 'vagrant', private_key_path: 'key'} }
17
- env[:machine].communicate.stub :sudo
18
- Vagrant::Util::Subprocess.stub(:execute).and_return Vagrant::Util::Subprocess::Result.new 0, nil, nil
16
+ allow(env[:machine]).to receive(:ssh_info) { {host: '127.0.0.1', port: 22, username: 'vagrant', private_key_path: ['key']} }
17
+ allow(env[:machine].communicate).to receive :sudo
18
+ allow(Vagrant::Util::Subprocess).to receive_messages :execute => Vagrant::Util::Subprocess::Result.new(0, nil, nil)
19
19
  end
20
20
 
21
21
  it_behaves_like 'a proxmox action call'
22
22
 
23
23
  it 'should print a message to the user interface' do
24
24
  expect(env[:ui]).to receive(:info).with("Rsyncing folder: #{Dir.pwd}/ => /vagrant")
25
- subject.call env
25
+ action.call env
26
26
  end
27
27
 
28
28
  it 'should create a directory on the vm with the predefined ownership' do
29
29
  expect(env[:machine].communicate).to receive(:sudo).with("mkdir -p '/vagrant'")
30
30
  expect(env[:machine].communicate).to receive(:sudo).with("chown vagrant '/vagrant'")
31
- subject.call env
31
+ action.call env
32
32
  end
33
33
 
34
34
  it 'should rsync the directory with the vm' do
@@ -36,12 +36,12 @@ module VagrantPlugins::Proxmox
36
36
  'rsync', '--verbose', '--archive', '--compress', '--delete',
37
37
  '-e', "ssh -p 22 -i 'key' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null",
38
38
  "#{Dir.pwd}/", 'vagrant@127.0.0.1:/vagrant')
39
- subject.call env
39
+ action.call env
40
40
  end
41
41
 
42
42
  it 'should raise an error if the rsync fails' do
43
- allow(Vagrant::Util::Subprocess).to receive(:execute).and_return(Vagrant::Util::Subprocess::Result.new 1, nil, nil)
44
- expect { subject.call(env) }.to raise_error Errors::RsyncError
43
+ allow(Vagrant::Util::Subprocess).to receive_messages :execute => Vagrant::Util::Subprocess::Result.new(1, nil, nil)
44
+ expect { action.call(env) }.to raise_error Errors::RsyncError
45
45
  end
46
46
 
47
47
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'actions/proxmox_action_shared'
3
+
4
+ module VagrantPlugins::Proxmox
5
+
6
+ describe Action::UploadIsoFile do
7
+
8
+ let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile_qemu' }
9
+ let(:connection) { Connection.new 'https://your.proxmox.server/api2/json' }
10
+ let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
11
+ proxmox_connection: connection, proxmox_selected_node: node} }
12
+ let(:iso_file) { 'some_iso.iso' }
13
+ let(:iso_file_exists) { true }
14
+ let(:node) { 'node1' }
15
+
16
+ subject(:action) { described_class.new(-> (_) {}, environment) }
17
+
18
+ before do
19
+ env[:machine].provider_config.qemu_iso_file = iso_file
20
+ allow(File).to receive(:exist?).with(iso_file).and_return(iso_file_exists)
21
+ end
22
+
23
+ context 'with a specified iso file' do
24
+
25
+ it 'should upload the iso file into the local storage of the selected node' do
26
+ expect(connection).to receive(:upload_file).with(iso_file, content_type: 'iso', node: node, storage: 'local')
27
+ action.call env
28
+ end
29
+ end
30
+
31
+ it 'should return :ok after a successful upload' do
32
+ allow(connection).to receive(:upload_file).with(iso_file, content_type: 'iso', node: node, storage: 'local')
33
+ action.call env
34
+ expect(env[:result]).to eq(:ok)
35
+ end
36
+
37
+ context 'when a server error occurs' do
38
+
39
+ before do
40
+ allow(connection).to receive(:upload_file).and_raise ApiError::ServerError
41
+ end
42
+
43
+ it 'should return :server_error' do
44
+ action.call env
45
+ expect(env[:result]).to eq(:server_upload_error)
46
+ end
47
+ end
48
+
49
+ context 'without a specified iso file' do
50
+
51
+ let(:iso_file) { nil }
52
+
53
+ it 'does nothing and returns OK' do
54
+ expect(connection).not_to receive(:upload_file)
55
+ action.call env
56
+ expect(env[:result]).to eq(:ok)
57
+ end
58
+ end
59
+
60
+ context 'the specified iso file does not exist' do
61
+
62
+ let (:iso_file_exists) { false }
63
+
64
+ it 'should return :file_not_found' do
65
+ action.call env
66
+ expect(env[:result]).to eq(:file_not_found)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'actions/proxmox_action_shared'
3
+
4
+ module VagrantPlugins::Proxmox
5
+
6
+ describe Action::UploadTemplateFile do
7
+
8
+ let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
9
+ let(:connection) { Connection.new 'https://your.proxmox.server/api2/json' }
10
+ let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox),
11
+ proxmox_connection: connection, proxmox_selected_node: node} }
12
+ let(:template_file) { 'template.tar.gz' }
13
+ let(:template_file_exists) { true }
14
+ let(:node) { 'node1' }
15
+
16
+ subject(:action) { described_class.new(-> (_) {}, environment) }
17
+
18
+ before do
19
+ env[:machine].provider_config.openvz_template_file = template_file
20
+ allow(File).to receive(:exist?).with(template_file).and_return(template_file_exists)
21
+ end
22
+
23
+ context 'with a specified template file' do
24
+
25
+ it 'should upload the template file into the local storage of the selected node' do
26
+ expect(connection).to receive(:upload_file).with(template_file, content_type: 'vztmpl', node: node, storage: 'local')
27
+ action.call env
28
+ end
29
+ end
30
+
31
+ it 'should return :ok after a successful upload' do
32
+ allow(connection).to receive(:upload_file).with(template_file, content_type: 'vztmpl', node: node, storage: 'local')
33
+ action.call env
34
+ expect(env[:result]).to eq(:ok)
35
+ end
36
+
37
+ context 'when a server error occurs' do
38
+
39
+ before do
40
+ allow(connection).to receive(:upload_file).and_raise ApiError::ServerError
41
+ end
42
+
43
+ it 'should return :server_error' do
44
+ action.call env
45
+ expect(env[:result]).to eq(:server_upload_error)
46
+ end
47
+ end
48
+
49
+ context 'without a specified template file' do
50
+
51
+ let(:template_file) { nil }
52
+
53
+ it 'does nothing and returns OK' do
54
+ expect(connection).not_to receive(:upload_file)
55
+ action.call env
56
+ expect(env[:result]).to eq(:ok)
57
+ end
58
+ end
59
+
60
+ context 'the specified template file does not exist' do
61
+
62
+ let (:template_file_exists) { false }
63
+
64
+ it 'should return :file_not_found' do
65
+ action.call env
66
+ expect(env[:result]).to eq(:file_not_found)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -10,10 +10,10 @@ module VagrantPlugins::Proxmox
10
10
 
11
11
  context 'the vm is not created on the proxmox server' do
12
12
  it 'should call the appropriate actions to print a ui message that the vm is not created' do
13
- Action::ConnectProxmox.should be_called { |env| env[:proxmox_ticket] = 'ticket' }
14
- Action::IsCreated.should be_called { |env| env[:result] = false }
15
- Action::MessageNotCreated.should be_called
16
- Action::DestroyVm.should be_ommited
13
+ expect(Action::ConnectProxmox).to be_called
14
+ expect(Action::IsCreated).to be_called { |env| env[:result] = false }
15
+ expect(Action::MessageNotCreated).to be_called
16
+ expect(Action::DestroyVm).to be_omitted
17
17
  execute_vagrant_command environment, :destroy
18
18
  end
19
19
  end
@@ -22,11 +22,11 @@ module VagrantPlugins::Proxmox
22
22
 
23
23
  context 'the destroy command is not confirmed' do
24
24
  it 'should call the appropriate actions to print a ui message that the vm will not be destroyed' do
25
- Action::ConnectProxmox.should be_called { |env| env[:proxmox_ticket] = 'ticket' }
26
- Action::IsCreated.should be_called { |env| env[:result] = true }
27
- ::Vagrant::Action::Builtin::DestroyConfirm.should be_called { |env| env[:result] = false }
28
- ::VagrantPlugins::ProviderVirtualBox::Action::MessageWillNotDestroy.should be_called
29
- Action::DestroyVm.should be_ommited
25
+ expect(Action::ConnectProxmox).to be_called
26
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
27
+ expect(::Vagrant::Action::Builtin::DestroyConfirm).to be_called { |env| env[:result] = false }
28
+ expect(::VagrantPlugins::ProviderVirtualBox::Action::MessageWillNotDestroy).to be_called
29
+ expect(Action::DestroyVm).to be_omitted
30
30
  execute_vagrant_command environment, :destroy
31
31
  end
32
32
  end
@@ -34,28 +34,28 @@ module VagrantPlugins::Proxmox
34
34
  context 'the destroy command is confirmed' do
35
35
  context 'the vm is running' do
36
36
  it 'should call the appropriate actions to destroy the vm' do
37
- Action::ConnectProxmox.should be_called { |env| env[:proxmox_ticket] = 'ticket' }
38
- Action::IsCreated.should be_called { |env| env[:result] = true }
39
- ::Vagrant::Action::Builtin::DestroyConfirm.should be_called { |env| env[:result] = true }
40
- Action::IsStopped.should be_called { |env| env[:result] = false }
41
- Action::ShutdownVm.should be_called
42
- Action::DestroyVm.should be_called
43
- ::Vagrant::Action::Builtin::ProvisionerCleanup.should be_called
44
- Action::CleanupAfterDestroy.should be_called
37
+ expect(Action::ConnectProxmox).to be_called
38
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
39
+ expect(::Vagrant::Action::Builtin::DestroyConfirm).to be_called { |env| env[:result] = true }
40
+ expect(Action::IsStopped).to be_called { |env| env[:result] = false }
41
+ expect(Action::ShutdownVm).to be_called
42
+ expect(Action::DestroyVm).to be_called
43
+ expect(::Vagrant::Action::Builtin::ProvisionerCleanup).to be_called
44
+ expect(Action::CleanupAfterDestroy).to be_called
45
45
  execute_vagrant_command environment, :destroy
46
46
  end
47
47
  end
48
48
 
49
49
  context 'the vm is stopped' do
50
50
  it 'should call the appropriate actions to destroy the vm' do
51
- Action::ConnectProxmox.should be_called { |env| env[:proxmox_ticket] = 'ticket' }
52
- Action::IsCreated.should be_called { |env| env[:result] = true }
53
- Action::DestroyConfirm.should be_called { |env| env[:result] = true }
54
- Action::IsStopped.should be_called { |env| env[:result] = true }
55
- Action::DestroyVm.should be_called
56
- ::Vagrant::Action::Builtin::ProvisionerCleanup.should be_called
57
- Action::CleanupAfterDestroy.should be_called
58
- Action::ShutdownVm.should be_ommited
51
+ expect(Action::ConnectProxmox).to be_called
52
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
53
+ expect(Action::DestroyConfirm).to be_called { |env| env[:result] = true }
54
+ expect(Action::IsStopped).to be_called { |env| env[:result] = true }
55
+ expect(Action::DestroyVm).to be_called
56
+ expect(::Vagrant::Action::Builtin::ProvisionerCleanup).to be_called
57
+ expect(Action::CleanupAfterDestroy).to be_called
58
+ expect(Action::ShutdownVm).to be_omitted
59
59
  execute_vagrant_command environment, :destroy
60
60
  end
61
61
  end
@@ -9,34 +9,34 @@ module VagrantPlugins::Proxmox
9
9
 
10
10
  context 'the vm is not created on the proxmox server' do
11
11
  it 'should call the appropriate actions and print a ui message that the vm is not created' do
12
- Action::ConfigValidate.should be_called
13
- Action::IsCreated.should be_called { |env| env[:result] = false }
14
- Action::MessageNotCreated.should be_called
15
- Action::ConnectProxmox.should be_ommited
16
- Action::ShutdownVm.should be_ommited
12
+ expect(Action::ConfigValidate).to be_called
13
+ expect(Action::IsCreated).to be_called { |env| env[:result] = false }
14
+ expect(Action::MessageNotCreated).to be_called
15
+ expect(Action::ConnectProxmox).to be_omitted
16
+ expect(Action::ShutdownVm).to be_omitted
17
17
  execute_vagrant_command environment, :halt
18
18
  end
19
19
  end
20
20
 
21
21
  context 'the vm is stopped' do
22
- it 'should call the appropriate actions to shut down the vm' do
23
- Action::ConfigValidate.should be_called
24
- Action::IsCreated.should be_called { |env| env[:result] = true }
25
- Action::IsStopped.should be_called { |env| env[:result] = true }
26
- Action::MessageAlreadyStopped.should be_called
27
- Action::ConnectProxmox.should be_ommited
28
- Action::ShutdownVm.should be_ommited
22
+ it 'should not shut down the vm and print a vm message that the vm is already stopped' do
23
+ expect(Action::ConfigValidate).to be_called
24
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
25
+ expect(Action::IsStopped).to be_called { |env| env[:result] = true }
26
+ expect(Action::MessageAlreadyStopped).to be_called
27
+ expect(Action::ConnectProxmox).to be_omitted
28
+ expect(Action::ShutdownVm).to be_omitted
29
29
  execute_vagrant_command environment, :halt
30
30
  end
31
31
  end
32
32
 
33
33
  context 'the vm is running' do
34
34
  it 'should call the appropriate actions to shut down the vm' do
35
- Action::ConfigValidate.should be_called
36
- Action::IsCreated.should be_called { |env| env[:result] = true }
37
- Action::IsStopped.should be_called { |env| env[:result] = false }
38
- Action::ConnectProxmox.should be_called { |env| env[:proxmox_ticket] = 'ticket' }
39
- Action::ShutdownVm.should be_called
35
+ expect(Action::ConfigValidate).to be_called
36
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
37
+ expect(Action::IsStopped).to be_called { |env| env[:result] = false }
38
+ expect(Action::ConnectProxmox).to be_called
39
+ expect(Action::ShutdownVm).to be_called
40
40
  execute_vagrant_command environment, :halt
41
41
  end
42
42
  end
@@ -9,25 +9,38 @@ module VagrantPlugins::Proxmox
9
9
 
10
10
  context 'the vm is not created on the proxmox server' do
11
11
  it 'should call the appropriate actions and print a ui message that the vm is not created' do
12
- Action::ConfigValidate.should be_called
13
- Action::IsCreated.should be_called { |env| env[:result] = false }
14
- Action::MessageNotCreated.should be_called
15
- Action::Provision.should be_ommited
16
- Action::SyncFolders.should be_ommited
12
+ expect(Action::ConfigValidate).to be_called
13
+ expect(Action::IsCreated).to be_called { |env| env[:result] = false }
14
+ expect(Action::MessageNotCreated).to be_called
15
+ expect(Action::Provision).to be_omitted
16
+ expect(Action::SyncFolders).to be_omitted
17
17
  execute_vagrant_command environment, :provision
18
18
  end
19
19
  end
20
20
 
21
21
  context 'the vm exists on the proxmox server' do
22
22
  it 'should call the appropriate actions and provision the vm' do
23
- Action::ConfigValidate.should be_called
24
- Action::IsCreated.should be_called { |env| env[:result] = true }
25
- Action::Provision.should be_called
26
- Action::SyncFolders.should be_called
23
+ expect(Action::ConfigValidate).to be_called
24
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
25
+ expect(Action::IsStopped).to be_called { |env| env[:result] = false }
26
+ expect(Action::Provision).to be_called
27
+ expect(Action::SyncFolders).to be_called
27
28
  execute_vagrant_command environment, :provision
28
29
  end
29
30
  end
30
31
 
32
+ context 'the vm exists on the proxmox server but is not running' do
33
+
34
+ it 'should state that the machine is not currently running' do
35
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
36
+ expect(Action::IsStopped).to be_called { |env| env[:result] = true }
37
+ expect(Action::MessageNotRunning).to be_called
38
+ expect(Action::Provision).to be_omitted
39
+ execute_vagrant_command environment, :provision
40
+ end
41
+
42
+ end
43
+
31
44
  end
32
45
 
33
46
  end
@@ -9,9 +9,9 @@ module VagrantPlugins::Proxmox
9
9
 
10
10
  context 'the vm is not created on the proxmox server' do
11
11
  it 'should call the appropriate actions and print a ui message that the vm is not created' do
12
- Action::IsCreated.should be_called { |env| env[:result] = false }
13
- Action::MessageNotCreated.should be_called
14
- Action::SSHExec.should be_ommited
12
+ expect(Action::IsCreated).to be_called { |env| env[:result] = false }
13
+ expect(Action::MessageNotCreated).to be_called
14
+ expect(Action::SSHExec).to be_omitted
15
15
  execute_vagrant_command environment, :ssh
16
16
  end
17
17
  end
@@ -19,8 +19,21 @@ module VagrantPlugins::Proxmox
19
19
  context 'the vm exists on the proxmox server' do
20
20
 
21
21
  it 'should call the appropriate actions to open a ssh connection' do
22
- Action::IsCreated.should be_called { |env| env[:result] = true }
23
- Action::SSHExec.should be_called
22
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
23
+ expect(Action::IsStopped).to be_called { |env| env[:result] = false }
24
+ expect(Action::SSHExec).to be_called
25
+ execute_vagrant_command environment, :ssh
26
+ end
27
+
28
+ end
29
+
30
+ context 'the vm exists on the proxmox server but is not running' do
31
+
32
+ it 'should state that the machine is not currently running' do
33
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
34
+ expect(Action::IsStopped).to be_called { |env| env[:result] = true }
35
+ expect(Action::MessageNotRunning).to be_called
36
+ expect(Action::SSHExec).to be_omitted
24
37
  execute_vagrant_command environment, :ssh
25
38
  end
26
39
 
@@ -10,19 +10,32 @@ module VagrantPlugins::Proxmox
10
10
 
11
11
  context 'the vm is not created on the proxmox server' do
12
12
  it 'should call the appropriate actions and print a ui message that the vm is not created' do
13
- Action::IsCreated.should be_called { |env| env[:result] = false }
14
- Action::MessageNotCreated.should be_called
15
- Action::SSHRun.should be_ommited
13
+ expect(Action::IsCreated).to be_called { |env| env[:result] = false }
14
+ expect(Action::MessageNotCreated).to be_called
15
+ expect(Action::SSHRun).to be_omitted
16
16
  execute_vagrant_command environment, :ssh, '--command', 'foo'
17
17
  end
18
18
  end
19
19
 
20
20
  context 'the vm exists on the proxmox server' do
21
- before { env[:machine].stub(:ssh_info) { {host: '127.0.0.1', port: 22, username: 'vagrant', private_key_path: 'key'} } }
21
+ before { allow(env[:machine]).to receive(:ssh_info) { {host: '127.0.0.1', port: 22, username: 'vagrant', private_key_path: 'key'} } }
22
22
 
23
23
  it 'should call the appropriate actions to execute a command via ssh on the vm' do
24
- Action::IsCreated.should be_called { |env| env[:result] = true }
25
- Action::SSHRun.should be_called
24
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
25
+ expect(Action::IsStopped).to be_called { |env| env[:result] = false }
26
+ expect(Action::SSHRun).to be_called
27
+ execute_vagrant_command environment, :ssh, '--command', 'foo'
28
+ end
29
+ end
30
+
31
+ context 'the vm exists on the proxmox server and is not running' do
32
+ before { allow(env[:machine]).to receive(:ssh_info) { {host: '127.0.0.1', port: 22, username: 'vagrant', private_key_path: 'key'} } }
33
+
34
+ it 'should call the appropriate actions to execute a command via ssh on the vm' do
35
+ expect(Action::IsCreated).to be_called { |env| env[:result] = true }
36
+ expect(Action::IsStopped).to be_called { |env| env[:result] = true }
37
+ expect(Action::MessageNotRunning).to be_called
38
+ expect(Action::SSHRun).to be_omitted
26
39
  execute_vagrant_command environment, :ssh, '--command', 'foo'
27
40
  end
28
41
  end