foreman_fog_proxmox 0.12.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -6
  3. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +36 -2
  4. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +134 -60
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +2 -50
  6. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume.js +39 -0
  7. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cdrom.js +63 -0
  8. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_volume_cloudinit.js +25 -0
  9. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
  10. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +23 -25
  11. data/app/helpers/proxmox_compute_controllers_helper.rb +39 -0
  12. data/app/helpers/proxmox_compute_resources_helper.rb +49 -0
  13. data/app/helpers/proxmox_compute_selectors_helper.rb +6 -44
  14. data/app/helpers/proxmox_form_helper.rb +12 -4
  15. data/app/{models/concerns/fog_extensions/proxmox/volume.rb → helpers/proxmox_storages_helper.rb} +5 -8
  16. data/app/helpers/proxmox_vm_cdrom_helper.rb +35 -0
  17. data/app/helpers/proxmox_vm_cloudinit_helper.rb +43 -0
  18. data/app/helpers/proxmox_vm_config_helper.rb +160 -0
  19. data/app/helpers/proxmox_vm_helper.rb +24 -62
  20. data/app/helpers/proxmox_vm_interfaces_helper.rb +85 -0
  21. data/app/helpers/proxmox_vm_os_template_helper.rb +47 -0
  22. data/app/{models/foreman_fog_proxmox/proxmox_token_expiration.rb → helpers/proxmox_vm_uuid_helper.rb} +14 -10
  23. data/app/helpers/proxmox_vm_volumes_helper.rb +105 -0
  24. data/app/models/concerns/fog_extensions/proxmox/disk.rb +17 -2
  25. data/app/models/concerns/fog_extensions/proxmox/interface.rb +19 -4
  26. data/app/models/concerns/fog_extensions/proxmox/server.rb +12 -3
  27. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +8 -30
  28. data/app/models/concerns/host_ext/proxmox/interfaces.rb +7 -2
  29. data/app/models/concerns/orchestration/proxmox/compute.rb +49 -0
  30. data/app/models/foreman_fog_proxmox/proxmox.rb +58 -15
  31. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +14 -18
  32. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +14 -9
  33. data/app/models/foreman_fog_proxmox/proxmox_images.rb +2 -1
  34. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +53 -28
  35. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +1 -1
  36. data/app/models/foreman_fog_proxmox/proxmox_version.rb +7 -2
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +19 -31
  38. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +108 -94
  39. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +9 -6
  40. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +79 -22
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +6 -2
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +1 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +23 -10
  44. data/app/views/compute_resources/show/_proxmox.html.erb +6 -6
  45. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +3 -1
  46. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +46 -29
  47. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +3 -3
  48. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +2 -1
  49. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +8 -7
  50. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +0 -2
  51. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +15 -14
  52. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cdrom.html.erb +34 -0
  54. data/app/views/compute_resources_vms/form/proxmox/server/_volume_cloud_init.html.erb +29 -0
  55. data/app/views/compute_resources_vms/form/proxmox/server/{_volume.html.erb → _volume_hard_disk.html.erb} +7 -3
  56. data/app/views/compute_resources_vms/show/_proxmox.html.erb +2 -0
  57. data/config/routes.rb +7 -7
  58. data/db/migrate/20210312105013_update_proxmox_uuid_host.rb +29 -0
  59. data/lib/foreman_fog_proxmox/engine.rb +15 -10
  60. data/lib/foreman_fog_proxmox/hash_collection.rb +69 -0
  61. data/lib/foreman_fog_proxmox/version.rb +1 -1
  62. data/lib/tasks/foreman_fog_proxmox_tasks.rake +0 -3
  63. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +20 -8
  64. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +5 -5
  65. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +17 -7
  66. data/test/factories/proxmox_factory.rb +4 -4
  67. data/test/functional/compute_resources_controller_test.rb +4 -4
  68. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +53 -32
  69. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +56 -31
  70. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -20
  71. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_uuid_helper_test.rb +38 -0
  72. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_volumes_helper_test.rb +50 -0
  73. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +10 -11
  74. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +38 -10
  75. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +10 -10
  76. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +34 -24
  77. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +8 -8
  78. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cdrom_test.rb +181 -0
  79. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_cloudinit_test.rb +131 -0
  80. 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
  81. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +21 -21
  82. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +3 -3
  83. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +3 -3
  84. metadata +47 -26
  85. data/app/helpers/proxmox_container_helper.rb +0 -163
  86. data/app/helpers/proxmox_server_helper.rb +0 -155
@@ -19,9 +19,8 @@
19
19
 
20
20
  module ForemanFogProxmox
21
21
  module ProxmoxServerMockFactory
22
- def mock_server_vm
23
- interface_attributes = {
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(interface_attributes)
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('pve')
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: 'pve',
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, interface_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/proxmox/models/node'
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 :pve do
41
- identity { 'pve' }
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 :pve_node, :class => Fog::Proxmox::Compute::Node, :traits => [:pve, :service]
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 => 'pve', :storage => 'local' }
24
+ get :isos_by_id_and_node_and_storage, params: { :compute_resource_id => 1, :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 => 'pve', :storage => 'local' }
30
+ get :ostemplates_by_id_and_node_and_storage, params: { :compute_resource_id => 1, :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 => 'pve' }
36
+ get :isos_by_id_and_node, params: { :compute_resource_id => 1, :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 => 'pve' }
42
+ get :ostemplates_by_id_and_node, params: { :compute_resource_id => 1, :node_id => 'proxmox' }
43
43
  assert_response :found
44
44
  show_response = @response.body
45
45
  assert_not show_response.empty?
@@ -21,18 +21,20 @@ 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(:host) do
30
+ let(:type) do
31
+ 'lxc'
32
+ end
33
+
34
+ let(:host_form) do
32
35
  { 'vmid' => '100',
33
- 'name' => 'test',
34
36
  'type' => 'lxc',
35
- 'node_id' => 'pve',
37
+ 'node_id' => 'proxmox',
36
38
  'ostemplate_storage' => 'local',
37
39
  'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
38
40
  'password' => 'proxmox01',
@@ -46,7 +48,7 @@ module ForemanFogProxmox
46
48
  'cpuunits' => '',
47
49
  'arch' => 'amd64',
48
50
  'ostype' => 'debian',
49
- 'hostname' => '',
51
+ 'hostname' => 'toto-tata.pve',
50
52
  'nameserver' => '',
51
53
  'searchdomain' => ''
52
54
 
@@ -56,19 +58,40 @@ module ForemanFogProxmox
56
58
  '1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' }
57
59
  },
58
60
  'interfaces_attributes' => {
59
- '0' => { 'id' => 'net0', 'name' => 'eth0', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp', 'rate' => '', 'gw' => '192.168.56.100', 'gw6' => '2001:0:1234::c1c0:abcd:876' },
60
- '1' => { 'id' => 'net1', 'name' => 'eth1', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp', 'gw' => '192.168.56.100', 'gw6' => '2001:0:1234::c1c0:abcd:876' }
61
+ '0' => {
62
+ 'id' => 'net0',
63
+ 'compute_attributes' => {
64
+ 'name' => 'eth0',
65
+ 'bridge' => 'vmbr0',
66
+ 'ip' => 'dhcp',
67
+ 'ip6' => 'dhcp',
68
+ 'rate' => '',
69
+ 'gw' => '192.168.56.100',
70
+ 'gw6' => '2001:0:1234::c1c0:abcd:876'
71
+ }
72
+ },
73
+ '1' => {
74
+ 'id' => 'net1',
75
+ 'compute_attributes' => {
76
+ 'name' => 'eth1',
77
+ 'bridge' => 'vmbr0',
78
+ 'ip' => 'dhcp',
79
+ 'ip6' => 'dhcp',
80
+ 'gw' => '192.168.56.100',
81
+ 'gw6' => '2001:0:1234::c1c0:abcd:876'
82
+ }
83
+ }
61
84
  } }
62
85
  end
63
86
 
64
87
  let(:container) do
65
88
  { 'vmid' => '100',
66
89
  :vmid => '100',
67
- 'name' => 'test',
90
+ 'hostname' => 'toto-tata.pve',
68
91
  'type' => 'lxc',
69
92
  :type => 'lxc',
70
- 'node_id' => 'pve',
71
- :node_id => 'pve',
93
+ 'node_id' => 'proxmox',
94
+ :node_id => 'proxmox',
72
95
  :memory => 536_870_912,
73
96
  'templated' => 0,
74
97
  :onboot => 0,
@@ -90,13 +113,13 @@ module ForemanFogProxmox
90
113
  { 'vmid' => '100',
91
114
  'name' => 'test',
92
115
  'type' => 'lxc',
93
- 'node_id' => 'pve',
116
+ 'node_id' => 'proxmox',
94
117
  'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' } },
95
118
  'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'name' => 'eth0' } } }
96
119
  end
97
120
 
98
121
  test '#memory' do
99
- memory = parse_container_memory(host['config_attributes'])
122
+ memory = parse_typed_memory(host_form['config_attributes'], type)
100
123
  assert memory.key?(:memory)
101
124
  assert_equal 536_870_912, memory[:memory]
102
125
  assert memory.key?(:swap)
@@ -104,47 +127,45 @@ module ForemanFogProxmox
104
127
  end
105
128
 
106
129
  test '#cpu' do
107
- cpu = parse_container_cpu(host['config_attributes'])
130
+ cpu = parse_typed_cpu(host_form['config_attributes'], type)
108
131
  assert cpu.key?(:cores)
109
- assert_equal 1, cpu[:cores]
132
+ assert_equal '1', cpu[:cores]
110
133
  assert cpu.key?(:arch)
111
134
  assert_equal 'amd64', cpu[:arch]
112
135
  end
113
136
 
114
137
  test '#ostemplate' do
115
- ostemplate = parse_container_ostemplate(host)
138
+ ostemplate = parse_container_ostemplate(host_form)
116
139
  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'
140
+ :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
120
141
  }
121
142
  assert_equal expected_ostemplate, ostemplate
122
143
  end
123
144
 
124
- test '#vm host' do
125
- vm = parse_container_vm(host)
145
+ test '#vm host_form' do
146
+ vm = parse_typed_vm(host_form, type)
126
147
  assert_equal 536_870_912, vm[:memory]
127
148
  assert_equal 'local-lvm:1073741824', vm[:rootfs]
128
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]
129
151
  assert_not vm.key?(:config)
130
152
  assert_not vm.key?(:node)
131
153
  assert_not vm.key?(:type)
132
154
  end
133
155
 
134
156
  test '#vm container' do
135
- vm = parse_container_vm(host)
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
- :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
146
- :ostemplate_file => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
147
- :ostemplate_storage => 'local',
165
+ :cores => '1',
166
+ :arch => 'amd64',
167
+ :ostype => 'debian',
168
+ :hostname => 'toto-tata.pve',
148
169
  :net0 => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
149
170
  :net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp,gw=192.168.56.100,gw6=2001:0:1234::c1c0:abcd:876',
150
171
  :rootfs => 'local-lvm:1073741824',
@@ -154,7 +175,7 @@ module ForemanFogProxmox
154
175
  end
155
176
 
156
177
  test '#volume with rootfs 1Gb' do
157
- volumes = parse_container_volumes(host['volumes_attributes'])
178
+ volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
158
179
  assert_not volumes.empty?
159
180
  assert_equal 2, volumes.size
160
181
  assert rootfs = volumes.first
@@ -168,7 +189,7 @@ module ForemanFogProxmox
168
189
  test '#interface with name eth0 and bridge' do
169
190
  deletes = []
170
191
  nics = []
171
- add_container_interface(host['interfaces_attributes']['0'], deletes, nics)
192
+ add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], deletes, nics, type)
172
193
  assert 1, nics.length
173
194
  assert nics[0].key?(:net0)
174
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]
@@ -177,7 +198,7 @@ module ForemanFogProxmox
177
198
  test '#interface with name eth1 and bridge' do
178
199
  deletes = []
179
200
  nics = []
180
- add_container_interface(host['interfaces_attributes']['1'], deletes, nics)
201
+ add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], deletes, nics, type)
181
202
  assert 1, nics.length
182
203
  assert nics[0].key?(:net1)
183
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]
@@ -186,14 +207,14 @@ module ForemanFogProxmox
186
207
  test '#interface delete net0' do
187
208
  deletes = []
188
209
  nics = []
189
- add_container_interface(host_delete['interfaces_attributes']['0'], deletes, nics)
210
+ add_or_delete_typed_interface(host_delete['interfaces_attributes']['0'], deletes, nics, type)
190
211
  assert_empty nics
191
212
  assert_equal 1, deletes.length
192
213
  assert_equal 'net0', deletes[0]
193
214
  end
194
215
 
195
216
  test '#interfaces' do
196
- interfaces_to_add, interfaces_to_delete = parse_container_interfaces(host['interfaces_attributes'])
217
+ interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(host_form, type)
197
218
  assert_empty interfaces_to_delete
198
219
  assert_equal 2, interfaces_to_add.length
199
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' }
@@ -21,63 +21,89 @@ 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(:host) do
30
+ let(:type) do
31
+ 'qemu'
32
+ end
33
+
34
+ let(:host_form) do
32
35
  { 'vmid' => '100',
33
- 'name' => 'test',
34
- 'node_id' => 'pve',
36
+ 'name' => 'toto-tata.pve',
37
+ 'node_id' => 'proxmox',
35
38
  'type' => 'qemu',
36
39
  'config_attributes' => {
40
+ 'name' => 'toto-tata.pve',
37
41
  'memory' => '536870912',
38
42
  'balloon' => '268435456',
39
43
  'shares' => '5',
40
44
  'cpu_type' => 'kvm64',
41
- 'spectre' => '1',
45
+ 'spectre' => '+1',
42
46
  'pcid' => '0',
43
47
  'cores' => '1',
44
48
  'sockets' => '1'
45
49
  },
46
50
  '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' }
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' }
49
54
  },
50
55
  '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' }
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' } }
53
58
  } }
54
59
  end
55
60
 
56
61
  let(:host_delete) do
57
62
  { 'vmid' => '100',
58
- 'node_id' => 'pve',
63
+ 'node_id' => 'proxmox',
59
64
  'name' => 'test',
60
65
  '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' } } }
66
+ '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' }
69
+ },
70
+ 'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'compute_attributes' => { 'model' => 'virtio' } } } }
65
71
  end
66
72
 
67
73
  test '#memory' do
68
- memory = parse_server_memory(host['config_attributes'])
74
+ memory = parse_typed_memory(host_form['config_attributes'], type)
69
75
  assert memory.key?(:memory)
70
76
  assert_equal 536_870_912, memory[:memory]
71
77
  end
72
78
 
73
79
  test '#cpu' do
74
- cpu = parse_server_cpu(host['config_attributes'])
80
+ cpu = parse_typed_cpu(host_form['config_attributes'], type)
75
81
  assert cpu.key?(:cpu)
76
82
  assert_equal 'cputype=kvm64,flags=+spec-ctrl', cpu[:cpu]
77
83
  end
78
84
 
85
+ test '#cdrom none' do
86
+ cdrom = parse_server_cdrom(host_form['volumes_attributes']['2'])
87
+ assert cdrom.key?(:id)
88
+ assert_equal 'ide2', cdrom[:id]
89
+ assert cdrom.key?(:volid)
90
+ assert_equal 'none', cdrom[:volid]
91
+ assert cdrom.key?(:media)
92
+ assert_equal 'cdrom', cdrom[:media]
93
+ end
94
+
95
+ test '#cdrom image' do
96
+ cdrom = parse_server_cdrom(host_delete['volumes_attributes']['1'])
97
+ assert cdrom.key?(:id)
98
+ assert_equal 'ide2', cdrom[:id]
99
+ assert cdrom.key?(:volid)
100
+ assert_equal 'local-lvm:iso/debian-netinst.iso', cdrom[:volid]
101
+ assert cdrom.key?(:media)
102
+ assert_equal 'cdrom', cdrom[:media]
103
+ end
104
+
79
105
  test '#vm' do
80
- vm = parse_server_vm(host)
106
+ vm = parse_typed_vm(host_form, type)
81
107
  assert_equal '1', vm['cores']
82
108
  assert_equal '1', vm['sockets']
83
109
  assert_equal 'cputype=kvm64,flags=+spec-ctrl', vm[:cpu]
@@ -86,32 +112,31 @@ module ForemanFogProxmox
86
112
  assert_equal 5, vm[:shares]
87
113
  assert_equal 'local-lvm:1073741824,cache=none', vm[:scsi0]
88
114
  assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
115
+ assert_equal 'toto-tata.pve', vm[:name]
89
116
  assert_not vm.key?(:config)
90
117
  assert_not vm.key?(:node)
91
118
  end
92
119
 
93
120
  test '#volume with scsi 1Gb' do
94
- volumes = parse_server_volumes(host['volumes_attributes'])
121
+ volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
95
122
  assert_not volumes.empty?
96
- assert volumes.size, 2
97
- assert volume = volumes.first
98
- assert volume.key?(:scsi0)
99
- assert_equal 'local-lvm:1073741824,cache=none', volume[:scsi0]
123
+ assert volumes.size, 3
124
+ scsi0 = (volumes.select { |volume| volume.key?(:scsi0) }).first
125
+ assert_equal 'local-lvm:1073741824,cache=none', scsi0[:scsi0]
100
126
  end
101
127
 
102
128
  test '#volume with virtio 1Gb' do
103
- volumes = parse_server_volumes(host['volumes_attributes'])
129
+ volumes = parse_typed_volumes(host_form['volumes_attributes'], type)
104
130
  assert_not volumes.empty?
105
- assert volumes.size, 2
106
- assert volume = volumes[1]
107
- assert volume.key?(:virtio0)
108
- assert_equal 'local-lvm:1073741824,cache=none', volume[:virtio0]
131
+ assert volumes.size, 3
132
+ virtio0 = (volumes.select { |volume| volume.key?(:virtio0) }).first
133
+ assert_equal 'local-lvm:1073741824,cache=none', virtio0[:virtio0]
109
134
  end
110
135
 
111
136
  test '#interface with model virtio and bridge' do
112
137
  interfaces_to_delete = []
113
138
  interfaces_to_add = []
114
- add_server_interface(host['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add)
139
+ add_or_delete_typed_interface(host_form['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add, type)
115
140
  assert_empty interfaces_to_delete
116
141
  assert_equal 1, interfaces_to_add.length
117
142
  assert interfaces_to_add[0].key?(:net0)
@@ -121,7 +146,7 @@ module ForemanFogProxmox
121
146
  test '#interface with model e1000 and bridge' do
122
147
  interfaces_to_delete = []
123
148
  interfaces_to_add = []
124
- add_server_interface(host['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add)
149
+ add_or_delete_typed_interface(host_form['interfaces_attributes']['1'], interfaces_to_delete, interfaces_to_add, type)
125
150
  assert_empty interfaces_to_delete
126
151
  assert_equal 1, interfaces_to_add.length
127
152
  assert interfaces_to_add[0].key?(:net1)
@@ -131,14 +156,14 @@ module ForemanFogProxmox
131
156
  test '#interface delete net0' do
132
157
  interfaces_to_delete = []
133
158
  interfaces_to_add = []
134
- add_server_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add)
159
+ add_or_delete_typed_interface(host_delete['interfaces_attributes']['0'], interfaces_to_delete, interfaces_to_add, type)
135
160
  assert_empty interfaces_to_add
136
161
  assert_equal 1, interfaces_to_delete.length
137
162
  assert_equal 'net0', interfaces_to_delete[0]
138
163
  end
139
164
 
140
165
  test '#interfaces' do
141
- interfaces_to_add, interfaces_to_delete = parse_server_interfaces(host['interfaces_attributes'])
166
+ interfaces_to_add, interfaces_to_delete = parse_typed_interfaces(host_form, type)
142
167
  assert_empty interfaces_to_delete
143
168
  assert_equal 2, interfaces_to_add.length
144
169
  assert_includes interfaces_to_add, { net0: 'model=virtio,bridge=vmbr0,firewall=0,link_down=0' }