foreman_fog_proxmox 0.12.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 +7 -0
- data/LICENSE +619 -0
- data/README.md +290 -0
- data/Rakefile +49 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +33 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +187 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +24 -0
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +125 -0
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +41 -0
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +86 -0
- data/app/helpers/node_dashboard_helper.rb +35 -0
- data/app/helpers/proxmox_compute_selectors_helper.rb +184 -0
- data/app/helpers/proxmox_container_helper.rb +163 -0
- data/app/helpers/proxmox_form_helper.rb +70 -0
- data/app/helpers/proxmox_server_helper.rb +155 -0
- data/app/helpers/proxmox_vm_helper.rb +88 -0
- data/app/models/concerns/fog_extensions/proxmox/disk.rb +29 -0
- data/app/models/concerns/fog_extensions/proxmox/interface.rb +40 -0
- data/app/models/concerns/fog_extensions/proxmox/node.rb +41 -0
- data/app/models/concerns/fog_extensions/proxmox/server.rb +93 -0
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +71 -0
- data/app/models/concerns/fog_extensions/proxmox/volume.rb +29 -0
- data/app/models/concerns/host_ext/proxmox/interfaces.rb +52 -0
- data/app/models/concerns/orchestration/proxmox/compute.rb +42 -0
- data/app/models/foreman_fog_proxmox/options_select.rb +36 -0
- data/app/models/foreman_fog_proxmox/proxmox.rb +133 -0
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +67 -0
- data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
- data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
- data/app/models/foreman_fog_proxmox/proxmox_images.rb +61 -0
- data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +103 -0
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
- data/app/models/foreman_fog_proxmox/proxmox_pools.rb +56 -0
- data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
- data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +116 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +178 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +75 -0
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +94 -0
- data/app/models/foreman_fog_proxmox/vms.rb +37 -0
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +34 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_node_to_new_form.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +34 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +26 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +25 -0
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +25 -0
- data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +25 -0
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -0
- data/app/views/compute_resources/form/_proxmox.html.erb +29 -0
- data/app/views/compute_resources/show/_proxmox.html.erb +37 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +23 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +24 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_node_to_new_form.html.erb +24 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +28 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +32 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +30 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +71 -0
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +39 -0
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +39 -0
- data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +19 -0
- data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +27 -0
- 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 +27 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +33 -0
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +27 -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/server/_config.html.erb +60 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +30 -0
- data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +28 -0
- data/app/views/compute_resources_vms/index/_proxmox.html.erb +49 -0
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +42 -0
- data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +21 -0
- data/app/views/images/form/_proxmox.html.erb +21 -0
- data/config/routes.rb +30 -0
- data/lib/foreman_fog_proxmox.rb +23 -0
- data/lib/foreman_fog_proxmox/engine.rb +105 -0
- data/lib/foreman_fog_proxmox/semver.rb +102 -0
- data/lib/foreman_fog_proxmox/value.rb +26 -0
- data/lib/foreman_fog_proxmox/version.rb +22 -0
- data/lib/tasks/foreman_fog_proxmox_tasks.rake +37 -0
- data/locale/Makefile +60 -0
- data/locale/en/foreman_fog_proxmox.po +401 -0
- data/locale/foreman_fog_proxmox.pot +627 -0
- data/locale/fr/foreman_fog_proxmox.po +401 -0
- data/locale/gemspec.rb +4 -0
- data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +137 -0
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +87 -0
- data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
- data/test/factories/proxmox_factory.rb +79 -0
- data/test/functional/compute_resources_controller_test.rb +48 -0
- data/test/test_plugin_helper.rb +19 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +204 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +149 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +216 -0
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +124 -0
- data/test/unit/foreman_fog_proxmox/proxmox_images_test.rb +52 -0
- data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +117 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +58 -0
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +94 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +280 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +110 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +222 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb +308 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +68 -0
- data/test/unit/foreman_fog_proxmox/semver_test.rb +111 -0
- metadata +249 -0
@@ -0,0 +1,149 @@
|
|
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 ProxmoxServerHelperTest < ActiveSupport::TestCase
|
24
|
+
include ProxmoxServerHelper
|
25
|
+
include ProxmoxVmHelper
|
26
|
+
|
27
|
+
describe 'parse' do
|
28
|
+
setup { Fog.mock! }
|
29
|
+
teardown { Fog.unmock! }
|
30
|
+
|
31
|
+
let(:host) do
|
32
|
+
{ 'vmid' => '100',
|
33
|
+
'name' => 'test',
|
34
|
+
'node_id' => 'pve',
|
35
|
+
'type' => 'qemu',
|
36
|
+
'config_attributes' => {
|
37
|
+
'memory' => '536870912',
|
38
|
+
'balloon' => '268435456',
|
39
|
+
'shares' => '5',
|
40
|
+
'cpu_type' => 'kvm64',
|
41
|
+
'spectre' => '1',
|
42
|
+
'pcid' => '0',
|
43
|
+
'cores' => '1',
|
44
|
+
'sockets' => '1'
|
45
|
+
},
|
46
|
+
'volumes_attributes' => {
|
47
|
+
'0' => { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
|
48
|
+
'1' => { 'controller' => 'virtio', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' }
|
49
|
+
},
|
50
|
+
'interfaces_attributes' => {
|
51
|
+
'0' => { 'id' => 'net0', 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0', 'rate' => nil },
|
52
|
+
'1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0' }
|
53
|
+
} }
|
54
|
+
end
|
55
|
+
|
56
|
+
let(:host_delete) do
|
57
|
+
{ 'vmid' => '100',
|
58
|
+
'node_id' => 'pve',
|
59
|
+
'name' => 'test',
|
60
|
+
'type' => 'qemu',
|
61
|
+
'cdrom' => 'image',
|
62
|
+
'cdrom_iso' => 'local-lvm:iso/debian-netinst.iso',
|
63
|
+
'volumes_attributes' => { '0' => { '_delete' => '1', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' } },
|
64
|
+
'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'model' => 'virtio' } } }
|
65
|
+
end
|
66
|
+
|
67
|
+
test '#memory' do
|
68
|
+
memory = parse_server_memory(host['config_attributes'])
|
69
|
+
assert memory.key?(:memory)
|
70
|
+
assert_equal 536_870_912, memory[:memory]
|
71
|
+
end
|
72
|
+
|
73
|
+
test '#cpu' do
|
74
|
+
cpu = parse_server_cpu(host['config_attributes'])
|
75
|
+
assert cpu.key?(:cpu)
|
76
|
+
assert_equal 'cputype=kvm64,flags=+spec-ctrl', cpu[:cpu]
|
77
|
+
end
|
78
|
+
|
79
|
+
test '#vm' do
|
80
|
+
vm = parse_server_vm(host)
|
81
|
+
assert_equal '1', vm['cores']
|
82
|
+
assert_equal '1', vm['sockets']
|
83
|
+
assert_equal 'cputype=kvm64,flags=+spec-ctrl', vm[:cpu]
|
84
|
+
assert_equal 536_870_912, vm[:memory]
|
85
|
+
assert_equal 268_435_456, vm[:balloon]
|
86
|
+
assert_equal 5, vm[:shares]
|
87
|
+
assert_equal 'local-lvm:1073741824,cache=none', vm[:scsi0]
|
88
|
+
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
|
89
|
+
assert_not vm.key?(:config)
|
90
|
+
assert_not vm.key?(:node)
|
91
|
+
end
|
92
|
+
|
93
|
+
test '#volume with scsi 1Gb' do
|
94
|
+
volumes = parse_server_volumes(host['volumes_attributes'])
|
95
|
+
assert_not volumes.empty?
|
96
|
+
assert volumes.size, 2
|
97
|
+
assert volume = volumes.first
|
98
|
+
assert volume.key?(:scsi0)
|
99
|
+
assert_equal 'local-lvm:1073741824,cache=none', volume[:scsi0]
|
100
|
+
end
|
101
|
+
|
102
|
+
test '#volume with virtio 1Gb' do
|
103
|
+
volumes = parse_server_volumes(host['volumes_attributes'])
|
104
|
+
assert_not volumes.empty?
|
105
|
+
assert volumes.size, 2
|
106
|
+
assert volume = volumes[1]
|
107
|
+
assert volume.key?(:virtio0)
|
108
|
+
assert_equal 'local-lvm:1073741824,cache=none', volume[:virtio0]
|
109
|
+
end
|
110
|
+
|
111
|
+
test '#interface with model virtio and bridge' do
|
112
|
+
interfaces_to_delete = []
|
113
|
+
interfaces_to_add = []
|
114
|
+
add_server_interface(host['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add)
|
115
|
+
assert_empty interfaces_to_delete
|
116
|
+
assert_equal 1, interfaces_to_add.length
|
117
|
+
assert interfaces_to_add[0].key?(:net0)
|
118
|
+
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', interfaces_to_add[0][:net0]
|
119
|
+
end
|
120
|
+
|
121
|
+
test '#interface with model e1000 and bridge' do
|
122
|
+
interfaces_to_delete = []
|
123
|
+
interfaces_to_add = []
|
124
|
+
add_server_interface(host['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add)
|
125
|
+
assert_empty interfaces_to_delete
|
126
|
+
assert_equal 1, interfaces_to_add.length
|
127
|
+
assert interfaces_to_add[0].key?(:net1)
|
128
|
+
assert_equal 'model=e1000,bridge=vmbr0,firewall=0,link_down=0', interfaces_to_add[0][:net1]
|
129
|
+
end
|
130
|
+
|
131
|
+
test '#interface delete net0' do
|
132
|
+
interfaces_to_delete = []
|
133
|
+
interfaces_to_add = []
|
134
|
+
add_server_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add)
|
135
|
+
assert_empty interfaces_to_add
|
136
|
+
assert_equal 1, interfaces_to_delete.length
|
137
|
+
assert_equal 'net0', interfaces_to_delete[0]
|
138
|
+
end
|
139
|
+
|
140
|
+
test '#interfaces' do
|
141
|
+
interfaces_to_add, interfaces_to_delete = parse_server_interfaces(host['interfaces_attributes'])
|
142
|
+
assert_empty interfaces_to_delete
|
143
|
+
assert_equal 2, interfaces_to_add.length
|
144
|
+
assert_includes interfaces_to_add, { net0: 'model=virtio,bridge=vmbr0,firewall=0,link_down=0' }
|
145
|
+
assert_includes interfaces_to_add, { net1: 'model=e1000,bridge=vmbr0,firewall=0,link_down=0' }
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,216 @@
|
|
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 'fog/compute/proxmox/models/server'
|
22
|
+
require 'fog/compute/proxmox/models/server_config'
|
23
|
+
require 'fog/compute/proxmox/models/interface'
|
24
|
+
require 'fog/compute/proxmox/models/interfaces'
|
25
|
+
require 'fog/compute/proxmox/models/disk'
|
26
|
+
require 'fog/compute/proxmox/models/disks'
|
27
|
+
require 'fog/compute/proxmox/models/snapshots'
|
28
|
+
require 'fog/compute/proxmox/models/tasks'
|
29
|
+
|
30
|
+
module ForemanFogProxmox
|
31
|
+
class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
32
|
+
include ProxmoxVmHelper
|
33
|
+
|
34
|
+
let(:container) do
|
35
|
+
service = mock('service')
|
36
|
+
service.stubs(:get_server_config).returns(nil)
|
37
|
+
service.stubs(:list_tasks).returns([])
|
38
|
+
Fog::Proxmox::Compute::Server.new(
|
39
|
+
'vmid' => '100',
|
40
|
+
'hostname' => 'test',
|
41
|
+
:type => 'lxc',
|
42
|
+
:node_id => 'pve',
|
43
|
+
:service => service,
|
44
|
+
'templated' => '0',
|
45
|
+
'memory' => '536870912',
|
46
|
+
'swap' => '',
|
47
|
+
'cores' => '1',
|
48
|
+
'arch' => 'amd64',
|
49
|
+
'ostype' => 'debian',
|
50
|
+
'rootfs' => 'local-lvm:1073741824',
|
51
|
+
'mp0' => 'local-lvm:1073741824',
|
52
|
+
'net0' => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp',
|
53
|
+
'net1' => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp'
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:server) do
|
58
|
+
service = mock('service')
|
59
|
+
service.stubs(:get_server_config).returns(nil)
|
60
|
+
service.stubs(:list_tasks).returns([])
|
61
|
+
Fog::Proxmox::Compute::Server.new(
|
62
|
+
'vmid' => '100',
|
63
|
+
'name' => 'test',
|
64
|
+
:node_id => 'pve',
|
65
|
+
:service => service,
|
66
|
+
:type => 'qemu',
|
67
|
+
'templated' => '0',
|
68
|
+
'ide2' => 'local-lvm:iso/debian-netinst.iso,media=cdrom',
|
69
|
+
'memory' => '536870912',
|
70
|
+
'min_memory' => '',
|
71
|
+
'ballon' => '',
|
72
|
+
'shares' => '',
|
73
|
+
'cpu_type' => 'kvm64',
|
74
|
+
'spectre' => '1',
|
75
|
+
'pcid' => '0',
|
76
|
+
'cores' => '1',
|
77
|
+
'sockets' => '1',
|
78
|
+
'scsi0' => 'local-lvm:1073741824,cache=none',
|
79
|
+
'net0' => 'model=virtio,bridge=vmbr0',
|
80
|
+
'net1' => 'model=e1000,bridge=vmbr0'
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
let(:host_server) do
|
85
|
+
{ 'vmid' => '100',
|
86
|
+
'name' => 'test',
|
87
|
+
'node_id' => 'pve',
|
88
|
+
'type' => 'qemu',
|
89
|
+
'config_attributes' => {
|
90
|
+
'memory' => '536870912',
|
91
|
+
'min_memory' => nil,
|
92
|
+
'ballon' => '',
|
93
|
+
'shares' => '',
|
94
|
+
'cpu_type' => 'kvm64',
|
95
|
+
'spectre' => '1',
|
96
|
+
'pcid' => '0',
|
97
|
+
'cores' => '1',
|
98
|
+
'sockets' => '1'
|
99
|
+
},
|
100
|
+
'volumes_attributes' => {
|
101
|
+
'0' => { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' }
|
102
|
+
},
|
103
|
+
'interfaces_attributes' => {
|
104
|
+
'0' => { 'id' => 'net0', 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'disconnect' => '0' },
|
105
|
+
'1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'disconnect' => '0' }
|
106
|
+
} }
|
107
|
+
end
|
108
|
+
|
109
|
+
let(:host_container) do
|
110
|
+
{ 'vmid' => '100',
|
111
|
+
'name' => 'test',
|
112
|
+
'type' => 'lxc',
|
113
|
+
'node_id' => 'pve',
|
114
|
+
'ostemplate_storage' => 'local',
|
115
|
+
'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
116
|
+
'password' => 'proxmox01',
|
117
|
+
'config_attributes' => {
|
118
|
+
'onboot' => '0',
|
119
|
+
'description' => '',
|
120
|
+
'memory' => '536870912',
|
121
|
+
'swap' => '',
|
122
|
+
'cores' => '1',
|
123
|
+
'cpulimit' => '',
|
124
|
+
'cpuunits' => '',
|
125
|
+
'arch' => 'amd64',
|
126
|
+
'ostype' => 'debian',
|
127
|
+
'hostname' => '',
|
128
|
+
'nameserver' => '',
|
129
|
+
'searchdomain' => ''
|
130
|
+
|
131
|
+
},
|
132
|
+
'volumes_attributes' => {
|
133
|
+
'0' => { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '1073741824' },
|
134
|
+
'1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824' }
|
135
|
+
},
|
136
|
+
'interfaces_attributes' => {
|
137
|
+
'0' => { 'id' => 'net0', 'name' => 'eth0', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' },
|
138
|
+
'1' => { 'id' => 'net1', 'name' => 'eth1', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' }
|
139
|
+
} }
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'object_to_config_hash' do
|
143
|
+
setup { Fog.mock! }
|
144
|
+
teardown { Fog.unmock! }
|
145
|
+
|
146
|
+
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| ['templated', 'ide2', 'scsi0', 'net0', 'net1'].include? key }
|
149
|
+
assert_equal expected_config_hash, config_hash['config_attributes']
|
150
|
+
end
|
151
|
+
|
152
|
+
it '#server lxc' do
|
153
|
+
config_hash = object_to_config_hash(server)
|
154
|
+
assert config_hash.key?('config_attributes')
|
155
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key, _value| ['templated', 'ide2', 'scsi0', 'net0', 'net1'].include? key }
|
156
|
+
assert_equal expected_config_hash, config_hash['config_attributes']
|
157
|
+
end
|
158
|
+
|
159
|
+
it '#container qemu' do
|
160
|
+
config_hash = object_to_config_hash(container)
|
161
|
+
assert config_hash.key?('config_attributes')
|
162
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value| ['templated', 'rootfs', 'mp0', 'net0', 'net1'].include? key }
|
163
|
+
assert_equal expected_config_hash, config_hash['config_attributes']
|
164
|
+
end
|
165
|
+
|
166
|
+
it '#container lxc' do
|
167
|
+
config_hash = object_to_config_hash(container)
|
168
|
+
assert config_hash.key?('config_attributes')
|
169
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value| ['templated', 'rootfs', 'mp0', 'net0', 'net1'].include? key }
|
170
|
+
assert_equal expected_config_hash, config_hash['config_attributes']
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe 'convert_sizes' do
|
175
|
+
setup { Fog.mock! }
|
176
|
+
teardown { Fog.unmock! }
|
177
|
+
|
178
|
+
it '#server' do
|
179
|
+
convert_sizes(host_server)
|
180
|
+
assert_equal '512', host_server['config_attributes']['memory']
|
181
|
+
assert_equal '1', host_server['volumes_attributes']['0']['size']
|
182
|
+
end
|
183
|
+
|
184
|
+
it '#container' do
|
185
|
+
convert_sizes(host_container)
|
186
|
+
assert_equal '512', host_container['config_attributes']['memory']
|
187
|
+
assert_equal '1', host_container['volumes_attributes']['0']['size']
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe 'convert_memory_size' do
|
192
|
+
setup { Fog.mock! }
|
193
|
+
teardown { Fog.unmock! }
|
194
|
+
|
195
|
+
it '#server memory' do
|
196
|
+
convert_memory_size(host_server['config_attributes'], 'memory')
|
197
|
+
assert_equal '512', host_server['config_attributes']['memory']
|
198
|
+
end
|
199
|
+
|
200
|
+
it '#server min_memory nil' do
|
201
|
+
convert_memory_size(host_server['config_attributes'], 'min_memory')
|
202
|
+
assert_nil host_server['config_attributes']['min_memory']
|
203
|
+
end
|
204
|
+
|
205
|
+
it '#container memory' do
|
206
|
+
convert_memory_size(host_container['config_attributes'], 'memory')
|
207
|
+
assert_equal '512', host_container['config_attributes']['memory']
|
208
|
+
end
|
209
|
+
|
210
|
+
it '#container swap empty' do
|
211
|
+
convert_memory_size(host_container['config_attributes'], 'swap')
|
212
|
+
assert_empty host_container['config_attributes']['swap']
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,124 @@
|
|
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 'factories/foreman_fog_proxmox/proxmox_node_mock_factory'
|
23
|
+
require 'factories/foreman_fog_proxmox/proxmox_server_mock_factory'
|
24
|
+
require 'factories/foreman_fog_proxmox/proxmox_container_mock_factory'
|
25
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
26
|
+
|
27
|
+
module ForemanFogProxmox
|
28
|
+
class ProxmoxComputeAttributesTest < ActiveSupport::TestCase
|
29
|
+
include ComputeResourceTestHelpers
|
30
|
+
include ProxmoxNodeMockFactory
|
31
|
+
include ProxmoxServerMockFactory
|
32
|
+
include ProxmoxContainerMockFactory
|
33
|
+
include ProxmoxVmHelper
|
34
|
+
|
35
|
+
describe 'host_compute_attrs' do
|
36
|
+
before do
|
37
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'raises Foreman::Exception when server ostype does not match os family' do
|
41
|
+
operatingsystem = FactoryBot.build(:solaris)
|
42
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true)
|
43
|
+
host = FactoryBot.build(
|
44
|
+
:host_empty,
|
45
|
+
:interfaces => [physical_nic],
|
46
|
+
:operatingsystem => operatingsystem,
|
47
|
+
:compute_attributes => {
|
48
|
+
'type' => 'qemu',
|
49
|
+
'config_attributes' => {
|
50
|
+
'ostype' => 'l26'
|
51
|
+
},
|
52
|
+
'interfaces_attributes' => {
|
53
|
+
'0' => physical_nic
|
54
|
+
}
|
55
|
+
}
|
56
|
+
)
|
57
|
+
err = assert_raises Foreman::Exception do
|
58
|
+
@cr.host_compute_attrs(host)
|
59
|
+
end
|
60
|
+
assert err.message.end_with?('Operating system family Solaris is not consistent with l26')
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'sets container hostname with host name' do
|
64
|
+
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true, :compute_attributes => { 'dhcpv4' => '1', 'dhcpv6' => '1' })
|
65
|
+
host = FactoryBot.build(
|
66
|
+
:host_empty,
|
67
|
+
:interfaces => [physical_nic],
|
68
|
+
:compute_attributes => {
|
69
|
+
'type' => 'lxc',
|
70
|
+
'config_attributes' => {
|
71
|
+
'hostname' => ''
|
72
|
+
},
|
73
|
+
'interfaces_attributes' => {
|
74
|
+
'0' => {}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
)
|
78
|
+
@cr.host_compute_attrs(host)
|
79
|
+
assert_equal host.name, host.compute_attributes['config_attributes']['hostname']
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe 'vm_compute_attributes' do
|
84
|
+
before do
|
85
|
+
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'converts a server to hash' do
|
89
|
+
vm, config_attributes, volume_attributes, interface_attributes = mock_server_vm
|
90
|
+
vm_attrs = @cr.vm_compute_attributes(vm)
|
91
|
+
assert_not vm_attrs.key?(:config)
|
92
|
+
assert vm_attrs.key?(:config_attributes)
|
93
|
+
assert_equal config_attributes.reject { |key, value| [:vmid, :disks, :interfaces].include?(key) || value.to_s.empty? }, vm_attrs[:config_attributes]
|
94
|
+
assert_not vm_attrs[:config_attributes].key?(:disks)
|
95
|
+
assert vm_attrs.key?(:volumes_attributes)
|
96
|
+
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
97
|
+
assert_not vm_attrs[:config_attributes].key?(:interfaces)
|
98
|
+
assert vm_attrs.key?(:interfaces_attributes)
|
99
|
+
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
|
100
|
+
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:identifier]
|
101
|
+
assert_equal interface_attributes[:macaddr], vm_attrs[:interfaces_attributes]['0'][:mac]
|
102
|
+
assert_equal interface_attributes[:model], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:model]
|
103
|
+
assert_equal interface_attributes[:bridge], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'converts a container to hash' do
|
107
|
+
vm, config_attributes, volume_attributes, interface_attributes = mock_container_vm
|
108
|
+
vm_attrs = @cr.vm_compute_attributes(vm)
|
109
|
+
assert_not vm_attrs.key?(:config)
|
110
|
+
assert vm_attrs.key?(:config_attributes)
|
111
|
+
assert_equal config_attributes.reject { |key, value| [:vmid, :disks, :interfaces].include?(key) || value.to_s.empty? }, vm_attrs[:config_attributes]
|
112
|
+
assert_not vm_attrs[:config_attributes].key?(:disks)
|
113
|
+
assert vm_attrs.key?(:volumes_attributes)
|
114
|
+
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
115
|
+
assert vm_attrs.key?(:interfaces_attributes)
|
116
|
+
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
|
117
|
+
assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:identifier]
|
118
|
+
assert_equal interface_attributes[:name], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:name]
|
119
|
+
assert_equal interface_attributes[:mac], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:mac]
|
120
|
+
assert_equal interface_attributes[:bridge], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|