foreman_fog_proxmox 0.8.0 → 0.8.2
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 +11 -1
- data/Rakefile +3 -1
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +2 -2
- data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +2 -2
- data/app/helpers/node_dashboard_helper.rb +13 -14
- data/app/helpers/proxmox_compute_selectors_helper.rb +49 -50
- data/app/helpers/proxmox_container_helper.rb +42 -36
- data/app/helpers/proxmox_form_helper.rb +38 -40
- data/app/helpers/proxmox_server_helper.rb +39 -41
- data/app/helpers/proxmox_vm_helper.rb +21 -25
- data/app/models/concerns/fog_extensions/proxmox/disk.rb +8 -8
- data/app/models/concerns/fog_extensions/proxmox/interface.rb +8 -8
- data/app/models/concerns/fog_extensions/proxmox/node.rb +24 -22
- data/app/models/concerns/fog_extensions/proxmox/server.rb +71 -59
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +47 -39
- data/app/models/concerns/fog_extensions/proxmox/volume.rb +8 -8
- data/app/models/concerns/host_ext/proxmox/interfaces.rb +21 -13
- data/app/models/concerns/orchestration/proxmox/compute.rb +14 -10
- data/app/models/foreman_fog_proxmox/options_select.rb +14 -14
- data/app/models/foreman_fog_proxmox/proxmox.rb +30 -466
- data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +54 -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 +53 -0
- data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +60 -0
- data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -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 +108 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +162 -0
- data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +74 -0
- data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +85 -0
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +7 -6
- data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +13 -11
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +13 -11
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +8 -7
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +7 -6
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +7 -6
- data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +7 -6
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +16 -16
- data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -1
- data/app/views/compute_resources/form/_proxmox.html.erb +3 -0
- data/app/views/compute_resources/show/_proxmox.html.erb +8 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +5 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +6 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +6 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +6 -2
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +8 -2
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +6 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +15 -1
- data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +2 -2
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +6 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +2 -2
- data/config/routes.rb +4 -4
- data/lib/foreman_fog_proxmox/engine.rb +14 -14
- data/lib/foreman_fog_proxmox/semver.rb +78 -78
- data/lib/foreman_fog_proxmox/value.rb +5 -3
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/lib/tasks/foreman_fog_proxmox_tasks.rake +3 -13
- data/locale/en/foreman_fog_proxmox.edit.po +472 -0
- data/locale/en/foreman_fog_proxmox.po +48 -24
- data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/foreman_fog_proxmox.pot +140 -102
- data/locale/fr/foreman_fog_proxmox.edit.po +472 -0
- data/locale/fr/foreman_fog_proxmox.po +52 -28
- data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
- data/locale/gemspec.rb +2 -0
- data/test/{unit/foreman_fog_proxmox/proxmox_test_helpers.rb → factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb} +4 -140
- data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +61 -0
- data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
- data/test/factories/proxmox_factory.rb +15 -15
- data/test/functional/compute_resources_controller_test.rb +12 -10
- data/test/test_plugin_helper.rb +2 -0
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +178 -182
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +122 -126
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +180 -187
- data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +116 -0
- data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +71 -0
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +9 -479
- data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +82 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +207 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +92 -0
- data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +324 -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 +63 -0
- data/test/unit/foreman_fog_proxmox/semver_test.rb +67 -53
- metadata +52 -14
@@ -20,132 +20,128 @@
|
|
20
20
|
require 'test_plugin_helper'
|
21
21
|
|
22
22
|
module ForemanFogProxmox
|
23
|
-
class ProxmoxServerHelperTest < ActiveSupport::TestCase
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
+
'min_memory' => '',
|
39
|
+
'ballon' => '',
|
40
|
+
'shares' => '',
|
41
|
+
'cpu_type' => 'kvm64',
|
42
|
+
'spectre' => '1',
|
43
|
+
'pcid' => '0',
|
44
|
+
'cores' => '1',
|
45
|
+
'sockets' => '1'
|
46
|
+
},
|
47
|
+
'volumes_attributes' => {
|
48
|
+
'0' => { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
|
49
|
+
'1' => { 'controller' => 'virtio', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' }
|
50
|
+
},
|
51
|
+
'interfaces_attributes' => {
|
52
|
+
'0' => { 'id' => 'net0', 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0', 'rate' => nil },
|
53
|
+
'1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0' }
|
54
|
+
} }
|
55
|
+
end
|
56
|
+
|
57
|
+
let(:host_delete) do
|
58
|
+
{ 'vmid' => '100',
|
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 'local-lvm:1073741824,cache=none', vm[:scsi0]
|
86
|
+
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
|
87
|
+
assert_not vm.key?(:config)
|
88
|
+
assert_not vm.key?(:node)
|
89
|
+
end
|
90
|
+
|
91
|
+
test '#volume with scsi 1Gb' do
|
92
|
+
volumes = parse_server_volumes(host['volumes_attributes'])
|
93
|
+
assert_not volumes.empty?
|
94
|
+
assert volumes.size, 2
|
95
|
+
assert volume = volumes.first
|
96
|
+
assert volume.key?(:scsi0)
|
97
|
+
assert_equal 'local-lvm:1073741824,cache=none', volume[:scsi0]
|
98
|
+
end
|
99
|
+
|
100
|
+
test '#volume with virtio 1Gb' do
|
101
|
+
volumes = parse_server_volumes(host['volumes_attributes'])
|
102
|
+
assert_not volumes.empty?
|
103
|
+
assert volumes.size, 2
|
104
|
+
assert volume = volumes[1]
|
105
|
+
assert volume.key?(:virtio0)
|
106
|
+
assert_equal 'local-lvm:1073741824,cache=none', volume[:virtio0]
|
107
|
+
end
|
108
|
+
|
109
|
+
test '#interface with model virtio and bridge' do
|
110
|
+
interfaces_to_delete = []
|
111
|
+
interfaces_to_add = []
|
112
|
+
add_server_interface(host['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add)
|
113
|
+
assert interfaces_to_delete.empty?
|
114
|
+
assert_equal 1, interfaces_to_add.length
|
115
|
+
assert interfaces_to_add[0].key?(:net0)
|
116
|
+
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', interfaces_to_add[0][:net0]
|
117
|
+
end
|
118
|
+
|
119
|
+
test '#interface with model e1000 and bridge' do
|
120
|
+
interfaces_to_delete = []
|
121
|
+
interfaces_to_add = []
|
122
|
+
add_server_interface(host['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add)
|
123
|
+
assert interfaces_to_delete.empty?
|
124
|
+
assert_equal 1, interfaces_to_add.length
|
125
|
+
assert interfaces_to_add[0].key?(:net1)
|
126
|
+
assert_equal 'model=e1000,bridge=vmbr0,firewall=0,link_down=0', interfaces_to_add[0][:net1]
|
127
|
+
end
|
128
|
+
|
129
|
+
test '#interface delete net0' do
|
130
|
+
interfaces_to_delete = []
|
131
|
+
interfaces_to_add = []
|
132
|
+
add_server_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add)
|
133
|
+
assert interfaces_to_add.empty?
|
134
|
+
assert_equal 1, interfaces_to_delete.length
|
135
|
+
assert_equal 'net0', interfaces_to_delete[0]
|
136
|
+
end
|
137
|
+
|
138
|
+
test '#interfaces' do
|
139
|
+
interfaces_to_add, interfaces_to_delete = parse_server_interfaces(host['interfaces_attributes'])
|
140
|
+
assert interfaces_to_delete.empty?
|
141
|
+
assert_equal 2, interfaces_to_add.length
|
142
|
+
assert interfaces_to_add.include?(net0: 'model=virtio,bridge=vmbr0,firewall=0,link_down=0')
|
143
|
+
assert interfaces_to_add.include?(net1: 'model=e1000,bridge=vmbr0,firewall=0,link_down=0')
|
144
|
+
end
|
57
145
|
end
|
58
|
-
|
59
|
-
let(:host_delete) do
|
60
|
-
{ 'vmid' => '100',
|
61
|
-
'name' => 'test',
|
62
|
-
'type' => 'qemu',
|
63
|
-
'cdrom' => 'image',
|
64
|
-
'cdrom_iso' => 'local-lvm:iso/debian-netinst.iso',
|
65
|
-
'volumes_attributes' => { '0' => { '_delete' => '1', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' }},
|
66
|
-
'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'model' => 'virtio' } }
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
test '#memory' do
|
71
|
-
memory = parse_server_memory(host['config_attributes'])
|
72
|
-
assert memory.has_key?(:memory)
|
73
|
-
assert_equal 536870912, memory[:memory]
|
74
|
-
end
|
75
|
-
|
76
|
-
test '#cpu' do
|
77
|
-
cpu = parse_server_cpu(host['config_attributes'])
|
78
|
-
assert cpu.has_key?(:cpu)
|
79
|
-
assert_equal 'cputype=kvm64,flags=+spec-ctrl', cpu[:cpu]
|
80
|
-
end
|
81
|
-
|
82
|
-
test '#vm' do
|
83
|
-
vm = parse_server_vm(host)
|
84
|
-
assert_equal '1', vm['cores']
|
85
|
-
assert_equal '1', vm['sockets']
|
86
|
-
assert_equal 'cputype=kvm64,flags=+spec-ctrl', vm[:cpu]
|
87
|
-
assert_equal 536870912, vm[:memory]
|
88
|
-
assert_equal 'local-lvm:1073741824,cache=none', vm[:scsi0]
|
89
|
-
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
|
90
|
-
assert !vm.has_key?(:config)
|
91
|
-
assert !vm.has_key?(:node)
|
92
|
-
end
|
93
|
-
|
94
|
-
test '#volume with scsi 1Gb' do
|
95
|
-
volumes = parse_server_volumes(host['volumes_attributes'])
|
96
|
-
assert !volumes.empty?
|
97
|
-
assert volumes.size, 2
|
98
|
-
assert volume = volumes.first
|
99
|
-
assert volume.has_key?(:scsi0)
|
100
|
-
assert_equal 'local-lvm:1073741824,cache=none', volume[:scsi0]
|
101
|
-
end
|
102
|
-
|
103
|
-
test '#volume with virtio 1Gb' do
|
104
|
-
volumes = parse_server_volumes(host['volumes_attributes'])
|
105
|
-
assert !volumes.empty?
|
106
|
-
assert volumes.size, 2
|
107
|
-
assert volume = volumes[1]
|
108
|
-
assert volume.has_key?(:virtio0)
|
109
|
-
assert_equal 'local-lvm:1073741824,cache=none', volume[:virtio0]
|
110
|
-
end
|
111
|
-
|
112
|
-
test '#interface with model virtio and bridge' do
|
113
|
-
interfaces_to_delete = []
|
114
|
-
interfaces_to_add = []
|
115
|
-
add_server_interface(host['interfaces_attributes']['0'],interfaces_to_delete,interfaces_to_add)
|
116
|
-
assert interfaces_to_delete.empty?
|
117
|
-
assert_equal 1, interfaces_to_add.length
|
118
|
-
assert interfaces_to_add[0].has_key?(:net0)
|
119
|
-
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', interfaces_to_add[0][:net0]
|
120
|
-
end
|
121
|
-
|
122
|
-
test '#interface with model e1000 and bridge' do
|
123
|
-
interfaces_to_delete = []
|
124
|
-
interfaces_to_add = []
|
125
|
-
interface = add_server_interface(host['interfaces_attributes']['1'],interfaces_to_delete,interfaces_to_add)
|
126
|
-
assert interfaces_to_delete.empty?
|
127
|
-
assert_equal 1, interfaces_to_add.length
|
128
|
-
assert interfaces_to_add[0].has_key?(:net1)
|
129
|
-
assert_equal 'model=e1000,bridge=vmbr0,firewall=0,link_down=0', interfaces_to_add[0][:net1]
|
130
|
-
end
|
131
|
-
|
132
|
-
test '#interface delete net0' do
|
133
|
-
interfaces_to_delete = []
|
134
|
-
interfaces_to_add = []
|
135
|
-
add_server_interface(host_delete['interfaces_attributes']['0'],interfaces_to_delete,interfaces_to_add)
|
136
|
-
assert interfaces_to_add.empty?
|
137
|
-
assert_equal 1, interfaces_to_delete.length
|
138
|
-
assert_equal 'net0', interfaces_to_delete[0]
|
139
|
-
end
|
140
|
-
|
141
|
-
test '#interfaces' do
|
142
|
-
interfaces_to_add, interfaces_to_delete = parse_server_interfaces(host['interfaces_attributes'])
|
143
|
-
assert interfaces_to_delete.empty?
|
144
|
-
assert_equal 2, interfaces_to_add.length
|
145
|
-
assert interfaces_to_add.include?({ net0: 'model=virtio,bridge=vmbr0,firewall=0,link_down=0'})
|
146
|
-
assert interfaces_to_add.include?({ net1: 'model=e1000,bridge=vmbr0,firewall=0,link_down=0'})
|
147
|
-
end
|
148
|
-
|
149
146
|
end
|
150
147
|
end
|
151
|
-
end
|
@@ -28,196 +28,189 @@ require 'fog/compute/proxmox/models/snapshots'
|
|
28
28
|
require 'fog/compute/proxmox/models/tasks'
|
29
29
|
|
30
30
|
module ForemanFogProxmox
|
31
|
-
class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
}
|
108
|
-
end
|
109
|
-
|
110
|
-
let(:host_container) do
|
111
|
-
{ 'vmid' => '100',
|
112
|
-
'name' => 'test',
|
113
|
-
'type' => 'lxc',
|
114
|
-
'node_id' => 'pve',
|
115
|
-
'ostemplate_storage' => 'local',
|
116
|
-
'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
117
|
-
'password' => 'proxmox01',
|
118
|
-
'config_attributes' => {
|
119
|
-
'onboot' => '0',
|
120
|
-
'description' => '',
|
121
|
-
'memory' => '536870912',
|
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',
|
122
46
|
'swap' => '',
|
123
47
|
'cores' => '1',
|
124
|
-
'cpulimit' => '',
|
125
|
-
'cpuunits' => '',
|
126
48
|
'arch' => 'amd64',
|
127
49
|
'ostype' => 'debian',
|
128
|
-
'
|
129
|
-
'
|
130
|
-
'
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
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 host_container['config_attributes']['swap'].empty?
|
213
|
+
end
|
214
|
+
end
|
220
215
|
end
|
221
|
-
|
222
216
|
end
|
223
|
-
end
|