foreman_fog_proxmox 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of foreman_fog_proxmox might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +24 -12
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +26 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +92 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +60 -0
- data/app/assets/javascripts/foreman_fog_proxmox/{proxmox.js → proxmox_vm_server.js} +10 -10
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +9 -1
- data/app/helpers/node_dashboard_helper.rb +36 -0
- data/app/helpers/proxmox_compute_selectors_helper.rb +23 -0
- data/app/helpers/proxmox_container_helper.rb +157 -0
- data/app/helpers/proxmox_form_helper.rb +67 -0
- data/app/helpers/{proxmox_compute_helper.rb → proxmox_server_helper.rb} +49 -38
- data/app/helpers/proxmox_vm_helper.rb +86 -0
- data/app/models/concerns/fog_extensions/proxmox/container.rb +57 -0
- data/{test/factories/foreman_fog_proxmox_factories.rb → app/models/concerns/fog_extensions/proxmox/container_config.rb} +16 -13
- data/app/models/concerns/fog_extensions/proxmox/server.rb +8 -2
- data/app/models/foreman_fog_proxmox/proxmox.rb +160 -67
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +24 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +32 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +24 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +24 -0
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
- data/app/views/compute_resources/form/_proxmox.html.erb +7 -4
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +25 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +73 -0
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +16 -23
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +37 -0
- data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +2 -7
- data/app/views/compute_resources_vms/form/proxmox/container/_advanced.html.erb +31 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +41 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +26 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +25 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +25 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +24 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +31 -0
- data/app/views/compute_resources_vms/form/proxmox/{_config.html.erb → server/_config.html.erb} +11 -8
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +29 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +27 -0
- data/app/views/compute_resources_vms/index/_proxmox.html.erb +4 -2
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +9 -2
- data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +4 -2
- data/app/views/images/form/_proxmox.html.erb +17 -0
- data/config/routes.rb +1 -0
- data/lib/foreman_fog_proxmox/engine.rb +10 -3
- data/lib/foreman_fog_proxmox/value.rb +24 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/locale/en/foreman_fog_proxmox.edit.po +456 -0
- data/locale/en/foreman_fog_proxmox.po +327 -11
- data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/foreman_fog_proxmox.pot +515 -8
- data/locale/fr/foreman_fog_proxmox.edit.po +456 -0
- data/locale/fr/foreman_fog_proxmox.po +327 -11
- data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
- data/test/factories/proxmox_factory.rb +72 -0
- data/test/functional/compute_resources_controller_test.rb +34 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +205 -0
- data/test/{helpers/proxmox_compute_helper_test.rb → unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb} +36 -28
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +240 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +327 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test_helpers.rb +251 -0
- metadata +83 -14
- data/app/views/compute_resources_vms/form/proxmox/_volume.html.erb +0 -23
- data/test/unit/foreman_fog_proxmox_test.rb +0 -11
@@ -0,0 +1,327 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of ForemanFogProxmox.
|
6
|
+
|
7
|
+
# ForemanFogProxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# ForemanFogProxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require 'test_plugin_helper'
|
21
|
+
require 'models/compute_resources/compute_resource_test_helpers'
|
22
|
+
require 'unit/foreman_fog_proxmox/proxmox_test_helpers'
|
23
|
+
|
24
|
+
module ForemanFogProxmox
|
25
|
+
|
26
|
+
class ProxmoxTest < ActiveSupport::TestCase
|
27
|
+
include ComputeResourceTestHelpers
|
28
|
+
include ForemanFogProxmox::ProxmoxTestHelpers
|
29
|
+
|
30
|
+
should validate_presence_of(:url)
|
31
|
+
should validate_presence_of(:user)
|
32
|
+
should validate_presence_of(:password)
|
33
|
+
should validate_presence_of(:node_name)
|
34
|
+
should allow_value('root@pam').for(:user)
|
35
|
+
should_not allow_value('root').for(:user)
|
36
|
+
should_not allow_value('a').for(:url)
|
37
|
+
should allow_values('http://foo.com', 'http://bar.com/baz').for(:url)
|
38
|
+
|
39
|
+
test "#associated_host matches any NIC" do
|
40
|
+
mac = 'ca:d0:e6:32:16:97'
|
41
|
+
host = FactoryBot.create(:host, :mac => mac)
|
42
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
43
|
+
vm = mock('vm', :mac => mac)
|
44
|
+
assert_equal host, (as_admin { cr.associated_host(vm) })
|
45
|
+
end
|
46
|
+
|
47
|
+
test "#node" do
|
48
|
+
node_name = 'pve'
|
49
|
+
cr = FactoryBot.build_stubbed(:proxmox_cr)
|
50
|
+
assert_equal node_name, (as_admin { cr.node.to_s })
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "destroy_vm" do
|
54
|
+
it "handles situation when vm is not present" do
|
55
|
+
cr = mock_cr_servers(ForemanFogProxmox::Proxmox.new, empty_servers)
|
56
|
+
cr.expects(:find_vm_by_uuid).raises(ActiveRecord::RecordNotFound)
|
57
|
+
assert cr.destroy_vm('abc')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "find_vm_by_uuid" do
|
62
|
+
it "raises Foreman::Exception when the uuid does not match" do
|
63
|
+
cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, empty_servers)
|
64
|
+
assert_raises Foreman::Exception do
|
65
|
+
cr.find_vm_by_uuid('100')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "raises RecordNotFound when the compute raises retrieve error" do
|
70
|
+
exception = Fog::Proxmox::Errors::ServiceError.new(StandardError.new('VM not found'))
|
71
|
+
cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers_raising_exception(exception))
|
72
|
+
assert_raises ActiveRecord::RecordNotFound do
|
73
|
+
cr.find_vm_by_uuid('qemu_100')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "host_interfaces_attrs" do
|
79
|
+
before do
|
80
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "raises Foreman::Exception when physical identifier is empty" do
|
84
|
+
physical_nic = FactoryBot.build(:nic_base_empty)
|
85
|
+
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic])
|
86
|
+
err = assert_raises Foreman::Exception do
|
87
|
+
@cr.host_interfaces_attrs(host)
|
88
|
+
end
|
89
|
+
assert err.message.end_with?('Identifier interface[0] required.')
|
90
|
+
end
|
91
|
+
|
92
|
+
it "raises Foreman::Exception when physical identifier does not match net[k] with k integer" do
|
93
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0')
|
94
|
+
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic])
|
95
|
+
err = assert_raises Foreman::Exception do
|
96
|
+
@cr.host_interfaces_attrs(host)
|
97
|
+
end
|
98
|
+
assert err.message.end_with?('Invalid identifier interface[0]. Must be net[n] with n integer >= 0')
|
99
|
+
end
|
100
|
+
|
101
|
+
it "sets compute id with identifier, ip and ip6" do
|
102
|
+
ip = IPAddr.new(1, Socket::AF_INET).to_s
|
103
|
+
ip6 = Array.new(4) { '%x' % rand(16**4) }.join(':') + '::1'
|
104
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6)
|
105
|
+
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic])
|
106
|
+
nic_attributes = @cr.host_interfaces_attrs(host).values.select(&:present?)
|
107
|
+
nic_attr = nic_attributes.first
|
108
|
+
assert_equal 'net0', nic_attr[:id]
|
109
|
+
assert_equal ip, nic_attr[:ip]
|
110
|
+
assert_equal ip6, nic_attr[:ip6]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "host_compute_attrs" do
|
115
|
+
before do
|
116
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "raises Foreman::Exception when server ostype does not match os family" do
|
120
|
+
operatingsystem = FactoryBot.build(:solaris)
|
121
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
|
122
|
+
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic], :operatingsystem => operatingsystem, :compute_attributes => { 'type' => 'qemu', 'config_attributes' => { 'ostype' => 'l26' } })
|
123
|
+
err = assert_raises Foreman::Exception do
|
124
|
+
@cr.host_compute_attrs(host)
|
125
|
+
end
|
126
|
+
assert err.message.end_with?('Operating system family Solaris is not consistent with l26')
|
127
|
+
end
|
128
|
+
|
129
|
+
it "sets container hostname with host name" do
|
130
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
|
131
|
+
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic], :compute_attributes => { 'type' => 'lxc', 'config_attributes' => { 'hostname' => '' } })
|
132
|
+
@cr.host_compute_attrs(host)
|
133
|
+
assert_equal host.name, host.compute_attributes['config_attributes']['hostname']
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
describe "vm_compute_attributes" do
|
139
|
+
before do
|
140
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "converts to hash a server" do
|
144
|
+
vm, config_attributes, volume_attributes, interface_attributes = mock_server_vm
|
145
|
+
vm_attrs = @cr.vm_compute_attributes(vm)
|
146
|
+
assert !vm_attrs.has_key?(:config)
|
147
|
+
assert vm_attrs.has_key?(:config_attributes)
|
148
|
+
assert_equal config_attributes.reject { |key,value| [:disks,:interfaces].include?(key) || value.to_s.empty?}, vm_attrs[:config_attributes]
|
149
|
+
assert !vm_attrs[:config_attributes].has_key?(:disks)
|
150
|
+
assert vm_attrs.has_key?(:volumes_attributes)
|
151
|
+
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
152
|
+
assert !vm_attrs[:config_attributes].has_key?(:interfaces)
|
153
|
+
assert vm_attrs.has_key?(:interfaces_attributes)
|
154
|
+
assert_equal interface_attributes, vm_attrs[:interfaces_attributes]['0']
|
155
|
+
end
|
156
|
+
|
157
|
+
it "converts to hash a container" do
|
158
|
+
vm, config_attributes, volume_attributes, interface_attributes = mock_container_vm
|
159
|
+
vm_attrs = @cr.vm_compute_attributes(vm)
|
160
|
+
assert !vm_attrs.has_key?(:config)
|
161
|
+
assert vm_attrs.has_key?(:config_attributes)
|
162
|
+
assert_equal config_attributes.reject { |key,value| [:mount_points,:interfaces].include?(key) || value.to_s.empty?}, vm_attrs[:config_attributes]
|
163
|
+
assert !vm_attrs[:config_attributes].has_key?(:mount_points)
|
164
|
+
assert vm_attrs.has_key?(:volumes_attributes)
|
165
|
+
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
166
|
+
assert vm_attrs.has_key?(:interfaces_attributes)
|
167
|
+
assert_equal interface_attributes, vm_attrs[:interfaces_attributes]['0']
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
describe 'save_vm' do
|
173
|
+
before do
|
174
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'saves modified server config' do
|
178
|
+
uuid = 'qemu_100'
|
179
|
+
config = mock('config')
|
180
|
+
config.stubs(:attributes).returns({ :cores => '' })
|
181
|
+
vm = mock('vm')
|
182
|
+
vm.stubs(:config).returns(config)
|
183
|
+
vm.stubs(:container?).returns(false)
|
184
|
+
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
185
|
+
attr = { 'templated' => '0', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1' } }
|
186
|
+
@cr.stubs(:parse_server_vm).returns({ 'vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1' })
|
187
|
+
expected_attr = { :cores => '1', :cpulimit => '1' }
|
188
|
+
vm.expects(:update, expected_attr)
|
189
|
+
@cr.save_vm(uuid,attr)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'saves modified container config' do
|
193
|
+
uuid = 'lxc_100'
|
194
|
+
config = mock('config')
|
195
|
+
config.stubs(:attributes).returns({ :cores => '' })
|
196
|
+
vm = mock('vm')
|
197
|
+
vm.stubs(:config).returns(config)
|
198
|
+
vm.stubs(:container?).returns(true)
|
199
|
+
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
200
|
+
attr = { 'templated' => '0', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1' } }
|
201
|
+
@cr.stubs(:parse_container_vm).returns({ 'vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1' })
|
202
|
+
expected_attr = { :cores => '1', :cpulimit => '1' }
|
203
|
+
vm.expects(:update, expected_attr)
|
204
|
+
@cr.save_vm(uuid,attr)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe 'create_vm' do
|
209
|
+
|
210
|
+
it 'raises Foreman::Exception when vmid is invalid' do
|
211
|
+
args = { vmid: '100' }
|
212
|
+
servers = mock('servers')
|
213
|
+
servers.stubs(:id_valid?).returns(false)
|
214
|
+
cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
|
215
|
+
err = assert_raises Foreman::Exception do
|
216
|
+
cr.create_vm(args)
|
217
|
+
end
|
218
|
+
assert err.message.end_with?('invalid vmid=100')
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'creates server' do
|
222
|
+
args = { vmid: '100', type: 'qemu' }
|
223
|
+
servers = mock('servers')
|
224
|
+
servers.stubs(:id_valid?).returns(true)
|
225
|
+
cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
|
226
|
+
cr.stubs(:convert_sizes).with(args)
|
227
|
+
cr.stubs(:parse_server_vm).with(args).returns(args)
|
228
|
+
servers.stubs(:create).with(args)
|
229
|
+
vm = mock('vm')
|
230
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:type]}_#{args[:vmid]}").returns(vm)
|
231
|
+
cr.create_vm(args)
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'creates container' do
|
235
|
+
args = { vmid: '100', type: 'lxc' }
|
236
|
+
servers = mock('servers')
|
237
|
+
servers.stubs(:id_valid?).returns(true)
|
238
|
+
containers = mock('containers')
|
239
|
+
containers.stubs(:create).with(vmid: 100, type: 'lxc')
|
240
|
+
cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
|
241
|
+
cr.stubs(:convert_sizes).with(args)
|
242
|
+
cr.stubs(:parse_container_vm).with(args).returns(args)
|
243
|
+
vm = mock('vm')
|
244
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:type]}_#{args[:vmid]}").returns(vm)
|
245
|
+
cr.create_vm(args)
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'clones server' do
|
249
|
+
args = { vmid: '100', type: 'qemu', image_id: '999', name: 'name' }
|
250
|
+
servers = mock('servers')
|
251
|
+
servers.stubs(:id_valid?).returns(true)
|
252
|
+
cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
|
253
|
+
cr.stubs(:convert_sizes).with(args)
|
254
|
+
cr.stubs(:parse_server_vm).with(args).returns(args)
|
255
|
+
servers.stubs(:create).with(args)
|
256
|
+
image = mock('image')
|
257
|
+
clone = mock('clone')
|
258
|
+
image.stubs(:clone).with(100)
|
259
|
+
servers.stubs(:get).with(100).returns(clone)
|
260
|
+
servers.stubs(:get).with('999').returns(image)
|
261
|
+
clone.stubs(:update).with(name: 'name')
|
262
|
+
vm = mock('vm')
|
263
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:type]}_#{args[:vmid]}").returns(vm)
|
264
|
+
cr.create_vm(args)
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'clones container' do
|
268
|
+
args = { vmid: '100', type: 'lxc', image_id: '999', name: 'name' }
|
269
|
+
servers = mock('servers')
|
270
|
+
servers.stubs(:id_valid?).returns(true)
|
271
|
+
containers = mock('containers')
|
272
|
+
containers.stubs(:create).with(vmid: 100, type: 'lxc')
|
273
|
+
image = mock('image')
|
274
|
+
clone = mock('clone')
|
275
|
+
image.stubs(:clone).with(100)
|
276
|
+
servers.stubs(:get).with(100).returns(clone)
|
277
|
+
servers.stubs(:get).with('999').returns(image)
|
278
|
+
clone.stubs(:update).with(name: 'name')
|
279
|
+
cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
|
280
|
+
cr.stubs(:convert_sizes).with(args)
|
281
|
+
cr.stubs(:parse_container_vm).with(args).returns(args)
|
282
|
+
vm = mock('vm')
|
283
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:type]}_#{args[:vmid]}").returns(vm)
|
284
|
+
cr.create_vm(args)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe 'new_vm' do
|
289
|
+
before do
|
290
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'new server with attr empty' do
|
294
|
+
attr = {}
|
295
|
+
vm = mock('vm')
|
296
|
+
config = mock('config')
|
297
|
+
config.stubs(:inspect).returns('config')
|
298
|
+
vm.stubs(:config).returns(config)
|
299
|
+
@cr.stubs(:new_server_vm).with(attr).returns(vm)
|
300
|
+
assert_equal vm, @cr.new_vm(attr)
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'new server with attr not empty' do
|
304
|
+
attr = {'type' => 'qemu'}
|
305
|
+
vm = mock('vm')
|
306
|
+
config = mock('config')
|
307
|
+
config.stubs(:inspect).returns('config')
|
308
|
+
vm.stubs(:config).returns(config)
|
309
|
+
@cr.stubs(:new_server_vm).with(attr).returns(vm)
|
310
|
+
assert_equal vm, @cr.new_vm(attr)
|
311
|
+
end
|
312
|
+
|
313
|
+
it 'new container with attr not empty' do
|
314
|
+
attr = {'type' => 'lxc'}
|
315
|
+
vm = mock('vm')
|
316
|
+
config = mock('config')
|
317
|
+
config.stubs(:inspect).returns('config')
|
318
|
+
vm.stubs(:config).returns(config)
|
319
|
+
@cr.stubs(:new_container_vm).with(attr).returns(vm)
|
320
|
+
assert_equal vm, @cr.new_vm(attr)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
|
326
|
+
end
|
327
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2018 Tristan Robert
|
4
|
+
|
5
|
+
# This file is part of ForemanFogProxmox.
|
6
|
+
|
7
|
+
# ForemanFogProxmox is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
|
12
|
+
# ForemanFogProxmox is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
module ForemanFogProxmox
|
21
|
+
module ProxmoxTestHelpers
|
22
|
+
|
23
|
+
def mock_node_servers(cr, servers)
|
24
|
+
node = mock('node')
|
25
|
+
node.stubs(:servers).returns(servers)
|
26
|
+
cr.stubs(:node).returns(node)
|
27
|
+
cr
|
28
|
+
end
|
29
|
+
|
30
|
+
def mock_node_servers_containers(cr, servers, containers)
|
31
|
+
node = mock('node')
|
32
|
+
node.stubs(:containers).returns(containers)
|
33
|
+
node.stubs(:servers).returns(servers)
|
34
|
+
cr.stubs(:node).returns(node)
|
35
|
+
cr
|
36
|
+
end
|
37
|
+
|
38
|
+
def mock_server_vm
|
39
|
+
interface_attributes = {
|
40
|
+
id: 'net0',
|
41
|
+
mac: '36:25:8C:53:0C:50',
|
42
|
+
model: 'virtio',
|
43
|
+
name: nil,
|
44
|
+
ip: nil,
|
45
|
+
ip6: nil,
|
46
|
+
bridge: 'vmbr0',
|
47
|
+
firewall: nil,
|
48
|
+
link_down: nil,
|
49
|
+
rate: nil,
|
50
|
+
queues: nil,
|
51
|
+
tag: nil
|
52
|
+
}
|
53
|
+
interface = mock('interface')
|
54
|
+
interface.stubs(:attributes).returns(interface_attributes)
|
55
|
+
interfaces = [interface]
|
56
|
+
volume_attributes = {
|
57
|
+
id: 'scsi0',
|
58
|
+
volid: 'local-lvm:vm-100-disk-1',
|
59
|
+
size: 8,
|
60
|
+
storage: 'local-lvm',
|
61
|
+
cache: 'none',
|
62
|
+
replicate: nil,
|
63
|
+
media: nil,
|
64
|
+
format: nil,
|
65
|
+
model: 'scsi',
|
66
|
+
shared: nil,
|
67
|
+
snapshot: nil,
|
68
|
+
backup: nil,
|
69
|
+
aio: nil
|
70
|
+
}
|
71
|
+
volume = mock('volume')
|
72
|
+
volume.stubs(:attributes).returns(volume_attributes)
|
73
|
+
volumes = [volume]
|
74
|
+
config = mock('config')
|
75
|
+
config_attributes = {
|
76
|
+
vmid: 100,
|
77
|
+
digest: '0',
|
78
|
+
description: '',
|
79
|
+
ostype: 'l26',
|
80
|
+
smbios1: '0',
|
81
|
+
numa: 0,
|
82
|
+
kvm: 0,
|
83
|
+
vcpus: 1,
|
84
|
+
cores: 1,
|
85
|
+
bootdisk: 'scsi0',
|
86
|
+
onboot: 0,
|
87
|
+
boot: 'scsi0',
|
88
|
+
agent: 0,
|
89
|
+
scsihw: 'scsi',
|
90
|
+
sockets: 1,
|
91
|
+
memory: 512,
|
92
|
+
min_memory: 0,
|
93
|
+
shares: 0,
|
94
|
+
balloon: 0,
|
95
|
+
name: 'test',
|
96
|
+
cpu: 1,
|
97
|
+
cpulimit: nil,
|
98
|
+
cpuunits: nil,
|
99
|
+
keyboard: 'fr',
|
100
|
+
vga: 'std',
|
101
|
+
interfaces: interfaces,
|
102
|
+
disks: volumes
|
103
|
+
}
|
104
|
+
config.stubs(:attributes).returns(config_attributes)
|
105
|
+
config.stubs(:disks).returns(volumes)
|
106
|
+
config.stubs(:interfaces).returns(interfaces)
|
107
|
+
vm = mock('vm')
|
108
|
+
vm.stubs(:config).returns(config)
|
109
|
+
vm_attributes = {
|
110
|
+
vmid: 100,
|
111
|
+
id: 'qemu/100',
|
112
|
+
node: 'pve',
|
113
|
+
config: config,
|
114
|
+
name: 'test',
|
115
|
+
type: 'qemu',
|
116
|
+
maxdisk: 0,
|
117
|
+
disk: 0,
|
118
|
+
diskwrite: 0,
|
119
|
+
diskread: 0,
|
120
|
+
uptime: 0,
|
121
|
+
netout: 0,
|
122
|
+
netin: 0,
|
123
|
+
cpu: 1,
|
124
|
+
cpus: 1,
|
125
|
+
template: 0,
|
126
|
+
status: 'stopped',
|
127
|
+
maxcpu: 0,
|
128
|
+
mem: 0,
|
129
|
+
maxmem: 512,
|
130
|
+
qmpstatus: 'stopped',
|
131
|
+
ha: {},
|
132
|
+
pid: 0,
|
133
|
+
blockstat: 0,
|
134
|
+
balloon: 0,
|
135
|
+
ballooninfo: 0,
|
136
|
+
snapshots: []
|
137
|
+
}
|
138
|
+
vm.stubs(:attributes).returns(vm_attributes)
|
139
|
+
vm.stubs(:container?).returns(false)
|
140
|
+
return vm, config_attributes, volume_attributes, interface_attributes
|
141
|
+
end
|
142
|
+
|
143
|
+
def mock_container_vm
|
144
|
+
interface_attributes = {
|
145
|
+
id: 'net0',
|
146
|
+
mac: '36:25:8C:53:0C:50',
|
147
|
+
model: nil,
|
148
|
+
name: 'eth0',
|
149
|
+
ip: nil,
|
150
|
+
ip6: nil,
|
151
|
+
bridge: 'vmbr0',
|
152
|
+
firewall: nil,
|
153
|
+
link_down: nil,
|
154
|
+
rate: nil,
|
155
|
+
queues: nil,
|
156
|
+
tag: nil
|
157
|
+
}
|
158
|
+
interface = mock('interface')
|
159
|
+
interface.stubs(:attributes).returns(interface_attributes)
|
160
|
+
interfaces = [interface]
|
161
|
+
volume_attributes = {
|
162
|
+
id: 'rootfs',
|
163
|
+
volid: 'local-lvm:vm-100-disk-1',
|
164
|
+
size: 8,
|
165
|
+
storage: 'local-lvm',
|
166
|
+
cache: 'none',
|
167
|
+
replicate: nil,
|
168
|
+
media: nil,
|
169
|
+
format: nil,
|
170
|
+
model: 'rootfs',
|
171
|
+
shared: nil,
|
172
|
+
snapshot: nil,
|
173
|
+
backup: nil,
|
174
|
+
aio: nil
|
175
|
+
}
|
176
|
+
volume = mock('volume')
|
177
|
+
volume.stubs(:attributes).returns(volume_attributes)
|
178
|
+
volumes = [volume]
|
179
|
+
config = mock('config')
|
180
|
+
config_attributes = {
|
181
|
+
vmid: 100,
|
182
|
+
digest: '0',
|
183
|
+
ostype: 'alpine',
|
184
|
+
storage: 'local-lvm',
|
185
|
+
template: 0,
|
186
|
+
arch: 'amd64',
|
187
|
+
memory: 512,
|
188
|
+
swap: nil,
|
189
|
+
hostname: 'test',
|
190
|
+
nameserver: nil,
|
191
|
+
searchdomain: nil,
|
192
|
+
password: 'proxmox01',
|
193
|
+
onboot: 0,
|
194
|
+
startup: nil,
|
195
|
+
rootfs: 'local-lvm:vm-100-disk-1',
|
196
|
+
cores: 1,
|
197
|
+
cpuunits: nil,
|
198
|
+
cpulimit: nil,
|
199
|
+
description: nil,
|
200
|
+
console: nil,
|
201
|
+
cmode: nil,
|
202
|
+
tty: nil,
|
203
|
+
force: nil,
|
204
|
+
lock: nil,
|
205
|
+
pool: nil,
|
206
|
+
bwlimit: nil,
|
207
|
+
unprivileged: nil,
|
208
|
+
interfaces: interfaces,
|
209
|
+
mount_points: volumes
|
210
|
+
}
|
211
|
+
config.stubs(:attributes).returns(config_attributes)
|
212
|
+
config.stubs(:mount_points).returns(volumes)
|
213
|
+
config.stubs(:interfaces).returns(interfaces)
|
214
|
+
vm = mock('vm')
|
215
|
+
vm.stubs(:config).returns(config)
|
216
|
+
vm_attributes = {
|
217
|
+
vmid: 100,
|
218
|
+
id: 'lxc/100',
|
219
|
+
node: 'pve',
|
220
|
+
config: config,
|
221
|
+
name: 'test',
|
222
|
+
type: 'lxc',
|
223
|
+
maxdisk: 0,
|
224
|
+
disk: 0,
|
225
|
+
diskwrite: 0,
|
226
|
+
diskread: 0,
|
227
|
+
uptime: 0,
|
228
|
+
netout: 0,
|
229
|
+
netin: 0,
|
230
|
+
cpu: 1,
|
231
|
+
cpus: 1,
|
232
|
+
template: 0,
|
233
|
+
status: 'stopped',
|
234
|
+
maxcpu: 0,
|
235
|
+
mem: 0,
|
236
|
+
maxmem: 512,
|
237
|
+
qmpstatus: 'stopped',
|
238
|
+
ha: {},
|
239
|
+
pid: 0,
|
240
|
+
blockstat: 0,
|
241
|
+
balloon: 0,
|
242
|
+
ballooninfo: 0,
|
243
|
+
snapshots: []
|
244
|
+
}
|
245
|
+
vm.stubs(:attributes).returns(vm_attributes)
|
246
|
+
vm.stubs(:container?).returns(true)
|
247
|
+
return vm, config_attributes, volume_attributes, interface_attributes
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
end
|