foreman_wreckingball 3.2.0 → 4.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/assets/javascripts/foreman_wreckingball/modal.js +26 -17
- data/app/assets/javascripts/foreman_wreckingball/status_hosts_table.js +34 -2
- data/app/assets/javascripts/foreman_wreckingball/status_managed_hosts_dashboard.js +14 -0
- data/app/assets/stylesheets/foreman_wreckingball/status_hosts_table.css.scss +7 -0
- data/app/assets/stylesheets/foreman_wreckingball/status_managed_hosts_dashboard.css.scss +8 -0
- data/app/controllers/foreman_wreckingball/hosts_controller.rb +73 -43
- data/app/helpers/foreman_wreckingball/statuses_helper.rb +21 -0
- data/app/lib/actions/foreman_wreckingball/bulk_remediate.rb +27 -0
- data/app/lib/vsphere_os_identifiers/data.yaml +14 -0
- data/app/models/concerns/foreman_wreckingball/host_extensions.rb +4 -0
- data/app/models/concerns/foreman_wreckingball/host_status_extensions.rb +1 -1
- data/app/models/foreman_wreckingball/spectre_v2_status.rb +1 -1
- data/app/models/foreman_wreckingball/vmware_hypervisor_facet.rb +4 -7
- data/app/models/setting/wreckingball.rb +7 -3
- data/app/services/foreman_wreckingball/vmware_hypervisor_importer.rb +1 -3
- data/app/views/foreman_wreckingball/hosts/_hosts.json.rabl +9 -13
- data/app/views/foreman_wreckingball/hosts/_status_dashboard_content.erb +2 -0
- data/app/views/foreman_wreckingball/hosts/_status_managed_hosts_dashboard_cards.html.erb +16 -0
- data/app/views/foreman_wreckingball/hosts/_status_managed_hosts_dashboard_cards_card.html.erb +11 -0
- data/app/views/foreman_wreckingball/hosts/_status_row.html.erb +8 -12
- data/app/views/foreman_wreckingball/hosts/_status_row_actions.html.erb +22 -0
- data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table.html.erb +8 -1
- data/app/views/foreman_wreckingball/hosts/_status_row_hosts_table_actions.html.erb +9 -0
- data/app/views/foreman_wreckingball/hosts/schedule_remediate.html.erb +44 -26
- data/app/views/foreman_wreckingball/hosts/status_dashboard.html.erb +6 -6
- data/app/views/foreman_wreckingball/hosts/status_managed_hosts_dashboard.html.erb +121 -28
- data/config/routes.rb +2 -4
- data/lib/foreman_wreckingball/engine.rb +41 -24
- data/lib/foreman_wreckingball/version.rb +1 -1
- data/lib/tasks/foreman_vmware_checks_tasks.rake +1 -1
- data/test/actions/foreman_wreckingball/bulk_remediate_test.rb +31 -0
- data/test/actions/foreman_wreckingball/host/refresh_vmware_facet_test.rb +3 -3
- data/test/actions/foreman_wreckingball/host/remediate_hardware_version_test.rb +2 -2
- data/test/actions/foreman_wreckingball/host/remediate_spectre_v2_test.rb +2 -2
- data/test/actions/foreman_wreckingball/host/remediate_vmware_operatingsystem_test.rb +1 -1
- data/test/controllers/foreman_wreckingball/hosts_controller_test.rb +83 -31
- data/test/factories/compute_resource.rb +1 -1
- data/test/factories/foreman_wreckingball_factories.rb +120 -116
- data/test/factories/task.rb +3 -3
- data/test/helpers/foreman_wreckingball/status_helper.rb +10 -0
- data/test/integration/hosts_status_dashboard_test.rb +15 -15
- data/test/integration/hosts_status_managed_hosts_test.rb +30 -18
- data/test/integration_test_plugin_helper.rb +1 -0
- data/test/models/foreman_wreckingball/vmware_facet_test.rb +5 -5
- data/test/models/host_test.rb +2 -2
- data/test/test_plugin_helper.rb +2 -0
- metadata +20 -9
@@ -114,9 +114,9 @@ module ForemanWreckingball
|
|
114
114
|
@missing_host = FactoryBot.create(:host, :managed, :with_vmware_facet, compute_resource: cr, owner: admin, uuid: 2)
|
115
115
|
|
116
116
|
mock_vm = mock('vm')
|
117
|
-
mock_vm.stubs(:
|
117
|
+
mock_vm.stubs(:id).returns(@managed_host.uuid)
|
118
118
|
mock_vm.stubs(:name).returns(@managed_host.name)
|
119
|
-
Foreman::Model::Vmware.any_instance.stubs(:vms).returns(Array(mock_vm))
|
119
|
+
Foreman::Model::Vmware.any_instance.stubs(:vms).returns(OpenStruct.new(all: Array(mock_vm)))
|
120
120
|
end
|
121
121
|
|
122
122
|
test 'shows a status page' do
|
@@ -222,56 +222,108 @@ module ForemanWreckingball
|
|
222
222
|
end
|
223
223
|
|
224
224
|
describe '#schedule_remediate' do
|
225
|
-
let(:host)
|
226
|
-
|
227
|
-
end
|
225
|
+
let(:host) { FactoryBot.create(:host, :with_wreckingball_statuses) }
|
226
|
+
let(:status_ids) { [host.vmware_tools_status_object.id] }
|
228
227
|
|
229
228
|
test 'shows a remediation schedule page' do
|
230
|
-
get :schedule_remediate, params: {
|
229
|
+
get :schedule_remediate, params: { status_ids: status_ids }, session: set_session_user
|
231
230
|
assert_response :success
|
232
231
|
end
|
233
232
|
|
234
|
-
|
235
|
-
|
236
|
-
|
233
|
+
context 'with status_id' do
|
234
|
+
let(:hosts) { FactoryBot.create_list(:host, 2, :with_wreckingball_statuses) }
|
235
|
+
let(:status_ids) { [hosts.first.vmware_operatingsystem_status_object.id] }
|
236
|
+
|
237
|
+
test 'remediate selected statuses' do
|
238
|
+
get :schedule_remediate, params: { status_ids: status_ids }, session: set_session_user
|
239
|
+
assert_same_elements HostStatus::Status.find(status_ids), assigns['statuses']
|
240
|
+
end
|
237
241
|
end
|
238
242
|
|
239
|
-
|
240
|
-
FactoryBot.
|
241
|
-
|
242
|
-
|
243
|
+
context 'with host_association' do
|
244
|
+
let(:hosts) { FactoryBot.create_list(:host, 2, :with_wreckingball_statuses, owner: users(:admin)) }
|
245
|
+
let(:statuses) { hosts.map { |h| h.send(host_association) } }
|
246
|
+
let(:status_class) { ForemanWreckingball::OperatingsystemStatus }
|
247
|
+
let(:host_association) { status_class.host_association }
|
248
|
+
|
249
|
+
setup do
|
250
|
+
hosts.each { |h| h.send(host_association).update(status: status_class::MISMATCH) }
|
251
|
+
end
|
252
|
+
|
253
|
+
test 'remediate all statuses' do
|
254
|
+
get :schedule_remediate, params: { host_association: host_association }, session: set_session_user
|
255
|
+
assert_same_elements statuses, assigns['statuses']
|
256
|
+
end
|
257
|
+
|
258
|
+
context 'with owned_only' do
|
259
|
+
setup do
|
260
|
+
hosts_list = FactoryBot.create_list(:host, 2, :with_wreckingball_statuses, owner: users(:one))
|
261
|
+
hosts_list.each { |h| h.send(host_association).update(status: status_class::MISMATCH) }
|
262
|
+
end
|
263
|
+
|
264
|
+
test 'remediate only those statuses where the user is the owner of the host' do
|
265
|
+
get :schedule_remediate, params: { host_association: host_association, owned_only: true }, session: set_session_user
|
266
|
+
assert_same_elements statuses, assigns['statuses']
|
267
|
+
end
|
268
|
+
end
|
243
269
|
end
|
244
270
|
end
|
245
271
|
|
246
272
|
describe '#submit_remediate' do
|
247
|
-
let(:host)
|
248
|
-
|
273
|
+
let(:host) { FactoryBot.create(:host, :with_wreckingball_statuses) }
|
274
|
+
let(:status_ids) { [host.vmware_tools_status_object.id] }
|
275
|
+
|
276
|
+
setup do
|
277
|
+
ForemanTasks.stubs(:async_task).returns(fake_task)
|
249
278
|
end
|
250
279
|
|
251
280
|
test 'redirects to scheduled task' do
|
252
|
-
|
253
|
-
post :submit_remediate, params: { status_id: host.vmware_operatingsystem_status_object.id, id: host.id }, session: set_session_user
|
281
|
+
post :submit_remediate, params: { status_ids: status_ids }, session: set_session_user
|
254
282
|
assert_response :redirect
|
255
|
-
|
256
|
-
assert_redirected_to foreman_tasks_task_path(123)
|
283
|
+
assert_redirected_to foreman_tasks_task_path(fake_task.id)
|
257
284
|
end
|
258
285
|
|
259
|
-
test '
|
260
|
-
|
261
|
-
|
262
|
-
post :submit_remediate, params: { status_id: host.vmware_tools_status_object.id, id: host.id }, session: set_session_user
|
263
|
-
end
|
286
|
+
test 'returns not found when status_ids param is invalid' do
|
287
|
+
post :submit_remediate, params: { status_ids: 'invalid' }, session: set_session_user
|
288
|
+
assert_response :not_found
|
264
289
|
end
|
265
290
|
|
266
|
-
|
267
|
-
|
268
|
-
|
291
|
+
context 'with status_id' do
|
292
|
+
let(:hosts) { FactoryBot.create_list(:host, 2, :with_wreckingball_statuses) }
|
293
|
+
let(:status_ids) { [hosts.first.vmware_operatingsystem_status_object.id] }
|
294
|
+
|
295
|
+
test 'remediate selected statuses' do
|
296
|
+
post :submit_remediate, params: { status_ids: status_ids }, session: set_session_user
|
297
|
+
assert_same_elements HostStatus::Status.find(status_ids), assigns['statuses']
|
298
|
+
end
|
269
299
|
end
|
270
300
|
|
271
|
-
|
272
|
-
FactoryBot.
|
273
|
-
|
274
|
-
|
301
|
+
context 'with host_association' do
|
302
|
+
let(:hosts) { FactoryBot.create_list(:host, 2, :with_wreckingball_statuses, owner: users(:admin)) }
|
303
|
+
let(:statuses) { hosts.map { |h| h.send(host_association) } }
|
304
|
+
let(:status_class) { ForemanWreckingball::OperatingsystemStatus }
|
305
|
+
let(:host_association) { status_class.host_association }
|
306
|
+
|
307
|
+
setup do
|
308
|
+
hosts.each { |h| h.send(host_association).update(status: status_class::MISMATCH) }
|
309
|
+
end
|
310
|
+
|
311
|
+
test 'remediate all statuses' do
|
312
|
+
post :submit_remediate, params: { host_association: host_association }, session: set_session_user
|
313
|
+
assert_same_elements statuses, assigns['statuses']
|
314
|
+
end
|
315
|
+
|
316
|
+
context 'with owned_only' do
|
317
|
+
setup do
|
318
|
+
hosts_list = FactoryBot.create_list(:host, 2, :with_wreckingball_statuses, owner: users(:one))
|
319
|
+
hosts_list.each { |h| h.send(host_association).update(status: status_class::MISMATCH) }
|
320
|
+
end
|
321
|
+
|
322
|
+
test 'remediate only those statuses where the user is the owner of the host' do
|
323
|
+
post :submit_remediate, params: { host_association: host_association, owned_only: true }, session: set_session_user
|
324
|
+
assert_same_elements statuses, assigns['statuses']
|
325
|
+
end
|
326
|
+
end
|
275
327
|
end
|
276
328
|
end
|
277
329
|
end
|
@@ -3,129 +3,133 @@
|
|
3
3
|
FactoryBot.define do
|
4
4
|
factory :vmware_facet, class: 'ForemanWreckingball::VmwareFacet' do
|
5
5
|
vmware_cluster
|
6
|
-
tools_state 2 #:toolsOk
|
7
|
-
power_state 1 #:poweredOn
|
8
|
-
cpus 2
|
9
|
-
corespersocket 1
|
10
|
-
memory_mb 8192
|
11
|
-
guest_id 'rhel6_64Guest'
|
12
|
-
cpu_hot_add false
|
13
|
-
hardware_version 'vmx-10'
|
14
|
-
cpu_features
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
6
|
+
tools_state { 2 } #:toolsOk
|
7
|
+
power_state { 1 } #:poweredOn
|
8
|
+
cpus { 2 }
|
9
|
+
corespersocket { 1 }
|
10
|
+
memory_mb { 8192 }
|
11
|
+
guest_id { 'rhel6_64Guest' }
|
12
|
+
cpu_hot_add { false }
|
13
|
+
hardware_version { 'vmx-10' }
|
14
|
+
cpu_features do
|
15
|
+
[
|
16
|
+
'cpuid.SSE3',
|
17
|
+
'cpuid.PCLMULQDQ',
|
18
|
+
'cpuid.SSSE3',
|
19
|
+
'cpuid.CMPXCHG16B',
|
20
|
+
'cpuid.PCID',
|
21
|
+
'cpuid.SSE41',
|
22
|
+
'cpuid.SSE42',
|
23
|
+
'cpuid.POPCNT',
|
24
|
+
'cpuid.AES',
|
25
|
+
'cpuid.XSAVE',
|
26
|
+
'cpuid.AVX',
|
27
|
+
'cpuid.DS',
|
28
|
+
'cpuid.SS',
|
29
|
+
'cpuid.XCR0_MASTER_SSE',
|
30
|
+
'cpuid.XCR0_MASTER_YMM_H',
|
31
|
+
'cpuid.LAHF64',
|
32
|
+
'cpuid.NX',
|
33
|
+
'cpuid.RDTSCP',
|
34
|
+
'cpuid.LM',
|
35
|
+
'cpuid.Intel'
|
36
|
+
]
|
37
|
+
end
|
36
38
|
host
|
37
39
|
end
|
38
40
|
|
39
41
|
factory :vmware_hypervisor_facet, class: 'ForemanWreckingball::VmwareHypervisorFacet' do
|
40
42
|
host
|
41
43
|
vmware_cluster
|
42
|
-
cpu_cores 18
|
43
|
-
cpu_sockets 1
|
44
|
-
cpu_threads 36
|
45
|
-
memory 412_046_372_864
|
44
|
+
cpu_cores { 18 }
|
45
|
+
cpu_sockets { 1 }
|
46
|
+
cpu_threads { 36 }
|
47
|
+
memory { 412_046_372_864 }
|
46
48
|
uuid { SecureRandom.uuid }
|
47
|
-
feature_capabilities
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
49
|
+
feature_capabilities do
|
50
|
+
[
|
51
|
+
'cpuid.3DNOW',
|
52
|
+
'cpuid.3DNOWPLUS',
|
53
|
+
'cpuid.3DNPREFETCH',
|
54
|
+
'cpuid.ABM',
|
55
|
+
'cpuid.ADX',
|
56
|
+
'cpuid.AES',
|
57
|
+
'cpuid.AMD',
|
58
|
+
'cpuid.AVX',
|
59
|
+
'cpuid.AVX2',
|
60
|
+
'cpuid.BMI1',
|
61
|
+
'cpuid.BMI2',
|
62
|
+
'cpuid.CMPXCHG16B',
|
63
|
+
'cpuid.CR8AVAIL',
|
64
|
+
'cpuid.Cyrix',
|
65
|
+
'cpuid.DS',
|
66
|
+
'cpuid.ENFSTRG',
|
67
|
+
'cpuid.EXTAPICSPC',
|
68
|
+
'cpuid.F16C',
|
69
|
+
'cpuid.FFXSR',
|
70
|
+
'cpuid.FMA',
|
71
|
+
'cpuid.FMA4',
|
72
|
+
'cpuid.FSGSBASE',
|
73
|
+
'cpuid.HLE',
|
74
|
+
'cpuid.IBPB',
|
75
|
+
'cpuid.IBRS',
|
76
|
+
'cpuid.INVPCID',
|
77
|
+
'cpuid.Intel',
|
78
|
+
'cpuid.LAHF64',
|
79
|
+
'cpuid.LM',
|
80
|
+
'cpuid.MISALIGNED_SSE',
|
81
|
+
'cpuid.MMXEXT',
|
82
|
+
'cpuid.MOVBE',
|
83
|
+
'cpuid.MWAIT',
|
84
|
+
'cpuid.NX',
|
85
|
+
'cpuid.PCID',
|
86
|
+
'cpuid.PCLMULQDQ',
|
87
|
+
'cpuid.PDPE1GB',
|
88
|
+
'cpuid.POPCNT',
|
89
|
+
'cpuid.PSN',
|
90
|
+
'cpuid.RDRAND',
|
91
|
+
'cpuid.RDSEED',
|
92
|
+
'cpuid.RDTSCP',
|
93
|
+
'cpuid.RTM',
|
94
|
+
'cpuid.SMAP',
|
95
|
+
'cpuid.SMEP',
|
96
|
+
'cpuid.SS',
|
97
|
+
'cpuid.SSE3',
|
98
|
+
'cpuid.SSE41',
|
99
|
+
'cpuid.SSE42',
|
100
|
+
'cpuid.SSE4A',
|
101
|
+
'cpuid.SSSE3',
|
102
|
+
'cpuid.STIBP',
|
103
|
+
'cpuid.SVM',
|
104
|
+
'cpuid.SVM_DECODE_ASSISTS',
|
105
|
+
'cpuid.SVM_FLUSH_BY_ASID',
|
106
|
+
'cpuid.SVM_NPT',
|
107
|
+
'cpuid.SVM_NRIP',
|
108
|
+
'cpuid.SVM_VMCB_CLEAN',
|
109
|
+
'cpuid.TBM',
|
110
|
+
'cpuid.VIA',
|
111
|
+
'cpuid.VMX',
|
112
|
+
'cpuid.XCR0_MASTER_SSE',
|
113
|
+
'cpuid.XCR0_MASTER_YMM_H',
|
114
|
+
'cpuid.XOP',
|
115
|
+
'cpuid.XSAVE',
|
116
|
+
'cpuid.XSAVEOPT',
|
117
|
+
'hv.capable',
|
118
|
+
'misc.cpuidFaulting',
|
119
|
+
'vpmc.fixctr.0',
|
120
|
+
'vpmc.fixedWidth',
|
121
|
+
'vpmc.genWidth',
|
122
|
+
'vpmc.genctr.0',
|
123
|
+
'vpmc.genctr.1',
|
124
|
+
'vpmc.genctr.2',
|
125
|
+
'vpmc.genctr.3',
|
126
|
+
'vpmc.microarchitecture.ivybridge',
|
127
|
+
'vpmc.numFixedCtrs',
|
128
|
+
'vpmc.numGenCtrs',
|
129
|
+
'vpmc.version',
|
130
|
+
'vt.realmode'
|
131
|
+
]
|
132
|
+
end
|
129
133
|
end
|
130
134
|
|
131
135
|
factory :vmware_cluster, class: 'ForemanWreckingball::VmwareCluster' do
|
data/test/factories/task.rb
CHANGED
@@ -3,15 +3,15 @@
|
|
3
3
|
FactoryBot.modify do
|
4
4
|
factory :some_task do
|
5
5
|
trait :running do
|
6
|
-
state 'running'
|
6
|
+
state { 'running' }
|
7
7
|
end
|
8
8
|
|
9
9
|
trait :stopped do
|
10
|
-
state 'stopped'
|
10
|
+
state { 'stopped' }
|
11
11
|
end
|
12
12
|
|
13
13
|
trait :vmware_sync do
|
14
|
-
label ::Actions::ForemanWreckingball::Vmware::ScheduleVmwareSync.to_s
|
14
|
+
label { ::Actions::ForemanWreckingball::Vmware::ScheduleVmwareSync.to_s }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanWreckingball
|
4
|
+
module StatusHelper
|
5
|
+
def assert_statuses(expected)
|
6
|
+
actual = request.env['action_controller.instance'].instance_variable_get('@statuses')
|
7
|
+
assert_same_elements expected, actual
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -23,28 +23,28 @@ class HostsStatusDashboardTest < ActionDispatch::IntegrationTest
|
|
23
23
|
lists = find_all('div.list-view-pf-main-info')
|
24
24
|
|
25
25
|
# VMWare Tools
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
assert_includes lists[0].text, '1 OK'
|
27
|
+
assert_includes lists[0].text, '0 Warning'
|
28
|
+
assert_includes lists[0].text, '0 Critical'
|
29
29
|
|
30
30
|
# VMWare Operating System
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
assert_includes lists[1].text, '2 OK'
|
32
|
+
assert_includes lists[1].text, '0 Warning'
|
33
|
+
assert_includes lists[1].text, '0 Critical'
|
34
34
|
|
35
35
|
# VMWare CPU Hot Plug
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
assert_includes lists[2].text, '3 OK'
|
37
|
+
assert_includes lists[2].text, '0 Warning'
|
38
|
+
assert_includes lists[2].text, '0 Critical'
|
39
39
|
|
40
40
|
# VMWare Spectre V2
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
assert_includes lists[3].text, '4 OK'
|
42
|
+
assert_includes lists[3].text, '0 Warning'
|
43
|
+
assert_includes lists[3].text, '5 Critical'
|
44
44
|
|
45
45
|
# VMWare Hardware Version
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
assert_includes lists[4].text, '6 OK'
|
47
|
+
assert_includes lists[4].text, '7 Warning'
|
48
|
+
assert_includes lists[4].text, '0 Critical'
|
49
49
|
end
|
50
50
|
end
|
@@ -25,9 +25,9 @@ class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
|
|
25
25
|
missing_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 2)
|
26
26
|
|
27
27
|
mock_vm = mock('vm')
|
28
|
-
mock_vm.stubs(:
|
28
|
+
mock_vm.stubs(:id).returns(managed_host.uuid)
|
29
29
|
mock_vm.stubs(:name).returns(managed_host.name)
|
30
|
-
Foreman::Model::Vmware.any_instance.stubs(:vms).returns(Array(mock_vm))
|
30
|
+
Foreman::Model::Vmware.any_instance.stubs(:vms).returns(OpenStruct.new(all: Array(mock_vm)))
|
31
31
|
|
32
32
|
visit status_managed_hosts_dashboard_hosts_path
|
33
33
|
|
@@ -36,25 +36,37 @@ class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
|
|
36
36
|
refute_includes list.text, managed_host.name
|
37
37
|
end
|
38
38
|
|
39
|
-
test 'shows
|
40
|
-
|
39
|
+
test 'shows hosts associated to wrong compute resource' do
|
40
|
+
other_cr = FactoryBot.create(
|
41
|
+
:vmware_cr,
|
42
|
+
uuid: 'bla',
|
43
|
+
organizations: [organization],
|
44
|
+
locations: [tax_location]
|
45
|
+
)
|
46
|
+
|
47
|
+
correct_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 1)
|
48
|
+
incorrect_host = FactoryBot.create(:host, :managed, compute_resource: cr, owner: admin, uuid: 2)
|
41
49
|
|
42
50
|
mock1_vm = mock('vm1')
|
43
|
-
mock1_vm.stubs(:
|
51
|
+
mock1_vm.stubs(:id).returns(correct_host.uuid)
|
44
52
|
mock1_vm.stubs(:name).returns('foo01.example.com')
|
45
53
|
mock2_vm = mock('vm2')
|
46
|
-
mock2_vm.stubs(:
|
54
|
+
mock2_vm.stubs(:id).returns(incorrect_host.uuid)
|
47
55
|
mock2_vm.stubs(:name).returns('foo02.example.com')
|
48
|
-
|
56
|
+
|
57
|
+
cr.stubs(:vms).returns(OpenStruct.new(all: [mock1_vm]))
|
58
|
+
other_cr.stubs(:vms).returns(OpenStruct.new(all: [mock2_vm]))
|
59
|
+
|
60
|
+
Foreman::Model::Vmware.stubs(:unscoped).returns(OpenStruct.new(all: [cr, other_cr]))
|
49
61
|
|
50
62
|
visit status_managed_hosts_dashboard_hosts_path
|
51
63
|
|
52
|
-
list = page.find('#
|
53
|
-
|
54
|
-
assert_includes list.text,
|
64
|
+
list = page.find('#wrong_hosts')
|
65
|
+
refute_includes list.text, correct_host.name
|
66
|
+
assert_includes list.text, incorrect_host.name
|
55
67
|
end
|
56
68
|
|
57
|
-
test 'shows hosts
|
69
|
+
test 'shows hosts that can be found one more than one compute resource' do
|
58
70
|
other_cr = FactoryBot.create(
|
59
71
|
:vmware_cr,
|
60
72
|
uuid: 'bla',
|
@@ -69,23 +81,23 @@ class HostsStatusManagedHostsTest < ActionDispatch::IntegrationTest
|
|
69
81
|
managed3_host = FactoryBot.create(:host, :managed, compute_resource: other_cr, owner: admin, uuid: 3)
|
70
82
|
|
71
83
|
mock1_vm = mock('vm1')
|
72
|
-
mock1_vm.stubs(:
|
84
|
+
mock1_vm.stubs(:id).returns(managed1_host.uuid)
|
73
85
|
mock1_vm.stubs(:name).returns(managed1_host.name)
|
74
86
|
mock2_vm = mock('vm2')
|
75
|
-
mock2_vm.stubs(:
|
87
|
+
mock2_vm.stubs(:id).returns(managed2_host.uuid)
|
76
88
|
mock2_vm.stubs(:name).returns(managed2_host.name)
|
77
89
|
mock3_vm = mock('vm3')
|
78
|
-
mock3_vm.stubs(:
|
90
|
+
mock3_vm.stubs(:id).returns(managed3_host.uuid)
|
79
91
|
mock3_vm.stubs(:name).returns(managed3_host.name)
|
80
92
|
|
81
|
-
cr.stubs(:vms).returns([mock1_vm, mock2_vm])
|
82
|
-
other_cr.stubs(:vms).returns([mock3_vm])
|
93
|
+
cr.stubs(:vms).returns(OpenStruct.new(all: [mock1_vm, mock2_vm]))
|
94
|
+
other_cr.stubs(:vms).returns(OpenStruct.new(all: [mock2_vm, mock3_vm]))
|
83
95
|
|
84
|
-
|
96
|
+
Foreman::Model::Vmware.stubs(:unscoped).returns(OpenStruct.new(all: [cr, other_cr]))
|
85
97
|
|
86
98
|
visit status_managed_hosts_dashboard_hosts_path
|
87
99
|
|
88
|
-
list = page.find('#
|
100
|
+
list = page.find('#more_than_one_hosts')
|
89
101
|
refute_includes list.text, managed1_host.name
|
90
102
|
assert_includes list.text, managed2_host.name
|
91
103
|
refute_includes list.text, managed3_host.name
|
@@ -6,6 +6,7 @@ require 'webmock/minitest'
|
|
6
6
|
require 'webmock'
|
7
7
|
|
8
8
|
# Add plugin to FactoryBot's paths
|
9
|
+
FactoryBot.definition_file_paths << File.join(ForemanTasks::Engine.root, 'test', 'factories')
|
9
10
|
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|
10
11
|
FactoryBot.reload
|
11
12
|
|
@@ -62,12 +62,12 @@ module ForemanWreckingball
|
|
62
62
|
|
63
63
|
setup do
|
64
64
|
::Fog.mock!
|
65
|
-
::
|
65
|
+
::ForemanWreckingball.fog_vsphere_namespace::Mock.any_instance.stubs(:get_vm_ref).returns(vm)
|
66
66
|
# this is not stubbed correctly in fog-vsphere
|
67
|
-
::
|
68
|
-
::
|
69
|
-
::
|
70
|
-
::
|
67
|
+
::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:cpuHotAddEnabled).returns(false)
|
68
|
+
::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:hardware_version).returns('vmx-9')
|
69
|
+
::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:corespersocket).returns(1)
|
70
|
+
::ForemanWreckingball.fog_vsphere_namespace::Server.any_instance.stubs(:power_state).returns('poweredOn')
|
71
71
|
end
|
72
72
|
teardown { ::Fog.unmock! }
|
73
73
|
|
data/test/models/host_test.rb
CHANGED
@@ -24,9 +24,9 @@ class Host::ManagedTest < ActiveSupport::TestCase
|
|
24
24
|
FactoryBot.create(:host, :managed, owner: usergroup_with_user),
|
25
25
|
FactoryBot.create(:host, :managed, owner: FactoryBot.create(:usergroup, usergroups: [usergroup_with_user]))
|
26
26
|
]
|
27
|
-
actual = Host::Managed.owned_by_current_user_or_group_with_current_user
|
27
|
+
actual = Host::Managed.owned_by_current_user_or_group_with_current_user.all
|
28
28
|
|
29
|
-
|
29
|
+
assert_same_elements expected, actual
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/test/test_plugin_helper.rb
CHANGED
@@ -5,6 +5,8 @@ require 'test_helper'
|
|
5
5
|
require 'database_cleaner'
|
6
6
|
require 'dynflow/testing'
|
7
7
|
|
8
|
+
Dir["#{__dir__}/helpers/foreman_wreckingball/**.rb"].each { |f| require f }
|
9
|
+
|
8
10
|
# Add plugin to FactoryBot's paths
|
9
11
|
FactoryBot.definition_file_paths << File.join(ForemanTasks::Engine.root, 'test', 'factories')
|
10
12
|
FactoryBot.definition_file_paths << File.join(File.dirname(__FILE__), 'factories')
|