forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rhcloud_iop.py
More file actions
354 lines (272 loc) · 13.3 KB
/
Copy pathtest_rhcloud_iop.py
File metadata and controls
354 lines (272 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
"""Tests for RH Cloud - IOP
:Requirement: RHCloud
:CaseAutomation: Automated
:CaseComponent: Insights-Advisor
:Team: Proton
:CaseImportance: High
"""
import pytest
from robottelo.constants import OPENSSH_RECOMMENDATION
from tests.foreman.ui.test_rhcloud_insights import (
create_insights_vulnerability as create_insights_recommendation,
)
@pytest.mark.e2e
@pytest.mark.pit_server
@pytest.mark.pit_client
@pytest.mark.no_containers
@pytest.mark.rhel_ver_match(r'^(?![78]).*')
@pytest.mark.parametrize('module_target_sat_insights', [False], ids=['local'], indirect=True)
def test_iop_recommendations_e2e(
rhel_insights_vm,
rhcloud_manifest_org,
module_target_sat_insights,
):
"""Set up Satellite with iop enabled, create conditions to cause advisor recommendation,
and apply remediation.
:id: 84bb1530-acdc-418c-8577-57fcfec138c6
:steps:
1. Set up Satellite with iop enabled.
2. In Satellite UI, go to Red Hat Lightspeed > Recommendations.
3. Run remediation for "OpenSSH config permissions" recommendation against host.
4. Verify that the remediation job completed successfully.
5. Search for previously remediated issue.
6. Unregister host from insights
:expectedresults:
1. Red Hat Lightspeed recommendation related to "OpenSSH config permissions" issue is listed
for misconfigured machine.
2. Remediation job finished successfully.
3. Red Hat Lightspeed recommendation related to "OpenSSH config permissions" issue is not listed.
4. Host was successfully unregistered from insights
:CaseImportance: Critical
:Verifies: SAT-32566
:parametrized: yes
:CaseAutomation: Automated
"""
org_name = rhcloud_manifest_org.name
# Verify insights-client package is installed
assert rhel_insights_vm.execute('insights-client --version').status == 0
# Prepare misconfigured machine and upload data to Insights
create_insights_recommendation(rhel_insights_vm)
with module_target_sat_insights.ui_session() as session:
session.organization.select(org_name=org_name)
# Verify that we can see the rule hit via insights-client
result = rhel_insights_vm.execute('insights-client --diagnosis')
assert result.status == 0
assert 'OPENSSH_HARDENING_CONFIG_PERMS' in result.stdout
# Search for the recommendation.
result = session.recommendationstab.search(OPENSSH_RECOMMENDATION)
assert result[0]['Name'] == OPENSSH_RECOMMENDATION
# Remediate the Affected System.
result = session.recommendationstab.remediate_affected_system(
OPENSSH_RECOMMENDATION, rhel_insights_vm.hostname
)
# Verify that the job Succeeded
assert result['status']['Succeeded'] != 0
assert result['overall_status']['is_success']
# Verify that the Satellite is not affected by SAT-35946
result = module_target_sat_insights.execute(
'grep "502 Bad Gateway" /var/log/foreman/production.log'
)
assert result.status != 0
# Verify that the recommendation is not listed anymore.
assert (
'No recommendations None of your connected systems are affected by enabled recommendations'
in session.recommendationstab.search(OPENSSH_RECOMMENDATION)[0]['Name']
)
# Verify that unregistering host succeeded
result = rhel_insights_vm.execute('insights-client --unregister')
assert 'Successfully unregistered from the Red Hat Insights Service' in result.stdout
result = rhel_insights_vm.execute('insights-client --status')
assert 'System is NOT registered locally' in result.stdout
@pytest.mark.e2e
@pytest.mark.no_containers
@pytest.mark.rhel_ver_match(r'^(?![78]).*')
@pytest.mark.parametrize('module_target_sat_insights', [False], ids=['local'], indirect=True)
def test_iop_recommendations_remediate_multiple_hosts(
rhel_insights_vms,
rhcloud_manifest_org,
module_target_sat_insights,
):
"""Set up Satellite with iop enabled, register multiple hosts, create conditions that violate
advisor rules on both hosts, and bulk apply remediation.
:id: 5b29a791-b42a-4ab9-b632-cab919d06daa
:steps:
1. Set up Satellite with iop enabled and register multiple hosts.
2. In Satellite UI, go to Red Hat Lightspeed > Recommendations.
3. Run remediation for "OpenSSH config permissions" recommendation against multiple hosts.
4. Verify that the remediation job completed successfully.
5. Search for previously remediated issue.
:expectedresults:
1. Red Hat Lightspeed recommendation related to "OpenSSH config permissions" issue is listed
for misconfigured machines.
2. Remediation job finished successfully.
3. Red Hat Lightspeed recommendation related to "OpenSSH config permissions" issue is not listed.
:CaseImportance: Critical
:Verifies: SAT-32566
:parametrized: yes
:CaseAutomation: Automated
"""
org_name = rhcloud_manifest_org.name
hostnames = [host.hostname for host in rhel_insights_vms]
# Prepare misconfigured machines and upload data to Insights
for vm in rhel_insights_vms:
create_insights_recommendation(vm)
with module_target_sat_insights.ui_session() as session:
session.organization.select(org_name=org_name)
# Search for the recommendations
result = session.recommendationstab.search(OPENSSH_RECOMMENDATION)
assert result[0]['Name'] == OPENSSH_RECOMMENDATION
assert result[0]['Systems'] == '2'
# Bulk remediate the Affected System.
result = session.recommendationstab.bulk_remediate_affected_systems(OPENSSH_RECOMMENDATION)
# Verify that the job Succeeded
assert result['status']['Succeeded'] != 0
assert result['overall_status']['is_success']
assert len(result['hosts']) == len(rhel_insights_vms)
# Verify that the expected hostnames are in results
expected = {h.strip().lower() for h in hostnames}
found = {r['Name'].strip().lower() for r in result['hosts']}
missing = expected - found
assert not missing, f"Missing hosts in results: {sorted(missing)}"
# Verify that the recommendation is not listed anymore.
assert (
'No recommendations None of your connected systems are affected by enabled recommendations'
in session.recommendationstab.search(OPENSSH_RECOMMENDATION)[0]['Name']
)
@pytest.mark.e2e
@pytest.mark.pit_server
@pytest.mark.pit_client
@pytest.mark.no_containers
@pytest.mark.rhel_ver_match(r'^(?![78]).*')
@pytest.mark.parametrize('module_target_sat_insights', [False], ids=['local'], indirect=True)
def test_iop_recommendations_host_details_e2e(
rhel_insights_vm,
rhcloud_manifest_org,
module_target_sat_insights,
):
"""Set up Satellite with iop enabled, create condition on the host that violates advisor rules,
see the recommendation on the host details page, and apply the remediation.
:id: 282a7ef0-33a4-4dd4-8712-064a30cb54c6
:steps:
1. Set up Satellite with iop enabled.
2. In Satellite UI, go to All Hosts > Hostname > Recommendations.
3. Run remediation for "OpenSSH config permissions" recommendation against host.
4. Verify that the remediation job completed successfully.
5. Search for previously remediated issue.
:expectedresults:
1. Host recommendation related to "OpenSSH config permissions" issue is listed
for misconfigured machine.
2. Remediation job finished successfully.
3. Host recommendation related to "OpenSSH config permissions" issue is not listed.
:CaseImportance: Critical
:Verifies: SAT-32566
:parametrized: yes
:CaseAutomation: Automated
"""
org_name = rhcloud_manifest_org.name
# Verify insights-client package is installed
assert rhel_insights_vm.execute('insights-client --version').status == 0
# Prepare misconfigured machine and upload data to Insights
create_insights_recommendation(rhel_insights_vm)
with module_target_sat_insights.ui_session() as session:
session.organization.select(org_name=org_name)
# Verify that we can see the rule hit via insights-client
result = rhel_insights_vm.execute('insights-client --diagnosis')
assert result.status == 0
assert 'OPENSSH_HARDENING_CONFIG_PERMS' in result.stdout
result = session.host_new.get_recommendations(rhel_insights_vm.hostname)
assert any(row.get('Description') == OPENSSH_RECOMMENDATION for row in result), (
f"No row found with Recommendation == {OPENSSH_RECOMMENDATION}"
)
# Remediate the Affected System.
result = session.host_new.remediate_host_recommendation(
rhel_insights_vm.hostname,
OPENSSH_RECOMMENDATION,
)
# Verify that the job Succeeded
assert result['status']['Succeeded'] != 0
assert result['overall_status']['is_success']
# Verify that the recommendation is not listed anymore.
result = session.host_new.get_recommendations(rhel_insights_vm.hostname)
assert not any(row.get('Description') == OPENSSH_RECOMMENDATION for row in result), (
f"Recommendation found: {OPENSSH_RECOMMENDATION}"
)
# @pytest.mark.parametrize("module_target_sat_insights", [False], ids=["local"], indirect=True)
def test_rhcloud_inventory_disabled_local_insights(module_target_sat_insights):
"""Verify that the 'Red Hat Lightspeed > Inventory Upload' navigation item is not available
when the Satellite is configured to use IoP.
:id: 84023ae9-7bc4-4332-9aaf-749d6c48c2d2
:steps:
1. Configure Satellite to use local Insights advisor engine.
2. Navigate to the Insights Recommendations page.
3. Select Insights > Inventory Upload from the navigation menu.
:expectedresults:
1. "Inventory Upload" is not visible under "Insights".
:CaseImportance: Medium
:CaseAutomation: Automated
"""
with module_target_sat_insights.ui_session() as session:
insights_view = session.cloudinsights.navigate_to(session.cloudinsights, 'All')
with pytest.raises(Exception, match='not found in navigation tree'):
insights_view.menu.select('Insights', 'Inventory Upload')
@pytest.mark.e2e
@pytest.mark.no_containers
@pytest.mark.rhel_ver_match('10')
@pytest.mark.parametrize('module_target_sat_insights', [False], ids=['local'], indirect=True)
def test_iop_recommendations_remediation_type_and_status(
rhel_insights_vm,
rhcloud_manifest_org,
module_target_sat_insights,
):
"""Set up Satellite with iop enabled, verify recommendations remediation type,
disable the recommendation, check status, then re-enable the recommendation.
:id: 62834698-b4b8-4218-855c-2b2aa584b364
:steps:
1. Set up Satellite with iop enabled.
2. In Satellite UI, go to Red Hat Lightspeed > Recommendations.
3. Search for "OpenSSH config permissions" recommendation.
4. Verify the recommendation's remediation type is "Playbook".
5. Disable recommendation.
6. Verify recommendation is disabled.
7. Re-enable recommendation.
8. Verify recommendation is enabled.
:expectedresults:
1. Red Hat Lightspeed recommendation related to "OpenSSH config permissions" issue is listed
for misconfigured machine.
2. The recommendation has remediation type "Playbook".
3. Recommendation can be disabled and re-enabled.
:Verifies: SAT-32566, SAT-38139
:parametrized: yes
:CaseAutomation: Automated
"""
org_name = rhcloud_manifest_org.name
# Verify insights-client package is installed
assert rhel_insights_vm.execute('insights-client --version').status == 0
# Prepare misconfigured machine and upload data to Insights
create_insights_recommendation(rhel_insights_vm)
with module_target_sat_insights.ui_session() as session:
session.organization.select(org_name=org_name)
# Verify that we can see the rule hit via insights-client
result = rhel_insights_vm.execute('insights-client --diagnosis')
assert result.status == 0
assert 'OPENSSH_HARDENING_CONFIG_PERMS' in result.stdout
# Search for the recommendation and assert its remediation type
result = session.recommendationstab.search(OPENSSH_RECOMMENDATION)
assert result[0]['Name'] == OPENSSH_RECOMMENDATION
assert result[0]['Remediation type'] == 'Playbook'
# Disable recommendation
session.recommendationstab.disable_recommendation(
recommendation_name=OPENSSH_RECOMMENDATION
)
# Verify that the disabled recommendation is filtered
result = session.recommendationstab.apply_filter("Status", "Disabled")
assert 'Decreased security: OpenSSH config permissions' in result[0]['Name']
session.recommendationstab.enable_recommendation(
recommendation_name='Decreased security: OpenSSH config permissions'
)
# Verify that recommendation is enabled
session.recommendationstab.apply_filter("Status", "Enabled")
result = session.recommendationstab.apply_filter(
"Name", OPENSSH_RECOMMENDATION, is_search=True
)
assert 'Decreased security: OpenSSH config permissions' in result[0]['Name']