foreman_fog_proxmox 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -29
  3. data/app/controllers/concerns/foreman_fog_proxmox/compute_resources_vms_controller.rb +17 -7
  4. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  5. data/app/controllers/concerns/foreman_fog_proxmox/hosts_controller.rb +8 -3
  6. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +6 -3
  7. data/app/helpers/proxmox_compute_controllers_helper.rb +2 -1
  8. data/app/helpers/proxmox_compute_resources_helper.rb +3 -3
  9. data/app/helpers/proxmox_compute_resources_vms_helper.rb +16 -7
  10. data/app/helpers/proxmox_form_helper.rb +9 -5
  11. data/app/helpers/proxmox_vm_config_helper.rb +16 -25
  12. data/app/helpers/proxmox_vm_interfaces_helper.rb +19 -6
  13. data/app/helpers/proxmox_vm_os_template_helper.rb +2 -5
  14. data/app/helpers/proxmox_vm_uuid_helper.rb +1 -1
  15. data/app/helpers/proxmox_vm_volumes_helper.rb +22 -25
  16. data/app/models/concerns/fog_extensions/proxmox/node.rb +2 -2
  17. data/app/models/concerns/fog_extensions/proxmox/server.rb +9 -5
  18. data/app/models/concerns/host_ext/proxmox/associator.rb +3 -2
  19. data/app/models/concerns/host_ext/proxmox/for_vm.rb +1 -1
  20. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -3
  21. data/app/models/concerns/orchestration/proxmox/compute.rb +11 -4
  22. data/app/models/foreman_fog_proxmox/options_select.rb +1 -3
  23. data/app/models/foreman_fog_proxmox/proxmox.rb +12 -10
  24. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +15 -3
  25. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +6 -2
  26. data/app/models/foreman_fog_proxmox/proxmox_console.rb +3 -1
  27. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -2
  28. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +28 -6
  29. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +6 -1
  30. data/app/models/foreman_fog_proxmox/proxmox_pools.rb +4 -4
  31. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -3
  32. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +9 -7
  33. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +37 -24
  34. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +4 -5
  35. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +23 -12
  36. data/app/models/foreman_fog_proxmox/vms.rb +2 -2
  37. data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +2 -2
  38. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
  39. data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +1 -1
  40. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +3 -3
  41. data/app/views/compute_resources_vms/form/proxmox/server/_volume_hard_disk.html.erb +1 -1
  42. data/config/routes.rb +8 -4
  43. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +1 -2
  44. data/lib/foreman_fog_proxmox/engine.rb +4 -3
  45. data/lib/foreman_fog_proxmox/semver.rb +1 -4
  46. data/lib/foreman_fog_proxmox/version.rb +1 -1
  47. data/locale/en/foreman_fog_proxmox.po +140 -47
  48. data/locale/foreman_fog_proxmox.pot +300 -137
  49. data/locale/fr/foreman_fog_proxmox.po +145 -52
  50. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +6 -7
  51. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +6 -7
  52. data/test/functional/compute_resources_controller_test.rb +4 -2
  53. data/test/test_plugin_helper.rb +12 -7
  54. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +38 -47
  55. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +49 -34
  56. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +29 -65
  57. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +3 -3
  58. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +22 -13
  59. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +18 -9
  60. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +45 -35
  61. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +0 -4
  62. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +34 -22
  63. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +20 -14
  64. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_hard_disk_test.rb +76 -54
  65. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +26 -15
  66. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +1 -1
  67. data/test/unit/foreman_fog_proxmox/semver_test.rb +2 -1
  68. metadata +35 -21
@@ -41,8 +41,8 @@ module ForemanFogProxmox
41
41
  'config_attributes' => {
42
42
  'onboot' => '0',
43
43
  'description' => '',
44
- 'memory' => '536870912',
45
- 'swap' => '536870912',
44
+ 'memory' => '1024',
45
+ 'swap' => '512',
46
46
  'cores' => '1',
47
47
  'cpulimit' => '',
48
48
  'cpuunits' => '',
@@ -50,12 +50,12 @@ module ForemanFogProxmox
50
50
  'ostype' => 'debian',
51
51
  'hostname' => 'toto-tata.pve',
52
52
  'nameserver' => '',
53
- 'searchdomain' => ''
53
+ 'searchdomain' => '',
54
54
 
55
55
  },
56
56
  'volumes_attributes' => {
57
- '0' => { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => '' },
58
- '1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' }
57
+ '0' => { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '1', 'cache' => '' },
58
+ '1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1', 'mp' => '/opt/path' },
59
59
  },
60
60
  'interfaces_attributes' => {
61
61
  '0' => {
@@ -67,8 +67,8 @@ module ForemanFogProxmox
67
67
  'ip6' => 'dhcp',
68
68
  'rate' => '',
69
69
  'gw' => '192.168.56.100',
70
- 'gw6' => '2001:0:1234::c1c0:abcd:876'
71
- }
70
+ 'gw6' => '2001:0:1234::c1c0:abcd:876',
71
+ },
72
72
  },
73
73
  '1' => {
74
74
  'id' => 'net1',
@@ -78,9 +78,9 @@ module ForemanFogProxmox
78
78
  'ip' => 'dhcp',
79
79
  'ip6' => 'dhcp',
80
80
  'gw' => '192.168.56.100',
81
- 'gw6' => '2001:0:1234::c1c0:abcd:876'
82
- }
83
- }
81
+ 'gw6' => '2001:0:1234::c1c0:abcd:876',
82
+ },
83
+ },
84
84
  } }
85
85
  end
86
86
 
@@ -92,10 +92,10 @@ module ForemanFogProxmox
92
92
  :type => 'lxc',
93
93
  'node_id' => 'proxmox',
94
94
  :node_id => 'proxmox',
95
- :memory => 536_870_912,
96
- 'templated' => 0,
97
- :onboot => 0,
98
- :swap => 536_870_912,
95
+ :memory => '1024',
96
+ 'templated' => '0',
97
+ :onboot => '0',
98
+ :swap => '512',
99
99
  'cores' => '1',
100
100
  :arch => 'amd64',
101
101
  :ostype => 'debian',
@@ -103,8 +103,8 @@ module ForemanFogProxmox
103
103
  'ostemplate_storage' => 'local',
104
104
  'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
105
105
  'password' => 'proxmox01',
106
- :rootfs => 'local-lvm:1073741824',
107
- :mp0 => 'local-lvm:1073741824,mp=/opt/path',
106
+ :rootfs => 'local-lvm:1',
107
+ :mp0 => 'local-lvm:1,mp=/opt/path',
108
108
  'net0' => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
109
109
  'net1' => 'model=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876' }
110
110
  end
@@ -114,22 +114,20 @@ module ForemanFogProxmox
114
114
  'name' => 'test',
115
115
  'type' => 'lxc',
116
116
  'node_id' => 'proxmox',
117
- 'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' } },
117
+ 'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1', 'mp' => '/opt/path' } },
118
118
  'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'name' => 'eth0' } } }
119
119
  end
120
120
 
121
121
  test '#memory' do
122
- memory = parse_typed_memory(host_form['config_attributes'], type)
123
- assert memory.key?(:memory)
124
- assert_equal 536_870_912, memory[:memory]
125
- assert memory.key?(:swap)
126
- assert_equal 536_870_912, memory[:swap]
122
+ memory = parse_typed_memory(host_form['config_attributes'].select { |key, _value| config_typed_keys(type)[:memory].include? key }, type)
123
+ assert memory.key?('memory')
124
+ assert_equal '1024', memory['memory']
125
+ assert memory.key?('swap')
126
+ assert_equal '512', memory['swap']
127
127
  end
128
128
 
129
129
  test '#cpu' do
130
- cpu = parse_typed_cpu(host_form['config_attributes'], type)
131
- assert cpu.key?(:cores)
132
- assert_equal '1', cpu[:cores]
130
+ cpu = parse_typed_cpu(host_form['config_attributes'].select { |key, _value| config_typed_keys(type)[:cpu].include? key }, type)
133
131
  assert cpu.key?(:arch)
134
132
  assert_equal 'amd64', cpu[:arch]
135
133
  end
@@ -137,22 +135,11 @@ module ForemanFogProxmox
137
135
  test '#ostemplate' do
138
136
  ostemplate = parse_container_ostemplate(host_form)
139
137
  expected_ostemplate = {
140
- :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
138
+ :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
141
139
  }
142
140
  assert_equal expected_ostemplate, ostemplate
143
141
  end
144
142
 
145
- test '#vm host_form' do
146
- vm = parse_typed_vm(host_form, type)
147
- assert_equal 536_870_912, vm[:memory]
148
- assert_equal 'local-lvm:1073741824', vm[:rootfs]
149
- assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876', vm[:net0]
150
- assert_equal 'toto-tata.pve', vm[:hostname]
151
- assert_not vm.key?(:config)
152
- assert_not vm.key?(:node)
153
- assert_not vm.key?(:type)
154
- end
155
-
156
143
  test '#vm container' do
157
144
  vm = parse_typed_vm(host_form, type)
158
145
  expected_vm = ActiveSupport::HashWithIndifferentAccess.new(
@@ -160,16 +147,16 @@ module ForemanFogProxmox
160
147
  :password => 'proxmox01',
161
148
  :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
162
149
  :onboot => '0',
163
- :memory => 536_870_912,
164
- :swap => 536_870_912,
150
+ :memory => '1024',
151
+ :swap => '512',
165
152
  :cores => '1',
166
153
  :arch => 'amd64',
167
154
  :ostype => 'debian',
168
155
  :hostname => 'toto-tata.pve',
169
156
  :net0 => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
170
157
  :net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
171
- :rootfs => 'local-lvm:1073741824',
172
- :mp0 => 'local-lvm:1073741824,mp=/opt/path'
158
+ :rootfs => 'local-lvm:1',
159
+ :mp0 => 'local-lvm:1,mp=/opt/path'
173
160
  )
174
161
  assert_equal expected_vm, vm
175
162
  end
@@ -180,10 +167,10 @@ module ForemanFogProxmox
180
167
  assert_equal 2, volumes.size
181
168
  assert rootfs = volumes.first
182
169
  assert rootfs.key?(:rootfs)
183
- assert_equal 'local-lvm:1073741824', rootfs[:rootfs]
170
+ assert_equal 'local-lvm:1', rootfs[:rootfs]
184
171
  assert mp0 = volumes[1]
185
172
  assert mp0.key?(:mp0)
186
- assert_equal 'local-lvm:1073741824,mp=/opt/path', mp0[:mp0]
173
+ assert_equal 'local-lvm:1,mp=/opt/path', mp0[:mp0]
187
174
  end
188
175
 
189
176
  test '#interface with name eth0 and bridge' do
@@ -192,7 +179,8 @@ module ForemanFogProxmox
192
179
  add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], deletes, nics, type)
193
180
  assert 1, nics.length
194
181
  assert nics[0].key?(:net0)
195
- 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]
182
+ assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
183
+ nics[0][:net0]
196
184
  end
197
185
 
198
186
  test '#interface with name eth1 and bridge' do
@@ -201,7 +189,8 @@ module ForemanFogProxmox
201
189
  add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], deletes, nics, type)
202
190
  assert 1, nics.length
203
191
  assert nics[0].key?(:net1)
204
- 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]
192
+ assert_equal 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
193
+ nics[0][:net1]
205
194
  end
206
195
 
207
196
  test '#interface delete net0' do
@@ -217,8 +206,10 @@ module ForemanFogProxmox
217
206
  interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(host_form, type)
218
207
  assert_empty interfaces_to_delete
219
208
  assert_equal 2, interfaces_to_add.length
220
- 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' }
221
- assert_includes interfaces_to_add, { net1: 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876' }
209
+ assert_includes interfaces_to_add,
210
+ { net0: 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876' }
211
+ assert_includes interfaces_to_add,
212
+ { net1: 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876' }
222
213
  end
223
214
  end
224
215
  end
@@ -38,23 +38,27 @@ module ForemanFogProxmox
38
38
  'type' => 'qemu',
39
39
  'config_attributes' => {
40
40
  'name' => 'toto-tata.pve',
41
- 'memory' => '536870912',
42
- 'balloon' => '268435456',
43
- 'shares' => '5',
41
+ 'memory' => '1024',
42
+ 'balloon' => '512',
43
+ 'shares' => '512',
44
44
  'cpu_type' => 'kvm64',
45
45
  'spectre' => '+1',
46
46
  'pcid' => '0',
47
47
  'cores' => '1',
48
- 'sockets' => '1'
48
+ 'sockets' => '1',
49
49
  },
50
50
  'volumes_attributes' => {
51
- '0' => { 'id' => 'scsi0', 'storage_type' => 'hard_disk', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
52
- '1' => { 'id' => 'virtio0', 'storage_type' => 'hard_disk', 'controller' => 'virtio', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
53
- '2' => { 'id' => 'ide2', 'storage_type' => 'cdrom', 'controller' => 'ide', 'device' => '2', 'storage' => 'local-lvm', 'cdrom' => 'none' }
51
+ '0' => { 'id' => 'scsi0', 'storage_type' => 'hard_disk', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '10', 'cache' => 'none' },
52
+ '1' => { 'id' => 'virtio0', 'storage_type' => 'hard_disk', 'controller' => 'virtio', 'device' => '0', 'storage' => 'local-lvm', 'size' => '10', 'cache' => 'none' },
53
+ '2' => { 'id' => 'ide2', 'storage_type' => 'cdrom', 'controller' => 'ide', 'device' => '2', 'storage' => 'local-lvm', 'cdrom' => 'none' },
54
54
  },
55
55
  'interfaces_attributes' => {
56
- '0' => { 'id' => 'net0', 'compute_attributes' => { 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0', 'rate' => nil } },
57
- '1' => { 'id' => 'net1', 'compute_attributes' => { 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0' } }
56
+ '0' => { 'id' => 'net0',
57
+ 'compute_attributes' => { 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0',
58
+ 'rate' => nil } },
59
+ '1' => { 'id' => 'net1',
60
+ 'compute_attributes' => { 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0',
61
+ 'link_down' => '0' } },
58
62
  } }
59
63
  end
60
64
 
@@ -64,20 +68,21 @@ module ForemanFogProxmox
64
68
  'name' => 'test',
65
69
  'type' => 'qemu',
66
70
  'volumes_attributes' => {
67
- '0' => { '_delete' => '1', 'storage_type' => 'hard_disk', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' },
68
- '1' => { '_delete' => '', 'storage_type' => 'cdrom', 'controller' => 'ide', 'device' => '2', 'storage' => 'local-lvm', 'volid' => 'local-lvm:iso/debian-netinst.iso', 'cdrom' => 'image' }
71
+ '0' => { '_delete' => '1', 'storage_type' => 'hard_disk', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '10' },
72
+ '1' => { '_delete' => '', 'storage_type' => 'cdrom', 'controller' => 'ide', 'device' => '2', 'storage' => 'local-lvm', 'volid' => 'local-lvm:iso/debian-netinst.iso', 'cdrom' => 'image' },
69
73
  },
70
- 'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'compute_attributes' => { 'model' => 'virtio' } } } }
74
+ 'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0',
75
+ 'compute_attributes' => { 'model' => 'virtio' } } } }
71
76
  end
72
77
 
73
78
  test '#memory' do
74
- memory = parse_typed_memory(host_form['config_attributes'], type)
75
- assert memory.key?(:memory)
76
- assert_equal 536_870_912, memory[:memory]
79
+ memory = parse_typed_memory(host_form['config_attributes'].select { |key, _value| config_typed_keys(type)[:memory].include? key }, type)
80
+ expected_memory = { 'memory' => '1024', 'balloon' => '512', 'shares' => '512' }
81
+ assert_equal expected_memory, memory
77
82
  end
78
83
 
79
84
  test '#cpu' do
80
- cpu = parse_typed_cpu(host_form['config_attributes'], type)
85
+ cpu = parse_typed_cpu(host_form['config_attributes'].select { |key, _value| config_typed_keys(type)[:cpu].include? key }, type)
81
86
  assert cpu.key?(:cpu)
82
87
  assert_equal 'cputype=kvm64,flags=+spec-ctrl', cpu[:cpu]
83
88
  end
@@ -103,40 +108,48 @@ module ForemanFogProxmox
103
108
  end
104
109
 
105
110
  test '#vm' do
111
+ expected_vm = ActiveSupport::HashWithIndifferentAccess.new(
112
+ {
113
+ 'vmid' => '100',
114
+ 'name' => 'toto-tata.pve',
115
+ 'memory' => '1024',
116
+ 'balloon' => '512',
117
+ 'shares' => '512',
118
+ 'cores' => '1',
119
+ 'sockets' => '1',
120
+ 'cpu' => 'cputype=kvm64,flags=+spec-ctrl',
121
+ 'net0' => 'model=virtio,bridge=vmbr0,firewall=0,link_down=0',
122
+ 'net1' => 'model=e1000,bridge=vmbr0,firewall=0,link_down=0',
123
+ 'scsi0' => 'local-lvm:10,cache=none',
124
+ 'virtio0' => 'local-lvm:10,cache=none',
125
+ 'ide2' => 'none,media=cdrom',
126
+ }
127
+ )
106
128
  vm = parse_typed_vm(host_form, type)
107
- assert_equal '1', vm['cores']
108
- assert_equal '1', vm['sockets']
109
- assert_equal 'cputype=kvm64,flags=+spec-ctrl', vm[:cpu]
110
- assert_equal 536_870_912, vm[:memory]
111
- assert_equal 268_435_456, vm[:balloon]
112
- assert_equal 5, vm[:shares]
113
- assert_equal 'local-lvm:1073741824,cache=none', vm[:scsi0]
114
- assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
115
- assert_equal 'toto-tata.pve', vm[:name]
116
- assert_not vm.key?(:config)
117
- assert_not vm.key?(:node)
129
+ assert_equal expected_vm, vm
118
130
  end
119
131
 
120
- test '#volume with scsi 1Gb' do
132
+ test '#volume with scsi 10Gb' do
121
133
  volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
122
134
  assert_not volumes.empty?
123
135
  assert volumes.size, 3
124
136
  scsi0 = (volumes.select { |volume| volume.key?(:scsi0) }).first
125
- assert_equal 'local-lvm:1073741824,cache=none', scsi0[:scsi0]
137
+ assert_equal 'local-lvm:10,cache=none', scsi0[:scsi0]
126
138
  end
127
139
 
128
- test '#volume with virtio 1Gb' do
140
+ test '#volume with virtio 10Gb' do
129
141
  volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
130
142
  assert_not volumes.empty?
131
143
  assert volumes.size, 3
132
144
  virtio0 = (volumes.select { |volume| volume.key?(:virtio0) }).first
133
- assert_equal 'local-lvm:1073741824,cache=none', virtio0[:virtio0]
145
+ assert_equal 'local-lvm:10,cache=none', virtio0[:virtio0]
134
146
  end
135
147
 
136
148
  test '#interface with model virtio and bridge' do
137
149
  interfaces_to_delete = []
138
150
  interfaces_to_add = []
139
- add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add, type)
151
+ add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add,
152
+ type)
140
153
  assert_empty interfaces_to_delete
141
154
  assert_equal 1, interfaces_to_add.length
142
155
  assert interfaces_to_add[0].key?(:net0)
@@ -146,7 +159,8 @@ module ForemanFogProxmox
146
159
  test '#interface with model e1000 and bridge' do
147
160
  interfaces_to_delete = []
148
161
  interfaces_to_add = []
149
- add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add, type)
162
+ add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add,
163
+ type)
150
164
  assert_empty interfaces_to_delete
151
165
  assert_equal 1, interfaces_to_add.length
152
166
  assert interfaces_to_add[0].key?(:net1)
@@ -156,7 +170,8 @@ module ForemanFogProxmox
156
170
  test '#interface delete net0' do
157
171
  interfaces_to_delete = []
158
172
  interfaces_to_add = []
159
- add_or_delete_typed_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add, type)
173
+ add_or_delete_typed_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete,
174
+ interfaces_to_add, type)
160
175
  assert_empty interfaces_to_add
161
176
  assert_equal 1, interfaces_to_delete.length
162
177
  assert_equal 'net0', interfaces_to_delete[0]
@@ -42,13 +42,13 @@ module ForemanFogProxmox
42
42
  :node_id => 'proxmox',
43
43
  :service => service,
44
44
  'templated' => '0',
45
- 'memory' => '536870912',
45
+ 'memory' => '512',
46
46
  'swap' => '',
47
47
  'cores' => '1',
48
48
  'arch' => 'amd64',
49
49
  'ostype' => 'debian',
50
- 'rootfs' => 'local-lvm:1073741824',
51
- 'mp0' => 'local-lvm:1073741824',
50
+ 'rootfs' => 'local-lvm:10',
51
+ 'mp0' => 'local-lvm:10',
52
52
  'net0' => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp',
53
53
  'net1' => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp'
54
54
  )
@@ -66,8 +66,7 @@ module ForemanFogProxmox
66
66
  :type => 'qemu',
67
67
  'templated' => '0',
68
68
  'ide2' => 'local-lvm:iso/debian-netinst.iso,media=cdrom',
69
- 'memory' => '536870912',
70
- 'min_memory' => '',
69
+ 'memory' => '1024',
71
70
  'ballon' => '',
72
71
  'shares' => '',
73
72
  'cpu_type' => 'kvm64',
@@ -75,7 +74,7 @@ module ForemanFogProxmox
75
74
  'pcid' => '0',
76
75
  'cores' => '1',
77
76
  'sockets' => '1',
78
- 'scsi0' => 'local-lvm:1073741824,cache=none',
77
+ 'scsi0' => 'local-lvm:10,cache=none',
79
78
  'net0' => 'model=virtio,bridge=vmbr0',
80
79
  'net1' => 'model=e1000,bridge=vmbr0'
81
80
  )
@@ -87,22 +86,21 @@ module ForemanFogProxmox
87
86
  'node_id' => 'proxmox',
88
87
  'type' => 'qemu',
89
88
  'config_attributes' => {
90
- 'memory' => '536870912',
91
- 'min_memory' => nil,
92
- 'ballon' => '',
93
- 'shares' => '',
89
+ 'memory' => '1024',
90
+ 'balloon' => '512',
91
+ 'shares' => '512',
94
92
  'cpu_type' => 'kvm64',
95
93
  'spectre' => '1',
96
94
  'pcid' => '0',
97
95
  'cores' => '1',
98
- 'sockets' => '1'
96
+ 'sockets' => '1',
99
97
  },
100
98
  'volumes_attributes' => {
101
- '0' => { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' }
99
+ '0' => { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '10', 'cache' => 'none' },
102
100
  },
103
101
  'interfaces_attributes' => {
104
102
  '0' => { 'id' => 'net0', 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'disconnect' => '0' },
105
- '1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'disconnect' => '0' }
103
+ '1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'disconnect' => '0' },
106
104
  } }
107
105
  end
108
106
 
@@ -117,8 +115,8 @@ module ForemanFogProxmox
117
115
  'config_attributes' => {
118
116
  'onboot' => '0',
119
117
  'description' => '',
120
- 'memory' => '536870912',
121
- 'swap' => '',
118
+ 'memory' => '1024',
119
+ 'swap' => '512',
122
120
  'cores' => '1',
123
121
  'cpulimit' => '',
124
122
  'cpuunits' => '',
@@ -126,16 +124,16 @@ module ForemanFogProxmox
126
124
  'ostype' => 'debian',
127
125
  'hostname' => '',
128
126
  'nameserver' => '',
129
- 'searchdomain' => ''
127
+ 'searchdomain' => '',
130
128
 
131
129
  },
132
130
  'volumes_attributes' => {
133
- '0' => { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '1073741824' },
134
- '1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824' }
131
+ '0' => { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '10' },
132
+ '1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '10' },
135
133
  },
136
134
  'interfaces_attributes' => {
137
135
  '0' => { 'id' => 'net0', 'name' => 'eth0', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' },
138
- '1' => { 'id' => 'net1', 'name' => 'eth1', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' }
136
+ '1' => { 'id' => 'net1', 'name' => 'eth1', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' },
139
137
  } }
140
138
  end
141
139
 
@@ -147,72 +145,38 @@ module ForemanFogProxmox
147
145
 
148
146
  it '#server qemu' do
149
147
  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 }
148
+ expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject do |key, _value|
149
+ excluded_qemu_keys.include? key
150
+ end
151
151
  assert_equal expected_config_hash, config_hash['config_attributes']
152
152
  end
153
153
 
154
154
  it '#server lxc' do
155
155
  config_hash = object_to_config_hash(server, 'lxc')
156
156
  assert config_hash.key?('config_attributes')
157
- expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key, _value| excluded_qemu_keys.include? key }
157
+ expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject do |key, _value|
158
+ excluded_qemu_keys.include? key
159
+ end
158
160
  assert_equal expected_config_hash, config_hash['config_attributes']
159
161
  end
160
162
 
161
163
  it '#container qemu' do
162
164
  config_hash = object_to_config_hash(container, 'qemu')
163
165
  assert config_hash.key?('config_attributes')
164
- expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value| excluded_lxc_keys.include? key }
166
+ expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject do |key, _value|
167
+ excluded_lxc_keys.include? key
168
+ end
165
169
  assert_equal expected_config_hash, config_hash['config_attributes']
166
170
  end
167
171
 
168
172
  it '#container lxc' do
169
173
  config_hash = object_to_config_hash(container, 'lxc')
170
174
  assert config_hash.key?('config_attributes')
171
- expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key, _value| excluded_lxc_keys.include? key }
175
+ expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject do |key, _value|
176
+ excluded_lxc_keys.include? key
177
+ end
172
178
  assert_equal expected_config_hash, config_hash['config_attributes']
173
179
  end
174
180
  end
175
-
176
- describe 'convert_sizes' do
177
- setup { Fog.mock! }
178
- teardown { Fog.unmock! }
179
-
180
- it '#server' do
181
- convert_sizes(host_server)
182
- assert_equal '512', host_server['config_attributes']['memory']
183
- assert_equal '1', host_server['volumes_attributes']['0']['size']
184
- end
185
-
186
- it '#container' do
187
- convert_sizes(host_container)
188
- assert_equal '512', host_container['config_attributes']['memory']
189
- assert_equal '1', host_container['volumes_attributes']['0']['size']
190
- end
191
- end
192
-
193
- describe 'convert_memory_size' do
194
- setup { Fog.mock! }
195
- teardown { Fog.unmock! }
196
-
197
- it '#server memory' do
198
- convert_memory_size(host_server['config_attributes'], 'memory')
199
- assert_equal '512', host_server['config_attributes']['memory']
200
- end
201
-
202
- it '#server min_memory nil' do
203
- convert_memory_size(host_server['config_attributes'], 'min_memory')
204
- assert_nil host_server['config_attributes']['min_memory']
205
- end
206
-
207
- it '#container memory' do
208
- convert_memory_size(host_container['config_attributes'], 'memory')
209
- assert_equal '512', host_container['config_attributes']['memory']
210
- end
211
-
212
- it '#container swap empty' do
213
- convert_memory_size(host_container['config_attributes'], 'swap')
214
- assert_empty host_container['config_attributes']['swap']
215
- end
216
- end
217
181
  end
218
182
  end
@@ -33,9 +33,9 @@ module ForemanFogProxmox
33
33
  'id' => 'scsi0',
34
34
  'volid' => 'local-lvm:vm-100-disk',
35
35
  'storage' => 'local-lvm',
36
- 'storage_type' => 'hard_disk'
37
- }
38
- }
36
+ 'storage_type' => 'hard_disk',
37
+ },
38
+ },
39
39
  }
40
40
 
41
41
  it '# server volumes' do
@@ -47,11 +47,11 @@ module ForemanFogProxmox
47
47
  :compute_attributes => {
48
48
  'type' => 'qemu',
49
49
  'config_attributes' => {
50
- 'ostype' => 'l26'
50
+ 'ostype' => 'l26',
51
51
  },
52
52
  'interfaces_attributes' => {
53
- '0' => physical_nic
54
- }
53
+ '0' => physical_nic,
54
+ },
55
55
  }
56
56
  )
57
57
  err = assert_raises Foreman::Exception do
@@ -61,18 +61,19 @@ 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 => { 'dhcp' => '1', 'dhcp6' => '1' })
64
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true,
65
+ :compute_attributes => { 'dhcp' => '1', 'dhcp6' => '1' })
65
66
  host = FactoryBot.build(
66
67
  :host_empty,
67
68
  :interfaces => [physical_nic],
68
69
  :compute_attributes => {
69
70
  'type' => 'lxc',
70
71
  'config_attributes' => {
71
- 'hostname' => ''
72
+ 'hostname' => '',
72
73
  },
73
74
  'interfaces_attributes' => {
74
- '0' => {}
75
- }
75
+ '0' => {},
76
+ },
76
77
  }
77
78
  )
78
79
  @cr.host_compute_attrs(host)
@@ -91,7 +92,9 @@ module ForemanFogProxmox
91
92
  vm_attrs = @cr.vm_compute_attributes(vm)
92
93
  assert_not vm_attrs.key?(:config)
93
94
  assert vm_attrs.key?(:config_attributes)
94
- assert_equal config_attributes.reject { |key, value| excluded_keys.include?(key) || value.to_s.empty? }, vm_attrs[:config_attributes]
95
+ assert_equal config_attributes.reject { |key, value|
96
+ excluded_keys.include?(key) || value.to_s.empty?
97
+ }, vm_attrs[:config_attributes]
95
98
  assert_not vm_attrs[:config_attributes].key?(:disks)
96
99
  assert vm_attrs.key?(:volumes_attributes)
97
100
  assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
@@ -99,8 +102,10 @@ module ForemanFogProxmox
99
102
  assert vm_attrs.key?(:interfaces_attributes)
100
103
  assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
101
104
  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]
105
+ assert_equal interface_attributes[:compute_attributes][:model],
106
+ vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:model]
107
+ assert_equal interface_attributes[:compute_attributes][:bridge],
108
+ vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
104
109
  end
105
110
 
106
111
  it 'converts a container to hash' do
@@ -108,15 +113,19 @@ module ForemanFogProxmox
108
113
  vm_attrs = @cr.vm_compute_attributes(vm)
109
114
  assert_not vm_attrs.key?(:config)
110
115
  assert vm_attrs.key?(:config_attributes)
111
- assert_equal config_attributes.reject { |key, value| excluded_keys.include?(key) || value.to_s.empty? }, vm_attrs[:config_attributes]
116
+ assert_equal config_attributes.reject { |key, value|
117
+ excluded_keys.include?(key) || value.to_s.empty?
118
+ }, vm_attrs[:config_attributes]
112
119
  assert_not vm_attrs[:config_attributes].key?(:disks)
113
120
  assert vm_attrs.key?(:volumes_attributes)
114
121
  assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
115
122
  assert vm_attrs.key?(:interfaces_attributes)
116
123
  assert_equal interface_attributes[:id], vm_attrs[:interfaces_attributes]['0'][:id]
117
- assert_equal interface_attributes[:compute_attributes][:name], vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:name]
124
+ assert_equal interface_attributes[:compute_attributes][:name],
125
+ vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:name]
118
126
  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]
127
+ assert_equal interface_attributes[:compute_attributes][:bridge],
128
+ vm_attrs[:interfaces_attributes]['0'][:compute_attributes][:bridge]
120
129
  end
121
130
  end
122
131
  end