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
@@ -8,8 +8,8 @@ module VagrantPlugins::Proxmox
|
|
8
8
|
let(:ui) { double('ui').as_null_object }
|
9
9
|
|
10
10
|
specify do
|
11
|
-
Action::ConnectProxmox.
|
12
|
-
Action::ReadState.
|
11
|
+
expect(Action::ConnectProxmox).to be_called
|
12
|
+
expect(Action::ReadState).to be_called { |env| env[:machine_state_id] = :stopped }
|
13
13
|
expect(ui).to receive(:info).with /stopped \(proxmox\)/, anything
|
14
14
|
execute_vagrant_command environment, :status
|
15
15
|
end
|
@@ -5,51 +5,191 @@ module VagrantPlugins::Proxmox
|
|
5
5
|
describe 'Vagrant Proxmox provider up command' do
|
6
6
|
|
7
7
|
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
8
|
+
let(:connection) { Connection.new 'https://your.proxmox.server/api2/json' }
|
9
|
+
let(:env) { {machine: environment.machine(environment.primary_machine_name, :proxmox)} }
|
8
10
|
let(:ui) { double('ui').as_null_object }
|
11
|
+
let(:proxmox_vm_type) { :openvz }
|
12
|
+
let(:qemu_os) { :l26 }
|
13
|
+
let(:qemu_iso) { 'someiso.iso' }
|
14
|
+
let(:qemu_disk_size) { '30G' }
|
9
15
|
|
10
16
|
before do
|
11
|
-
Vagrant::UI::Interface.
|
17
|
+
allow(Vagrant::UI::Interface).to receive_messages :new => ui
|
18
|
+
env[:machine].provider_config.vm_type = proxmox_vm_type
|
12
19
|
end
|
13
20
|
|
14
|
-
context 'the
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
context 'the vm_type is :openvz' do
|
22
|
+
|
23
|
+
context 'the vm is not yet created' do
|
24
|
+
it 'should call the appropriate actions and print a ui message that the vm will be created' do
|
25
|
+
expect(Action::ConnectProxmox).to be_called
|
26
|
+
expect(Action::GetNodeList).to be_called { |env| env[:proxmox_nodes] = ['localhost'] }
|
27
|
+
expect(Action::SelectNode).to be_called { |env| env[:proxmox_selected_node] = ['localhost'] }
|
28
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = false }
|
29
|
+
expect(Action::UploadTemplateFile).to be_called { |env| env[:result] = :ok }
|
30
|
+
expect(Action::UploadIsoFile).to be_omitted
|
31
|
+
expect(Action::CreateVm).to be_called { |env| env[:machine].id = 'localhost/100' }
|
32
|
+
expect(Action::Provision).to be_called
|
33
|
+
expect(Action::StartVm).to be_called
|
34
|
+
expect(Action::SyncFolders).to be_called
|
35
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
36
|
+
end
|
24
37
|
end
|
25
|
-
end
|
26
38
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
39
|
+
context 'the vm is stopped' do
|
40
|
+
it 'should call the appropriate actions and print a ui message that the vm will be started' do
|
41
|
+
expect(Action::ConnectProxmox).to be_called
|
42
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = true }
|
43
|
+
expect(Action::IsStopped).to be_called { |env| env[:result] = true }
|
44
|
+
expect(Action::Provision).to be_called
|
45
|
+
expect(Action::StartVm).to be_called
|
46
|
+
expect(Action::SyncFolders).to be_called
|
47
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
48
|
+
expect(Action::UploadIsoFile).to be_omitted
|
49
|
+
expect(Action::CreateVm).to be_omitted
|
50
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
51
|
+
end
|
37
52
|
end
|
38
|
-
end
|
39
53
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
context 'the vm is already running' do
|
55
|
+
it 'should call the appropriate actions and print a ui message that the vm is already running' do
|
56
|
+
expect(Action::ConnectProxmox).to be_called
|
57
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = true }
|
58
|
+
expect(Action::IsStopped).to be_called { |env| env[:result] = false }
|
59
|
+
expect(Action::MessageAlreadyRunning).to be_called
|
60
|
+
expect(Action::Provision).to be_omitted
|
61
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
62
|
+
expect(Action::UploadIsoFile).to be_omitted
|
63
|
+
expect(Action::CreateVm).to be_omitted
|
64
|
+
expect(Action::StartVm).to be_omitted
|
65
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'an invalid local template file is specified' do
|
70
|
+
|
71
|
+
it 'should call the appropriate actions and print a ui message that a file was not found' do
|
72
|
+
expect(Action::ConnectProxmox).to be_called
|
73
|
+
expect(Action::GetNodeList).to be_called { |env| env[:proxmox_nodes] = ['localhost'] }
|
74
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = false }
|
75
|
+
expect(Action::Provision).to be_called
|
76
|
+
expect(Action::UploadTemplateFile).to be_called { |env| env[:result] = :file_not_found }
|
77
|
+
expect(Action::UploadIsoFile).to be_omitted
|
78
|
+
expect(Action::MessageFileNotFound).to be_called
|
79
|
+
expect(Action::CreateVm).to be_omitted
|
80
|
+
expect(Action::StartVm).to be_omitted
|
81
|
+
expect(Action::SyncFolders).to be_omitted
|
82
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'a server error occurs' do
|
87
|
+
|
88
|
+
it 'should call the appropriate actions and print a ui message that a server error occured' do
|
89
|
+
expect(Action::ConnectProxmox).to be_called
|
90
|
+
expect(Action::GetNodeList).to be_called { |env| env[:proxmox_nodes] = ['localhost'] }
|
91
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = false }
|
92
|
+
expect(Action::Provision).to be_called
|
93
|
+
expect(Action::UploadTemplateFile).to be_called { |env| env[:result] = :server_upload_error }
|
94
|
+
expect(Action::UploadIsoFile).to be_omitted
|
95
|
+
expect(Action::MessageUploadServerError).to be_called
|
96
|
+
expect(Action::CreateVm).to be_omitted
|
97
|
+
expect(Action::StartVm).to be_omitted
|
98
|
+
expect(Action::SyncFolders).to be_omitted
|
99
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
100
|
+
end
|
50
101
|
end
|
51
102
|
end
|
52
103
|
|
53
|
-
|
104
|
+
context 'the vm_type is :qemu' do
|
105
|
+
|
106
|
+
let(:proxmox_vm_type) { :qemu }
|
107
|
+
|
108
|
+
before do
|
109
|
+
env[:machine].provider_config.qemu_os = qemu_os
|
110
|
+
env[:machine].provider_config.qemu_iso = qemu_iso
|
111
|
+
env[:machine].provider_config.qemu_disk_size = qemu_disk_size
|
112
|
+
end
|
54
113
|
|
114
|
+
context 'the vm is not yet created' do
|
115
|
+
it 'should call the appropriate actions and print a ui message that the vm will be created' do
|
116
|
+
expect(Action::ConnectProxmox).to be_called
|
117
|
+
expect(Action::GetNodeList).to be_called { |env| env[:proxmox_nodes] = ['localhost'] }
|
118
|
+
expect(Action::SelectNode).to be_called { |env| env[:proxmox_selected_node] = ['localhost'] }
|
119
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = false }
|
120
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
121
|
+
expect(Action::UploadIsoFile).to be_called { |env| env[:result] = :ok }
|
122
|
+
expect(Action::CreateVm).to be_called { |env| env[:machine].id = 'localhost/100' }
|
123
|
+
expect(Action::Provision).to be_called
|
124
|
+
expect(Action::StartVm).to be_called
|
125
|
+
expect(Action::SyncFolders).to be_called
|
126
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'the vm is stopped' do
|
131
|
+
it 'should call the appropriate actions and print a ui message that the vm will be started' do
|
132
|
+
expect(Action::ConnectProxmox).to be_called
|
133
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = true }
|
134
|
+
expect(Action::IsStopped).to be_called { |env| env[:result] = true }
|
135
|
+
expect(Action::Provision).to be_called
|
136
|
+
expect(Action::StartVm).to be_called
|
137
|
+
expect(Action::SyncFolders).to be_called
|
138
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
139
|
+
expect(Action::UploadIsoFile).to be_omitted
|
140
|
+
expect(Action::CreateVm).to be_omitted
|
141
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'the vm is already running' do
|
146
|
+
it 'should call the appropriate actions and print a ui message that the vm is already running' do
|
147
|
+
expect(Action::ConnectProxmox).to be_called
|
148
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = true }
|
149
|
+
expect(Action::IsStopped).to be_called { |env| env[:result] = false }
|
150
|
+
expect(Action::MessageAlreadyRunning).to be_called
|
151
|
+
expect(Action::Provision).to be_omitted
|
152
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
153
|
+
expect(Action::UploadIsoFile).to be_omitted
|
154
|
+
expect(Action::CreateVm).to be_omitted
|
155
|
+
expect(Action::StartVm).to be_omitted
|
156
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'an invalid local iso file is specified' do
|
161
|
+
|
162
|
+
it 'should call the appropriate actions and print a ui message that a file was not found' do
|
163
|
+
expect(Action::ConnectProxmox).to be_called
|
164
|
+
expect(Action::GetNodeList).to be_called { |env| env[:proxmox_nodes] = ['localhost'] }
|
165
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = false }
|
166
|
+
expect(Action::Provision).to be_called
|
167
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
168
|
+
expect(Action::UploadIsoFile).to be_called { |env| env[:result] = :file_not_found }
|
169
|
+
expect(Action::MessageFileNotFound).to be_called
|
170
|
+
expect(Action::CreateVm).to be_omitted
|
171
|
+
expect(Action::StartVm).to be_omitted
|
172
|
+
expect(Action::SyncFolders).to be_omitted
|
173
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'a server error occurs' do
|
178
|
+
|
179
|
+
it 'should call the appropriate actions and print a ui message that a server error occured' do
|
180
|
+
expect(Action::ConnectProxmox).to be_called
|
181
|
+
expect(Action::GetNodeList).to be_called { |env| env[:proxmox_nodes] = ['localhost'] }
|
182
|
+
expect(Action::IsCreated).to be_called { |env| env[:result] = false }
|
183
|
+
expect(Action::Provision).to be_called
|
184
|
+
expect(Action::UploadTemplateFile).to be_omitted
|
185
|
+
expect(Action::UploadIsoFile).to be_called { |env| env[:result] = :server_upload_error }
|
186
|
+
expect(Action::MessageUploadServerError).to be_called
|
187
|
+
expect(Action::CreateVm).to be_omitted
|
188
|
+
expect(Action::StartVm).to be_omitted
|
189
|
+
expect(Action::SyncFolders).to be_omitted
|
190
|
+
execute_vagrant_command environment, :up, '--provider=proxmox'
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
55
195
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -6,66 +6,345 @@ describe VagrantPlugins::Proxmox::Config do
|
|
6
6
|
describe 'defaults' do
|
7
7
|
subject { super().tap { |o| o.finalize! } }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
its(:vm_id_range) { should == (900..999) }
|
14
|
-
its(:vm_name_prefix) { should == 'vagrant_' }
|
15
|
-
its(:vm_memory) { should == 512 }
|
16
|
-
its(:task_timeout) { should == 60 }
|
17
|
-
its(:task_status_check_interval) { should == 2 }
|
18
|
-
end
|
9
|
+
describe '#endpoint' do
|
10
|
+
subject { super().endpoint }
|
11
|
+
it { is_expected.to be_nil }
|
12
|
+
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
describe '#user_name' do
|
15
|
+
subject { super().user_name }
|
16
|
+
it { is_expected.to be_nil }
|
17
|
+
end
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
its(:password) { should == 'password' }
|
29
|
-
its(:os_template) { should == 'local:vztmpl/template.tgz' }
|
30
|
-
its(:vm_id_range) { should == (900..910) }
|
31
|
-
its(:vm_name_prefix) { should == 'vagrant_test_' }
|
32
|
-
its(:vm_memory) { should == 256 }
|
33
|
-
its(:task_timeout) { should == 30 }
|
34
|
-
its(:task_status_check_interval) { should == 1 }
|
35
|
-
end
|
19
|
+
describe '#password' do
|
20
|
+
subject { super().password }
|
21
|
+
it { is_expected.to be_nil }
|
22
|
+
end
|
36
23
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
24
|
+
describe '#vm_type' do
|
25
|
+
subject { super().vm_type }
|
26
|
+
it { is_expected.to be_nil }
|
27
|
+
end
|
41
28
|
|
42
|
-
|
29
|
+
describe '#openvz_os_template' do
|
30
|
+
subject { super().openvz_os_template }
|
31
|
+
it { is_expected.to be_nil }
|
32
|
+
end
|
43
33
|
|
44
|
-
describe '
|
45
|
-
|
46
|
-
|
47
|
-
end
|
34
|
+
describe '#openvz_template_file' do
|
35
|
+
subject { super().openvz_template_file }
|
36
|
+
it { is_expected.to be_nil }
|
48
37
|
end
|
49
38
|
|
50
|
-
describe '
|
51
|
-
|
52
|
-
|
39
|
+
describe '#vm_id_range' do
|
40
|
+
subject { super().vm_id_range }
|
41
|
+
it { is_expected.to eq(900..999) }
|
53
42
|
end
|
54
43
|
|
55
|
-
describe '
|
56
|
-
|
57
|
-
|
44
|
+
describe '#vm_name_prefix' do
|
45
|
+
subject { super().vm_name_prefix }
|
46
|
+
it { is_expected.to eq('vagrant_') }
|
58
47
|
end
|
59
48
|
|
60
|
-
describe '
|
61
|
-
|
62
|
-
|
49
|
+
describe '#vm_memory' do
|
50
|
+
subject { super().vm_memory }
|
51
|
+
it { is_expected.to eq(512) }
|
63
52
|
end
|
64
53
|
|
65
|
-
describe '
|
66
|
-
|
67
|
-
|
54
|
+
describe '#task_timeout' do
|
55
|
+
subject { super().task_timeout }
|
56
|
+
it { is_expected.to eq(60) }
|
68
57
|
end
|
58
|
+
|
59
|
+
describe '#task_status_check_interval' do
|
60
|
+
subject { super().task_status_check_interval }
|
61
|
+
it { is_expected.to eq(2) }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#ssh_timeout' do
|
65
|
+
subject { super().ssh_timeout }
|
66
|
+
it { is_expected.to eq(60) }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#ssh_status_check_interval' do
|
70
|
+
subject { super().ssh_status_check_interval }
|
71
|
+
it { is_expected.to eq(5) }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#imgcopy_timeout' do
|
75
|
+
subject { super().imgcopy_timeout }
|
76
|
+
it { is_expected.to eq(120) }
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#qemu_os' do
|
80
|
+
subject { super().qemu_os }
|
81
|
+
it { is_expected.to be_nil }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#qemu_iso' do
|
85
|
+
subject { super().qemu_iso }
|
86
|
+
it { is_expected.to be_nil }
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#qemu_iso_file' do
|
90
|
+
subject { super().qemu_iso_file }
|
91
|
+
it { is_expected.to be_nil }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#qemu_disk_size' do
|
95
|
+
subject { super().qemu_disk_size }
|
96
|
+
it { is_expected.to be_nil }
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'of a given Vagrantfile' do
|
102
|
+
|
103
|
+
let(:proxmox_qemu_iso) { '' }
|
104
|
+
let(:proxmox_openvz_os_template) { "proxmox.openvz_os_template = 'local:vztmpl/template.tar.gz'" }
|
105
|
+
let(:proxmox_openvz_template_file) { '' }
|
106
|
+
let(:proxmox_vm_type) { 'proxmox.vm_type = :openvz' }
|
107
|
+
let(:proxmox_qemu_iso_file) { '' }
|
108
|
+
let(:proxmox_qemu_disk_size) { '' }
|
109
|
+
let(:vagrantfile_content) { "
|
110
|
+
Vagrant.configure('2') do |config|
|
111
|
+
config.vm.provider :proxmox do |proxmox|
|
112
|
+
proxmox.endpoint = 'https://proxmox.example.com/api2/json'
|
113
|
+
proxmox.user_name = 'vagrant'
|
114
|
+
proxmox.password = 'password'
|
115
|
+
#{proxmox_vm_type}
|
116
|
+
#{proxmox_openvz_os_template}
|
117
|
+
#{proxmox_openvz_template_file}
|
118
|
+
#{proxmox_qemu_iso}
|
119
|
+
#{proxmox_qemu_iso_file}
|
120
|
+
#{proxmox_qemu_disk_size}
|
121
|
+
proxmox.vm_id_range = 900..910
|
122
|
+
proxmox.vm_name_prefix = 'vagrant_test_'
|
123
|
+
proxmox.vm_memory = 256
|
124
|
+
proxmox.task_timeout = 30
|
125
|
+
proxmox.task_status_check_interval = 1
|
69
126
|
end
|
70
127
|
|
128
|
+
config.vm.define :machine, primary: true do |machine|
|
129
|
+
machine.vm.box = 'b681e2bc-617b-4b35-94fa-edc92e1071b8'
|
130
|
+
end
|
71
131
|
end
|
132
|
+
" }
|
133
|
+
|
134
|
+
let(:vagrantfile) do
|
135
|
+
File.open("#{Dir.tmpdir}/#{Dir::Tmpname.make_tmpname 'rspec', nil }", 'w').tap do |file|
|
136
|
+
file.write vagrantfile_content
|
137
|
+
file.flush
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: vagrantfile.path }
|
142
|
+
let(:config) { environment.machine(environment.primary_machine_name, :proxmox).config.vm.get_provider_config :proxmox }
|
143
|
+
|
144
|
+
after { File.unlink (vagrantfile.path) }
|
145
|
+
|
146
|
+
describe 'overwriting defaults' do
|
147
|
+
|
148
|
+
subject { config }
|
149
|
+
|
150
|
+
describe '#endpoint' do
|
151
|
+
subject { super().endpoint }
|
152
|
+
it { is_expected.to eq('https://proxmox.example.com/api2/json') }
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#user_name' do
|
156
|
+
subject { super().user_name }
|
157
|
+
it { is_expected.to eq('vagrant') }
|
158
|
+
end
|
159
|
+
|
160
|
+
describe '#password' do
|
161
|
+
subject { super().password }
|
162
|
+
it { is_expected.to eq('password') }
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with an existing template file' do
|
166
|
+
describe '#openvz_os_template' do
|
167
|
+
before do
|
168
|
+
end
|
169
|
+
subject { super().openvz_os_template }
|
170
|
+
it { is_expected.to eq('local:vztmpl/template.tar.gz') }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'with a new template file' do
|
175
|
+
let(:proxmox_openvz_os_template) { "" }
|
176
|
+
let(:proxmox_openvz_template_file) { "proxmox.openvz_template_file = 'template.tar.gz'" }
|
177
|
+
|
178
|
+
describe '#openvz_template_file' do
|
179
|
+
before do
|
180
|
+
end
|
181
|
+
subject { super().openvz_template_file }
|
182
|
+
it { is_expected.to eq('template.tar.gz') }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe '#vm_id_range' do
|
187
|
+
subject { super().vm_id_range }
|
188
|
+
it { is_expected.to eq(900..910) }
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '#vm_name_prefix' do
|
192
|
+
subject { super().vm_name_prefix }
|
193
|
+
it { is_expected.to eq('vagrant_test_') }
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#vm_memory' do
|
197
|
+
subject { super().vm_memory }
|
198
|
+
it { is_expected.to eq(256) }
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '#task_timeout' do
|
202
|
+
subject { super().task_timeout }
|
203
|
+
it { is_expected.to eq(30) }
|
204
|
+
end
|
205
|
+
|
206
|
+
describe '#task_status_check_interval' do
|
207
|
+
subject { super().task_status_check_interval }
|
208
|
+
it { is_expected.to eq(1) }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe 'is validated' do
|
213
|
+
let(:machine) { double 'machine' }
|
214
|
+
let(:environment) { Vagrant::Environment.new vagrantfile_name: 'dummy_box/Vagrantfile' }
|
215
|
+
let(:config) { environment.machine(environment.primary_machine_name, :proxmox).config.vm.get_provider_config :proxmox }
|
216
|
+
|
217
|
+
subject { config }
|
218
|
+
|
219
|
+
context 'when the vagrantfile is valid' do
|
220
|
+
specify 'the configuration should be valid' do
|
221
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => []})
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context 'when the vagrantfile is erroneous' do
|
226
|
+
|
227
|
+
describe 'because of a missing endpoint' do
|
228
|
+
before { subject.endpoint = nil }
|
229
|
+
specify 'it should report an error' do
|
230
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No endpoint specified.']})
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe 'because of a missing user_name' do
|
235
|
+
before { subject.user_name = nil }
|
236
|
+
specify 'it should report an error' do
|
237
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No user_name specified.']})
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
describe 'because of a missing password' do
|
242
|
+
before { subject.password = nil }
|
243
|
+
specify 'it should report an error' do
|
244
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No password specified.']})
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe 'because of a missing vm_type' do
|
249
|
+
before { subject.vm_type = nil }
|
250
|
+
specify 'it should report an error' do
|
251
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No vm_type specified']})
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'with vm_type = :openvz' do
|
256
|
+
|
257
|
+
describe 'because of a missing openvz_os_template and missing openvz_template_file' do
|
258
|
+
before do
|
259
|
+
subject.openvz_os_template = nil
|
260
|
+
subject.openvz_template_file = nil
|
261
|
+
end
|
262
|
+
specify 'it should report an error' do
|
263
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No openvz_os_template or openvz_template_file specified for vm_type=:openvz']})
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'with vm_type = :qemu' do
|
269
|
+
|
270
|
+
before do
|
271
|
+
subject.vm_type = :qemu
|
272
|
+
subject.qemu_os = :l26
|
273
|
+
subject.qemu_iso = 'anyiso.iso'
|
274
|
+
subject.qemu_disk_size = '30G'
|
275
|
+
end
|
276
|
+
|
277
|
+
describe 'because of a missing qemu_iso and missing qemu_iso_file' do
|
278
|
+
before do
|
279
|
+
subject.qemu_iso = nil
|
280
|
+
subject.qemu_iso_file = nil
|
281
|
+
end
|
282
|
+
specify 'it should report an error' do
|
283
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No qemu_iso or qemu_iso_file specified for vm_type=:qemu']})
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
describe 'because of a missing qemu_os_type' do
|
288
|
+
before do
|
289
|
+
subject.qemu_os = nil
|
290
|
+
end
|
291
|
+
specify 'it should report an error' do
|
292
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No qemu_os specified for vm_type=:qemu']})
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
describe 'because of a missing qemu_disk_size' do
|
297
|
+
before do
|
298
|
+
subject.qemu_disk_size = nil
|
299
|
+
end
|
300
|
+
specify 'it should report an error' do
|
301
|
+
expect(subject.validate(machine)).to eq({'Proxmox Provider' => ['No qemu_disk_size specified for vm_type=:qemu']})
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe 'is finalized' do
|
310
|
+
|
311
|
+
context 'with vm_type=:openvz' do
|
312
|
+
|
313
|
+
context 'a template file was specified' do
|
314
|
+
|
315
|
+
let(:proxmox_openvz_os_template) { '' }
|
316
|
+
let(:proxmox_openvz_template_file) { "proxmox.openvz_template_file = '/my/dir/mytemplate.tar.gz'" }
|
317
|
+
|
318
|
+
it 'should set the openvz_os_template to the uploaded template file' do
|
319
|
+
expect(config.openvz_os_template).to eq('local:vztmpl/mytemplate.tar.gz')
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
context 'with vm_type=:qemu' do
|
326
|
+
|
327
|
+
context 'an iso file was specified' do
|
328
|
+
|
329
|
+
let(:proxmox_openvz_os_template) { '' }
|
330
|
+
let(:proxmox_openvz_template_file) { '' }
|
331
|
+
let(:proxmox_qemu_iso) { '' }
|
332
|
+
let(:proxmox_qemu_iso_file) { "proxmox.qemu_iso_file = '/my/dir/myiso.iso'" }
|
333
|
+
|
334
|
+
it 'should set the openvz_os_template to the uploaded template file' do
|
335
|
+
expect(config.qemu_iso).to eq('local:iso/myiso.iso')
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context 'when the disk size contains a unit' do
|
340
|
+
|
341
|
+
let (:proxmox_qemu_disk_size) {"proxmox.qemu_disk_size = '15G' "}
|
342
|
+
|
343
|
+
it 'should be converted into gigabytes' do
|
344
|
+
expect(config.qemu_disk_size).to eq('15')
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|