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.

Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -1
  3. data/Rakefile +3 -1
  4. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +2 -2
  5. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +2 -2
  6. data/app/helpers/node_dashboard_helper.rb +13 -14
  7. data/app/helpers/proxmox_compute_selectors_helper.rb +49 -50
  8. data/app/helpers/proxmox_container_helper.rb +42 -36
  9. data/app/helpers/proxmox_form_helper.rb +38 -40
  10. data/app/helpers/proxmox_server_helper.rb +39 -41
  11. data/app/helpers/proxmox_vm_helper.rb +21 -25
  12. data/app/models/concerns/fog_extensions/proxmox/disk.rb +8 -8
  13. data/app/models/concerns/fog_extensions/proxmox/interface.rb +8 -8
  14. data/app/models/concerns/fog_extensions/proxmox/node.rb +24 -22
  15. data/app/models/concerns/fog_extensions/proxmox/server.rb +71 -59
  16. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +47 -39
  17. data/app/models/concerns/fog_extensions/proxmox/volume.rb +8 -8
  18. data/app/models/concerns/host_ext/proxmox/interfaces.rb +21 -13
  19. data/app/models/concerns/orchestration/proxmox/compute.rb +14 -10
  20. data/app/models/foreman_fog_proxmox/options_select.rb +14 -14
  21. data/app/models/foreman_fog_proxmox/proxmox.rb +30 -466
  22. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +54 -0
  23. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
  24. data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
  25. data/app/models/foreman_fog_proxmox/proxmox_images.rb +53 -0
  26. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +60 -0
  27. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
  28. data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
  29. data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
  30. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +108 -0
  31. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +162 -0
  32. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +74 -0
  33. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +85 -0
  34. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +7 -6
  35. data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +13 -11
  36. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +13 -11
  37. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +8 -7
  38. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +7 -6
  39. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +7 -6
  40. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +7 -6
  41. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +16 -16
  42. data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -1
  43. data/app/views/compute_resources/form/_proxmox.html.erb +3 -0
  44. data/app/views/compute_resources/show/_proxmox.html.erb +8 -0
  45. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +5 -0
  46. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +6 -1
  47. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +6 -0
  48. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +6 -2
  49. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +8 -2
  50. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +6 -0
  51. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +15 -1
  52. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +2 -2
  53. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
  54. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +6 -1
  55. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +1 -1
  56. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +1 -1
  57. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +1 -1
  58. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +2 -2
  59. data/config/routes.rb +4 -4
  60. data/lib/foreman_fog_proxmox/engine.rb +14 -14
  61. data/lib/foreman_fog_proxmox/semver.rb +78 -78
  62. data/lib/foreman_fog_proxmox/value.rb +5 -3
  63. data/lib/foreman_fog_proxmox/version.rb +1 -1
  64. data/lib/tasks/foreman_fog_proxmox_tasks.rake +3 -13
  65. data/locale/en/foreman_fog_proxmox.edit.po +472 -0
  66. data/locale/en/foreman_fog_proxmox.po +48 -24
  67. data/locale/en/foreman_fog_proxmox.po.time_stamp +0 -0
  68. data/locale/foreman_fog_proxmox.pot +140 -102
  69. data/locale/fr/foreman_fog_proxmox.edit.po +472 -0
  70. data/locale/fr/foreman_fog_proxmox.po +52 -28
  71. data/locale/fr/foreman_fog_proxmox.po.time_stamp +0 -0
  72. data/locale/gemspec.rb +2 -0
  73. data/test/{unit/foreman_fog_proxmox/proxmox_test_helpers.rb → factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb} +4 -140
  74. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +61 -0
  75. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
  76. data/test/factories/proxmox_factory.rb +15 -15
  77. data/test/functional/compute_resources_controller_test.rb +12 -10
  78. data/test/test_plugin_helper.rb +2 -0
  79. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +178 -182
  80. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +122 -126
  81. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +180 -187
  82. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +116 -0
  83. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +71 -0
  84. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +9 -479
  85. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +82 -0
  86. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +207 -0
  87. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +92 -0
  88. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +324 -0
  89. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
  90. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
  91. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +63 -0
  92. data/test/unit/foreman_fog_proxmox/semver_test.rb +67 -53
  93. metadata +52 -14
@@ -20,29 +20,29 @@
20
20
  require 'fog/compute/proxmox/models/node'
21
21
 
22
22
  FactoryBot.define do
23
-
24
23
  factory :proxmox_resource, :class => ComputeResource do
25
24
  sequence(:name) { |n| "compute_resource#{n}" }
25
+ organizations { [Organization.find_by(name: 'Organization 1')] }
26
+ locations { [Location.find_by(name: 'Location 1')] }
26
27
 
27
28
  trait :proxmox do
28
- provider 'Proxmox'
29
- user 'root@pam'
30
- password 'proxmox01'
31
- url 'https://192.168.56.101:8006/api2/json'
32
- node_id 'pve'
29
+ provider { 'Proxmox' }
30
+ user { 'root@pam' }
31
+ password { 'proxmox01' }
32
+ url { 'https://192.168.56.101:8006/api2/json' }
33
+ node_id { 'pve' }
33
34
  end
34
35
 
35
36
  factory :proxmox_cr, :class => ForemanFogProxmox::Proxmox, :traits => [:proxmox]
36
-
37
37
  end
38
38
 
39
39
  factory :node, :class => Fog::Proxmox::Compute::Node do
40
40
  sequence(:identity) { |n| "node#{n}" }
41
41
  trait :pve do
42
- identity 'pve'
42
+ identity { 'pve' }
43
43
  end
44
44
  trait :service do
45
- service :proxmox_cr
45
+ service { :proxmox_cr }
46
46
  end
47
47
  factory :pve_node, :class => Fog::Proxmox::Compute::Node, :traits => [:pve, :service]
48
48
  end
@@ -50,22 +50,23 @@ FactoryBot.define do
50
50
  def deferred_nic_attrs
51
51
  [:ip, :ip6, :mac, :subnet, :domain]
52
52
  end
53
-
53
+
54
54
  def set_nic_attributes(host, attributes, evaluator)
55
55
  attributes.each do |nic_attribute|
56
- next unless evaluator.send(nic_attribute).present?
56
+ next if evaluator.send(nic_attribute).blank?
57
+
57
58
  host.primary_interface.send(:"#{nic_attribute}=", evaluator.send(nic_attribute))
58
59
  end
59
60
  host
60
61
  end
61
62
 
62
63
  factory :nic_base_empty, :class => Nic::Base do
63
- type 'Nic::Base'
64
+ type { 'Nic::Base' }
64
65
  end
65
66
 
66
67
  factory :nic_managed_empty, :class => Nic::Managed, :parent => :nic_base_empty do
67
- type 'Nic::Managed'
68
- identifier 'net0'
68
+ type { 'Nic::Managed' }
69
+ identifier { 'net0' }
69
70
  end
70
71
 
71
72
  factory :host_empty, :class => Host do
@@ -76,5 +77,4 @@ FactoryBot.define do
76
77
  end
77
78
  compute_attributes { { 'type' => 'qemu' } }
78
79
  end
79
-
80
80
  end
@@ -18,17 +18,19 @@
18
18
  # along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
19
  require 'test_plugin_helper'
20
20
 
21
- class ::ForemanFogProxmox::ComputeResourcesControllerTest < ActionController::TestCase
21
+ module ForemanFogProxmox
22
+ class ComputeResourcesControllerTest < ActionController::TestCase
22
23
  test 'should get isos' do
23
- get :isos, params: { :storage => 'local' }
24
- assert_response :found
25
- show_response = @response.body
26
- assert !show_response.empty?
24
+ get :isos, params: { :storage => 'local' }
25
+ assert_response :found
26
+ show_response = @response.body
27
+ assert_not show_response.empty?
27
28
  end
28
29
  test 'should get ostemplates' do
29
- get :ostemplates, params: { :storage => 'local' }
30
- assert_response :found
31
- show_response = @response.body
32
- assert !show_response.empty?
30
+ get :ostemplates, params: { :storage => 'local' }
31
+ assert_response :found
32
+ show_response = @response.body
33
+ assert_not show_response.empty?
33
34
  end
34
- end
35
+ end
36
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This calls the main test_helper in Foreman-core
2
4
 
3
5
  require 'simplecov'
@@ -20,189 +20,185 @@
20
20
  require 'test_plugin_helper'
21
21
 
22
22
  module ForemanFogProxmox
23
- class ProxmoxContainerHelperTest < ActiveSupport::TestCase
24
- include ProxmoxContainerHelper
25
- include ProxmoxVmHelper
26
-
27
- describe 'parse' do
28
-
29
- setup { Fog.mock! }
30
- teardown { Fog.unmock! }
31
-
32
- let(:host) do
33
- { 'vmid' => '100',
34
- 'name' => 'test',
35
- 'type' => 'lxc',
36
- 'node_id' => 'pve',
37
- 'ostemplate_storage' => 'local',
38
- 'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
39
- 'password' => 'proxmox01',
40
- 'config_attributes' => {
41
- 'onboot' => '0',
42
- 'description' => '',
43
- 'memory' => '536870912',
44
- 'swap' => '536870912',
23
+ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
24
+ include ProxmoxContainerHelper
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
+ 'type' => 'lxc',
35
+ 'node_id' => 'pve',
36
+ 'ostemplate_storage' => 'local',
37
+ 'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
38
+ 'password' => 'proxmox01',
39
+ 'config_attributes' => {
40
+ 'onboot' => '0',
41
+ 'description' => '',
42
+ 'memory' => '536870912',
43
+ 'swap' => '536870912',
44
+ 'cores' => '1',
45
+ 'cpulimit' => '',
46
+ 'cpuunits' => '',
47
+ 'arch' => 'amd64',
48
+ 'ostype' => 'debian',
49
+ 'hostname' => '',
50
+ 'nameserver' => '',
51
+ 'searchdomain' => ''
52
+
53
+ },
54
+ 'volumes_attributes' => {
55
+ '0' => { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => '' },
56
+ '1' => { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' }
57
+ },
58
+ 'interfaces_attributes' => {
59
+ '0' => { 'id' => 'net0', 'name' => 'eth0', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp', 'rate' => '' },
60
+ '1' => { 'id' => 'net1', 'name' => 'eth1', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' }
61
+ } }
62
+ end
63
+
64
+ let(:container) do
65
+ { 'vmid' => '100',
66
+ :vmid => '100',
67
+ 'name' => 'test',
68
+ 'type' => 'lxc',
69
+ :type => 'lxc',
70
+ 'node_id' => 'pve',
71
+ :node_id => 'pve',
72
+ :memory => 536_870_912,
73
+ 'templated' => 0,
74
+ :onboot => 0,
75
+ :swap => 536_870_912,
45
76
  'cores' => '1',
46
- 'cpulimit' => '',
47
- 'cpuunits' => '',
48
- 'arch' => 'amd64',
49
- 'ostype' => 'debian',
50
- 'hostname' => '',
51
- 'nameserver' => '',
52
- 'searchdomain' => '',
53
-
54
- },
55
- 'volumes_attributes' => {
56
- '0'=> { 'id' => 'rootfs', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => '' },
57
- '1'=> { 'id' => 'mp0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' }
58
- },
59
- 'interfaces_attributes' => {
60
- '0' => { 'id' => 'net0', 'name' => 'eth0', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp', 'rate' => '' },
61
- '1' => { 'id' => 'net1', 'name' => 'eth1', 'bridge' => 'vmbr0', 'ip' => 'dhcp', 'ip6' => 'dhcp' }
62
- }
63
- }
77
+ :arch => 'amd64',
78
+ :ostype => 'debian',
79
+ 'ostemplate' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
80
+ 'ostemplate_storage' => 'local',
81
+ 'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
82
+ 'password' => 'proxmox01',
83
+ :rootfs => 'local-lvm:1073741824',
84
+ :mp0 => 'local-lvm:1073741824,mp=/opt/path',
85
+ 'net0' => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp',
86
+ 'net1' => 'model=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp' }
87
+ end
88
+
89
+ let(:host_delete) do
90
+ { 'vmid' => '100',
91
+ 'name' => 'test',
92
+ 'type' => 'lxc',
93
+ 'node_id' => 'pve',
94
+ 'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' } },
95
+ 'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'name' => 'eth0' } } }
96
+ end
97
+
98
+ test '#memory' do
99
+ memory = parse_container_memory(host['config_attributes'])
100
+ assert memory.key?(:memory)
101
+ assert_equal 536_870_912, memory[:memory]
102
+ assert memory.key?(:swap)
103
+ assert_equal 536_870_912, memory[:swap]
104
+ end
105
+
106
+ test '#cpu' do
107
+ cpu = parse_container_cpu(host['config_attributes'])
108
+ assert cpu.key?(:cores)
109
+ assert_equal 1, cpu[:cores]
110
+ assert cpu.key?(:arch)
111
+ assert_equal 'amd64', cpu[:arch]
112
+ end
113
+
114
+ test '#ostemplate' do
115
+ ostemplate = parse_container_ostemplate(host)
116
+ 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'
120
+ }
121
+ assert_equal expected_ostemplate, ostemplate
122
+ end
123
+
124
+ test '#vm host' do
125
+ vm = parse_container_vm(host)
126
+ assert_equal 536_870_912, vm[:memory]
127
+ assert_equal 'local-lvm:1073741824', vm[:rootfs]
128
+ assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp', vm[:net0]
129
+ assert_not vm.key?(:config)
130
+ assert_not vm.key?(:node)
131
+ assert_not vm.key?(:type)
132
+ end
133
+
134
+ test '#vm container' do
135
+ vm = parse_container_vm(host)
136
+ expected_vm = ActiveSupport::HashWithIndifferentAccess.new(
137
+ :vmid => '100',
138
+ :password => 'proxmox01',
139
+ :onboot => '0',
140
+ :ostype => 'debian',
141
+ :arch => 'amd64',
142
+ :cores => 1,
143
+ :memory => 536_870_912,
144
+ :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',
148
+ :net0 => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp',
149
+ :net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp',
150
+ :rootfs => 'local-lvm:1073741824',
151
+ :mp0 => 'local-lvm:1073741824,mp=/opt/path'
152
+ )
153
+ assert_equal expected_vm, vm
154
+ end
155
+
156
+ test '#volume with rootfs 1Gb' do
157
+ volumes = parse_container_volumes(host['volumes_attributes'])
158
+ assert_not volumes.empty?
159
+ assert_equal 2, volumes.size
160
+ assert rootfs = volumes.first
161
+ assert rootfs.key?(:rootfs)
162
+ assert_equal 'local-lvm:1073741824', rootfs[:rootfs]
163
+ assert mp0 = volumes[1]
164
+ assert mp0.key?(:mp0)
165
+ assert_equal 'local-lvm:1073741824,mp=/opt/path', mp0[:mp0]
166
+ end
167
+
168
+ test '#interface with name eth0 and bridge' do
169
+ deletes = []
170
+ nics = []
171
+ add_container_interface(host['interfaces_attributes']['0'], deletes, nics)
172
+ assert 1, nics.length
173
+ assert nics[0].key?(:net0)
174
+ assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp', nics[0][:net0]
175
+ end
176
+
177
+ test '#interface with name eth1 and bridge' do
178
+ deletes = []
179
+ nics = []
180
+ add_container_interface(host['interfaces_attributes']['1'], deletes, nics)
181
+ assert 1, nics.length
182
+ assert nics[0].key?(:net1)
183
+ assert_equal 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp', nics[0][:net1]
184
+ end
185
+
186
+ test '#interface delete net0' do
187
+ deletes = []
188
+ nics = []
189
+ add_container_interface(host_delete['interfaces_attributes']['0'], deletes, nics)
190
+ assert nics.empty?
191
+ assert_equal 1, deletes.length
192
+ assert_equal 'net0', deletes[0]
193
+ end
194
+
195
+ test '#interfaces' do
196
+ interfaces_to_add, interfaces_to_delete = parse_container_interfaces(host['interfaces_attributes'])
197
+ assert interfaces_to_delete.empty?
198
+ assert_equal 2, interfaces_to_add.length
199
+ assert interfaces_to_add.include?(net0: 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp')
200
+ assert interfaces_to_add.include?(net1: 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp')
201
+ end
64
202
  end
65
-
66
- let(:container) do
67
- { 'vmid' => '100',
68
- :vmid => '100',
69
- 'name' => 'test',
70
- 'type' => 'lxc',
71
- :type => 'lxc',
72
- 'node_id' => 'pve',
73
- :node_id => 'pve',
74
- :memory => 536870912,
75
- 'templated' => 0,
76
- :onboot => 0,
77
- :swap => 536870912,
78
- 'cores' => '1',
79
- :arch => 'amd64',
80
- :ostype => 'debian',
81
- 'ostemplate' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
82
- 'ostemplate_storage' => 'local',
83
- 'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
84
- 'password' => 'proxmox01',
85
- :rootfs => 'local-lvm:1073741824',
86
- :mp0 => 'local-lvm:1073741824,mp=/opt/path',
87
- 'net0' => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp',
88
- 'net1' => 'model=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp'
89
- }
90
- end
91
-
92
- let(:host_delete) do
93
- { 'vmid' => '100',
94
- 'name' => 'test',
95
- 'type' => 'lxc',
96
- 'node_id' => 'pve',
97
- 'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'mp' => '/opt/path' }},
98
- 'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'name' => 'eth0' } }
99
- }
100
- end
101
-
102
- test '#memory' do
103
- memory = parse_container_memory(host['config_attributes'])
104
- assert memory.has_key?(:memory)
105
- assert_equal 536870912, memory[:memory]
106
- assert memory.has_key?(:swap)
107
- assert_equal 536870912, memory[:swap]
108
- end
109
-
110
- test '#cpu' do
111
- cpu = parse_container_cpu(host['config_attributes'])
112
- assert cpu.has_key?(:cores)
113
- assert_equal 1, cpu[:cores]
114
- assert cpu.has_key?(:arch)
115
- assert_equal 'amd64', cpu[:arch]
116
- end
117
-
118
- test '#ostemplate' do
119
- ostemplate = parse_container_ostemplate(host)
120
- expected_ostemplate = {
121
- :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
122
- :ostemplate_storage => 'local',
123
- :ostemplate_file => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
124
- }
125
- assert_equal expected_ostemplate, ostemplate
126
- end
127
-
128
- test '#vm host' do
129
- vm = parse_container_vm(host)
130
- assert_equal 536870912, vm[:memory]
131
- assert_equal 'local-lvm:1073741824', vm[:rootfs]
132
- assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp', vm[:net0]
133
- assert !vm.has_key?(:config)
134
- assert !vm.has_key?(:node)
135
- assert !vm.has_key?(:type)
136
- end
137
-
138
- test '#vm container' do
139
- vm = parse_container_vm(host)
140
- expected_vm = ActiveSupport::HashWithIndifferentAccess.new(
141
- :vmid => '100',
142
- :password => 'proxmox01',
143
- :onboot => '0',
144
- :ostype => 'debian',
145
- :arch => 'amd64',
146
- :cores => 1,
147
- :memory => 536870912,
148
- :swap => 536870912,
149
- :ostemplate => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
150
- :ostemplate_file => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
151
- :ostemplate_storage => 'local',
152
- :net0 => 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp',
153
- :net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp',
154
- :rootfs => 'local-lvm:1073741824',
155
- :mp0 => 'local-lvm:1073741824,mp=/opt/path' )
156
- assert_equal expected_vm, vm
157
- end
158
-
159
- test '#volume with rootfs 1Gb' do
160
- volumes = parse_container_volumes(host['volumes_attributes'])
161
- assert !volumes.empty?
162
- assert_equal 2, volumes.size
163
- assert rootfs = volumes.first
164
- assert rootfs.has_key?(:rootfs)
165
- assert_equal 'local-lvm:1073741824', rootfs[:rootfs]
166
- assert mp0 = volumes[1]
167
- assert mp0.has_key?(:mp0)
168
- assert_equal 'local-lvm:1073741824,mp=/opt/path', mp0[:mp0]
169
- end
170
-
171
- test '#interface with name eth0 and bridge' do
172
- deletes = []
173
- nics = []
174
- add_container_interface(host['interfaces_attributes']['0'], deletes, nics)
175
- assert 1, nics.length
176
- assert nics[0].has_key?(:net0)
177
- assert_equal 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp', nics[0][:net0]
178
- end
179
-
180
- test '#interface with name eth1 and bridge' do
181
- deletes = []
182
- nics = []
183
- add_container_interface(host['interfaces_attributes']['1'], deletes, nics)
184
- assert 1, nics.length
185
- assert nics[0].has_key?(:net1)
186
- assert_equal 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp', nics[0][:net1]
187
- end
188
-
189
- test '#interface delete net0' do
190
- deletes = []
191
- nics = []
192
- add_container_interface(host_delete['interfaces_attributes']['0'], deletes, nics)
193
- assert nics.empty?
194
- assert_equal 1, deletes.length
195
- assert_equal 'net0', deletes[0]
196
- end
197
-
198
- test '#interfaces' do
199
- interfaces_to_add, interfaces_to_delete = parse_container_interfaces(host['interfaces_attributes'])
200
- assert interfaces_to_delete.empty?
201
- assert_equal 2, interfaces_to_add.length
202
- assert interfaces_to_add.include?({ net0: 'name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp'})
203
- assert interfaces_to_add.include?({ net1: 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp'})
204
- end
205
-
206
203
  end
207
204
  end
208
- end