foreman_fog_proxmox 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -39,7 +39,8 @@ module ForemanFogProxmox
39
39
 
40
40
  it 'raises Foreman::Exception when server proxmox NIC id does not match net[k] with k integer' do
41
41
  compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'dsfqsfqzef' })
42
- physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0', :compute_attributes => compute_attributes)
42
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0',
43
+ :compute_attributes => compute_attributes)
43
44
  host = FactoryBot.build(
44
45
  :host_empty,
45
46
  :interfaces => [physical_nic],
@@ -56,7 +57,8 @@ module ForemanFogProxmox
56
57
  mac_address = '36:25:8c:53:0c:50'
57
58
  ip6 = Array.new(4) { format('%<x>s', x: rand(16**4)) }.join(':') + '::1'
58
59
  compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0' })
59
- physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :mac => mac_address, :compute_attributes => compute_attributes)
60
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
61
+ :mac => mac_address, :compute_attributes => compute_attributes)
60
62
  host = FactoryBot.build(
61
63
  :host_empty,
62
64
  :interfaces => [physical_nic],
@@ -72,7 +74,8 @@ module ForemanFogProxmox
72
74
 
73
75
  it 'raises Foreman::Exception when container proxmox NIC id does not match net[k] with k integer' do
74
76
  compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'dsfqsfqzef' })
75
- physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0', :compute_attributes => compute_attributes)
77
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0',
78
+ :compute_attributes => compute_attributes)
76
79
  host = FactoryBot.build(
77
80
  :host_empty,
78
81
  :interfaces => [physical_nic],
@@ -88,8 +91,10 @@ module ForemanFogProxmox
88
91
  ip = '192.168.56.100'
89
92
  cidr = '31'
90
93
  ip6 = Array.new(4) { format('%<x>s', x: rand(16**4)) }.join(':') + '::1'
91
- compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'cidr' => cidr, 'gw' => ip, 'ip' => ip, 'dhcp6' => '1' })
92
- physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :compute_attributes => compute_attributes)
94
+ compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'cidr' => cidr, 'gw' => ip,
95
+ 'ip' => ip, 'dhcp6' => '1' })
96
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
97
+ :compute_attributes => compute_attributes)
93
98
  host = FactoryBot.build(
94
99
  :host_empty,
95
100
  :interfaces => [physical_nic],
@@ -107,8 +112,10 @@ module ForemanFogProxmox
107
112
  ip = '192.168.56.100'
108
113
  cidr6 = '100'
109
114
  ip6 = '2001:0:1234::c1c0:abcd:876'
110
- compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'cidr6' => cidr6, 'dhcp' => '1', 'gw6' => ip6 })
111
- physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :compute_attributes => compute_attributes)
115
+ compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'cidr6' => cidr6,
116
+ 'dhcp' => '1', 'gw6' => ip6 })
117
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
118
+ :compute_attributes => compute_attributes)
112
119
  host = FactoryBot.build(
113
120
  :host_empty,
114
121
  :interfaces => [physical_nic],
@@ -127,8 +134,10 @@ module ForemanFogProxmox
127
134
  mac_address = '36:25:8c:53:0c:50'
128
135
  ip6 = '2001:0:1234::c1c0:abcd:876'
129
136
  firewall = '1'
130
- compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'dhcp' => '1', 'ip6' => ip6, 'firewall' => firewall })
131
- physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6, :mac => mac_address, :compute_attributes => compute_attributes)
137
+ compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'dhcp' => '1',
138
+ 'ip6' => ip6, 'firewall' => firewall })
139
+ physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
140
+ :mac => mac_address, :compute_attributes => compute_attributes)
132
141
  host = FactoryBot.build(
133
142
  :host_empty,
134
143
  :interfaces => [physical_nic],
@@ -46,8 +46,10 @@ module ForemanFogProxmox
46
46
  vm.stubs(:node_id).returns('proxmox')
47
47
  vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc')
48
48
  @cr.stubs(:find_vm_by_uuid).returns(vm)
49
- attr = { 'templated' => '0', 'node_id' => 'proxmox', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
50
- @cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox2', 'type' => 'lxc', 'cores' => '1', 'cpulimit' => '1')
49
+ attr = { 'templated' => '0', 'node_id' => 'proxmox',
50
+ 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
51
+ @cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox2', 'type' => 'lxc',
52
+ 'cores' => '1', 'cpulimit' => '1')
51
53
  expected_attr = { :cores => '1', :cpulimit => '1' }
52
54
  vm.expects(:update, expected_attr)
53
55
  @cr.save_vm(uuid, attr)
@@ -64,8 +66,10 @@ module ForemanFogProxmox
64
66
  vm.stubs(:node_id).returns('proxmox')
65
67
  vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc')
66
68
  @cr.stubs(:find_vm_by_uuid).returns(vm)
67
- attr = { 'templated' => '0', 'node_id' => 'proxmox', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
68
- @cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'lxc', 'cores' => '1', 'cpulimit' => '1')
69
+ attr = { 'templated' => '0', 'node_id' => 'proxmox',
70
+ 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0' } }.with_indifferent_access
71
+ @cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'lxc',
72
+ 'cores' => '1', 'cpulimit' => '1')
69
73
  expected_attr = { :cores => '1', :cpulimit => '1' }
70
74
  vm.expects(:update, expected_attr)
71
75
  @cr.save_vm(uuid, attr)
@@ -76,7 +80,9 @@ module ForemanFogProxmox
76
80
  config = mock('config')
77
81
  disks = mock('disks')
78
82
  disk = mock('disk')
79
- disk.stubs(:size).returns(1_073_741_824)
83
+ disk.stubs(:size).returns('1')
84
+ disk.stubs(:hard_disk?).returns(true)
85
+ disk.stubs(:cdrom?).returns(false)
80
86
  disk.stubs(:storage).returns('local-lvm')
81
87
  disk.stubs(:id).returns('mp0')
82
88
  disks.stubs(:get).returns
@@ -95,7 +101,7 @@ module ForemanFogProxmox
95
101
  'node_id' => 'proxmox',
96
102
  'config_attributes' => {
97
103
  'cores' => '1',
98
- 'cpulimit' => '1'
104
+ 'cpulimit' => '1',
99
105
  },
100
106
  'volumes_attributes' => {
101
107
  '0' => {
@@ -103,24 +109,25 @@ module ForemanFogProxmox
103
109
  '_delete' => '',
104
110
  'device' => '0',
105
111
  'storage' => 'local-lvm',
106
- 'size' => '2147483648',
112
+ 'size' => '2',
107
113
  'cache' => 'none',
108
- 'mp' => '/opt/path'
109
- }
110
- }
114
+ 'mp' => '/opt/path',
115
+ },
116
+ },
111
117
  }.with_indifferent_access
112
- @cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'lxc', 'cores' => '1', 'cpulimit' => '1')
118
+ @cr.stubs(:parse_container_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'lxc',
119
+ 'cores' => '1', 'cpulimit' => '1')
113
120
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
114
121
  expected_volume_attr =
115
122
  [
116
123
  {
117
124
  id: 'mp0',
118
125
  storage: 'local:lvm',
119
- size: (2_147_483_648 / GIGA).to_s
126
+ size: '2',
120
127
  },
121
128
  {
122
- mp: '/opt/path'
123
- }
129
+ mp: '/opt/path',
130
+ },
124
131
  ]
125
132
  vm.expects(:attach, expected_volume_attr)
126
133
  vm.expects(:update, expected_config_attr)
@@ -132,10 +139,13 @@ module ForemanFogProxmox
132
139
  config = mock('config')
133
140
  disks = mock('disks')
134
141
  disk = mock('disk')
135
- disk.stubs(:size).returns(1_073_741_824)
142
+ disk.stubs(:size).returns('1')
143
+ disk.stubs(:hard_disk?).returns(true)
144
+ disk.stubs(:cdrom?).returns(false)
136
145
  disk.stubs(:storage).returns('local-lvm')
146
+ disk.stubs(:volid).returns('local-lvm:vm-100-disk-0')
137
147
  disk.stubs(:id).returns('rootfs')
138
- disk.stubs(:attributes).returns(id: 'rootfs', storage: 'local-lvm', size: 1_073_741_824)
148
+ disk.stubs(:attributes).returns(id: 'rootfs', storage: 'local-lvm', size: '1')
139
149
  disks.stubs(:get).returns(disk)
140
150
  config.stubs(:disks).returns(disks)
141
151
  config.stubs(:attributes).returns(:cores => '')
@@ -145,7 +155,7 @@ module ForemanFogProxmox
145
155
  vm.stubs(:container?).returns(true)
146
156
  vm.stubs(:type).returns('lxc')
147
157
  vm.stubs(:node_id).returns('proxmox')
148
- vm.stubs(:attributes).returns(node_id: 'proxmox', type: 'lxc', 'rootfs' => '')
158
+ vm.stubs(:attributes).returns(:node_id => 'proxmox', :type => 'lxc', 'rootfs' => '')
149
159
  @cr.stubs(:find_vm_by_uuid).returns(vm)
150
160
  new_attributes =
151
161
  {
@@ -154,19 +164,19 @@ module ForemanFogProxmox
154
164
  'config_attributes' => {
155
165
  'cores' => '1',
156
166
  'cpulimit' => '1',
157
- 'onboot' => '0'
167
+ 'onboot' => '0',
158
168
  },
159
169
  'volumes_attributes' => {
160
170
  '0' => {
161
171
  'id' => 'rootfs',
162
172
  '_delete' => '',
163
- 'volid' => 'local-lvm:1073741824',
173
+ 'volid' => 'local-lvm:vm-100-disk-0',
164
174
  'device' => '0',
165
175
  'storage' => 'local-lvm',
166
- 'size' => '2147483648',
167
- 'cache' => 'none'
168
- }
169
- }
176
+ 'size' => '2',
177
+ 'cache' => 'none',
178
+ },
179
+ },
170
180
  }.with_indifferent_access
171
181
  @cr.stubs(:parse_container_vm).returns(
172
182
  'vmid' => '100',
@@ -188,11 +198,13 @@ module ForemanFogProxmox
188
198
  disks = mock('disks')
189
199
  disk = mock('disk')
190
200
  disk.stubs(:rootfs?).returns(false)
201
+ disk.stubs(:hard_disk?).returns(true)
202
+ disk.stubs(:cdrom?).returns(false)
191
203
  disk.stubs(:volid).returns('local-lvm:vm-100-disk-0')
192
204
  disk.stubs(:id).returns('mp0')
193
- disk.stubs(:size).returns(1_073_741_824)
205
+ disk.stubs(:size).returns('1')
194
206
  disk.stubs(:storage).returns('local-lvm')
195
- disk.stubs(:attributes).returns(id: 'mp0', storage: 'local-lvm', size: 1_073_741_824, volid: 'local-lvm:vm-100-disk-0')
207
+ disk.stubs(:attributes).returns(id: 'mp0', storage: 'local-lvm', size: '1', volid: 'local-lvm:vm-100-disk-0')
196
208
  disks.stubs(:get).returns(disk)
197
209
  config.stubs(:disks).returns(disks)
198
210
  config.stubs(:attributes).returns(:cores => '')
@@ -209,7 +221,7 @@ module ForemanFogProxmox
209
221
  'node_id' => 'proxmox',
210
222
  'config_attributes' => {
211
223
  'cores' => '1',
212
- 'cpulimit' => '1'
224
+ 'cpulimit' => '1',
213
225
  },
214
226
  'volumes_attributes' => {
215
227
  '0' => {
@@ -219,14 +231,15 @@ module ForemanFogProxmox
219
231
  'device' => '0',
220
232
  'controller' => 'mp',
221
233
  'storage' => 'local-lvm',
222
- 'size' => '1073741824',
223
- 'mp' => '/opt/toto'
224
- }
225
- }
234
+ 'size' => '1',
235
+ 'mp' => '/opt/toto',
236
+ },
237
+ },
226
238
  }.with_indifferent_access
227
- @cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
239
+ @cr.stubs(:parse_typed_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1',
240
+ 'cpulimit' => '1')
228
241
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
229
- expected_volume_attr = { :id => 'mp0', :volid => 'local-lvm:vm-100-disk-0', :size => 1_073_741_824 }, { :mp => '/opt/toto' }
242
+ expected_volume_attr = { :id => 'mp0', :volid => 'local-lvm:vm-100-disk-0', :size => '1' }, { :mp => '/opt/toto' }
230
243
  vm.expects(:attach, expected_volume_attr)
231
244
  vm.expects(:update, expected_config_attr)
232
245
  @cr.save_vm(uuid, new_attributes)
@@ -241,7 +254,6 @@ module ForemanFogProxmox
241
254
  containers = mock('containers')
242
255
  containers.stubs(:create).with(args)
243
256
  cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
244
- cr.stubs(:convert_sizes).with(args)
245
257
  cr.stubs(:parse_typed_vm).with(args, 'lxc').returns(args)
246
258
  vm = mock('vm')
247
259
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
@@ -256,7 +268,6 @@ module ForemanFogProxmox
256
268
  vm = mock('vm')
257
269
  containers.stubs(:create).with(args).returns(vm)
258
270
  cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
259
- cr.stubs(:convert_sizes).with(args)
260
271
  cr.stubs(:parse_typed_vm).with(args, 'lxc').returns(args)
261
272
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
262
273
  cr.stubs(:start_on_boot).with(vm, args).returns(vm)
@@ -271,7 +282,6 @@ module ForemanFogProxmox
271
282
  vm = mock('vm')
272
283
  containers.stubs(:create).with(args).returns(vm)
273
284
  cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, servers, containers)
274
- cr.stubs(:convert_sizes).with(args)
275
285
  cr.stubs(:parse_typed_vm).with(args, 'lxc').returns(args)
276
286
  cr.stubs(:find_vm_by_uuid).with((args[:vmid]).to_s).returns(vm)
277
287
  cr.create_vm(args)
@@ -48,7 +48,6 @@ module ForemanFogProxmox
48
48
  servers.stubs(:id_valid?).returns(true)
49
49
  servers.stubs(:next_id).returns('101')
50
50
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
51
- cr.stubs(:convert_sizes).with(args)
52
51
  cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
53
52
  servers.stubs(:create).with(args)
54
53
  vm = mock('vm')
@@ -61,7 +60,6 @@ module ForemanFogProxmox
61
60
  servers = mock('servers')
62
61
  servers.stubs(:id_valid?).returns(true)
63
62
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
64
- cr.stubs(:convert_sizes).with(args)
65
63
  cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
66
64
  servers.stubs(:create).with(args)
67
65
  vm = mock('vm')
@@ -74,7 +72,6 @@ module ForemanFogProxmox
74
72
  servers = mock('servers')
75
73
  servers.stubs(:id_valid?).returns(true)
76
74
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
77
- cr.stubs(:convert_sizes).with(args)
78
75
  cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
79
76
  vm = mock('vm')
80
77
  servers.stubs(:create).with(args).returns(vm)
@@ -88,7 +85,6 @@ module ForemanFogProxmox
88
85
  servers = mock('servers')
89
86
  servers.stubs(:id_valid?).returns(true)
90
87
  cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers)
91
- cr.stubs(:convert_sizes).with(args)
92
88
  cr.stubs(:parse_typed_vm).with(args, 'qemu').returns(args)
93
89
  vm = mock('vm')
94
90
  servers.stubs(:create).with(args).returns(vm)
@@ -24,7 +24,7 @@ require 'factories/foreman_fog_proxmox/proxmox_server_mock_factory'
24
24
  require 'active_support/core_ext/hash/indifferent_access'
25
25
 
26
26
  module ForemanFogProxmox
27
- class ProxmoxVmCommandsServerUpdateTest < ActiveSupport::TestCase
27
+ class ProxmoxVmCommandsServerUpdateCdromTest < ActiveSupport::TestCase
28
28
  include ComputeResourceTestHelpers
29
29
  include ProxmoxNodeMockFactory
30
30
  include ProxmoxServerMockFactory
@@ -42,6 +42,8 @@ module ForemanFogProxmox
42
42
  disk = mock('disk')
43
43
  disk.stubs(:storage).returns('local-lvm')
44
44
  disk.stubs(:id).returns('ide2')
45
+ disk.stubs(:hard_disk?).returns(false)
46
+ disk.stubs(:cdrom?).returns(true)
45
47
  disks.stubs(:get).returns
46
48
  config.stubs(:disks).returns(disks)
47
49
  config.stubs(:attributes).returns(:cores => '')
@@ -58,7 +60,7 @@ module ForemanFogProxmox
58
60
  'node_id' => 'proxmox',
59
61
  'config_attributes' => {
60
62
  'cores' => '1',
61
- 'cpulimit' => '1'
63
+ 'cpulimit' => '1',
62
64
  },
63
65
  'volumes_attributes' => {
64
66
  '0' => {
@@ -69,13 +71,15 @@ module ForemanFogProxmox
69
71
  'storage_type' => 'cdrom',
70
72
  'storage' => 'local-lvm',
71
73
  'cdrom' => 'image',
72
- 'volid' => 'local-lvm:iso/ubuntu-20_4.iso'
73
- }
74
- }
74
+ 'volid' => 'local-lvm:iso/ubuntu-20_4.iso',
75
+ },
76
+ },
75
77
  }.with_indifferent_access
76
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
78
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1',
79
+ 'cpulimit' => '1', 'onboot' => '0')
77
80
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
78
- expected_volume_attr = { id: 'ide2', storage: 'local:lvm', volid: 'local-lvm:iso/ubuntu-20_4.iso', media: 'cdrom' }
81
+ expected_volume_attr = { id: 'ide2', storage: 'local:lvm', volid: 'local-lvm:iso/ubuntu-20_4.iso',
82
+ media: 'cdrom' }
79
83
  vm.expects(:attach, expected_volume_attr)
80
84
  vm.expects(:update, expected_config_attr)
81
85
  @cr.save_vm(uuid, new_attributes)
@@ -86,17 +90,19 @@ module ForemanFogProxmox
86
90
  config = mock('config')
87
91
  disks = mock('disks')
88
92
  disk = mock('disk')
89
- disk.stubs(:size).returns(1_073_741_824)
93
+ disk.stubs(:size).returns('1')
94
+ disk.stubs(:hard_disk?).returns(false)
95
+ disk.stubs(:cdrom?).returns(true)
96
+ disk.stubs(:cloud_init?).returns(false)
90
97
  disk.stubs(:storage).returns('local-lvm')
91
98
  disk.stubs(:volid).returns('local-lvm:iso/ubuntu-20_4.iso')
92
99
  disk.stubs(:media).returns('cdrom')
93
100
  disk.stubs(:id).returns('ide2')
94
101
  disks.stubs(:get).returns(disk)
95
102
  config.stubs(:disks).returns(disks)
96
- config.stubs(:attributes).returns(:cores => '')
103
+ config.stubs(:attributes).returns(:cores => '1', :cpulimit => '1')
97
104
  vm = mock('vm')
98
105
  vm.stubs(:identity).returns(uuid)
99
- vm.stubs(:attributes).returns('ide2' => '')
100
106
  vm.stubs(:config).returns(config)
101
107
  vm.stubs(:container?).returns(false)
102
108
  vm.stubs(:templated?).returns(false)
@@ -108,7 +114,7 @@ module ForemanFogProxmox
108
114
  'node_id' => 'proxmox',
109
115
  'config_attributes' => {
110
116
  'cores' => '1',
111
- 'cpulimit' => '1'
117
+ 'cpulimit' => '1',
112
118
  },
113
119
  'volumes_attributes' => {
114
120
  '0' => {
@@ -117,11 +123,13 @@ module ForemanFogProxmox
117
123
  'device' => '2',
118
124
  'controller' => 'ide',
119
125
  'storage_type' => 'cdrom',
120
- 'cdrom' => 'none'
121
- }
122
- }
126
+ 'cdrom' => 'none',
127
+ 'volid' => '',
128
+ },
129
+ },
123
130
  }.with_indifferent_access
124
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
131
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1',
132
+ 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
125
133
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
126
134
  expected_volume_attr = 'ide2'
127
135
  vm.expects(:detach, expected_volume_attr)
@@ -134,12 +142,15 @@ module ForemanFogProxmox
134
142
  config = mock('config')
135
143
  disks = mock('disks')
136
144
  disk = mock('disk')
137
- disk.stubs(:size).returns(1_073_741_824)
145
+ disk.stubs(:size).returns('1')
146
+ disk.stubs(:hard_disk?).returns(false)
147
+ disk.stubs(:cdrom?).returns(true)
148
+ disk.stubs(:cloud_init?).returns(false)
138
149
  disk.stubs(:storage).returns('local-lvm')
139
150
  disk.stubs(:volid).returns('local-lvm:iso/ubuntu-20_4.iso')
140
151
  disk.stubs(:media).returns('cdrom')
141
152
  disk.stubs(:id).returns('ide2')
142
- disk.stubs(:attributes).returns(id: 'ide2', storage: 'local-lvm', volid: 'local-lvm:vm-100-disk-0', size: 1_073_741_824)
153
+ disk.stubs(:attributes).returns(id: 'ide2', storage: 'local-lvm', volid: 'local-lvm:vm-100-disk-0', size: '1')
143
154
  disks.stubs(:get).returns(disk)
144
155
  config.stubs(:disks).returns(disks)
145
156
  config.stubs(:attributes).returns(:cores => '')
@@ -156,7 +167,7 @@ module ForemanFogProxmox
156
167
  'node_id' => 'proxmox',
157
168
  'config_attributes' => {
158
169
  'cores' => '1',
159
- 'cpulimit' => '1'
170
+ 'cpulimit' => '1',
160
171
  },
161
172
  'volumes_attributes' => {
162
173
  '0' => {
@@ -165,11 +176,12 @@ module ForemanFogProxmox
165
176
  'device' => '2',
166
177
  'controller' => 'ide',
167
178
  'storage_type' => 'cdrom',
168
- 'cdrom' => 'cdrom'
169
- }
170
- }
179
+ 'cdrom' => 'cdrom',
180
+ },
181
+ },
171
182
  }.with_indifferent_access
172
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1')
183
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1',
184
+ 'cpulimit' => '1')
173
185
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
174
186
  expected_volume_attr = { :id => 'ide2', :cdrom => 'cdrom' }
175
187
  vm.expects(:attach, expected_volume_attr)
@@ -24,7 +24,7 @@ require 'factories/foreman_fog_proxmox/proxmox_server_mock_factory'
24
24
  require 'active_support/core_ext/hash/indifferent_access'
25
25
 
26
26
  module ForemanFogProxmox
27
- class ProxmoxVmCommandsServerUpdateTest < ActiveSupport::TestCase
27
+ class ProxmoxVmCommandsServerUpdateCloudinitTest < ActiveSupport::TestCase
28
28
  include ComputeResourceTestHelpers
29
29
  include ProxmoxNodeMockFactory
30
30
  include ProxmoxServerMockFactory
@@ -58,7 +58,7 @@ module ForemanFogProxmox
58
58
  'node_id' => 'proxmox',
59
59
  'config_attributes' => {
60
60
  'cores' => '1',
61
- 'cpulimit' => '1'
61
+ 'cpulimit' => '1',
62
62
  },
63
63
  'volumes_attributes' => {
64
64
  '0' => {
@@ -68,11 +68,12 @@ module ForemanFogProxmox
68
68
  'controller' => 'ide',
69
69
  'storage_type' => 'cloud_init',
70
70
  'storage' => 'local-lvm',
71
- 'volid' => 'local-lvm:cloudinit'
72
- }
73
- }
71
+ 'volid' => 'local-lvm:cloudinit',
72
+ },
73
+ },
74
74
  }.with_indifferent_access
75
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'onboot' => '0')
75
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1',
76
+ 'cpulimit' => '1', 'onboot' => '0')
76
77
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
77
78
  expected_volume_attr = { id: 'ide0', storage: 'local:lvm', volid: 'local-lvm:cloudinit', media: 'cdrom' }
78
79
  vm.expects(:attach, expected_volume_attr)
@@ -80,19 +81,22 @@ module ForemanFogProxmox
80
81
  @cr.save_vm(uuid, new_attributes)
81
82
  end
82
83
 
83
- it 'saves modified server config with removed cdrom' do
84
+ it 'saves modified server config with removed cloudinit' do
84
85
  uuid = '100'
85
86
  config = mock('config')
86
87
  disks = mock('disks')
87
88
  disk = mock('disk')
88
- disk.stubs(:size).returns(1_073_741_824)
89
+ disk.stubs(:size).returns('1')
89
90
  disk.stubs(:storage).returns('local-lvm')
90
91
  disk.stubs(:volid).returns('local-lvm:vm-100-cloudinit')
91
92
  disk.stubs(:media).returns('cdrom')
92
93
  disk.stubs(:id).returns('ide0')
94
+ disk.stubs(:hard_disk?).returns(false)
95
+ disk.stubs(:cdrom?).returns(false)
96
+ disk.stubs(:cloud_init?).returns(true)
93
97
  disks.stubs(:get).returns(disk)
94
98
  config.stubs(:disks).returns(disks)
95
- config.stubs(:attributes).returns(:cores => '')
99
+ config.stubs(:attributes).returns(:cores => '1')
96
100
  vm = mock('vm')
97
101
  vm.stubs(:identity).returns(uuid)
98
102
  vm.stubs(:attributes).returns('ide0' => '')
@@ -107,7 +111,7 @@ module ForemanFogProxmox
107
111
  'node_id' => 'proxmox',
108
112
  'config_attributes' => {
109
113
  'cores' => '1',
110
- 'cpulimit' => '1'
114
+ 'cpulimit' => '1',
111
115
  },
112
116
  'volumes_attributes' => {
113
117
  '0' => {
@@ -115,11 +119,13 @@ module ForemanFogProxmox
115
119
  '_delete' => '1',
116
120
  'device' => '0',
117
121
  'controller' => 'ide',
118
- 'storage_type' => 'cloud_init'
119
- }
120
- }
122
+ 'storage_type' => 'cloud_init',
123
+ 'volid' => 'local-lvm:vm-100-cloudinit',
124
+ },
125
+ },
121
126
  }.with_indifferent_access
122
- @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
127
+ @cr.stubs(:parse_server_vm).returns('vmid' => '100', 'node_id' => 'proxmox', 'type' => 'qemu', 'cores' => '1',
128
+ 'cpulimit' => '1', 'config_attributes' => { 'onboot' => '0' })
123
129
  expected_config_attr = { :cores => '1', :cpulimit => '1' }
124
130
  expected_volume_attr = 'ide0'
125
131
  vm.expects(:detach, expected_volume_attr)