foreman_wreckingball 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/app/controllers/foreman_wreckingball/hosts_controller.rb +15 -4
- data/app/helpers/concerns/foreman_wreckingball/hosts_helper_extensions.rb +1 -1
- data/app/jobs/update_hosts_vmware_facets.rb +1 -2
- data/app/lib/actions/foreman_wreckingball/host/refresh_vmware_facet.rb +5 -5
- data/app/lib/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem.rb +39 -38
- data/app/lib/actions/foreman_wreckingball/vmware/sync_compute_resource.rb +12 -14
- data/app/lib/vsphere_os_identifiers/data.yaml +121 -10
- data/app/lib/vsphere_os_identifiers/os.rb +3 -2
- data/app/lib/vsphere_os_identifiers.rb +3 -2
- data/app/models/concerns/foreman_wreckingball/compute_resource_extensions.rb +1 -1
- data/app/models/concerns/foreman_wreckingball/host_extensions.rb +16 -3
- data/app/models/concerns/foreman_wreckingball/vmware_facet_host_extensions.rb +10 -6
- data/app/models/concerns/foreman_wreckingball/vmware_hypervisor_facet_host_extensions.rb +0 -3
- data/app/models/foreman_wreckingball/cpu_hot_add_status.rb +1 -1
- data/app/models/foreman_wreckingball/operatingsystem_status.rb +3 -3
- data/app/models/foreman_wreckingball/tools_status.rb +1 -1
- data/app/models/foreman_wreckingball/vmware_cluster.rb +15 -6
- data/app/models/foreman_wreckingball/vmware_facet.rb +5 -4
- data/app/models/foreman_wreckingball/vmware_hypervisor_facet.rb +2 -2
- data/app/services/foreman_wreckingball/vmware_cluster_importer.rb +6 -6
- data/app/services/foreman_wreckingball/vmware_hypervisor_importer.rb +7 -3
- data/config/routes.rb +1 -1
- data/lib/foreman_wreckingball/engine.rb +11 -8
- data/lib/foreman_wreckingball/scheduled_jobs.rb +1 -1
- data/lib/foreman_wreckingball/version.rb +1 -1
- data/lib/tasks/foreman_vmware_checks_tasks.rake +2 -4
- data/test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb +57 -0
- data/test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb +74 -0
- data/test/actions/foreman_wreckingball/vmware/schedule_vmware_sync_test.rb +27 -0
- data/test/actions/foreman_wreckingball/vmware/sync_compute_resource_test.rb +48 -0
- data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +67 -0
- data/test/factories/compute_resource.rb +13 -0
- data/test/factories/foreman_wreckingball_factories.rb +45 -0
- data/test/factories/host.rb +38 -0
- data/test/models/compute_resource_test.rb +5 -0
- data/test/models/compute_resources/vmware_test.rb +12 -0
- data/test/models/foreman_wreckingball/cpu_hot_add_status_test.rb +86 -0
- data/test/models/foreman_wreckingball/operatingsystem_status_test.rb +95 -0
- data/test/models/foreman_wreckingball/tools_status_test.rb +55 -0
- data/test/models/foreman_wreckingball/vmware_cluster_test.rb +12 -0
- data/test/models/foreman_wreckingball/vmware_facet_test.rb +9 -0
- data/test/models/foreman_wreckingball/vmware_hypervisor_facet_test.rb +13 -0
- data/test/models/host_test.rb +10 -0
- data/test/test_plugin_helper.rb +3 -2
- data/test/unit/foreman_wreckingball/vmware_cluster_importer_test.rb +42 -0
- data/test/unit/foreman_wreckingball/vmware_hypervisor_importer_test.rb +72 -0
- metadata +48 -12
- data/test/unit/foreman_wreckingball_test.rb +0 -11
@@ -46,19 +46,19 @@ module ForemanWreckingball
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def relevant?(_options = {})
|
49
|
-
host &&
|
49
|
+
host && host.vmware_facet
|
50
50
|
end
|
51
51
|
|
52
52
|
def os_matches_identifier?
|
53
53
|
guest_id = host.vmware_facet.guest_id
|
54
54
|
vsphere_os = VsphereOsIdentifiers.lookup(guest_id)
|
55
55
|
return true unless vsphere_os
|
56
|
-
os = host.operatingsystem
|
57
56
|
return true unless host.operatingsystem && host.architecture
|
58
57
|
return false if vsphere_os.architecture && vsphere_os.architecture != host.architecture.name
|
59
58
|
return false if vsphere_os.osfamily && vsphere_os.osfamily != host.operatingsystem.family
|
60
59
|
return false if vsphere_os.name && vsphere_os.name != host.operatingsystem.name
|
61
|
-
return false if vsphere_os.major && vsphere_os.major
|
60
|
+
return false if vsphere_os.major && ![vsphere_os.major].flatten.include?(host.operatingsystem.major.to_i)
|
61
|
+
return false if vsphere_os.release && ![vsphere_os.release].flatten.include?(host.facts['os::release::full'])
|
62
62
|
true
|
63
63
|
end
|
64
64
|
end
|
@@ -1,14 +1,23 @@
|
|
1
1
|
module ForemanWreckingball
|
2
2
|
class VmwareCluster < ActiveRecord::Base
|
3
|
-
has_many :vmware_hypervisor_facets,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
has_many :
|
3
|
+
has_many :vmware_hypervisor_facets,
|
4
|
+
:class_name => '::ForemanWreckingball::VmwareHypervisorFacet',
|
5
|
+
:inverse_of => :vmware_cluster,
|
6
|
+
:dependent => :nullify
|
7
|
+
has_many :hosts, :class_name => '::Host::Managed',
|
8
|
+
:through => :vmware_hypervisor_facets,
|
9
|
+
:inverse_of => :vmware_cluster,
|
10
|
+
:dependent => :nullify
|
11
|
+
belongs_to :compute_resource,
|
12
|
+
:inverse_of => :vmware_clusters
|
13
|
+
has_many :vmware_facets,
|
14
|
+
:class_name => '::ForemanWreckingball::VmwareFacet',
|
15
|
+
:inverse_of => :vmware_cluster,
|
16
|
+
:dependent => :nullify
|
8
17
|
|
9
18
|
validates_lengths_from_database
|
10
19
|
|
11
20
|
validates :compute_resource, :presence => true, :allow_blank => false
|
12
|
-
validates :name, :presence => true, :allow_blank => false, uniqueness
|
21
|
+
validates :name, :presence => true, :allow_blank => false, :uniqueness => { scope: :compute_resource }
|
13
22
|
end
|
14
23
|
end
|
@@ -7,10 +7,11 @@ module ForemanWreckingball
|
|
7
7
|
enum :tools_state => VALID_GUEST_STATUSES
|
8
8
|
|
9
9
|
belongs_to :vmware_cluster, :class_name => '::ForemanWreckingball::VmwareCluster',
|
10
|
-
|
10
|
+
:inverse_of => :vmware_facets
|
11
11
|
|
12
|
-
has_many :vmware_hypervisor_facets, :class_name => '::ForemanWreckingball::VmwareHypervisorFacet',
|
13
|
-
|
12
|
+
has_many :vmware_hypervisor_facets, :class_name => '::ForemanWreckingball::VmwareHypervisorFacet',
|
13
|
+
:through => :vmware_cluster,
|
14
|
+
:inverse_of => :vmware_facets
|
14
15
|
|
15
16
|
validates_lengths_from_database
|
16
17
|
|
@@ -32,7 +33,7 @@ module ForemanWreckingball
|
|
32
33
|
def refresh!
|
33
34
|
vm = host.compute_object
|
34
35
|
return unless vm
|
35
|
-
|
36
|
+
update(
|
36
37
|
:vmware_cluster => ::ForemanWreckingball::VmwareCluster.find_by(:name => vm.cluster, :compute_resource => host.compute_resource),
|
37
38
|
:cpus => vm.cpus,
|
38
39
|
:corespersocket => vm.corespersocket,
|
@@ -9,10 +9,10 @@ module ForemanWreckingball
|
|
9
9
|
belongs_to :vmware_cluster, :inverse_of => :vmware_hypervisor_facets, :class_name => 'ForemanWreckingball::VmwareCluster'
|
10
10
|
|
11
11
|
has_many :vmware_facets, :class_name => '::ForemanWreckingball::VmwareFacet', :through => :vmware_clusters,
|
12
|
-
|
12
|
+
:inverse_of => :vmware_hypervisor_facets
|
13
13
|
|
14
14
|
def self.sanitize_name(name)
|
15
|
-
name.
|
15
|
+
name.tr('_', '-').chomp('.').downcase
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -13,16 +13,16 @@ module ForemanWreckingball
|
|
13
13
|
delete_removed_clusters
|
14
14
|
create_new_clusters
|
15
15
|
end
|
16
|
-
|
16
|
+
logger.info("Import clusters for '#{compute_resource}' completed. Added: #{counters[:added] || 0}, Updated: #{counters[:updated] || 0}, Deleted: #{counters[:deleted] || 0} clusters")
|
17
17
|
end
|
18
18
|
|
19
19
|
def delete_removed_clusters
|
20
20
|
delete_query = ::ForemanWreckingball::VmwareCluster.where(:compute_resource => compute_resource).where.not(:name => cluster_names)
|
21
|
-
if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql'
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
counters[:deleted] = if ActiveRecord::Base.connection.adapter_name.downcase.starts_with? 'mysql'
|
22
|
+
::ForemanWreckingball::VmwareCluster.where(:id => delete_query.pluck(:id)).delete_all
|
23
|
+
else
|
24
|
+
delete_query.delete_all
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def create_new_clusters
|
@@ -15,7 +15,7 @@ module ForemanWreckingball
|
|
15
15
|
compute_resource.vmware_clusters.each do |cluster|
|
16
16
|
import_hypervisors(cluster)
|
17
17
|
end
|
18
|
-
logger.info("Import hypervisors for '#{compute_resource}' completed. Added: #{counters[:added] || 0}, Updated: #{counters[:updated] || 0}, Deleted: #{counters[:deleted] || 0} hypervisors")
|
18
|
+
logger.info("Import hypervisors for '#{compute_resource}' completed. Added: #{counters[:added] || 0}, Updated: #{counters[:updated] || 0}, Deleted: #{counters[:deleted] || 0} hypervisors") # rubocop:disable Metrics/LineLength
|
19
19
|
end
|
20
20
|
|
21
21
|
def import_hypervisors(cluster)
|
@@ -30,7 +30,11 @@ module ForemanWreckingball
|
|
30
30
|
counter = host.vmware_hypervisor_facet ? :updated : :added
|
31
31
|
|
32
32
|
ipaddress6 = hypervisor.ipaddress6
|
33
|
-
ipaddress6 = nil if
|
33
|
+
ipaddress6 = nil if begin
|
34
|
+
IPAddr.new('fe80::/10').include?(ipaddress6)
|
35
|
+
rescue StandardError
|
36
|
+
false
|
37
|
+
end
|
34
38
|
|
35
39
|
hostname = hypervisor.hostname
|
36
40
|
domainname = hypervisor.domainname
|
@@ -74,7 +78,7 @@ module ForemanWreckingball
|
|
74
78
|
def find_host_for_hypervisor(hypervisor)
|
75
79
|
name = ::ForemanWreckingball::VmwareHypervisorFacet.sanitize_name(hypervisor.name)
|
76
80
|
hostname = ::ForemanWreckingball::VmwareHypervisorFacet.sanitize_name([hypervisor.hostname, hypervisor.domainname].join('.'))
|
77
|
-
hostname = nil
|
81
|
+
hostname = nil if hostname.blank?
|
78
82
|
katello_name = katello_hypervisor_hostname(hostname || name)
|
79
83
|
katello_uuid = katello_hypervisor_hostname(hypervisor.uuid)
|
80
84
|
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
scope '/wreckingball' do
|
3
3
|
constraints(:id => /[^\/]+/) do
|
4
|
-
resources :hosts, controller: 'foreman_wreckingball/hosts', :
|
4
|
+
resources :hosts, controller: 'foreman_wreckingball/hosts', only: [] do
|
5
5
|
member do
|
6
6
|
put :remediate
|
7
7
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'dynflow'
|
2
|
+
require 'foreman-tasks'
|
3
|
+
|
1
4
|
module ForemanWreckingball
|
2
5
|
class Engine < ::Rails::Engine
|
3
6
|
engine_name 'foreman_wreckingball'
|
@@ -7,7 +10,7 @@ module ForemanWreckingball
|
|
7
10
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
8
11
|
config.autoload_paths += Dir["#{config.root}/app/helpers/concerns"]
|
9
12
|
|
10
|
-
initializer
|
13
|
+
initializer 'foreman_wreckingball.register_paths' do |_app|
|
11
14
|
::ForemanTasks.dynflow.config.eager_load_paths.concat(%W[#{ForemanWreckingball::Engine.root}/app/lib/actions])
|
12
15
|
end
|
13
16
|
|
@@ -20,7 +23,7 @@ module ForemanWreckingball
|
|
20
23
|
|
21
24
|
initializer 'foreman_wreckingball.register_plugin', :before => :finisher_hook do |_app|
|
22
25
|
Foreman::Plugin.register :foreman_wreckingball do
|
23
|
-
requires_foreman '>= 1.
|
26
|
+
requires_foreman '>= 1.16'
|
24
27
|
|
25
28
|
security_block :foreman_wreckingball do
|
26
29
|
permission :refresh_vmware_status_hosts, {
|
@@ -37,9 +40,9 @@ module ForemanWreckingball
|
|
37
40
|
]
|
38
41
|
|
39
42
|
menu :top_menu, :wreckingball_status_dashboard, :url_hash => { :controller => :'foreman_wreckingball/hosts', :action => :status_dashboard },
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
+
:caption => N_('VMware Status'),
|
44
|
+
:parent => :hosts_menu,
|
45
|
+
:after => :hosts
|
43
46
|
|
44
47
|
register_custom_status(ForemanWreckingball::ToolsStatus)
|
45
48
|
register_custom_status(ForemanWreckingball::OperatingsystemStatus)
|
@@ -53,7 +56,7 @@ module ForemanWreckingball
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
|
-
initializer 'foreman_wreckingball.dynflow_world', :before => 'foreman_tasks.initialize_dynflow' do |
|
59
|
+
initializer 'foreman_wreckingball.dynflow_world', :before => 'foreman_tasks.initialize_dynflow' do |_app|
|
57
60
|
::ForemanTasks.dynflow.require!
|
58
61
|
end
|
59
62
|
|
@@ -71,11 +74,11 @@ module ForemanWreckingball
|
|
71
74
|
Fog::Compute::Vsphere::Host.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Host)
|
72
75
|
Fog::Compute::Vsphere::Real.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Real)
|
73
76
|
end
|
74
|
-
rescue => e
|
77
|
+
rescue StandardError => e
|
75
78
|
Rails.logger.warn "ForemanWreckingball: skipping engine hook (#{e})\n#{e.backtrace.join("\n")}"
|
76
79
|
end
|
77
80
|
|
78
|
-
#load 'foreman_wreckingball/scheduled_jobs.rb'
|
81
|
+
# load 'foreman_wreckingball/scheduled_jobs.rb'
|
79
82
|
end
|
80
83
|
|
81
84
|
initializer 'foreman_wreckingball.register_gettext', after: :load_config_initializers do |_app|
|
@@ -3,7 +3,7 @@ pending_jobs = ::Foreman::Application.dynflow.world.persistence.find_execution_p
|
|
3
3
|
scheduled_job = pending_jobs.select do |job|
|
4
4
|
delayed_plan = ::Foreman::Application.dynflow.world.persistence.load_delayed_plan(job.id)
|
5
5
|
next if delayed_plan.blank?
|
6
|
-
delayed_plan.to_hash[:serialized_args].first[
|
6
|
+
delayed_plan.to_hash[:serialized_args].first['job_class'] == 'UpdateHostsVmwareFacets'
|
7
7
|
end
|
8
8
|
|
9
9
|
# Only schedule the job if there isn't a scheduled job
|
@@ -33,7 +33,7 @@ namespace :foreman_wreckingball do
|
|
33
33
|
"#{ForemanWreckingball::Engine.root}/lib/**/*.rb",
|
34
34
|
"#{ForemanWreckingball::Engine.root}/test/**/*.rb"]
|
35
35
|
end
|
36
|
-
rescue
|
36
|
+
rescue StandardError
|
37
37
|
puts 'Rubocop not loaded.'
|
38
38
|
end
|
39
39
|
|
@@ -44,6 +44,4 @@ end
|
|
44
44
|
Rake::Task[:test].enhance ['test:foreman_wreckingball']
|
45
45
|
|
46
46
|
load 'tasks/jenkins.rake'
|
47
|
-
if Rake::Task.task_defined?(:'jenkins:unit')
|
48
|
-
Rake::Task['jenkins:unit'].enhance ['test:foreman_wreckingball', 'foreman_wreckingball:rubocop']
|
49
|
-
end
|
47
|
+
Rake::Task['jenkins:unit'].enhance ['test:foreman_wreckingball', 'foreman_wreckingball:rubocop'] if Rake::Task.task_defined?(:'jenkins:unit')
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanWreckingball
|
5
|
+
module Vmware
|
6
|
+
class RefreshVmwareFacetTest < ActiveSupport::TestCase
|
7
|
+
include ::Dynflow::Testing
|
8
|
+
setup do
|
9
|
+
::Fog.mock!
|
10
|
+
# this is not stubbed correctly in fog-vsphere
|
11
|
+
Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
|
12
|
+
end
|
13
|
+
teardown { ::Fog.unmock! }
|
14
|
+
|
15
|
+
let(:compute_resource) do
|
16
|
+
cr = FactoryGirl.create(:compute_resource, :vmware, :uuid => 'Solutions')
|
17
|
+
ComputeResource.find(cr.id)
|
18
|
+
end
|
19
|
+
let(:uuid) { '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
|
20
|
+
let(:vm) { compute_resource.find_vm_by_uuid(uuid) }
|
21
|
+
|
22
|
+
let(:host) do
|
23
|
+
FactoryGirl.create(
|
24
|
+
:host,
|
25
|
+
:managed,
|
26
|
+
:with_vmware_facet,
|
27
|
+
compute_resource: compute_resource,
|
28
|
+
uuid: uuid
|
29
|
+
).tap do |host|
|
30
|
+
host.vmware_facet.update_attribute(:guest_id, 'asianux4_64Guest')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:action_class) { ::Actions::ForemanWreckingball::Host::RefreshVmwareFacet }
|
35
|
+
let(:action) do
|
36
|
+
create_action(action_class).tap do |action|
|
37
|
+
action.stubs(:action_subject).returns(host)
|
38
|
+
action.input.update(
|
39
|
+
host: {
|
40
|
+
id: host.id
|
41
|
+
}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
let(:planned_action) do
|
46
|
+
plan_action(action, host)
|
47
|
+
end
|
48
|
+
let(:runned_action) { run_action(planned_action) }
|
49
|
+
|
50
|
+
test "it refreshes a host's vmware facet" do
|
51
|
+
assert_equal :success, runned_action.state
|
52
|
+
assert_equal 'rhel6_64Guest', host.reload.vmware_facet.guest_id
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanWreckingball
|
5
|
+
module Vmware
|
6
|
+
class RemediateVmwareOperatingsystemTest < ActiveSupport::TestCase
|
7
|
+
include ::Dynflow::Testing
|
8
|
+
setup do
|
9
|
+
::Fog.mock!
|
10
|
+
# this is not stubbed correctly in fog-vsphere
|
11
|
+
Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
|
12
|
+
end
|
13
|
+
teardown { ::Fog.unmock! }
|
14
|
+
|
15
|
+
let(:compute_resource) do
|
16
|
+
cr = FactoryGirl.create(:compute_resource, :vmware, :uuid => 'Solutions')
|
17
|
+
ComputeResource.find(cr.id)
|
18
|
+
end
|
19
|
+
let(:uuid) { '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
|
20
|
+
let(:vm) { compute_resource.find_vm_by_uuid(uuid) }
|
21
|
+
|
22
|
+
let(:operatingsystem) do
|
23
|
+
FactoryGirl.create(
|
24
|
+
:operatingsystem,
|
25
|
+
architectures: [architectures(:x86_64)],
|
26
|
+
major: 6,
|
27
|
+
minor: 1,
|
28
|
+
type: 'Redhat',
|
29
|
+
name: 'RedHat'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:host) do
|
34
|
+
FactoryGirl.create(
|
35
|
+
:host,
|
36
|
+
:managed,
|
37
|
+
:with_vmware_facet,
|
38
|
+
architecture: architectures(:x86_64),
|
39
|
+
operatingsystem: operatingsystem,
|
40
|
+
compute_resource: compute_resource,
|
41
|
+
uuid: uuid
|
42
|
+
).tap do |host|
|
43
|
+
host.vmware_facet.update_attribute(:guest_id, 'asianux4_64Guest')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
let(:action_class) { ::Actions::ForemanWreckingball::Host::RemediateVmwareOperatingsystem }
|
48
|
+
let(:action) do
|
49
|
+
create_action(action_class).tap do |action|
|
50
|
+
action.stubs(:action_subject).returns(host)
|
51
|
+
action.input.update(
|
52
|
+
host: {
|
53
|
+
id: host.id
|
54
|
+
}
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
let(:planned_action) do
|
59
|
+
plan_action(action, host)
|
60
|
+
end
|
61
|
+
let(:runned_action) { run_action(planned_action) }
|
62
|
+
|
63
|
+
test "it remediates the host's vm operatingsystem" do
|
64
|
+
assert_equal :success, runned_action.state
|
65
|
+
assert_equal 'asianux4_64Guest', runned_action.output.fetch('old_operatingsystem_id')
|
66
|
+
assert_equal 'rhel6_64Guest', runned_action.output.fetch('new_operatingsytem_id')
|
67
|
+
assert_equal true, runned_action.output.fetch('state')
|
68
|
+
assert_equal true, runned_action.output.fetch('initially_powered_on')
|
69
|
+
assert_equal 'rhel6_64Guest', host.reload.vmware_facet.guest_id
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanWreckingball
|
5
|
+
module Vmware
|
6
|
+
class ScheduleVmwareSyncTest < ActiveSupport::TestCase
|
7
|
+
include ::Dynflow::Testing
|
8
|
+
|
9
|
+
let(:action_class) { ::Actions::ForemanWreckingball::Vmware::ScheduleVmwareSync }
|
10
|
+
let(:sync_action_class) { ::Actions::ForemanWreckingball::Vmware::SyncComputeResource }
|
11
|
+
|
12
|
+
let(:action) do
|
13
|
+
create_action(action_class)
|
14
|
+
end
|
15
|
+
let(:planned_action) do
|
16
|
+
plan_action(action)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with a vmware compute resource' do
|
20
|
+
test 'syncs a compute resource' do
|
21
|
+
assert_action_planed_with(planned_action, sync_action_class, compute_resources(:vmware))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanWreckingball
|
5
|
+
module Vmware
|
6
|
+
class SyncComputeResourceTest < ActiveSupport::TestCase
|
7
|
+
include ::Dynflow::Testing
|
8
|
+
setup do
|
9
|
+
::Fog.mock!
|
10
|
+
# Only Solutionscluster has valid mock data, let's ignore the rest
|
11
|
+
::Foreman::Model::Vmware.any_instance.stubs(:clusters).returns(['Solutionscluster'])
|
12
|
+
end
|
13
|
+
teardown { ::Fog.unmock! }
|
14
|
+
|
15
|
+
let(:action_class) { ::Actions::ForemanWreckingball::Vmware::SyncComputeResource }
|
16
|
+
let(:compute_resource) do
|
17
|
+
FactoryGirl.create(
|
18
|
+
:vmware_cr,
|
19
|
+
uuid: 'Solutions'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:action) do
|
24
|
+
create_action(action_class).tap do |action|
|
25
|
+
action.stubs(:action_subject).returns(compute_resource)
|
26
|
+
action.input.update(
|
27
|
+
compute_resource: {
|
28
|
+
id: compute_resource.id
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
let(:planned_action) do
|
34
|
+
plan_action(action, compute_resource)
|
35
|
+
end
|
36
|
+
let(:runned_action) { run_action(planned_action) }
|
37
|
+
|
38
|
+
describe 'ComputeResource Sync' do
|
39
|
+
test 'syncs a compute resource' do
|
40
|
+
assert ::ForemanWreckingball::VmwareCluster.count.zero?
|
41
|
+
assert_equal :success, runned_action.state
|
42
|
+
refute ::ForemanWreckingball::VmwareCluster.count.zero?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
module ForemanWreckingball
|
4
|
+
class HostsControllerTest < ActionController::TestCase
|
5
|
+
let(:task_id) { 123 }
|
6
|
+
let(:fake_task) do
|
7
|
+
OpenStruct.new(
|
8
|
+
id: task_id
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#status_dashboard' do
|
13
|
+
test 'shows an empty status page' do
|
14
|
+
get :status_dashboard, {}, set_session_user
|
15
|
+
assert_response :success
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'shows a status page' do
|
19
|
+
FactoryGirl.create_list(:host, 5, :with_wreckingball_statuses)
|
20
|
+
get :status_dashboard, {}, set_session_user
|
21
|
+
assert_response :success
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#refresh_status_dashboard' do
|
26
|
+
test 'redirects to scheduled task' do
|
27
|
+
ForemanTasks.expects(:async_task).returns(fake_task)
|
28
|
+
put :refresh_status_dashboard, {}, set_session_user
|
29
|
+
assert_response :redirect
|
30
|
+
assert_includes flash[:success], 'successfully scheduled'
|
31
|
+
assert_redirected_to foreman_tasks_task_path(123)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#remediate' do
|
36
|
+
let(:host) do
|
37
|
+
FactoryGirl.create(:host, :with_wreckingball_statuses)
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'redirects to scheduled task' do
|
41
|
+
ForemanTasks.expects(:async_task).returns(fake_task)
|
42
|
+
put :remediate, { status_id: host.vmware_operatingsystem_status_object.id, id: host.id }, set_session_user
|
43
|
+
assert_response :redirect
|
44
|
+
assert_includes flash[:success], 'successfully scheduled'
|
45
|
+
assert_redirected_to foreman_tasks_task_path(123)
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'raises error when status can not be remediated' do
|
49
|
+
FactoryGirl.create(:host, :with_wreckingball_statuses)
|
50
|
+
assert_raises Foreman::Exception do
|
51
|
+
put :remediate, { status_id: host.vmware_tools_status_object.id, id: host.id }, set_session_user
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
test 'returns not found when host id is invalid' do
|
56
|
+
put :remediate, { status_id: nil, id: 'invalid' }, set_session_user
|
57
|
+
assert_response :not_found
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'returns not found when status id is invalid' do
|
61
|
+
FactoryGirl.create(:host, :with_wreckingball_statuses)
|
62
|
+
put :remediate, { status_id: 'invalid', id: host.id }, set_session_user
|
63
|
+
assert_response :not_found
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
FactoryGirl.modify do
|
2
|
+
factory :compute_resource do
|
3
|
+
trait :with_vmware_clusters do
|
4
|
+
transient do
|
5
|
+
vmware_clusters_count 1
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:create) do |compute_resource, evaluator|
|
9
|
+
create_list(:vmware_cluster, evaluator.vmware_clusters_count, compute_resource: compute_resource)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
FactoryGirl.define do
|
2
|
+
factory :vmware_facet, class: 'ForemanWreckingball::VmwareFacet' do
|
3
|
+
vmware_cluster
|
4
|
+
tools_state 2 #:toolsOk
|
5
|
+
cpus 2
|
6
|
+
corespersocket 1
|
7
|
+
memory_mb 8192
|
8
|
+
guest_id 'rhel6_64Guest'
|
9
|
+
cpu_hot_add false
|
10
|
+
host
|
11
|
+
end
|
12
|
+
|
13
|
+
factory :vmware_hypervisor_facet, class: 'ForemanWreckingball::VmwareHypervisorFacet' do
|
14
|
+
host
|
15
|
+
vmware_cluster
|
16
|
+
cpu_cores 18
|
17
|
+
cpu_sockets 1
|
18
|
+
cpu_threads 36
|
19
|
+
memory 412_046_372_864
|
20
|
+
uuid { SecureRandom.uuid }
|
21
|
+
end
|
22
|
+
|
23
|
+
factory :vmware_cluster, class: 'ForemanWreckingball::VmwareCluster' do
|
24
|
+
sequence(:name) { |n| "Cluster #{n}" }
|
25
|
+
association :compute_resource, factory: [:compute_resource, :vmware]
|
26
|
+
end
|
27
|
+
|
28
|
+
factory :vmware_tools_status, class: 'ForemanWreckingball::ToolsStatus' do
|
29
|
+
association :host, factory: [:host, :with_vmware_facet]
|
30
|
+
reported_at { Time.now.utc }
|
31
|
+
after(:build) { |status| status.status = status.to_status }
|
32
|
+
end
|
33
|
+
|
34
|
+
factory :vmware_operatingsystem_status, class: 'ForemanWreckingball::OperatingsystemStatus' do
|
35
|
+
association :host, factory: [:host, :with_vmware_facet]
|
36
|
+
reported_at { Time.now.utc }
|
37
|
+
after(:build) { |status| status.status = status.to_status }
|
38
|
+
end
|
39
|
+
|
40
|
+
factory :vmware_cpu_hot_add_status, class: 'ForemanWreckingball::CpuHotAddStatus' do
|
41
|
+
association :host, factory: [:host, :with_vmware_facet]
|
42
|
+
reported_at { Time.now.utc }
|
43
|
+
after(:build) { |status| status.status = status.to_status }
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
FactoryGirl.modify do
|
2
|
+
factory :host do
|
3
|
+
trait :with_vmware_facet do
|
4
|
+
vmware_facet
|
5
|
+
end
|
6
|
+
|
7
|
+
trait :with_vmware_hypervisor_facet do
|
8
|
+
vmware_hypervisor_facet
|
9
|
+
end
|
10
|
+
|
11
|
+
trait :with_vmware_tools_status do
|
12
|
+
with_vmware_facet
|
13
|
+
after(:create) do |host, _evaluator|
|
14
|
+
create :vmware_tools_status, host: host
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
trait :with_vmware_operatingsystem_status do
|
19
|
+
with_vmware_facet
|
20
|
+
after(:create) do |host, _evaluator|
|
21
|
+
create :vmware_operatingsystem_status, host: host
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
trait :with_vmware_cpu_hot_add_status do
|
26
|
+
with_vmware_facet
|
27
|
+
after(:create) do |host, _evaluator|
|
28
|
+
create :vmware_cpu_hot_add_status, host: host
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
trait :with_wreckingball_statuses do
|
33
|
+
with_vmware_tools_status
|
34
|
+
with_vmware_operatingsystem_status
|
35
|
+
with_vmware_cpu_hot_add_status
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test_plugin_helper'
|
2
|
+
|
3
|
+
class VmwareTest < ActiveSupport::TestCase
|
4
|
+
setup { Fog.mock! }
|
5
|
+
teardown { Fog.unmock! }
|
6
|
+
let(:compute_resource) { FactoryGirl.build(:vmware_cr, :uuid => 'Solutions') }
|
7
|
+
|
8
|
+
test '#hypervisors returns hosts by cluster' do
|
9
|
+
hosts = compute_resource.hypervisors(cluster_id: 'Solutionscluster').map(&:name)
|
10
|
+
assert_includes hosts, 'host1.example.com'
|
11
|
+
end
|
12
|
+
end
|