foreman_fog_proxmox 0.12.2 → 0.13.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -5
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +36 -2
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +134 -60
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -50
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js +39 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js +63 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js +25 -0
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
- data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
- data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
- data/app/helpers/proxmox_compute_selectors_helper.rb +6 -44
- data/app/helpers/proxmox_form_helper.rb +12 -4
- data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
- data/app/helpers/proxmox_vm_cdrom_helper.rb +35 -0
- data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
- data/app/helpers/proxmox_vm_config_helper.rb +160 -0
- data/app/helpers/proxmox_vm_helper.rb +24 -62
- data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
- data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
- data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_uuid_helper.rb} +14 -10
- data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
- data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
- data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
- data/app/models/concerns/fog_extensions/proxmox/server.rb +12 -3
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
- data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
- data/app/models/concerns/orchestration/proxmox/compute.rb +49 -0
- data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -18
- data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
- data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
- data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
- data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -31
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -6
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
- data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
- data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
- data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
- data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
- data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +15 -14
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
- data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
- data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
- data/config/routes.rb +7 -7
- data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
- data/lib/foreman_fog_proxmox/engine.rb +15 -10
- data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
- data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
- data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
- data/test/factories/proxmox_factory.rb +4 -4
- data/test/functional/compute_resources_controller_test.rb +4 -4
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +53 -32
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +56 -31
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -11
- data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +8 -8
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
- data/test/unit/foreman_fog_proxmox/{proxmox_vm_commands_server_update_volumes_test.rb → proxmox_vm_commands_server_update_hard_disk_test.rb} +45 -19
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
- data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
- data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
- metadata +44 -23
- data/app/helpers/proxmox_container_helper.rb +0 -163
- data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -18,14 +18,14 @@
|
|
18
18
|
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
20
|
require 'test_plugin_helper'
|
21
|
-
require 'fog/compute/
|
22
|
-
require 'fog/compute/
|
23
|
-
require 'fog/compute/
|
24
|
-
require 'fog/compute/
|
25
|
-
require 'fog/compute/
|
26
|
-
require 'fog/compute/
|
27
|
-
require 'fog/compute/
|
28
|
-
require 'fog/compute/
|
21
|
+
require 'fog/proxmox/compute/models/server'
|
22
|
+
require 'fog/proxmox/compute/models/server_config'
|
23
|
+
require 'fog/proxmox/compute/models/interface'
|
24
|
+
require 'fog/proxmox/compute/models/interfaces'
|
25
|
+
require 'fog/proxmox/compute/models/disk'
|
26
|
+
require 'fog/proxmox/compute/models/disks'
|
27
|
+
require 'fog/proxmox/compute/models/snapshots'
|
28
|
+
require 'fog/proxmox/compute/models/tasks'
|
29
29
|
|
30
30
|
module ForemanFogProxmox
|
31
31
|
class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
@@ -39,7 +39,7 @@ module ForemanFogProxmox
|
|
39
39
|
'vmid' => '100',
|
40
40
|
'hostname' => 'test',
|
41
41
|
:type => 'lxc',
|
42
|
-
:node_id => '
|
42
|
+
:node_id => 'proxmox',
|
43
43
|
:service => service,
|
44
44
|
'templated' => '0',
|
45
45
|
'memory' => '536870912',
|
@@ -61,7 +61,7 @@ module ForemanFogProxmox
|
|
61
61
|
Fog::Proxmox::Compute::Server.new(
|
62
62
|
'vmid' => '100',
|
63
63
|
'name' => 'test',
|
64
|
-
:node_id => '
|
64
|
+
:node_id => 'proxmox',
|
65
65
|
:service => service,
|
66
66
|
:type => 'qemu',
|
67
67
|
'templated' => '0',
|
@@ -84,7 +84,7 @@ module ForemanFogProxmox
|
|
84
84
|
let(:host_server) do
|
85
85
|
{ 'vmid' => '100',
|
86
86
|
'name' => 'test',
|
87
|
-
'node_id' => '
|
87
|
+
'node_id' => 'proxmox',
|
88
88
|
'type' => 'qemu',
|
89
89
|
'config_attributes' => {
|
90
90
|
'memory' => '536870912',
|
@@ -110,7 +110,7 @@ module ForemanFogProxmox
|
|
110
110
|
{ 'vmid' => '100',
|
111
111
|
'name' => 'test',
|
112
112
|
'type' => 'lxc',
|
113
|
-
'node_id' => '
|
113
|
+
'node_id' => 'proxmox',
|
114
114
|
'ostemplate_storage' => 'local',
|
115
115
|
'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
116
116
|
'password' => 'proxmox01',
|
@@ -142,31 +142,33 @@ module ForemanFogProxmox
|
|
142
142
|
describe 'object_to_config_hash' do
|
143
143
|
setup { Fog.mock! }
|
144
144
|
teardown { Fog.unmock! }
|
145
|
+
excluded_qemu_keys = ['templated', 'ide2', 'scsi0', 'net0', 'net1']
|
146
|
+
excluded_lxc_keys = ['templated', 'rootfs', 'mp0', 'net0', 'net1']
|
145
147
|
|
146
148
|
it '#server qemu' do
|
147
|
-
config_hash = object_to_config_hash(server)
|
148
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key, _value|
|
149
|
+
config_hash = object_to_config_hash(server, 'qemu')
|
150
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key, _value| excluded_qemu_keys.include? key }
|
149
151
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
150
152
|
end
|
151
153
|
|
152
154
|
it '#server lxc' do
|
153
|
-
config_hash = object_to_config_hash(server)
|
155
|
+
config_hash = object_to_config_hash(server, 'lxc')
|
154
156
|
assert config_hash.key?('config_attributes')
|
155
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key, _value|
|
157
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key, _value| excluded_qemu_keys.include? key }
|
156
158
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
157
159
|
end
|
158
160
|
|
159
161
|
it '#container qemu' do
|
160
|
-
config_hash = object_to_config_hash(container)
|
162
|
+
config_hash = object_to_config_hash(container, 'qemu')
|
161
163
|
assert config_hash.key?('config_attributes')
|
162
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value|
|
164
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value| excluded_lxc_keys.include? key }
|
163
165
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
164
166
|
end
|
165
167
|
|
166
168
|
it '#container lxc' do
|
167
|
-
config_hash = object_to_config_hash(container)
|
169
|
+
config_hash = object_to_config_hash(container, 'lxc')
|
168
170
|
assert config_hash.key?('config_attributes')
|
169
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value|
|
171
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value| excluded_lxc_keys.include? key }
|
170
172
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
171
173
|
end
|
172
174
|
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
|
22
|
+
module ForemanFogProxmox
|
23
|
+
class ProxmoxVmUuidHelperTest < ActiveSupport::TestCase
|
24
|
+
include ProxmoxVmUuidHelper
|
25
|
+
|
26
|
+
describe 'extract_vmid' do
|
27
|
+
setup { Fog.mock! }
|
28
|
+
teardown { Fog.unmock! }
|
29
|
+
|
30
|
+
it '#uuid=1_100 returns 100' do
|
31
|
+
assert_equal '100', extract_vmid('1_100')
|
32
|
+
end
|
33
|
+
it '#uuid=pve_100 returns ' do
|
34
|
+
assert_equal '', extract_vmid('pve_100')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
|
22
|
+
module ForemanFogProxmox
|
23
|
+
class ProxmoxVmVolumesHelperTest < ActiveSupport::TestCase
|
24
|
+
include ProxmoxVmVolumesHelper
|
25
|
+
|
26
|
+
describe 'remove_deletes' do
|
27
|
+
setup { Fog.mock! }
|
28
|
+
teardown { Fog.unmock! }
|
29
|
+
args = {
|
30
|
+
'volumes_attributes' => {
|
31
|
+
'0' => {
|
32
|
+
'_delete' => '',
|
33
|
+
'id' => 'scsi0',
|
34
|
+
'volid' => 'local-lvm:vm-100-disk',
|
35
|
+
'storage' => 'local-lvm',
|
36
|
+
'storage_type' => 'hard_disk'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
it '# server volumes' do
|
42
|
+
remove_volume_keys(args)
|
43
|
+
assert args.key?('volumes_attributes')
|
44
|
+
assert args['volumes_attributes'].key?('0')
|
45
|
+
assert_not args['volumes_attributes']['0'].key?('_delete')
|
46
|
+
# assert_not args['volumes_attributes']['0'].key?('storage_type')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -61,7 +61,7 @@ module ForemanFogProxmox
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'sets container hostname with host name' do
|
64
|
-
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true, :compute_attributes => { '
|
64
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true, :compute_attributes => { 'dhcp' => '1', 'dhcp6' => '1' })
|
65
65
|
host = FactoryBot.build(
|
66
66
|
:host_empty,
|
67
67
|
:interfaces => [physical_nic],
|
@@ -84,23 +84,23 @@ module ForemanFogProxmox
|
|
84
84
|
before do
|
85
85
|
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
86
86
|
end
|
87
|
+
excluded_keys = [:vmid, :disks, :interfaces]
|
87
88
|
|
88
89
|
it 'converts a server to hash' do
|
89
90
|
vm, config_attributes, volume_attributes, interface_attributes = mock_server_vm
|
90
91
|
vm_attrs = @cr.vm_compute_attributes(vm)
|
91
92
|
assert_not vm_attrs.key?(:config)
|
92
93
|
assert vm_attrs.key?(:config_attributes)
|
93
|
-
assert_equal config_attributes.reject { |key, value|
|
94
|
+
assert_equal config_attributes.reject { |key, value| excluded_keys.include?(key) || value.to_s.empty? }, vm_attrs[:config_attributes]
|
94
95
|
assert_not vm_attrs[:config_attributes].key?(:disks)
|
95
96
|
assert vm_attrs.key?(:volumes_attributes)
|
96
97
|
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
97
98
|
assert_not vm_attrs[:config_attributes].key?(:interfaces)
|
98
99
|
assert vm_attrs.key?(:interfaces_attributes)
|
99
100
|
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
|
100
|
-
assert_equal interface_attributes[:
|
101
|
-
assert_equal interface_attributes[:
|
102
|
-
assert_equal interface_attributes[:
|
103
|
-
assert_equal interface_attributes[:bridge], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
101
|
+
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:macaddr]
|
102
|
+
assert_equal interface_attributes[:compute_attributes][:model], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:model]
|
103
|
+
assert_equal interface_attributes[:compute_attributes][:bridge], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
104
104
|
end
|
105
105
|
|
106
106
|
it 'converts a container to hash' do
|
@@ -108,16 +108,15 @@ module ForemanFogProxmox
|
|
108
108
|
vm_attrs = @cr.vm_compute_attributes(vm)
|
109
109
|
assert_not vm_attrs.key?(:config)
|
110
110
|
assert vm_attrs.key?(:config_attributes)
|
111
|
-
assert_equal config_attributes.reject { |key, value|
|
111
|
+
assert_equal config_attributes.reject { |key, value| excluded_keys.include?(key) || value.to_s.empty? }, vm_attrs[:config_attributes]
|
112
112
|
assert_not vm_attrs[:config_attributes].key?(:disks)
|
113
113
|
assert vm_attrs.key?(:volumes_attributes)
|
114
114
|
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
115
115
|
assert vm_attrs.key?(:interfaces_attributes)
|
116
116
|
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
|
117
|
-
assert_equal interface_attributes[:
|
118
|
-
assert_equal interface_attributes[:
|
119
|
-
assert_equal interface_attributes[:
|
120
|
-
assert_equal interface_attributes[:bridge], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
117
|
+
assert_equal interface_attributes[:compute_attributes][:name], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:name]
|
118
|
+
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:hwaddr]
|
119
|
+
assert_equal interface_attributes[:compute_attributes][:bridge], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
121
120
|
end
|
122
121
|
end
|
123
122
|
end
|
@@ -46,10 +46,11 @@ module ForemanFogProxmox
|
|
46
46
|
assert err.message.end_with?('Invalid identifier interface[0]. Must be net[n] with n integer >= 0')
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'sets server compute id with identifier, ip and ip6' do
|
49
|
+
it 'sets server compute id with identifier, ip and ip6 and mac adress' do
|
50
50
|
ip = '192.168.56.100'
|
51
|
+
mac_address = '36:25:8C:53:0C:50'
|
51
52
|
ip6 = Array.new(4) { format('%<x>s', x: rand(16**4)) }.join(':') + '::1'
|
52
|
-
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6)
|
53
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :mac => mac_address)
|
53
54
|
host = FactoryBot.build(
|
54
55
|
:host_empty,
|
55
56
|
:interfaces => [physical_nic],
|
@@ -65,13 +66,14 @@ module ForemanFogProxmox
|
|
65
66
|
assert_equal 'net0', nic_attr[:id]
|
66
67
|
assert_equal ip, nic_attr[:ip]
|
67
68
|
assert_equal ip6, nic_attr[:ip6]
|
69
|
+
assert_equal mac_address, nic_attr[:macaddr]
|
68
70
|
end
|
69
71
|
|
70
72
|
it 'sets container compute id with identifier, ip/CIDR, gw and ip6' do
|
71
73
|
ip = '192.168.56.100'
|
72
|
-
|
74
|
+
cidr = '31'
|
73
75
|
ip6 = Array.new(4) { format('%<x>s', x: rand(16**4)) }.join(':') + '::1'
|
74
|
-
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :compute_attributes => { '
|
76
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :compute_attributes => { 'cidr' => cidr, 'gw' => ip, 'ip' => ip, 'dhcp6' => '1' })
|
75
77
|
host = FactoryBot.build(
|
76
78
|
:host_empty,
|
77
79
|
:interfaces => [physical_nic],
|
@@ -85,16 +87,16 @@ module ForemanFogProxmox
|
|
85
87
|
nic_attributes = @cr.host_interfaces_attrs(host).values.select(&:present?)
|
86
88
|
nic_attr = nic_attributes.first
|
87
89
|
assert_equal 'net0', nic_attr[:id]
|
88
|
-
assert_equal Fog::Proxmox::IpHelper.to_cidr(ip,
|
89
|
-
assert_equal ip, nic_attr[
|
90
|
+
assert_equal Fog::Proxmox::IpHelper.to_cidr(ip, cidr), nic_attr[:ip]
|
91
|
+
assert_equal ip, nic_attr['gw']
|
90
92
|
assert_equal 'dhcp', nic_attr[:ip6]
|
91
93
|
end
|
92
94
|
|
93
95
|
it 'sets container compute id with identifier, ip DHCP, gw6 and ip6' do
|
94
96
|
ip = '192.168.56.100'
|
95
|
-
|
97
|
+
cidr6 = '100'
|
96
98
|
ip6 = '2001:0:1234::c1c0:abcd:876'
|
97
|
-
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :compute_attributes => { '
|
99
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :compute_attributes => { 'cidr6' => cidr6, 'dhcp' => '1', 'gw6' => ip6 })
|
98
100
|
host = FactoryBot.build(
|
99
101
|
:host_empty,
|
100
102
|
:interfaces => [physical_nic],
|
@@ -109,8 +111,34 @@ module ForemanFogProxmox
|
|
109
111
|
nic_attr = nic_attributes.first
|
110
112
|
assert_equal 'net0', nic_attr[:id]
|
111
113
|
assert_equal 'dhcp', nic_attr[:ip]
|
112
|
-
assert_equal Fog::Proxmox::IpHelper.to_cidr6(ip6,
|
113
|
-
assert_equal ip6, nic_attr[
|
114
|
+
assert_equal Fog::Proxmox::IpHelper.to_cidr6(ip6, cidr6), nic_attr[:ip6]
|
115
|
+
assert_equal ip6, nic_attr['gw6']
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'sets container compute id with identifier, ip DHCP, mac adress and firewall' do
|
119
|
+
ip = '192.168.56.100'
|
120
|
+
mac_address = '36:25:8C:53:0C:50'
|
121
|
+
ip6 = '2001:0:1234::c1c0:abcd:876'
|
122
|
+
firewall = '1'
|
123
|
+
compute_attributes = { 'dhcp' => '1', 'ip6' => ip6, 'firewall' => firewall }
|
124
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :mac => mac_address, :compute_attributes => compute_attributes)
|
125
|
+
host = FactoryBot.build(
|
126
|
+
:host_empty,
|
127
|
+
:interfaces => [physical_nic],
|
128
|
+
:compute_attributes => {
|
129
|
+
'type' => 'lxc',
|
130
|
+
'interfaces_attributes' => {
|
131
|
+
'0' => physical_nic
|
132
|
+
}
|
133
|
+
}
|
134
|
+
)
|
135
|
+
nic_attributes = @cr.host_interfaces_attrs(host).values.select(&:present?)
|
136
|
+
nic_attr = nic_attributes.first
|
137
|
+
assert_equal 'net0', nic_attr[:id]
|
138
|
+
assert_equal 'dhcp', nic_attr[:ip]
|
139
|
+
assert_equal mac_address, nic_attr[:hwaddr]
|
140
|
+
assert_equal ip6, nic_attr[:ip6]
|
141
|
+
assert_equal firewall, nic_attr['firewall']
|
114
142
|
end
|
115
143
|
end
|
116
144
|
end
|
@@ -26,11 +26,11 @@ module ForemanFogProxmox
|
|
26
26
|
include ComputeResourceTestHelpers
|
27
27
|
include ProxmoxVmHelper
|
28
28
|
|
29
|
-
wrong_version = { version: '5.a', release: '1' }.with_indifferent_access
|
30
|
-
supported_version = { version: '5.4', release: '3' }.with_indifferent_access
|
31
|
-
supported_6_version = { version: '6.0', release: '1' }.with_indifferent_access
|
32
|
-
supported_6_1_version = { version: '6.1', release: '3' }.with_indifferent_access
|
33
|
-
unsupported_version = { version: '5.2', release: '2' }.with_indifferent_access
|
29
|
+
wrong_version = { version: '5.a', release: '5.a-1' }.with_indifferent_access
|
30
|
+
supported_version = { version: '5.4', release: '5.4-3' }.with_indifferent_access
|
31
|
+
supported_6_version = { version: '6.0', release: '6.0-1' }.with_indifferent_access
|
32
|
+
supported_6_1_version = { version: '6.1', release: '6.1-3' }.with_indifferent_access
|
33
|
+
unsupported_version = { version: '5.2', release: '5.2-2' }.with_indifferent_access
|
34
34
|
|
35
35
|
describe 'version' do
|
36
36
|
before do
|
@@ -41,17 +41,17 @@ module ForemanFogProxmox
|
|
41
41
|
|
42
42
|
it 'returns 5.a.1 with 5.a-1' do
|
43
43
|
@identity_client.stubs(:read_version).returns(wrong_version)
|
44
|
-
assert_equal '5.a
|
44
|
+
assert_equal '5.a', @cr.version
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'returns 5.4.3 with 5.4-3' do
|
48
48
|
@identity_client.stubs(:read_version).returns(supported_version)
|
49
|
-
assert_equal '5.4
|
49
|
+
assert_equal '5.4', @cr.version
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns 5.2.2 with 5.2-2' do
|
53
53
|
@identity_client.stubs(:read_version).returns(unsupported_version)
|
54
|
-
assert_equal '5.2
|
54
|
+
assert_equal '5.2', @cr.version
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -62,12 +62,12 @@ module ForemanFogProxmox
|
|
62
62
|
@cr.stubs(:identity_client).returns(@identity_client)
|
63
63
|
end
|
64
64
|
|
65
|
-
it 'raises error with 5.a
|
65
|
+
it 'raises error with 5.a' do
|
66
66
|
@identity_client.stubs(:read_version).returns(wrong_version)
|
67
67
|
err = assert_raises Foreman::Exception do
|
68
68
|
@cr.version_suitable?
|
69
69
|
end
|
70
|
-
assert err.message.end_with?('Proxmox version 5.a
|
70
|
+
assert err.message.end_with?('Proxmox version 5.a is not semver suitable')
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'is true with 5.4-3' do
|
@@ -43,10 +43,11 @@ module ForemanFogProxmox
|
|
43
43
|
vm.stubs(:config).returns(config)
|
44
44
|
vm.stubs(:container?).returns(true)
|
45
45
|
vm.stubs(:type).returns('lxc')
|
46
|
-
vm.stubs(:node_id).returns('
|
46
|
+
vm.stubs(:node_id).returns('proxmox')
|
47
|
+
vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc')
|
47
48
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
48
|
-
attr = { 'templated' => '0', 'node_id' => '
|
49
|
-
@cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => '
|
49
|
+
attr = { 'templated' => '0', 'node_id' => 'proxmox', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
|
50
|
+
@cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox2', 'type' => 'lxc', 'cores' => '1', 'cpulimit' => '1')
|
50
51
|
expected_attr = { :cores => '1', :cpulimit => '1' }
|
51
52
|
vm.expects(:update, expected_attr)
|
52
53
|
@cr.save_vm(uuid, attr)
|
@@ -60,10 +61,11 @@ module ForemanFogProxmox
|
|
60
61
|
vm.stubs(:config).returns(config)
|
61
62
|
vm.stubs(:container?).returns(true)
|
62
63
|
vm.stubs(:type).returns('lxc')
|
63
|
-
vm.stubs(:node_id).returns('
|
64
|
+
vm.stubs(:node_id).returns('proxmox')
|
65
|
+
vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc')
|
64
66
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
65
|
-
attr = { 'templated' => '0', 'node_id' => '
|
66
|
-
@cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => '
|
67
|
+
attr = { 'templated' => '0', 'node_id' => 'proxmox', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
|
68
|
+
@cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'lxc', 'cores' => '1', 'cpulimit' => '1')
|
67
69
|
expected_attr = { :cores => '1', :cpulimit => '1' }
|
68
70
|
vm.expects(:update, expected_attr)
|
69
71
|
@cr.save_vm(uuid, attr)
|
@@ -81,14 +83,16 @@ module ForemanFogProxmox
|
|
81
83
|
config.stubs(:disks).returns(disks)
|
82
84
|
config.stubs(:attributes).returns(:cores => '')
|
83
85
|
vm = mock('vm')
|
86
|
+
vm.stubs(:identity).returns(uuid)
|
84
87
|
vm.stubs(:config).returns(config)
|
85
88
|
vm.stubs(:container?).returns(true)
|
86
89
|
vm.stubs(:type).returns('lxc')
|
87
|
-
vm.stubs(:node_id).returns('
|
90
|
+
vm.stubs(:node_id).returns('proxmox')
|
91
|
+
vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc')
|
88
92
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
89
93
|
new_attributes = {
|
90
94
|
'templated' => '0',
|
91
|
-
'node_id' => '
|
95
|
+
'node_id' => 'proxmox',
|
92
96
|
'config_attributes' => {
|
93
97
|
'cores' => '1',
|
94
98
|
'cpulimit' => '1'
|
@@ -105,7 +109,7 @@ module ForemanFogProxmox
|
|
105
109
|
}
|
106
110
|
}
|
107
111
|
}.with_indifferent_access
|
108
|
-
@cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => '
|
112
|
+
@cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'lxc', 'cores' => '1', 'cpulimit' => '1')
|
109
113
|
expected_config_attr = { :cores => '1', :cpulimit => '1' }
|
110
114
|
expected_volume_attr =
|
111
115
|
[
|
@@ -131,19 +135,22 @@ module ForemanFogProxmox
|
|
131
135
|
disk.stubs(:size).returns(1_073_741_824)
|
132
136
|
disk.stubs(:storage).returns('local-lvm')
|
133
137
|
disk.stubs(:id).returns('rootfs')
|
138
|
+
disk.stubs(:attributes).returns(id: 'rootfs', storage: 'local-lvm', size: 1_073_741_824)
|
134
139
|
disks.stubs(:get).returns(disk)
|
135
140
|
config.stubs(:disks).returns(disks)
|
136
141
|
config.stubs(:attributes).returns(:cores => '')
|
137
142
|
vm = mock('vm')
|
143
|
+
vm.stubs(:identity).returns(uuid)
|
138
144
|
vm.stubs(:config).returns(config)
|
139
145
|
vm.stubs(:container?).returns(true)
|
140
146
|
vm.stubs(:type).returns('lxc')
|
141
|
-
vm.stubs(:node_id).returns('
|
147
|
+
vm.stubs(:node_id).returns('proxmox')
|
148
|
+
vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc', 'rootfs' => '')
|
142
149
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
143
150
|
new_attributes =
|
144
151
|
{
|
145
152
|
'templated' => '0',
|
146
|
-
'node_id' => '
|
153
|
+
'node_id' => 'proxmox',
|
147
154
|
'config_attributes' => {
|
148
155
|
'cores' => '1',
|
149
156
|
'cpulimit' => '1',
|
@@ -163,7 +170,7 @@ module ForemanFogProxmox
|
|
163
170
|
}.with_indifferent_access
|
164
171
|
@cr.stubs(:parse_container_vm).returns(
|
165
172
|
'vmid' => '100',
|
166
|
-
'node_id' => '
|
173
|
+
'node_id' => 'proxmox',
|
167
174
|
'type' => 'lxc',
|
168
175
|
'cores' => '1',
|
169
176
|
'cpulimit' => '1'
|
@@ -185,18 +192,21 @@ module ForemanFogProxmox
|
|
185
192
|
disk.stubs(:id).returns('mp0')
|
186
193
|
disk.stubs(:size).returns(1_073_741_824)
|
187
194
|
disk.stubs(:storage).returns('local-lvm')
|
195
|
+
disk.stubs(:attributes).returns(id: 'mp0', storage: 'local-lvm', size: 1_073_741_824, volid: 'local-lvm:vm-100-disk-0')
|
188
196
|
disks.stubs(:get).returns(disk)
|
189
197
|
config.stubs(:disks).returns(disks)
|
190
198
|
config.stubs(:attributes).returns(:cores => '')
|
191
199
|
vm = mock('vm')
|
200
|
+
vm.stubs(:identity).returns(uuid)
|
192
201
|
vm.stubs(:config).returns(config)
|
193
202
|
vm.stubs(:container?).returns(true)
|
194
203
|
vm.stubs(:type).returns('lxc')
|
195
|
-
vm.stubs(:node_id).returns('
|
204
|
+
vm.stubs(:node_id).returns('proxmox')
|
205
|
+
vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc')
|
196
206
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
197
207
|
new_attributes = {
|
198
208
|
'templated' => '0',
|
199
|
-
'node_id' => '
|
209
|
+
'node_id' => 'proxmox',
|
200
210
|
'config_attributes' => {
|
201
211
|
'cores' => '1',
|
202
212
|
'cpulimit' => '1'
|
@@ -214,7 +224,7 @@ module ForemanFogProxmox
|
|
214
224
|
}
|
215
225
|
}
|
216
226
|
}.with_indifferent_access
|
217
|
-
@cr.stubs(:
|
227
|
+
@cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
|
218
228
|
expected_config_attr = { :cores => '1', :cpulimit => '1' }
|
219
229
|
expected_volume_attr = { :id => 'mp0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824 }, { :mp => '/opt/toto' }
|
220
230
|
vm.expects(:attach, expected_volume_attr)
|
@@ -225,44 +235,44 @@ module ForemanFogProxmox
|
|
225
235
|
|
226
236
|
describe 'create_vm' do
|
227
237
|
it 'creates container without bootstart' do
|
228
|
-
args = { vmid: '100', type: 'lxc', node_id: '
|
238
|
+
args = { vmid: '100', type: 'lxc', node_id: 'proxmox', start_after_create: '0' }
|
229
239
|
servers = mock('servers')
|
230
240
|
servers.stubs(:id_valid?).returns(true)
|
231
241
|
containers = mock('containers')
|
232
|
-
containers.stubs(:create).with(
|
242
|
+
containers.stubs(:create).with(args)
|
233
243
|
cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
|
234
244
|
cr.stubs(:convert_sizes).with(args)
|
235
|
-
cr.stubs(:
|
245
|
+
cr.stubs(:parse_typed_vm).with(args, 'lxc').returns(args)
|
236
246
|
vm = mock('vm')
|
237
247
|
cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
|
238
248
|
cr.create_vm(args)
|
239
249
|
end
|
240
250
|
|
241
251
|
it 'creates container with bootstart' do
|
242
|
-
args = { vmid: '100', type: 'lxc', node_id: '
|
252
|
+
args = { vmid: '100', type: 'lxc', node_id: 'proxmox', start_after_create: '1' }
|
243
253
|
servers = mock('servers')
|
244
254
|
servers.stubs(:id_valid?).returns(true)
|
245
255
|
containers = mock('containers')
|
246
256
|
vm = mock('vm')
|
247
|
-
containers.stubs(:create).with(
|
257
|
+
containers.stubs(:create).with(args).returns(vm)
|
248
258
|
cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
|
249
259
|
cr.stubs(:convert_sizes).with(args)
|
250
|
-
cr.stubs(:
|
260
|
+
cr.stubs(:parse_typed_vm).with(args, 'lxc').returns(args)
|
251
261
|
cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
|
252
262
|
cr.stubs(:start_on_boot).with(vm, args).returns(vm)
|
253
263
|
cr.create_vm(args)
|
254
264
|
end
|
255
265
|
|
256
266
|
it 'creates container within pool' do
|
257
|
-
args = { vmid: '100', type: 'lxc', node_id: '
|
267
|
+
args = { vmid: '100', type: 'lxc', node_id: 'proxmox', start_after_create: '0', pool: 'pool1' }
|
258
268
|
servers = mock('servers')
|
259
269
|
servers.stubs(:id_valid?).returns(true)
|
260
270
|
containers = mock('containers')
|
261
271
|
vm = mock('vm')
|
262
|
-
containers.stubs(:create).with(
|
272
|
+
containers.stubs(:create).with(args).returns(vm)
|
263
273
|
cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
|
264
274
|
cr.stubs(:convert_sizes).with(args)
|
265
|
-
cr.stubs(:
|
275
|
+
cr.stubs(:parse_typed_vm).with(args, 'lxc').returns(args)
|
266
276
|
cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
|
267
277
|
cr.create_vm(args)
|
268
278
|
end
|