foreman_wreckingball 3.1.0 → 3.2.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 +3 -1
- data/app/assets/javascripts/foreman_wreckingball/modal.js +0 -1
- data/app/assets/javascripts/foreman_wreckingball/status_hosts_table.js +2 -2
- data/app/assets/javascripts/foreman_wreckingball/status_row.js +17 -0
- data/app/controllers/foreman_wreckingball/hosts_controller.rb +65 -35
- data/app/lib/actions/foreman_wreckingball/host/remediate_spectre_v2.rb +58 -0
- data/app/models/concerns/foreman_wreckingball/host_extensions.rb +10 -25
- data/app/models/concerns/foreman_wreckingball/host_status_extensions.rb +13 -0
- data/app/models/concerns/foreman_wreckingball/user_extensions.rb +12 -0
- data/app/models/concerns/foreman_wreckingball/usergroup_extensions.rb +18 -0
- data/app/models/concerns/foreman_wreckingball/vmware_facet_host_extensions.rb +10 -0
- data/app/models/foreman_wreckingball/cpu_hot_add_status.rb +8 -0
- data/app/models/foreman_wreckingball/hardware_version_status.rb +8 -0
- data/app/models/foreman_wreckingball/operatingsystem_status.rb +8 -0
- data/app/models/foreman_wreckingball/spectre_v2_status.rb +17 -1
- data/app/models/foreman_wreckingball/tools_status.rb +8 -0
- data/app/models/foreman_wreckingball/vmware_facet.rb +1 -5
- data/app/services/foreman_wreckingball/vmware_cluster_importer.rb +1 -6
- data/app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb +10 -21
- data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table.html.erb +1 -1
- data/app/views/foreman_wreckingball/hosts/status_dashboard.html.erb +1 -0
- data/app/views/foreman_wreckingball/hosts/status_managed_hosts_dashboard.html.erb +49 -0
- data/config/environments/production.rb +7 -0
- data/config/routes.rb +1 -0
- data/lib/foreman_wreckingball/engine.rb +21 -6
- data/lib/foreman_wreckingball/version.rb +1 -1
- data/test/actions/foreman_wreckingball/host/remediate_spectre_v2_test.rb +62 -0
- data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +180 -12
- data/test/factories/foreman_wreckingball_factories.rb +32 -0
- data/test/factories/host.rb +8 -0
- data/test/factories/task.rb +17 -0
- data/test/integration/hosts_status_dashboard_test.rb +50 -0
- data/test/integration/hosts_status_managed_hosts_test.rb +93 -0
- data/test/integration_test_plugin_helper.rb +12 -0
- data/test/models/host_status_test.rb +22 -0
- data/test/models/host_test.rb +64 -5
- data/test/models/usergroup_test.rb +25 -0
- data/test/test_plugin_helper.rb +17 -0
- data/test/unit/foreman_wreckingball/vmware_cluster_importer_test.rb +17 -2
- metadata +23 -2
@@ -7,6 +7,14 @@ module ForemanWreckingball
|
|
7
7
|
class Engine < ::Rails::Engine
|
8
8
|
engine_name 'foreman_wreckingball'
|
9
9
|
|
10
|
+
WRECKINGBALL_STATUSES = [
|
11
|
+
'ForemanWreckingball::ToolsStatus',
|
12
|
+
'ForemanWreckingball::OperatingsystemStatus',
|
13
|
+
'ForemanWreckingball::CpuHotAddStatus',
|
14
|
+
'ForemanWreckingball::SpectreV2Status',
|
15
|
+
'ForemanWreckingball::HardwareVersionStatus'
|
16
|
+
].freeze
|
17
|
+
|
10
18
|
config.autoload_paths += Dir["#{config.root}/app/lib"]
|
11
19
|
config.autoload_paths += Dir["#{config.root}/app/services"]
|
12
20
|
config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
|
@@ -47,7 +55,9 @@ module ForemanWreckingball
|
|
47
55
|
|
48
56
|
# Extend built in permissions
|
49
57
|
Foreman::AccessControl.permission(:view_hosts).actions.concat [
|
50
|
-
'foreman_wreckingball/hosts/status_dashboard'
|
58
|
+
'foreman_wreckingball/hosts/status_dashboard',
|
59
|
+
'foreman_wreckingball/hosts/status_managed_hosts_dashboard',
|
60
|
+
'foreman_wreckingball/hosts/status_hosts'
|
51
61
|
]
|
52
62
|
|
53
63
|
menu :top_menu, :wreckingball_status_dashboard, :url_hash => { :controller => :'foreman_wreckingball/hosts', :action => :status_dashboard },
|
@@ -55,11 +65,12 @@ module ForemanWreckingball
|
|
55
65
|
:parent => :hosts_menu,
|
56
66
|
:after => :hosts
|
57
67
|
|
58
|
-
register_custom_status(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
WRECKINGBALL_STATUSES.each { |status| register_custom_status(status.constantize) }
|
69
|
+
|
70
|
+
menu :top_menu, :wreckingball_status_managed_hosts_dashboard, url_hash: { :controller => :'foreman_wreckingball/hosts', :action => :status_managed_hosts_dashboard },
|
71
|
+
caption: N_('VMware Managed Status'),
|
72
|
+
parent: :monitor_menu,
|
73
|
+
after: :audits
|
63
74
|
|
64
75
|
register_facet(ForemanWreckingball::VmwareFacet, :vmware_facet)
|
65
76
|
|
@@ -87,12 +98,16 @@ module ForemanWreckingball
|
|
87
98
|
# Include concerns in this config.to_prepare block
|
88
99
|
config.to_prepare do
|
89
100
|
begin
|
101
|
+
::HostStatus.extend(ForemanWreckingball::HostStatusExtensions)
|
102
|
+
|
90
103
|
::ComputeResource.send(:include, ForemanWreckingball::ComputeResourceExtensions)
|
91
104
|
::Foreman::Model::Vmware.send(:include, ForemanWreckingball::VmwareExtensions)
|
92
105
|
::Host::Managed.send(:include, ForemanWreckingball::HostExtensions)
|
93
106
|
::Host::Managed.send(:include, ForemanWreckingball::VmwareFacetHostExtensions)
|
94
107
|
::Host::Managed.send(:include, ForemanWreckingball::VmwareHypervisorFacetHostExtensions)
|
95
108
|
::HostsHelper.send(:include, ForemanWreckingball::HostsHelperExtensions)
|
109
|
+
::User.send(:include, ForemanWreckingball::UserExtensions)
|
110
|
+
::Usergroup.send(:include, ForemanWreckingball::UsergroupExtensions)
|
96
111
|
|
97
112
|
if ForemanWreckingball.fog_patches_required?
|
98
113
|
Fog::Compute::Vsphere::Host.send(:include, FogExtensions::ForemanWreckingball::Vsphere::Host)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
module Actions
|
6
|
+
module ForemanWreckingball
|
7
|
+
module Vmware
|
8
|
+
class RemediateSpectreV2Test < ActiveSupport::TestCase
|
9
|
+
include ::Dynflow::Testing
|
10
|
+
setup do
|
11
|
+
::Fog.mock!
|
12
|
+
# this is not stubbed correctly in fog-vsphere
|
13
|
+
Fog::Compute::Vsphere::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
|
14
|
+
Fog::Compute::Vsphere::Server.any_instance.stubs(:hardware_version).returns('vmx-13')
|
15
|
+
::ForemanWreckingball::SpectreV2Status.any_instance.stubs(:recent_hw_version?).returns(true)
|
16
|
+
::PowerManager::Virt.any_instance.stubs(:ready?).returns(true)
|
17
|
+
Setting::Wreckingball.load_defaults
|
18
|
+
end
|
19
|
+
teardown { ::Fog.unmock! }
|
20
|
+
|
21
|
+
let(:compute_resource) do
|
22
|
+
cr = FactoryBot.create(:compute_resource, :vmware, :with_taxonomy, :uuid => 'Solutions')
|
23
|
+
ComputeResource.find(cr.id)
|
24
|
+
end
|
25
|
+
let(:uuid) { '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
|
26
|
+
let(:vm) { compute_resource.find_vm_by_uuid(uuid) }
|
27
|
+
|
28
|
+
let(:host) do
|
29
|
+
FactoryBot.create(
|
30
|
+
:host,
|
31
|
+
:managed,
|
32
|
+
:with_vmware_facet,
|
33
|
+
compute_resource: compute_resource,
|
34
|
+
uuid: uuid
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:action_class) { ::Actions::ForemanWreckingball::Host::RemediateSpectreV2 }
|
39
|
+
let(:action) do
|
40
|
+
create_action(action_class).tap do |action|
|
41
|
+
action.stubs(:action_subject).returns(host)
|
42
|
+
action.input.update(
|
43
|
+
host: {
|
44
|
+
id: host.id
|
45
|
+
}
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
let(:planned_action) do
|
50
|
+
plan_action(action, host)
|
51
|
+
end
|
52
|
+
let(:runned_action) { run_action(planned_action) }
|
53
|
+
|
54
|
+
test "it remediates the host's spectre v2 status" do
|
55
|
+
assert_equal :success, runned_action.state
|
56
|
+
assert_equal true, runned_action.output.fetch('state')
|
57
|
+
assert_equal true, runned_action.output.fetch('initially_powered_on')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -4,31 +4,152 @@ require 'test_plugin_helper'
|
|
4
4
|
|
5
5
|
module ForemanWreckingball
|
6
6
|
class HostsControllerTest < ActionController::TestCase
|
7
|
-
let(:
|
8
|
-
let(:fake_task) do
|
9
|
-
OpenStruct.new(
|
10
|
-
id: task_id
|
11
|
-
)
|
12
|
-
end
|
7
|
+
let(:fake_task) { OpenStruct.new(id: 123) }
|
13
8
|
|
14
9
|
setup do
|
15
10
|
Setting::Wreckingball.load_defaults
|
16
11
|
end
|
17
12
|
|
18
13
|
describe '#status_dashboard' do
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
context 'when there are no hosts with wreckingball statuses' do
|
15
|
+
test 'shows an empty status page' do
|
16
|
+
get :status_dashboard, session: set_session_user
|
17
|
+
assert_response :success
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when there are hosts with wreckingball statuses' do
|
22
|
+
context 'for admin user' do
|
23
|
+
setup do
|
24
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: users(:admin))
|
25
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:usergroup, users: [users(:admin)]))
|
26
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:user))
|
27
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:usergroup))
|
28
|
+
end
|
29
|
+
|
30
|
+
test 'shows a status page' do
|
31
|
+
get :status_dashboard, session: set_session_user
|
32
|
+
assert_response :success
|
33
|
+
end
|
34
|
+
|
35
|
+
test 'should count all hosts' do
|
36
|
+
get :status_dashboard, session: set_session_user
|
37
|
+
assert_equal 4, assigns[:data].first[:counter][:ok]
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'should count only owned hosts' do
|
41
|
+
get :status_dashboard, params: { owned_only: true }, session: set_session_user
|
42
|
+
assert_equal 2, assigns[:data].first[:counter][:ok]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'for user with custom role' do
|
47
|
+
let(:search) { "owner = current_user or (owner_type = Usergroup and owner_id = #{user.usergroups.first.id}) or hostgroup_id = #{hostgroup.id} or name ~ #{host_name_prefix}" }
|
48
|
+
let(:filter) do
|
49
|
+
FactoryBot.create(:filter,
|
50
|
+
search: search,
|
51
|
+
permissions: Permission.where(name: 'view_hosts'))
|
52
|
+
end
|
53
|
+
let(:role) { FactoryBot.create(:role) }
|
54
|
+
let(:user) { FactoryBot.create(:user, :with_mail, :with_usergroup, admin: false, roles: [role]) }
|
55
|
+
let(:hostgroup) { FactoryBot.create(:hostgroup) }
|
56
|
+
let(:host_name_prefix) { 'abc' }
|
57
|
+
|
58
|
+
setup do
|
59
|
+
# hosts that match search query
|
60
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: user)
|
61
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: user.usergroups.first)
|
62
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, hostgroup: hostgroup)
|
63
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, name: "#{host_name_prefix}123", hostname: "#{host_name_prefix}123")
|
64
|
+
# hosts that do not match search query
|
65
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:user))
|
66
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:usergroup))
|
67
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, hostgroup: FactoryBot.create(:hostgroup))
|
68
|
+
FactoryBot.create(:host, :with_wreckingball_statuses)
|
69
|
+
end
|
70
|
+
|
71
|
+
setup do
|
72
|
+
role.filters << filter
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'should count only hosts that match search query' do
|
76
|
+
get :status_dashboard, session: set_session_user(user)
|
77
|
+
|
78
|
+
expected_4_ok = { ok: 4, warning: 0, critical: 0 }
|
79
|
+
expected_4_critical = { ok: 0, warning: 0, critical: 4 }
|
80
|
+
|
81
|
+
assert_equal expected_4_ok, assigns[:data][0][:counter]
|
82
|
+
assert_equal expected_4_ok, assigns[:data][1][:counter]
|
83
|
+
assert_equal expected_4_ok, assigns[:data][2][:counter]
|
84
|
+
assert_equal expected_4_critical, assigns[:data][3][:counter]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#status_managed_hosts_dashboard' do
|
91
|
+
let(:admin) { users(:admin) }
|
92
|
+
let(:organization) { Organization.find_by(name: 'Organization 1') }
|
93
|
+
let(:tax_location) { Location.find_by(name: 'Location 1') }
|
94
|
+
let(:cr) do
|
95
|
+
FactoryBot.create(
|
96
|
+
:vmware_cr,
|
97
|
+
uuid: 'test',
|
98
|
+
organizations: [organization],
|
99
|
+
locations: [tax_location]
|
100
|
+
)
|
101
|
+
end
|
102
|
+
let(:other_cr) do
|
103
|
+
FactoryBot.create(
|
104
|
+
:vmware_cr,
|
105
|
+
uuid: 'bla',
|
106
|
+
organizations: [organization],
|
107
|
+
locations: [tax_location]
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
setup do
|
112
|
+
Fog.mock!
|
113
|
+
@managed_host = FactoryBot.create(:host, :managed, :with_vmware_facet, compute_resource: cr, owner: admin, uuid: 1)
|
114
|
+
@missing_host = FactoryBot.create(:host, :managed, :with_vmware_facet, compute_resource: cr, owner: admin, uuid: 2)
|
115
|
+
|
116
|
+
mock_vm = mock('vm')
|
117
|
+
mock_vm.stubs(:uuid).returns(@managed_host.uuid)
|
118
|
+
mock_vm.stubs(:name).returns(@managed_host.name)
|
119
|
+
Foreman::Model::Vmware.any_instance.stubs(:vms).returns(Array(mock_vm))
|
22
120
|
end
|
23
121
|
|
24
122
|
test 'shows a status page' do
|
25
|
-
|
26
|
-
get :status_dashboard, session: set_session_user
|
123
|
+
get :status_managed_hosts_dashboard, session: set_session_user
|
27
124
|
assert_response :success
|
28
125
|
end
|
126
|
+
|
127
|
+
test 'should contain host with missing vm' do
|
128
|
+
get :status_managed_hosts_dashboard, session: set_session_user
|
129
|
+
assert_includes assigns[:missing_hosts], @missing_host
|
130
|
+
end
|
131
|
+
|
132
|
+
test 'should filter host with vm' do
|
133
|
+
get :status_managed_hosts_dashboard, session: set_session_user
|
134
|
+
refute_includes assigns[:missing_hosts], @managed_host
|
135
|
+
end
|
29
136
|
end
|
30
137
|
|
31
138
|
describe '#status_hosts' do
|
139
|
+
test 'returns correct counts' do
|
140
|
+
FactoryBot.create_list(:vmware_hardware_version_status, 3, :with_ok_status)
|
141
|
+
FactoryBot.create_list(:vmware_hardware_version_status, 4, :with_out_of_date_status)
|
142
|
+
|
143
|
+
get :status_hosts, params: { status: ::ForemanWreckingball::HardwareVersionStatus.host_association },
|
144
|
+
session: set_session_user, xhr: true
|
145
|
+
|
146
|
+
assert_response :ok
|
147
|
+
json = JSON.parse(response.body)
|
148
|
+
assert_equal 4, json['recordsTotal']
|
149
|
+
assert_equal 4, json['recordsFiltered']
|
150
|
+
assert_equal 4, json['data'].size
|
151
|
+
end
|
152
|
+
|
32
153
|
test 'returns hosts for status' do
|
33
154
|
ok_status = FactoryBot.create(:vmware_hardware_version_status, :with_ok_status)
|
34
155
|
out_of_date_status = FactoryBot.create(:vmware_hardware_version_status, :with_out_of_date_status)
|
@@ -37,20 +158,67 @@ module ForemanWreckingball
|
|
37
158
|
session: set_session_user, xhr: true
|
38
159
|
|
39
160
|
assert_response :ok
|
40
|
-
|
161
|
+
|
162
|
+
data = JSON.parse(response.body)['data']
|
163
|
+
|
164
|
+
hosts_names = data.map { |host| host['name'] }
|
165
|
+
assert_equal 1, data.size
|
41
166
|
assert_includes hosts_names, out_of_date_status.host.name
|
42
167
|
refute_includes hosts_names, ok_status.host.name
|
43
168
|
end
|
169
|
+
|
170
|
+
test 'returns hosts for spectre v2 status' do
|
171
|
+
FactoryBot.create_list(:vmware_spectre_v2_status, 1, :with_enabled)
|
172
|
+
FactoryBot.create_list(:vmware_spectre_v2_status, 2, :with_missing)
|
173
|
+
|
174
|
+
get :status_hosts, params: { status: ::ForemanWreckingball::SpectreV2Status.host_association },
|
175
|
+
session: set_session_user, xhr: true
|
176
|
+
|
177
|
+
data = JSON.parse(response.body)['data']
|
178
|
+
assert_equal 2, data.size
|
179
|
+
end
|
180
|
+
|
181
|
+
describe 'filtering by owner' do
|
182
|
+
setup do
|
183
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: users(:admin))
|
184
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:usergroup, users: [users(:admin)]))
|
185
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:user))
|
186
|
+
FactoryBot.create(:host, :with_wreckingball_statuses, owner: FactoryBot.create(:usergroup))
|
187
|
+
end
|
188
|
+
|
189
|
+
test 'should show all hosts' do
|
190
|
+
get :status_hosts, params: { status: ::ForemanWreckingball::SpectreV2Status.host_association },
|
191
|
+
session: set_session_user, xhr: true
|
192
|
+
assert_equal 4, JSON.parse(response.body)['data'].count
|
193
|
+
end
|
194
|
+
|
195
|
+
test 'should show only owned hosts' do
|
196
|
+
get :status_hosts, params: { status: ::ForemanWreckingball::SpectreV2Status.host_association, owned_only: true },
|
197
|
+
session: set_session_user, xhr: true
|
198
|
+
assert_equal 2, JSON.parse(response.body)['data'].count
|
199
|
+
end
|
200
|
+
end
|
44
201
|
end
|
45
202
|
|
46
203
|
describe '#refresh_status_dashboard' do
|
47
204
|
test 'redirects to scheduled task' do
|
205
|
+
FactoryBot.create(:some_task, :vmware_sync, :stopped)
|
206
|
+
|
48
207
|
ForemanTasks.expects(:async_task).returns(fake_task)
|
49
208
|
put :refresh_status_dashboard, session: set_session_user
|
50
209
|
assert_response :redirect
|
51
210
|
assert_includes flash[:success], 'successfully scheduled'
|
52
211
|
assert_redirected_to foreman_tasks_task_path(123)
|
53
212
|
end
|
213
|
+
|
214
|
+
test 'show flash warning message when task is already running' do
|
215
|
+
FactoryBot.create(:some_task, :vmware_sync, :running)
|
216
|
+
|
217
|
+
put :refresh_status_dashboard, session: set_session_user
|
218
|
+
assert_response :redirect
|
219
|
+
assert_includes flash[:warning], 'task is already running'
|
220
|
+
assert_redirected_to status_dashboard_hosts_path
|
221
|
+
end
|
54
222
|
end
|
55
223
|
|
56
224
|
describe '#schedule_remediate' do
|
@@ -131,6 +131,24 @@ FactoryBot.define do
|
|
131
131
|
factory :vmware_cluster, class: 'ForemanWreckingball::VmwareCluster' do
|
132
132
|
sequence(:name) { |n| "Cluster #{n}" }
|
133
133
|
association :compute_resource, factory: [:compute_resource, :vmware]
|
134
|
+
|
135
|
+
trait(:with_hosts) do
|
136
|
+
after(:create) do |vmware_cluster|
|
137
|
+
create_list(:vmware_hypervisor_facet, 2, vmware_cluster: vmware_cluster)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
trait(:with_vmware_facets) do
|
142
|
+
after(:create) do |vmware_cluster|
|
143
|
+
create_list(:vmware_facet, 2, vmware_cluster: vmware_cluster)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
trait(:with_vmware_hypervisor_facets) do
|
148
|
+
after(:create) do |vmware_cluster|
|
149
|
+
create_list(:vmware_hypervisor_facet, 2, vmware_cluster: vmware_cluster)
|
150
|
+
end
|
151
|
+
end
|
134
152
|
end
|
135
153
|
|
136
154
|
factory :vmware_tools_status, class: 'ForemanWreckingball::ToolsStatus' do
|
@@ -151,6 +169,20 @@ FactoryBot.define do
|
|
151
169
|
after(:build) { |status| status.status = status.to_status }
|
152
170
|
end
|
153
171
|
|
172
|
+
factory :vmware_spectre_v2_status, class: 'ForemanWreckingball::SpectreV2Status' do
|
173
|
+
association :host, factory: [:host, :with_vmware_facet]
|
174
|
+
reported_at { Time.now.utc }
|
175
|
+
after(:build) { |status| status.status = status.to_status }
|
176
|
+
|
177
|
+
trait(:with_enabled) do
|
178
|
+
after(:build) { |status| status.status = ForemanWreckingball::SpectreV2Status::ENABLED }
|
179
|
+
end
|
180
|
+
|
181
|
+
trait(:with_missing) do
|
182
|
+
after(:build) { |status| status.status = ForemanWreckingball::SpectreV2Status::MISSING }
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
154
186
|
factory :vmware_hardware_version_status, class: 'ForemanWreckingball::HardwareVersionStatus' do
|
155
187
|
association :host, factory: [:host, :with_vmware_facet]
|
156
188
|
reported_at { Time.now.utc }
|
data/test/factories/host.rb
CHANGED
@@ -38,10 +38,18 @@ FactoryBot.modify do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
trait :with_vmware_spectrev2_status do
|
42
|
+
with_vmware_facet
|
43
|
+
after(:create) do |host, _evaluator|
|
44
|
+
create :vmware_spectre_v2_status, host: host
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
41
48
|
trait :with_wreckingball_statuses do
|
42
49
|
with_vmware_tools_status
|
43
50
|
with_vmware_operatingsystem_status
|
44
51
|
with_vmware_cpu_hot_add_status
|
52
|
+
with_vmware_spectrev2_status
|
45
53
|
with_vmware_hardware_version_status
|
46
54
|
end
|
47
55
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
FactoryBot.modify do
|
4
|
+
factory :some_task do
|
5
|
+
trait :running do
|
6
|
+
state 'running'
|
7
|
+
end
|
8
|
+
|
9
|
+
trait :stopped do
|
10
|
+
state 'stopped'
|
11
|
+
end
|
12
|
+
|
13
|
+
trait :vmware_sync do
|
14
|
+
label ::Actions::ForemanWreckingball::Vmware::ScheduleVmwareSync.to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'integration_test_plugin_helper'
|
4
|
+
|
5
|
+
class HostsStatusDashboardTest < ActionDispatch::IntegrationTest
|
6
|
+
setup do
|
7
|
+
Setting::Wreckingball.load_defaults
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'shows different vmware host statuses' do
|
11
|
+
FactoryBot.create_list(:host, 10)
|
12
|
+
FactoryBot.create_list(:vmware_tools_status, 1)
|
13
|
+
FactoryBot.create_list(:vmware_operatingsystem_status, 2)
|
14
|
+
FactoryBot.create_list(:vmware_cpu_hot_add_status, 3)
|
15
|
+
FactoryBot.create_list(:vmware_spectre_v2_status, 4, :with_enabled)
|
16
|
+
FactoryBot.create_list(:vmware_spectre_v2_status, 5, :with_missing)
|
17
|
+
FactoryBot.create_list(:vmware_hardware_version_status, 6, :with_ok_status)
|
18
|
+
FactoryBot.create_list(:vmware_hardware_version_status, 7, :with_out_of_date_status)
|
19
|
+
|
20
|
+
User.current = users(:admin)
|
21
|
+
visit status_dashboard_hosts_path
|
22
|
+
|
23
|
+
lists = find_all('div.list-view-pf-main-info')
|
24
|
+
|
25
|
+
# VMWare Tools
|
26
|
+
assert_text lists[0].text, '1 OK'
|
27
|
+
assert_text lists[0].text, '0 Warning'
|
28
|
+
assert_text lists[0].text, '0 Critical'
|
29
|
+
|
30
|
+
# VMWare Operating System
|
31
|
+
assert_text lists[1].text, '2 OK'
|
32
|
+
assert_text lists[1].text, '0 Warning'
|
33
|
+
assert_text lists[1].text, '0 Critical'
|
34
|
+
|
35
|
+
# VMWare CPU Hot Plug
|
36
|
+
assert_text lists[2].text, '3 OK'
|
37
|
+
assert_text lists[2].text, '0 Warning'
|
38
|
+
assert_text lists[2].text, '0 Critical'
|
39
|
+
|
40
|
+
# VMWare Spectre V2
|
41
|
+
assert_text lists[3].text, '4 OK'
|
42
|
+
assert_text lists[3].text, '0 Warning'
|
43
|
+
assert_text lists[3].text, '5 Critical'
|
44
|
+
|
45
|
+
# VMWare Hardware Version
|
46
|
+
assert_text lists[4].text, '6 OK'
|
47
|
+
assert_text lists[4].text, '7 Warning'
|
48
|
+
assert_text lists[4].text, '0 Critical'
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'integration_test_plugin_helper'
|
4
|
+
|
5
|
+
class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
|
6
|
+
setup do
|
7
|
+
Setting::Wreckingball.load_defaults
|
8
|
+
Fog.mock!
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:organization) { Organization.find_by(name: 'Organization 1') }
|
12
|
+
let(:tax_location) { Location.find_by(name: 'Location 1') }
|
13
|
+
let(:admin) { users(:admin) }
|
14
|
+
let(:cr) do
|
15
|
+
FactoryBot.create(
|
16
|
+
:vmware_cr,
|
17
|
+
uuid: 'test',
|
18
|
+
organizations: [organization],
|
19
|
+
locations: [tax_location]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'shows missing host without VMware vm' do
|
24
|
+
managed_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 1)
|
25
|
+
missing_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 2)
|
26
|
+
|
27
|
+
mock_vm = mock('vm')
|
28
|
+
mock_vm.stubs(:uuid).returns(managed_host.uuid)
|
29
|
+
mock_vm.stubs(:name).returns(managed_host.name)
|
30
|
+
Foreman::Model::Vmware.any_instance.stubs(:vms).returns(Array(mock_vm))
|
31
|
+
|
32
|
+
visit status_managed_hosts_dashboard_hosts_path
|
33
|
+
|
34
|
+
list = page.find('#missing_vms')
|
35
|
+
assert_includes list.text, missing_host.name
|
36
|
+
refute_includes list.text, managed_host.name
|
37
|
+
end
|
38
|
+
|
39
|
+
test 'shows duplicate vms with same uuid for a host' do
|
40
|
+
managed_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 1)
|
41
|
+
|
42
|
+
mock1_vm = mock('vm1')
|
43
|
+
mock1_vm.stubs(:uuid).returns(managed_host.uuid)
|
44
|
+
mock1_vm.stubs(:name).returns('foo01.example.com')
|
45
|
+
mock2_vm = mock('vm2')
|
46
|
+
mock2_vm.stubs(:uuid).returns(managed_host.uuid)
|
47
|
+
mock2_vm.stubs(:name).returns('foo02.example.com')
|
48
|
+
Foreman::Model::Vmware.any_instance.stubs(:vms).returns([mock1_vm, mock2_vm])
|
49
|
+
|
50
|
+
visit status_managed_hosts_dashboard_hosts_path
|
51
|
+
|
52
|
+
list = page.find('#duplicate_vms')
|
53
|
+
assert_includes list.text, 'foo01.example.com'
|
54
|
+
assert_includes list.text, 'foo02.example.com'
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'shows hosts with vm associated with a different compute resource' do
|
58
|
+
other_cr = FactoryBot.create(
|
59
|
+
:vmware_cr,
|
60
|
+
uuid: 'bla',
|
61
|
+
organizations: [organization],
|
62
|
+
locations: [tax_location]
|
63
|
+
)
|
64
|
+
|
65
|
+
# Host 2 is associated to other_cr, but shows up on cr
|
66
|
+
# Host 1 and 3 are correctly associated.
|
67
|
+
managed1_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 1)
|
68
|
+
managed2_host = FactoryBot.create(:host, :managed, compute_resource: other_cr, owner: admin, uuid: 2)
|
69
|
+
managed3_host = FactoryBot.create(:host, :managed, compute_resource: other_cr, owner: admin, uuid: 3)
|
70
|
+
|
71
|
+
mock1_vm = mock('vm1')
|
72
|
+
mock1_vm.stubs(:uuid).returns(managed1_host.uuid)
|
73
|
+
mock1_vm.stubs(:name).returns(managed1_host.name)
|
74
|
+
mock2_vm = mock('vm2')
|
75
|
+
mock2_vm.stubs(:uuid).returns(managed2_host.uuid)
|
76
|
+
mock2_vm.stubs(:name).returns(managed2_host.name)
|
77
|
+
mock3_vm = mock('vm3')
|
78
|
+
mock3_vm.stubs(:uuid).returns(managed3_host.uuid)
|
79
|
+
mock3_vm.stubs(:name).returns(managed3_host.name)
|
80
|
+
|
81
|
+
cr.stubs(:vms).returns([mock1_vm, mock2_vm])
|
82
|
+
other_cr.stubs(:vms).returns([mock3_vm])
|
83
|
+
|
84
|
+
ComputeResource.stubs(:where).returns([cr, other_cr])
|
85
|
+
|
86
|
+
visit status_managed_hosts_dashboard_hosts_path
|
87
|
+
|
88
|
+
list = page.find('#different_vms')
|
89
|
+
refute_includes list.text, managed1_host.name
|
90
|
+
assert_includes list.text, managed2_host.name
|
91
|
+
refute_includes list.text, managed3_host.name
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'integration_test_helper'
|
4
|
+
|
5
|
+
require 'webmock/minitest'
|
6
|
+
require 'webmock'
|
7
|
+
|
8
|
+
# Add plugin to FactoryBot's paths
|
9
|
+
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
10
|
+
FactoryBot.reload
|
11
|
+
|
12
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_plugin_helper'
|
4
|
+
|
5
|
+
class HostStatusTest < ActiveSupport::TestCase
|
6
|
+
describe '#wreckingball_statuses' do
|
7
|
+
test 'returns wreckingball statuses' do
|
8
|
+
expected = ForemanWreckingball::Engine::WRECKINGBALL_STATUSES.sort.map(&:constantize)
|
9
|
+
actual = HostStatus.wreckingball_statuses.sort_by(&:to_s)
|
10
|
+
assert_equal expected, actual
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#find_wreckingball_status_by_host_association' do
|
15
|
+
test 'returns expected wreckingball status' do
|
16
|
+
expected = ForemanWreckingball::Engine::WRECKINGBALL_STATUSES.first.constantize
|
17
|
+
actual = HostStatus.find_wreckingball_status_by_host_association(expected.host_association)
|
18
|
+
|
19
|
+
assert_equal expected, actual
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|