foreman_fog_proxmox 0.5.6 → 0.6.0
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.
Potentially problematic release.
This version of foreman_fog_proxmox might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +28 -18
- data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +1 -1
- data/app/helpers/proxmox_container_helper.rb +4 -3
- data/app/helpers/proxmox_server_helper.rb +3 -2
- data/app/helpers/proxmox_vm_helper.rb +6 -4
- data/app/models/concerns/fog_extensions/proxmox/{container_config.rb → node.rb} +6 -11
- data/app/models/concerns/fog_extensions/proxmox/server.rb +2 -13
- data/app/models/concerns/fog_extensions/proxmox/server_config.rb +18 -4
- data/app/models/foreman_fog_proxmox/proxmox.rb +104 -66
- data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +0 -9
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +1 -1
- data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +1 -1
- data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +3 -3
- data/app/views/compute_resources/form/_proxmox.html.erb +2 -2
- data/app/views/compute_resources/show/_proxmox.html.erb +4 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +1 -0
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +2 -1
- data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +0 -1
- data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +1 -1
- data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +0 -1
- data/app/views/compute_resources_vms/show/_proxmox.html.erb +1 -1
- data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +2 -2
- data/lib/foreman_fog_proxmox/engine.rb +3 -5
- data/lib/foreman_fog_proxmox/version.rb +1 -1
- data/test/factories/proxmox_factory.rb +9 -2
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +5 -5
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +2 -1
- data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +22 -14
- data/test/unit/foreman_fog_proxmox/proxmox_test.rb +22 -31
- data/test/unit/foreman_fog_proxmox/proxmox_test_helpers.rb +18 -4
- metadata +8 -9
- data/app/models/concerns/fog_extensions/proxmox/container.rb +0 -57
@@ -15,15 +15,6 @@
|
|
15
15
|
# You should have received a copy of the GNU General Public License
|
16
16
|
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
|
17
17
|
|
18
|
-
Deface::Override.new(
|
19
|
-
:virtual_path => "hosts/_compute_detail",
|
20
|
-
:name => "add_clone_to_new_vm_compute_detail",
|
21
|
-
:replace => "erb[silent]:contains('new_vm = @host.nil? || new_vm?(@host)')",
|
22
|
-
:text => "<% new_vm = @host.nil? || new_vm?(@host) || @host.name.nil? %>",
|
23
|
-
:original => "<% new_vm = @host.nil? || new_vm?(@host) %>"
|
24
|
-
)
|
25
|
-
|
26
|
-
|
27
18
|
Deface::Override.new(
|
28
19
|
:virtual_path => "hosts/_compute_detail",
|
29
20
|
:name => "add_from_profile_to_compute_detail",
|
@@ -20,7 +20,7 @@ Deface::Override.new(
|
|
20
20
|
:name => "add_vm_type_to_networks_form",
|
21
21
|
:replace => "erb[loud]:contains('render')",
|
22
22
|
:partial => "compute_resources_vms/form/proxmox/add_vm_type_to_networks_form",
|
23
|
-
:original => '
|
23
|
+
:original => 'ce82feb03418d25628001c9fc5f5f78025c5e5f8'
|
24
24
|
)
|
25
25
|
|
26
26
|
Deface::Override.new(
|
@@ -21,5 +21,5 @@ Deface::Override.new(
|
|
21
21
|
:replace => "erb[loud]:contains('f.fields_for')",
|
22
22
|
:closing_selector => "erb[silent]:contains('end')",
|
23
23
|
:partial => "compute_resources_vms/form/proxmox/add_vm_type_to_nic_provider_specific_form",
|
24
|
-
:original => '
|
24
|
+
:original => 'f1a2373efd9c7c993fd1662a2ee4752183542704'
|
25
25
|
)
|
@@ -25,13 +25,13 @@ module ForemanFogProxmox::NodeDashboard
|
|
25
25
|
@filter = filter
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def node_id
|
29
29
|
@compute_resource = ComputeResource.find_by(type: 'ForemanFogProxmox::Proxmox')
|
30
|
-
@compute_resource.
|
30
|
+
@compute_resource.node_id if @compute_resource
|
31
31
|
end
|
32
32
|
|
33
33
|
def statistics
|
34
|
-
node.statistics('rrddata', { timeframe: 'hour', cf: 'AVERAGE' }) if
|
34
|
+
node.statistics('rrddata', { timeframe: 'hour', cf: 'AVERAGE' }) if node_id
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -18,11 +18,11 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
18
18
|
<%= javascript_include_tag 'foreman_fog_proxmox/proxmox_compute_resource', "data-turbolinks-track" => true %>
|
19
19
|
|
20
20
|
<% nodes = f.object.nodes rescue nil %>
|
21
|
-
<%
|
21
|
+
<% node_id = !!f.object.node_id ? f.object.node_id : '' %>
|
22
22
|
<%= text_f f, :url, :help_block => _("e.g. https://127.0.0.1:8006/api2/json"), :help_inline_permanent => load_button_f(f, !!nodes, _("Test failed")) %>
|
23
23
|
<%= text_f f, :user , :help_block => _("e.g. root@pam") %>
|
24
24
|
<%= password_f f, :password, :keep_value => true, :unset => unset_password? %>
|
25
25
|
<%= checkbox_f f, :ssl_verify_peer, :label => _("SSL verify peer"), :checked => true, :onchange => "sslVerifyPeerSelected(this)" %>
|
26
26
|
<%= textarea_f f, :ssl_certs, :label => _("X509 Certification Authorities"), :size => "col-md-4",
|
27
27
|
:placeholder => _("Optionally provide a CA, or a correctly ordered CA chain. If left blank, disable ssl_verify_peer.") %>
|
28
|
-
<%= select_f f, :
|
28
|
+
<%= select_f f, :node_id, nodes, :node, :node, { :include_blank => true }, :label => _('Node'), :label_size => "col-md-2", :required => true, :disabled => (node_id != '') %>
|
@@ -16,8 +16,9 @@ You should have received a copy of the GNU General Public License
|
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
|
18
18
|
<% vm_type = f.object.respond_to?('type') ? f.object.type : nil %>
|
19
|
+
<% logger.debug("vm_type=#{vm_type}") %>
|
19
20
|
|
20
21
|
<%= render :partial => provider_partial(compute_resource, 'network'),
|
21
|
-
:locals => { :f => i, :vm_type => vm_type, :compute_resource => compute_resource, :new_host => new_host, :new_vm => new_vm, :remove_title => _('remove network interface') },
|
22
|
+
:locals => { :f => i, :vm_type => vm_type, :compute_resource => compute_resource, :new_host => new_host, :new_vm => new_vm, :remove_title => _('remove network interface'), :selected_cluster => selected_cluster },
|
22
23
|
:layout => 'compute_resources_vms/form/deletable_layout' %>
|
23
24
|
|
data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb
CHANGED
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
|
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
|
18
18
|
<% vm_type = f.object.respond_to?('type') ? f.object.type : nil %>
|
19
|
+
<% logger.debug("vm_type=#{vm_type}") %>
|
19
20
|
|
20
21
|
<%= new_child_fields_template(f, compute_resource.interfaces_attrs_name, {
|
21
22
|
:object => compute_resource.new_interface,
|
@@ -16,8 +16,9 @@ You should have received a copy of the GNU General Public License
|
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
<% compute_attributes = f.options[:parent_builder].object.compute_attributes %>
|
18
18
|
<% vm_type = compute_attributes ? compute_attributes['type'] : f.object.type %>
|
19
|
+
<% logger.debug("vm_type=#{vm_type}") %>
|
19
20
|
|
20
21
|
<%= f.fields_for 'compute_attributes', OpenStruct.new(f.object.compute_attributes) do |f| %>
|
21
|
-
<%= render provider_partial(@host.compute_resource, 'network'), :f => f, :vm_type => vm_type, :disabled => f.object.persisted?, :compute_resource => @host.compute_resource, :new_host => new_vm
|
22
|
+
<%= render provider_partial(@host.compute_resource, 'network'), :f => f, :vm_type => vm_type, :disabled => f.object.persisted?, :compute_resource => @host.compute_resource, :new_host => new_vm, :new_vm => new_vm %>
|
22
23
|
<% end %>
|
23
24
|
|
@@ -16,7 +16,6 @@ You should have received a copy of the GNU General Public License
|
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
|
18
18
|
<% type = f.object.type %>
|
19
|
-
<% logger.debug("type=#{type}") %>
|
20
19
|
<% server = type == 'qemu' %>
|
21
20
|
<% container = type == 'lxc' %>
|
22
21
|
|
@@ -20,7 +20,7 @@ along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
|
20
20
|
<%= field_set_tag _("General"), :id => "general" do %>
|
21
21
|
<%= checkbox_f f, :templated, :label => _('Create image?'), :disabled => untemplatable, :class => ('hide' if untemplatable), :no_label => untemplatable %>
|
22
22
|
<%= counter_f f, :vmid, :label => _('VM ID'), :label_size => "col-md-2", :required => true, :disabled => (!new_vm || from_profile) %>
|
23
|
-
<%= select_f f, :
|
23
|
+
<%= select_f f, :node_id, compute_resource.nodes, :node, :node, { }, :label => _('Node'), :label_size => "col-md-2", :required => true, :disabled => true %>
|
24
24
|
<% unless local_assigns[:hide_image] && !new_vm %>
|
25
25
|
<%
|
26
26
|
arch ||= nil ; os ||= nil
|
@@ -15,7 +15,6 @@ GNU General Public License for more details.
|
|
15
15
|
You should have received a copy of the GNU General Public License
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
|
18
|
-
|
19
18
|
<% server = type == 'qemu' %>
|
20
19
|
|
21
20
|
<%= field_set_tag _("Nic"), :id => "server_network", :style => ('display: none;' unless server), :disabled => !server do %>
|
@@ -16,6 +16,6 @@ You should have received a copy of the GNU General Public License
|
|
16
16
|
along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>. %>
|
17
17
|
|
18
18
|
<% data = ForemanFogProxmox::NodeDashboard::Data.new() %>
|
19
|
-
<%
|
20
|
-
<h4 class="header ca"><%= N_("Proxmox Node Statistics: %s") %
|
19
|
+
<% node_id = data.node_id rescue nil %>
|
20
|
+
<h4 class="header ca"><%= N_("Proxmox Node Statistics: %s") % node_id %></h4>
|
21
21
|
<%= render_node_statistics(data.statistics, :class => 'statistics-bar') rescue nil %>
|
@@ -38,7 +38,7 @@ module ForemanFogProxmox
|
|
38
38
|
|
39
39
|
initializer 'foreman_fog_proxmox.register_plugin', :before => :finisher_hook do |_app|
|
40
40
|
Foreman::Plugin.register :foreman_fog_proxmox do
|
41
|
-
requires_foreman '>= 1.
|
41
|
+
requires_foreman '>= 1.21.0'
|
42
42
|
# Register Proxmox VE compute resource in foreman
|
43
43
|
compute_resource ForemanFogProxmox::Proxmox
|
44
44
|
parameter_filter(ComputeResource, :uuid)
|
@@ -81,18 +81,16 @@ module ForemanFogProxmox
|
|
81
81
|
config.to_prepare do
|
82
82
|
require 'fog/compute/proxmox/models/server'
|
83
83
|
require 'fog/compute/proxmox/models/server_config'
|
84
|
-
require 'fog/compute/proxmox/models/container'
|
85
|
-
require 'fog/compute/proxmox/models/container_config'
|
86
84
|
require 'fog/compute/proxmox/models/disk'
|
87
85
|
require 'fog/compute/proxmox/models/volume'
|
86
|
+
require 'fog/compute/proxmox/models/node'
|
88
87
|
|
89
88
|
Fog::Compute::Proxmox::Server.send :include, FogExtensions::Proxmox::Server
|
90
89
|
Fog::Compute::Proxmox::ServerConfig.send :include, FogExtensions::Proxmox::ServerConfig
|
91
|
-
Fog::Compute::Proxmox::Container.send :include, FogExtensions::Proxmox::Container
|
92
|
-
Fog::Compute::Proxmox::ContainerConfig.send :include, FogExtensions::Proxmox::ContainerConfig
|
93
90
|
Fog::Compute::Proxmox::Disk.send :include, FogExtensions::Proxmox::Disk
|
94
91
|
Fog::Compute::Proxmox::Volume.send :include, FogExtensions::Proxmox::Volume
|
95
92
|
::ComputeResourcesController.send :include, ForemanFogProxmox::Controller::Parameters::ComputeResource
|
93
|
+
Fog::Compute::Proxmox::Node.send :include, FogExtensions::Proxmox::Node
|
96
94
|
end
|
97
95
|
|
98
96
|
end
|
@@ -29,7 +29,7 @@ FactoryBot.define do
|
|
29
29
|
user 'root@pam'
|
30
30
|
password 'proxmox01'
|
31
31
|
url 'https://192.168.56.101:8006/api2/json'
|
32
|
-
|
32
|
+
node_id 'pve'
|
33
33
|
end
|
34
34
|
|
35
35
|
factory :proxmox_cr, :class => ForemanFogProxmox::Proxmox, :traits => [:proxmox]
|
@@ -41,7 +41,10 @@ FactoryBot.define do
|
|
41
41
|
trait :pve do
|
42
42
|
identity 'pve'
|
43
43
|
end
|
44
|
-
|
44
|
+
trait :service do
|
45
|
+
service :proxmox_cr
|
46
|
+
end
|
47
|
+
factory :pve_node, :class => Fog::Compute::Proxmox::Node, :traits => [:pve, :service]
|
45
48
|
end
|
46
49
|
|
47
50
|
def deferred_nic_attrs
|
@@ -68,6 +71,10 @@ FactoryBot.define do
|
|
68
71
|
factory :host_empty, :class => Host do
|
69
72
|
sequence(:name) { |n| "host#{n}" }
|
70
73
|
sequence(:hostname) { |n| "host#{n}" }
|
74
|
+
trait :compute_attributes do
|
75
|
+
{ 'type' => 'qemu' }
|
76
|
+
end
|
77
|
+
compute_attributes { { 'type' => 'qemu' } }
|
71
78
|
end
|
72
79
|
|
73
80
|
end
|
@@ -22,6 +22,7 @@ require 'test_plugin_helper'
|
|
22
22
|
module ForemanFogProxmox
|
23
23
|
class ProxmoxContainerHelperTest < ActiveSupport::TestCase
|
24
24
|
include ProxmoxContainerHelper
|
25
|
+
include ProxmoxVmHelper
|
25
26
|
|
26
27
|
describe 'parse' do
|
27
28
|
|
@@ -32,7 +33,7 @@ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
|
|
32
33
|
{ 'vmid' => '100',
|
33
34
|
'name' => 'test',
|
34
35
|
'type' => 'lxc',
|
35
|
-
'
|
36
|
+
'node_id' => 'pve',
|
36
37
|
'ostemplate_storage' => 'local',
|
37
38
|
'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
38
39
|
'password' => 'proxmox01',
|
@@ -68,8 +69,8 @@ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
|
|
68
69
|
'name' => 'test',
|
69
70
|
'type' => 'lxc',
|
70
71
|
:type => 'lxc',
|
71
|
-
'
|
72
|
-
:
|
72
|
+
'node_id' => 'pve',
|
73
|
+
:node_id => 'pve',
|
73
74
|
:memory => 536870912,
|
74
75
|
'templated' => 0,
|
75
76
|
:onboot => 0,
|
@@ -92,6 +93,7 @@ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
|
|
92
93
|
{ 'vmid' => '100',
|
93
94
|
'name' => 'test',
|
94
95
|
'type' => 'lxc',
|
96
|
+
'node_id' => 'pve',
|
95
97
|
'volumes_attributes' => { '0' => { '_delete' => '1', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' }},
|
96
98
|
'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'name' => 'eth0' } }
|
97
99
|
}
|
@@ -151,8 +153,6 @@ class ProxmoxContainerHelperTest < ActiveSupport::TestCase
|
|
151
153
|
:net1 => 'name=eth1,bridge=vmbr0,ip=dhcp,ip6=dhcp',
|
152
154
|
:rootfs => 'local-lvm:1073741824',
|
153
155
|
:mp0 => 'local-lvm:1073741824' )
|
154
|
-
assert_equal expected_vm.length, vm.length
|
155
|
-
assert_equal expected_vm.keys, vm.keys
|
156
156
|
assert_equal expected_vm, vm
|
157
157
|
end
|
158
158
|
|
@@ -22,6 +22,7 @@ require 'test_plugin_helper'
|
|
22
22
|
module ForemanFogProxmox
|
23
23
|
class ProxmoxServerHelperTest < ActiveSupport::TestCase
|
24
24
|
include ProxmoxServerHelper
|
25
|
+
include ProxmoxVmHelper
|
25
26
|
|
26
27
|
describe 'parse' do
|
27
28
|
|
@@ -31,7 +32,7 @@ class ProxmoxServerHelperTest < ActiveSupport::TestCase
|
|
31
32
|
let(:host) do
|
32
33
|
{ 'vmid' => '100',
|
33
34
|
'name' => 'test',
|
34
|
-
'
|
35
|
+
'node_id' => 'pve',
|
35
36
|
'type' => 'qemu',
|
36
37
|
'config_attributes' => {
|
37
38
|
'memory' => '536870912',
|
@@ -20,23 +20,27 @@
|
|
20
20
|
require 'test_plugin_helper'
|
21
21
|
require 'fog/compute/proxmox/models/server'
|
22
22
|
require 'fog/compute/proxmox/models/server_config'
|
23
|
-
require 'fog/compute/proxmox/models/container'
|
24
|
-
require 'fog/compute/proxmox/models/container_config'
|
25
23
|
require 'fog/compute/proxmox/models/interface'
|
26
24
|
require 'fog/compute/proxmox/models/interfaces'
|
27
25
|
require 'fog/compute/proxmox/models/disk'
|
28
26
|
require 'fog/compute/proxmox/models/disks'
|
27
|
+
require 'fog/compute/proxmox/models/snapshots'
|
28
|
+
require 'fog/compute/proxmox/models/tasks'
|
29
29
|
|
30
30
|
module ForemanFogProxmox
|
31
31
|
class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
32
32
|
include ProxmoxVmHelper
|
33
33
|
|
34
34
|
let(:container) do
|
35
|
-
|
35
|
+
service = mock('service')
|
36
|
+
service.stubs(:get_server_config).returns(nil)
|
37
|
+
service.stubs(:list_tasks).returns([])
|
38
|
+
Fog::Compute::Proxmox::Server.new(
|
36
39
|
{ 'vmid' => '100',
|
37
40
|
'hostname' => 'test',
|
38
|
-
|
39
|
-
|
41
|
+
:type => 'lxc',
|
42
|
+
:node_id => 'pve',
|
43
|
+
:service => service,
|
40
44
|
'templated' => '0',
|
41
45
|
'memory' => '536870912',
|
42
46
|
'swap' => '',
|
@@ -51,11 +55,15 @@ class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
|
51
55
|
end
|
52
56
|
|
53
57
|
let(:server) do
|
58
|
+
service = mock('service')
|
59
|
+
service.stubs(:get_server_config).returns(nil)
|
60
|
+
service.stubs(:list_tasks).returns([])
|
54
61
|
Fog::Compute::Proxmox::Server.new(
|
55
62
|
{ 'vmid' => '100',
|
56
63
|
'name' => 'test',
|
57
|
-
|
58
|
-
|
64
|
+
:node_id => 'pve',
|
65
|
+
:service => service,
|
66
|
+
:type => 'qemu',
|
59
67
|
'templated' => '0',
|
60
68
|
'ide2' => 'local-lvm:iso/debian-netinst.iso,media=cdrom',
|
61
69
|
'memory' => '536870912',
|
@@ -76,7 +84,7 @@ class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
|
76
84
|
let(:host_server) do
|
77
85
|
{ 'vmid' => '100',
|
78
86
|
'name' => 'test',
|
79
|
-
'
|
87
|
+
'node_id' => 'pve',
|
80
88
|
'type' => 'qemu',
|
81
89
|
'config_attributes' => {
|
82
90
|
'memory' => '536870912',
|
@@ -103,7 +111,7 @@ class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
|
103
111
|
{ 'vmid' => '100',
|
104
112
|
'name' => 'test',
|
105
113
|
'type' => 'lxc',
|
106
|
-
'
|
114
|
+
'node_id' => 'pve',
|
107
115
|
'ostemplate_storage' => 'local',
|
108
116
|
'ostemplate_file' => 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz',
|
109
117
|
'password' => 'proxmox01',
|
@@ -138,30 +146,30 @@ class ProxmoxVmHelperTest < ActiveSupport::TestCase
|
|
138
146
|
setup { Fog.mock! }
|
139
147
|
teardown { Fog.unmock! }
|
140
148
|
|
141
|
-
it '#server qemu' do
|
149
|
+
it '#server qemu' do
|
142
150
|
config_hash = object_to_config_hash(server,'qemu')
|
143
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key,_value| %w[templated
|
151
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key,_value| %w[templated ide2 scsi0 net0 net1].include? key }
|
144
152
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
145
153
|
end
|
146
154
|
|
147
155
|
it '#server lxc' do
|
148
156
|
config_hash = object_to_config_hash(server,'lxc')
|
149
157
|
assert config_hash.has_key?('config_attributes')
|
150
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key,_value| %w[templated
|
158
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(server.config.attributes).reject { |key,_value| %w[templated ide2 scsi0 net0 net1].include? key }
|
151
159
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
152
160
|
end
|
153
161
|
|
154
162
|
it '#container qemu' do
|
155
163
|
config_hash = object_to_config_hash(container,'qemu')
|
156
164
|
assert config_hash.has_key?('config_attributes')
|
157
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key,_value| %w[templated
|
165
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key,_value| %w[templated rootfs mp0 net0 net1].include? key }
|
158
166
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
159
167
|
end
|
160
168
|
|
161
169
|
it '#container lxc' do
|
162
170
|
config_hash = object_to_config_hash(container,'lxc')
|
163
171
|
assert config_hash.has_key?('config_attributes')
|
164
|
-
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key,_value| %w[templated
|
172
|
+
expected_config_hash = ActiveSupport::HashWithIndifferentAccess.new(container.config.attributes).reject { |key,_value| %w[templated rootfs mp0 net0 net1].include? key }
|
165
173
|
assert_equal expected_config_hash, config_hash['config_attributes']
|
166
174
|
end
|
167
175
|
end
|
@@ -30,7 +30,7 @@ module ForemanFogProxmox
|
|
30
30
|
should validate_presence_of(:url)
|
31
31
|
should validate_presence_of(:user)
|
32
32
|
should validate_presence_of(:password)
|
33
|
-
should validate_presence_of(:
|
33
|
+
should validate_presence_of(:node_id)
|
34
34
|
should allow_value('root@pam').for(:user)
|
35
35
|
should_not allow_value('root').for(:user)
|
36
36
|
should_not allow_value('a').for(:url)
|
@@ -60,18 +60,16 @@ module ForemanFogProxmox
|
|
60
60
|
end
|
61
61
|
|
62
62
|
describe "find_vm_by_uuid" do
|
63
|
-
it "
|
64
|
-
cr =
|
65
|
-
|
66
|
-
cr.find_vm_by_uuid('100')
|
67
|
-
end
|
63
|
+
it "returns nil when the uuid does not match" do
|
64
|
+
cr = mock_node_servers_containers(ForemanFogProxmox::Proxmox.new, empty_servers, empty_servers)
|
65
|
+
assert cr.find_vm_by_uuid('100').nil?
|
68
66
|
end
|
69
67
|
|
70
|
-
it "raises RecordNotFound when the compute raises
|
71
|
-
exception = Fog::
|
68
|
+
it "raises RecordNotFound when the compute raises error" do
|
69
|
+
exception = Fog::Errors::Error.new
|
72
70
|
cr = mock_node_servers(ForemanFogProxmox::Proxmox.new, servers_raising_exception(exception))
|
73
71
|
assert_raises ActiveRecord::RecordNotFound do
|
74
|
-
cr.find_vm_by_uuid('
|
72
|
+
cr.find_vm_by_uuid('100')
|
75
73
|
end
|
76
74
|
end
|
77
75
|
end
|
@@ -80,16 +78,7 @@ module ForemanFogProxmox
|
|
80
78
|
before do
|
81
79
|
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
82
80
|
end
|
83
|
-
|
84
|
-
it "raises Foreman::Exception when physical identifier is empty" do
|
85
|
-
physical_nic = FactoryBot.build(:nic_base_empty)
|
86
|
-
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic])
|
87
|
-
err = assert_raises Foreman::Exception do
|
88
|
-
@cr.host_interfaces_attrs(host)
|
89
|
-
end
|
90
|
-
assert err.message.end_with?('Identifier interface[0] required.')
|
91
|
-
end
|
92
|
-
|
81
|
+
|
93
82
|
it "raises Foreman::Exception when physical identifier does not match net[k] with k integer" do
|
94
83
|
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0')
|
95
84
|
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic])
|
@@ -103,7 +92,7 @@ module ForemanFogProxmox
|
|
103
92
|
ip = IPAddr.new(1, Socket::AF_INET).to_s
|
104
93
|
ip6 = Array.new(4) { '%x' % rand(16**4) }.join(':') + '::1'
|
105
94
|
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6)
|
106
|
-
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic])
|
95
|
+
host = FactoryBot.build(:host_empty, :interfaces => [physical_nic], :compute_attributes => {'type' => 'qemu'})
|
107
96
|
nic_attributes = @cr.host_interfaces_attrs(host).values.select(&:present?)
|
108
97
|
nic_attr = nic_attributes.first
|
109
98
|
assert_equal 'net0', nic_attr[:id]
|
@@ -141,12 +130,12 @@ module ForemanFogProxmox
|
|
141
130
|
@cr = FactoryBot.build_stubbed(:proxmox_cr)
|
142
131
|
end
|
143
132
|
|
144
|
-
it "converts to hash
|
133
|
+
it "converts a server to hash" do
|
145
134
|
vm, config_attributes, volume_attributes, interface_attributes = mock_server_vm
|
146
135
|
vm_attrs = @cr.vm_compute_attributes(vm)
|
147
136
|
assert !vm_attrs.has_key?(:config)
|
148
137
|
assert vm_attrs.has_key?(:config_attributes)
|
149
|
-
assert_equal config_attributes.reject { |key,value| [:disks,:interfaces].include?(key) || value.to_s.empty?}, vm_attrs[:config_attributes]
|
138
|
+
assert_equal config_attributes.reject { |key,value| [:vmid,:disks,:interfaces].include?(key) || value.to_s.empty?}, vm_attrs[:config_attributes]
|
150
139
|
assert !vm_attrs[:config_attributes].has_key?(:disks)
|
151
140
|
assert vm_attrs.has_key?(:volumes_attributes)
|
152
141
|
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
@@ -155,13 +144,13 @@ module ForemanFogProxmox
|
|
155
144
|
assert_equal interface_attributes, vm_attrs[:interfaces_attributes]['0']
|
156
145
|
end
|
157
146
|
|
158
|
-
it "converts to hash
|
147
|
+
it "converts a container to hash" do
|
159
148
|
vm, config_attributes, volume_attributes, interface_attributes = mock_container_vm
|
160
149
|
vm_attrs = @cr.vm_compute_attributes(vm)
|
161
150
|
assert !vm_attrs.has_key?(:config)
|
162
151
|
assert vm_attrs.has_key?(:config_attributes)
|
163
|
-
assert_equal config_attributes.reject { |key,value| [:
|
164
|
-
assert !vm_attrs[:config_attributes].has_key?(:
|
152
|
+
assert_equal config_attributes.reject { |key,value| [:vmid,:disks,:interfaces].include?(key) || value.to_s.empty?}, vm_attrs[:config_attributes]
|
153
|
+
assert !vm_attrs[:config_attributes].has_key?(:disks)
|
165
154
|
assert vm_attrs.has_key?(:volumes_attributes)
|
166
155
|
assert_equal volume_attributes, vm_attrs[:volumes_attributes]['0']
|
167
156
|
assert vm_attrs.has_key?(:interfaces_attributes)
|
@@ -176,12 +165,13 @@ module ForemanFogProxmox
|
|
176
165
|
end
|
177
166
|
|
178
167
|
it 'saves modified server config' do
|
179
|
-
uuid = '
|
168
|
+
uuid = '100'
|
180
169
|
config = mock('config')
|
181
170
|
config.stubs(:attributes).returns({ :cores => '' })
|
182
171
|
vm = mock('vm')
|
183
172
|
vm.stubs(:config).returns(config)
|
184
173
|
vm.stubs(:container?).returns(false)
|
174
|
+
vm.stubs(:type).returns('qemu')
|
185
175
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
186
176
|
attr = { 'templated' => '0', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1' } }
|
187
177
|
@cr.stubs(:parse_server_vm).returns({ 'vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1' })
|
@@ -191,12 +181,13 @@ module ForemanFogProxmox
|
|
191
181
|
end
|
192
182
|
|
193
183
|
it 'saves modified container config' do
|
194
|
-
uuid = '
|
184
|
+
uuid = '100'
|
195
185
|
config = mock('config')
|
196
186
|
config.stubs(:attributes).returns({ :cores => '' })
|
197
187
|
vm = mock('vm')
|
198
188
|
vm.stubs(:config).returns(config)
|
199
189
|
vm.stubs(:container?).returns(true)
|
190
|
+
vm.stubs(:type).returns('lxc')
|
200
191
|
@cr.stubs(:find_vm_by_uuid).returns(vm)
|
201
192
|
attr = { 'templated' => '0', 'config_attributes' => { 'cores' => '1', 'cpulimit' => '1' } }
|
202
193
|
@cr.stubs(:parse_container_vm).returns({ 'vmid' => '100', 'type' => 'qemu', 'cores' => '1', 'cpulimit' => '1' })
|
@@ -228,7 +219,7 @@ module ForemanFogProxmox
|
|
228
219
|
cr.stubs(:parse_server_vm).with(args).returns(args)
|
229
220
|
servers.stubs(:create).with(args)
|
230
221
|
vm = mock('vm')
|
231
|
-
cr.stubs(:find_vm_by_uuid).with("#{args[:
|
222
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:vmid]}").returns(vm)
|
232
223
|
cr.create_vm(args)
|
233
224
|
end
|
234
225
|
|
@@ -242,7 +233,7 @@ module ForemanFogProxmox
|
|
242
233
|
cr.stubs(:convert_sizes).with(args)
|
243
234
|
cr.stubs(:parse_container_vm).with(args).returns(args)
|
244
235
|
vm = mock('vm')
|
245
|
-
cr.stubs(:find_vm_by_uuid).with("#{args[:
|
236
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:vmid]}").returns(vm)
|
246
237
|
cr.create_vm(args)
|
247
238
|
end
|
248
239
|
|
@@ -261,7 +252,7 @@ module ForemanFogProxmox
|
|
261
252
|
servers.stubs(:get).with('999').returns(image)
|
262
253
|
clone.stubs(:update).with(name: 'name')
|
263
254
|
vm = mock('vm')
|
264
|
-
cr.stubs(:find_vm_by_uuid).with("#{args[:
|
255
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:vmid]}").returns(vm)
|
265
256
|
cr.create_vm(args)
|
266
257
|
end
|
267
258
|
|
@@ -281,7 +272,7 @@ module ForemanFogProxmox
|
|
281
272
|
cr.stubs(:convert_sizes).with(args)
|
282
273
|
cr.stubs(:parse_container_vm).with(args).returns(args)
|
283
274
|
vm = mock('vm')
|
284
|
-
cr.stubs(:find_vm_by_uuid).with("#{args[:
|
275
|
+
cr.stubs(:find_vm_by_uuid).with("#{args[:vmid]}").returns(vm)
|
285
276
|
cr.create_vm(args)
|
286
277
|
end
|
287
278
|
end
|