foreman_fog_proxmox 0.11.1 → 0.13.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 +12 -3
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +24 -2
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +124 -52
- data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +0 -48
- 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/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 +11 -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/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_cdrom_helper.rb} +15 -10
- data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
- data/app/helpers/proxmox_vm_config_helper.rb +159 -0
- data/app/helpers/proxmox_vm_helper.rb +24 -70
- data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
- data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
- 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 +8 -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 +1 -0
- data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +20 -12
- 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 -30
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +2 -1
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
- 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 +4 -2
- 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 +16 -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/lib/foreman_fog_proxmox/engine.rb +9 -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 +49 -29
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +53 -30
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
- 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 +12 -5
- 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 +21 -7
- 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
- metadata +44 -27
- data/app/helpers/proxmox_container_helper.rb +0 -163
- data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -32,6 +32,3 @@ namespace :foreman_fog_proxmox do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
Rake::Task[:test].enhance ['test:foreman_fog_proxmox']
|
35
|
-
|
36
|
-
load 'tasks/jenkins.rake'
|
37
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_fog_proxmox', 'foreman_fog_proxmox:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
|
@@ -19,14 +19,15 @@
|
|
19
19
|
|
20
20
|
module ForemanFogProxmox
|
21
21
|
module ProxmoxContainerMockFactory
|
22
|
-
def
|
23
|
-
|
24
|
-
id: 'net0',
|
25
|
-
mac: '36:25:8C:53:0C:50',
|
22
|
+
def mock_container_interface_attributes
|
23
|
+
compute_attributes = {
|
26
24
|
model: nil,
|
27
25
|
name: 'eth0',
|
26
|
+
hwaddr: '36:25:8C:53:0C:50',
|
28
27
|
ip: nil,
|
29
28
|
ip6: nil,
|
29
|
+
gw: nil,
|
30
|
+
gw6: nil,
|
30
31
|
bridge: 'vmbr0',
|
31
32
|
firewall: nil,
|
32
33
|
link_down: nil,
|
@@ -34,8 +35,19 @@ module ForemanFogProxmox
|
|
34
35
|
queues: nil,
|
35
36
|
tag: nil
|
36
37
|
}
|
38
|
+
interface_attributes = {
|
39
|
+
id: 'net0',
|
40
|
+
mac: '36:25:8C:53:0C:50',
|
41
|
+
ip: nil,
|
42
|
+
ip6: nil,
|
43
|
+
compute_attributes: compute_attributes
|
44
|
+
}
|
45
|
+
interface_attributes
|
46
|
+
end
|
47
|
+
|
48
|
+
def mock_container_vm
|
37
49
|
interface = mock('interface')
|
38
|
-
interface.stubs(:attributes).returns(
|
50
|
+
interface.stubs(:attributes).returns(mock_container_interface_attributes)
|
39
51
|
interfaces = [interface]
|
40
52
|
volume_attributes = {
|
41
53
|
id: 'rootfs',
|
@@ -96,13 +108,13 @@ module ForemanFogProxmox
|
|
96
108
|
vm.stubs(:config).returns(config)
|
97
109
|
vm.stubs(:type).returns('lxc')
|
98
110
|
vm.stubs(:identity).returns(100)
|
99
|
-
vm.stubs(:node_id).returns('
|
111
|
+
vm.stubs(:node_id).returns('proxmox')
|
100
112
|
vm.stubs(:identity).returns(100)
|
101
113
|
service = mock('service')
|
102
114
|
vm_attributes = {
|
103
115
|
vmid: 100,
|
104
116
|
id: 'lxc/100',
|
105
|
-
node_id: '
|
117
|
+
node_id: 'proxmox',
|
106
118
|
service: service,
|
107
119
|
config: config,
|
108
120
|
name: 'test',
|
@@ -131,7 +143,7 @@ module ForemanFogProxmox
|
|
131
143
|
}
|
132
144
|
vm.stubs(:attributes).returns(vm_attributes)
|
133
145
|
vm.stubs(:container?).returns(true)
|
134
|
-
[vm, config_attributes, volume_attributes,
|
146
|
+
[vm, config_attributes, volume_attributes, mock_container_interface_attributes]
|
135
147
|
end
|
136
148
|
end
|
137
149
|
end
|
@@ -22,7 +22,7 @@ module ForemanFogProxmox
|
|
22
22
|
def mock_node_servers(cr, servers)
|
23
23
|
node = mock('node')
|
24
24
|
nodes = mock('nodes')
|
25
|
-
node.stubs(:node).returns('
|
25
|
+
node.stubs(:node).returns('proxmox')
|
26
26
|
node.stubs(:servers).returns(servers)
|
27
27
|
nodes.stubs(:get).returns(node)
|
28
28
|
nodes.stubs(:all).returns([node])
|
@@ -35,7 +35,7 @@ module ForemanFogProxmox
|
|
35
35
|
def mock_node_containers(cr, containers)
|
36
36
|
node = mock('node')
|
37
37
|
nodes = mock('nodes')
|
38
|
-
node.stubs(:node).returns('
|
38
|
+
node.stubs(:node).returns('proxmox')
|
39
39
|
node.stubs(:containers).returns(containers)
|
40
40
|
nodes.stubs(:get).returns(node)
|
41
41
|
nodes.stubs(:all).returns([node])
|
@@ -47,7 +47,7 @@ module ForemanFogProxmox
|
|
47
47
|
|
48
48
|
def mock_node_servers_containers(cr, servers, containers)
|
49
49
|
node = mock('node')
|
50
|
-
node.stubs(:node).returns('
|
50
|
+
node.stubs(:node).returns('proxmox')
|
51
51
|
node.stubs(:containers).returns(containers)
|
52
52
|
node.stubs(:servers).returns(servers)
|
53
53
|
nodes = mock('nodes')
|
@@ -69,8 +69,8 @@ module ForemanFogProxmox
|
|
69
69
|
node2.stubs(:servers).returns(n2s)
|
70
70
|
node2.stubs(:containers).returns(n2c)
|
71
71
|
nodes = mock('nodes')
|
72
|
-
nodes.stubs(:get).with('
|
73
|
-
nodes.stubs(:get).with('
|
72
|
+
nodes.stubs(:get).with('proxmox').returns(node1)
|
73
|
+
nodes.stubs(:get).with('proxmox2').returns(node2)
|
74
74
|
nodes.stubs(:all).returns([node1, node2])
|
75
75
|
client = mock('client')
|
76
76
|
client.stubs(:nodes).returns(nodes)
|
@@ -19,9 +19,8 @@
|
|
19
19
|
|
20
20
|
module ForemanFogProxmox
|
21
21
|
module ProxmoxServerMockFactory
|
22
|
-
def
|
23
|
-
|
24
|
-
id: 'net0',
|
22
|
+
def mock_server_interface_attributes
|
23
|
+
compute_attributes = {
|
25
24
|
macaddr: '36:25:8C:53:0C:50',
|
26
25
|
model: 'virtio',
|
27
26
|
name: nil,
|
@@ -34,8 +33,19 @@ module ForemanFogProxmox
|
|
34
33
|
queues: nil,
|
35
34
|
tag: nil
|
36
35
|
}
|
36
|
+
interface_attributes = {
|
37
|
+
id: 'net0',
|
38
|
+
mac: '36:25:8C:53:0C:50',
|
39
|
+
ip: nil,
|
40
|
+
ip6: nil,
|
41
|
+
compute_attributes: compute_attributes
|
42
|
+
}
|
43
|
+
interface_attributes
|
44
|
+
end
|
45
|
+
|
46
|
+
def mock_server_vm
|
37
47
|
interface = mock('interface')
|
38
|
-
interface.stubs(:attributes).returns(
|
48
|
+
interface.stubs(:attributes).returns(mock_server_interface_attributes)
|
39
49
|
interfaces = [interface]
|
40
50
|
volume_attributes = {
|
41
51
|
id: 'scsi0',
|
@@ -94,12 +104,12 @@ module ForemanFogProxmox
|
|
94
104
|
vm.stubs(:config).returns(config)
|
95
105
|
vm.stubs(:type).returns('qemu')
|
96
106
|
vm.stubs(:identity).returns(100)
|
97
|
-
vm.stubs(:node_id).returns('
|
107
|
+
vm.stubs(:node_id).returns('proxmox')
|
98
108
|
service = mock('service')
|
99
109
|
vm_attributes = {
|
100
110
|
vmid: 100,
|
101
111
|
id: 'qemu/100',
|
102
|
-
node_id: '
|
112
|
+
node_id: 'proxmox',
|
103
113
|
config: config,
|
104
114
|
service: service,
|
105
115
|
name: 'test',
|
@@ -128,7 +138,7 @@ module ForemanFogProxmox
|
|
128
138
|
}
|
129
139
|
vm.stubs(:attributes).returns(vm_attributes)
|
130
140
|
vm.stubs(:container?).returns(false)
|
131
|
-
[vm, config_attributes, volume_attributes,
|
141
|
+
[vm, config_attributes, volume_attributes, mock_server_interface_attributes]
|
132
142
|
end
|
133
143
|
end
|
134
144
|
end
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/node'
|
21
21
|
|
22
22
|
FactoryBot.define do
|
23
23
|
factory :proxmox_resource, :class => ComputeResource do
|
@@ -37,13 +37,13 @@ FactoryBot.define do
|
|
37
37
|
|
38
38
|
factory :node, :class => Fog::Proxmox::Compute::Node do
|
39
39
|
sequence(:identity) { |n| "node#{n}" }
|
40
|
-
trait :
|
41
|
-
identity { '
|
40
|
+
trait :proxmox do
|
41
|
+
identity { 'proxmox' }
|
42
42
|
end
|
43
43
|
trait :service do
|
44
44
|
service { :proxmox_cr }
|
45
45
|
end
|
46
|
-
factory :
|
46
|
+
factory :proxmox_node, :class => Fog::Proxmox::Compute::Node, :traits => [:proxmox, :service]
|
47
47
|
end
|
48
48
|
|
49
49
|
def deferred_nic_attrs
|
@@ -21,25 +21,25 @@ require 'test_plugin_helper'
|
|
21
21
|
module ForemanFogProxmox
|
22
22
|
class ComputeResourcesControllerTest < ActionController::TestCase
|
23
23
|
test 'should get isos by node and storage' do
|
24
|
-
get :isos_by_node_and_storage, params: { :node_id => '
|
24
|
+
get :isos_by_node_and_storage, params: { :node_id => 'proxmox', :storage => 'local' }
|
25
25
|
assert_response :found
|
26
26
|
show_response = @response.body
|
27
27
|
assert_not show_response.empty?
|
28
28
|
end
|
29
29
|
test 'should get ostemplates by node and storage' do
|
30
|
-
get :ostemplates_by_node_and_storage, params: { :node_id => '
|
30
|
+
get :ostemplates_by_node_and_storage, params: { :node_id => 'proxmox', :storage => 'local' }
|
31
31
|
assert_response :found
|
32
32
|
show_response = @response.body
|
33
33
|
assert_not show_response.empty?
|
34
34
|
end
|
35
35
|
test 'should get isos by node' do
|
36
|
-
get :isos_by_node, params: { :node_id => '
|
36
|
+
get :isos_by_node, params: { :node_id => 'proxmox' }
|
37
37
|
assert_response :found
|
38
38
|
show_response = @response.body
|
39
39
|
assert_not show_response.empty?
|
40
40
|
end
|
41
41
|
test 'should get ostemplates by node' do
|
42
|
-
get :ostemplates_by_node, params: { :node_id => '
|
42
|
+
get :ostemplates_by_node, params: { :node_id => 'proxmox' }
|
43
43
|
assert_response :found
|
44
44
|
show_response = @response.body
|
45
45
|
assert_not show_response.empty?
|
@@ -21,18 +21,21 @@ require 'test_plugin_helper'
|
|
21
21
|
|
22
22
|
module ForemanFogProxmox
|
23
23
|
class ProxmoxContainerHelperTest < ActiveSupport::TestCase
|
24
|
-
include ProxmoxContainerHelper
|
25
24
|
include ProxmoxVmHelper
|
26
25
|
|
27
26
|
describe 'parse' do
|
28
27
|
setup { Fog.mock! }
|
29
28
|
teardown { Fog.unmock! }
|
30
29
|
|
31
|
-
let(:
|
30
|
+
let(:type) do
|
31
|
+
'lxc'
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:host_form) do
|
32
35
|
{ 'vmid' => '100',
|
33
36
|
'name' => 'test',
|
34
37
|
'type' => 'lxc',
|
35
|
-
'node_id' => '
|
38
|
+
'node_id' => 'proxmox',
|
36
39
|
'ostemplate_storage' => 'local',
|
37
40
|
'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
38
41
|
'password' => 'proxmox01',
|
@@ -56,8 +59,29 @@ module ForemanFogProxmox
|
|
56
59
|
'1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' }
|
57
60
|
},
|
58
61
|
'interfaces_attributes' => {
|
59
|
-
'0' => {
|
60
|
-
|
62
|
+
'0' => {
|
63
|
+
'id' => 'net0',
|
64
|
+
'compute_attributes' => {
|
65
|
+
'name' => 'eth0',
|
66
|
+
'bridge' => 'vmbr0',
|
67
|
+
'ip' => 'dhcp',
|
68
|
+
'ip6' => 'dhcp',
|
69
|
+
'rate' => '',
|
70
|
+
'gw' => '192.168.56.100',
|
71
|
+
'gw6' => '2001:0:1234::c1c0:abcd:876'
|
72
|
+
}
|
73
|
+
},
|
74
|
+
'1' => {
|
75
|
+
'id' => 'net1',
|
76
|
+
'compute_attributes' => {
|
77
|
+
'name' => 'eth1',
|
78
|
+
'bridge' => 'vmbr0',
|
79
|
+
'ip' => 'dhcp',
|
80
|
+
'ip6' => 'dhcp',
|
81
|
+
'gw' => '192.168.56.100',
|
82
|
+
'gw6' => '2001:0:1234::c1c0:abcd:876'
|
83
|
+
}
|
84
|
+
}
|
61
85
|
} }
|
62
86
|
end
|
63
87
|
|
@@ -67,8 +91,8 @@ module ForemanFogProxmox
|
|
67
91
|
'name' => 'test',
|
68
92
|
'type' => 'lxc',
|
69
93
|
:type => 'lxc',
|
70
|
-
'node_id' => '
|
71
|
-
:node_id => '
|
94
|
+
'node_id' => 'proxmox',
|
95
|
+
:node_id => 'proxmox',
|
72
96
|
:memory => 536_870_912,
|
73
97
|
'templated' => 0,
|
74
98
|
:onboot => 0,
|
@@ -90,13 +114,13 @@ module ForemanFogProxmox
|
|
90
114
|
{ 'vmid' => '100',
|
91
115
|
'name' => 'test',
|
92
116
|
'type' => 'lxc',
|
93
|
-
'node_id' => '
|
117
|
+
'node_id' => 'proxmox',
|
94
118
|
'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' } },
|
95
119
|
'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'name' => 'eth0' } } }
|
96
120
|
end
|
97
121
|
|
98
122
|
test '#memory' do
|
99
|
-
memory =
|
123
|
+
memory = parse_typed_memory(host_form['config_attributes'], type)
|
100
124
|
assert memory.key?(:memory)
|
101
125
|
assert_equal 536_870_912, memory[:memory]
|
102
126
|
assert memory.key?(:swap)
|
@@ -104,25 +128,23 @@ module ForemanFogProxmox
|
|
104
128
|
end
|
105
129
|
|
106
130
|
test '#cpu' do
|
107
|
-
cpu =
|
131
|
+
cpu = parse_typed_cpu(host_form['config_attributes'], type)
|
108
132
|
assert cpu.key?(:cores)
|
109
|
-
assert_equal 1, cpu[:cores]
|
133
|
+
assert_equal '1', cpu[:cores]
|
110
134
|
assert cpu.key?(:arch)
|
111
135
|
assert_equal 'amd64', cpu[:arch]
|
112
136
|
end
|
113
137
|
|
114
138
|
test '#ostemplate' do
|
115
|
-
ostemplate = parse_container_ostemplate(
|
139
|
+
ostemplate = parse_container_ostemplate(host_form)
|
116
140
|
expected_ostemplate = {
|
117
|
-
:ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
|
118
|
-
:ostemplate_storage => 'local',
|
119
|
-
:ostemplate_file => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
|
141
|
+
:ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
|
120
142
|
}
|
121
143
|
assert_equal expected_ostemplate, ostemplate
|
122
144
|
end
|
123
145
|
|
124
|
-
test '#vm
|
125
|
-
vm =
|
146
|
+
test '#vm host_form' do
|
147
|
+
vm = parse_typed_vm(host_form, type)
|
126
148
|
assert_equal 536_870_912, vm[:memory]
|
127
149
|
assert_equal 'local-lvm:1073741824', vm[:rootfs]
|
128
150
|
assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876', vm[:net0]
|
@@ -132,19 +154,17 @@ module ForemanFogProxmox
|
|
132
154
|
end
|
133
155
|
|
134
156
|
test '#vm container' do
|
135
|
-
vm =
|
157
|
+
vm = parse_typed_vm(host_form, type)
|
136
158
|
expected_vm = ActiveSupport::HashWithIndifferentAccess.new(
|
137
159
|
:vmid => '100',
|
138
160
|
:password => 'proxmox01',
|
161
|
+
:ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
139
162
|
:onboot => '0',
|
140
|
-
:ostype => 'debian',
|
141
|
-
:arch => 'amd64',
|
142
|
-
:cores => 1,
|
143
163
|
:memory => 536_870_912,
|
144
164
|
:swap => 536_870_912,
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
165
|
+
:cores => '1',
|
166
|
+
:arch => 'amd64',
|
167
|
+
:ostype => 'debian',
|
148
168
|
:net0 => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
|
149
169
|
:net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
|
150
170
|
:rootfs => 'local-lvm:1073741824',
|
@@ -154,7 +174,7 @@ module ForemanFogProxmox
|
|
154
174
|
end
|
155
175
|
|
156
176
|
test '#volume with rootfs 1Gb' do
|
157
|
-
volumes =
|
177
|
+
volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
|
158
178
|
assert_not volumes.empty?
|
159
179
|
assert_equal 2, volumes.size
|
160
180
|
assert rootfs = volumes.first
|
@@ -168,7 +188,7 @@ module ForemanFogProxmox
|
|
168
188
|
test '#interface with name eth0 and bridge' do
|
169
189
|
deletes = []
|
170
190
|
nics = []
|
171
|
-
|
191
|
+
add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], deletes, nics, type)
|
172
192
|
assert 1, nics.length
|
173
193
|
assert nics[0].key?(:net0)
|
174
194
|
assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876', nics[0][:net0]
|
@@ -177,7 +197,7 @@ module ForemanFogProxmox
|
|
177
197
|
test '#interface with name eth1 and bridge' do
|
178
198
|
deletes = []
|
179
199
|
nics = []
|
180
|
-
|
200
|
+
add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], deletes, nics, type)
|
181
201
|
assert 1, nics.length
|
182
202
|
assert nics[0].key?(:net1)
|
183
203
|
assert_equal 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876', nics[0][:net1]
|
@@ -186,14 +206,14 @@ module ForemanFogProxmox
|
|
186
206
|
test '#interface delete net0' do
|
187
207
|
deletes = []
|
188
208
|
nics = []
|
189
|
-
|
209
|
+
add_or_delete_typed_interface(host_delete['interfaces_attributes']['0'], deletes, nics, type)
|
190
210
|
assert_empty nics
|
191
211
|
assert_equal 1, deletes.length
|
192
212
|
assert_equal 'net0', deletes[0]
|
193
213
|
end
|
194
214
|
|
195
215
|
test '#interfaces' do
|
196
|
-
interfaces_to_add, interfaces_to_delete =
|
216
|
+
interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(host_form, type)
|
197
217
|
assert_empty interfaces_to_delete
|
198
218
|
assert_equal 2, interfaces_to_add.length
|
199
219
|
assert_includes interfaces_to_add, { net0: 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876' }
|
@@ -21,63 +21,88 @@ require 'test_plugin_helper'
|
|
21
21
|
|
22
22
|
module ForemanFogProxmox
|
23
23
|
class ProxmoxServerHelperTest < ActiveSupport::TestCase
|
24
|
-
include ProxmoxServerHelper
|
25
24
|
include ProxmoxVmHelper
|
26
25
|
|
27
26
|
describe 'parse' do
|
28
27
|
setup { Fog.mock! }
|
29
28
|
teardown { Fog.unmock! }
|
30
29
|
|
31
|
-
let(:
|
30
|
+
let(:type) do
|
31
|
+
'qemu'
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:host_form) do
|
32
35
|
{ 'vmid' => '100',
|
33
36
|
'name' => 'test',
|
34
|
-
'node_id' => '
|
37
|
+
'node_id' => 'proxmox',
|
35
38
|
'type' => 'qemu',
|
36
39
|
'config_attributes' => {
|
37
40
|
'memory' => '536870912',
|
38
41
|
'balloon' => '268435456',
|
39
42
|
'shares' => '5',
|
40
43
|
'cpu_type' => 'kvm64',
|
41
|
-
'spectre' => '1',
|
44
|
+
'spectre' => '+1',
|
42
45
|
'pcid' => '0',
|
43
46
|
'cores' => '1',
|
44
47
|
'sockets' => '1'
|
45
48
|
},
|
46
49
|
'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' }
|
50
|
+
'0' => { 'id' => 'scsi0', 'storage_type' => 'hard_disk', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
|
51
|
+
'1' => { 'id' => 'virtio0', 'storage_type' => 'hard_disk', 'controller' => 'virtio', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
|
52
|
+
'2' => { 'id' => 'ide2', 'storage_type' => 'cdrom', 'controller' => 'ide', 'device' => '2', 'storage' => 'local-lvm', 'cdrom' => 'none' }
|
49
53
|
},
|
50
54
|
'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' }
|
55
|
+
'0' => { 'id' => 'net0', 'compute_attributes' => { 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0', 'rate' => nil } },
|
56
|
+
'1' => { 'id' => 'net1', 'compute_attributes' => { 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0' } }
|
53
57
|
} }
|
54
58
|
end
|
55
59
|
|
56
60
|
let(:host_delete) do
|
57
61
|
{ 'vmid' => '100',
|
58
|
-
'node_id' => '
|
62
|
+
'node_id' => 'proxmox',
|
59
63
|
'name' => 'test',
|
60
64
|
'type' => 'qemu',
|
61
|
-
'
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
'volumes_attributes' => {
|
66
|
+
'0' => { '_delete' => '1', 'storage_type' => 'hard_disk', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' },
|
67
|
+
'1' => { '_delete' => '', 'storage_type' => 'cdrom', 'controller' => 'ide', 'device' => '2', 'storage' => 'local-lvm', 'volid' => 'local-lvm:iso/debian-netinst.iso', 'cdrom' => 'image' }
|
68
|
+
},
|
69
|
+
'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'compute_attributes' => { 'model' => 'virtio' } } } }
|
65
70
|
end
|
66
71
|
|
67
72
|
test '#memory' do
|
68
|
-
memory =
|
73
|
+
memory = parse_typed_memory(host_form['config_attributes'], type)
|
69
74
|
assert memory.key?(:memory)
|
70
75
|
assert_equal 536_870_912, memory[:memory]
|
71
76
|
end
|
72
77
|
|
73
78
|
test '#cpu' do
|
74
|
-
cpu =
|
79
|
+
cpu = parse_typed_cpu(host_form['config_attributes'], type)
|
75
80
|
assert cpu.key?(:cpu)
|
76
81
|
assert_equal 'cputype=kvm64,flags=+spec-ctrl', cpu[:cpu]
|
77
82
|
end
|
78
83
|
|
84
|
+
test '#cdrom none' do
|
85
|
+
cdrom = parse_server_cdrom(host_form['volumes_attributes']['2'])
|
86
|
+
assert cdrom.key?(:id)
|
87
|
+
assert_equal 'ide2', cdrom[:id]
|
88
|
+
assert cdrom.key?(:volid)
|
89
|
+
assert_equal 'none', cdrom[:volid]
|
90
|
+
assert cdrom.key?(:media)
|
91
|
+
assert_equal 'cdrom', cdrom[:media]
|
92
|
+
end
|
93
|
+
|
94
|
+
test '#cdrom image' do
|
95
|
+
cdrom = parse_server_cdrom(host_delete['volumes_attributes']['1'])
|
96
|
+
assert cdrom.key?(:id)
|
97
|
+
assert_equal 'ide2', cdrom[:id]
|
98
|
+
assert cdrom.key?(:volid)
|
99
|
+
assert_equal 'local-lvm:iso/debian-netinst.iso', cdrom[:volid]
|
100
|
+
assert cdrom.key?(:media)
|
101
|
+
assert_equal 'cdrom', cdrom[:media]
|
102
|
+
end
|
103
|
+
|
79
104
|
test '#vm' do
|
80
|
-
vm =
|
105
|
+
vm = parse_typed_vm(host_form, type)
|
81
106
|
assert_equal '1', vm['cores']
|
82
107
|
assert_equal '1', vm['sockets']
|
83
108
|
assert_equal 'cputype=kvm64,flags=+spec-ctrl', vm[:cpu]
|
@@ -91,27 +116,25 @@ module ForemanFogProxmox
|
|
91
116
|
end
|
92
117
|
|
93
118
|
test '#volume with scsi 1Gb' do
|
94
|
-
volumes =
|
119
|
+
volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
|
95
120
|
assert_not volumes.empty?
|
96
|
-
assert volumes.size,
|
97
|
-
|
98
|
-
|
99
|
-
assert_equal 'local-lvm:1073741824,cache=none', volume[:scsi0]
|
121
|
+
assert volumes.size, 3
|
122
|
+
scsi0 = (volumes.select { |volume| volume.key?(:scsi0) }).first
|
123
|
+
assert_equal 'local-lvm:1073741824,cache=none', scsi0[:scsi0]
|
100
124
|
end
|
101
125
|
|
102
126
|
test '#volume with virtio 1Gb' do
|
103
|
-
volumes =
|
127
|
+
volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
|
104
128
|
assert_not volumes.empty?
|
105
|
-
assert volumes.size,
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal 'local-lvm:1073741824,cache=none', volume[:virtio0]
|
129
|
+
assert volumes.size, 3
|
130
|
+
virtio0 = (volumes.select { |volume| volume.key?(:virtio0) }).first
|
131
|
+
assert_equal 'local-lvm:1073741824,cache=none', virtio0[:virtio0]
|
109
132
|
end
|
110
133
|
|
111
134
|
test '#interface with model virtio and bridge' do
|
112
135
|
interfaces_to_delete = []
|
113
136
|
interfaces_to_add = []
|
114
|
-
|
137
|
+
add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add, type)
|
115
138
|
assert_empty interfaces_to_delete
|
116
139
|
assert_equal 1, interfaces_to_add.length
|
117
140
|
assert interfaces_to_add[0].key?(:net0)
|
@@ -121,7 +144,7 @@ module ForemanFogProxmox
|
|
121
144
|
test '#interface with model e1000 and bridge' do
|
122
145
|
interfaces_to_delete = []
|
123
146
|
interfaces_to_add = []
|
124
|
-
|
147
|
+
add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add, type)
|
125
148
|
assert_empty interfaces_to_delete
|
126
149
|
assert_equal 1, interfaces_to_add.length
|
127
150
|
assert interfaces_to_add[0].key?(:net1)
|
@@ -131,14 +154,14 @@ module ForemanFogProxmox
|
|
131
154
|
test '#interface delete net0' do
|
132
155
|
interfaces_to_delete = []
|
133
156
|
interfaces_to_add = []
|
134
|
-
|
157
|
+
add_or_delete_typed_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add, type)
|
135
158
|
assert_empty interfaces_to_add
|
136
159
|
assert_equal 1, interfaces_to_delete.length
|
137
160
|
assert_equal 'net0', interfaces_to_delete[0]
|
138
161
|
end
|
139
162
|
|
140
163
|
test '#interfaces' do
|
141
|
-
interfaces_to_add, interfaces_to_delete =
|
164
|
+
interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(host_form, type)
|
142
165
|
assert_empty interfaces_to_delete
|
143
166
|
assert_equal 2, interfaces_to_add.length
|
144
167
|
assert_includes interfaces_to_add, { net0: 'model=virtio,bridge=vmbr0,firewall=0,link_down=0' }
|