-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtest_health.py
More file actions
821 lines (627 loc) · 28.5 KB
/
Copy pathtest_health.py
File metadata and controls
821 lines (627 loc) · 28.5 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
"""Test module for satellite-maintain health functionality
:Requirement: foreman-maintain
:CaseAutomation: Automated
:CaseComponent: SatelliteMaintain
:Team: Rocket
:CaseImportance: Critical
"""
import time
from fauxfactory import gen_string
import pytest
from robottelo.config import settings
from robottelo.enums import NetworkType
from robottelo.utils.installer import InstallerCommand
upstream_url = {
'foreman_repo': 'https://yum.theforeman.org/releases/nightly/el9/x86_64/',
'puppet_repo': 'https://yum.puppetlabs.com/puppet/el/9/x86_64/',
'katello_repo': 'https://yum.theforeman.org/katello/nightly/katello/el9/x86_64/',
}
@pytest.mark.satellite_iop_only
def test_podman_login_check(request, sat_maintain):
"""Test Podman login check with local Red Hat Lightspeed(IoP) Satellite.
:id: 70fd6d86-a647-442c-a971-cbd1207b734b
:setup: Configure a Satellite with local Red Hat Lightspeed(IoP) enabled.
:steps:
1. Run satellite-maintain update check.
2. Verify that the Podman login check passes.
3. Log out of the remote container registry.
4. Run satellite-maintain update check.
5. Verify that the Podman login check fails.
:Verifies: SAT-35282
"""
iop_settings = settings.rh_cloud.iop
request.addfinalizer(lambda: sat_maintain.podman_logout(iop_settings.registry))
check_description = 'Check whether podman needs to be logged in to the registry'
fail_message = (
'You are using containers from registry.redhat.io,\n'
'but your system is not logged in to the registry, or the login expired.\n'
'Please login to registry.redhat.io.'
)
# Login to Prod registry to ensure the check runs correctly, it won't work for any other registry
sat_maintain.podman_login(iop_settings.username, iop_settings.token, iop_settings.registry)
result = sat_maintain.cli.Health.check(options={'label': 'container-podman-login'})
assert 'FAIL' not in result.stdout
assert check_description in result.stdout, result.stdout
sat_maintain.podman_logout(iop_settings.registry)
result = sat_maintain.cli.Health.check(options={'label': 'container-podman-login'})
assert 'FAIL' in result.stdout
assert fail_message in result.stdout, result.stdout
@pytest.mark.include_capsule
def test_positive_health_list(sat_maintain):
"""List health check in satellite-maintain
:id: 976ef4cd-e028-4545-91bb-72433d40d7ee
:parametrized: yes
:steps:
1. Run satellite-maintain health list
:expectedresults: Health check list should work.
"""
assert sat_maintain.cli.Health.list().status == 0
@pytest.mark.include_capsule
def test_positive_health_list_tags(sat_maintain):
"""List tags for health check in satellite-maintain
:id: d0a6c8c1-8266-464a-bfdf-01d405dd9bd2
:parametrized: yes
:steps:
1. Run satellite-maintain health list-tags
:expectedresults: Tags for health checks should list.
"""
assert sat_maintain.cli.Health.list_tags().status == 0
@pytest.mark.include_capsule
def test_positive_list_health_check_by_tags(sat_maintain):
"""List health check in satellite-maintain by tags
:id: 420d8e62-84d8-4496-8c24-037bd23febe9
:steps:
1. Run satellite-maintain health list --tags default
:expectedresults: health checks according to tag should list.
"""
result = sat_maintain.cli.Health.list_tags().stdout
output = [i.split("]\x1b[0m")[0] for i in result.split("\x1b[36m[") if i]
for tag in output:
assert sat_maintain.cli.Health.list({"tags": tag}).status == 0
@pytest.mark.e2e
@pytest.mark.upgrade
@pytest.mark.include_capsule
def test_positive_health_check(sat_maintain):
"""Verify satellite-maintain health check
:id: bfff93dd-adde-4630-8411-1bb6b74daddd
:parametrized: yes
:steps:
1. Run satellite-maintain health check
:expectedresults: Health check should pass.
:BZ: 1956210
:customerscenario: true
"""
result = sat_maintain.cli.Health.check(options={'assumeyes': True})
assert result.status == 0
if 'paused tasks in the system' not in result.stdout:
assert 'FAIL' not in result.stdout
result = sat_maintain.execute('tail /var/log/foreman-proxy/proxy.log')
assert 'sslv3 alert bad certificate' not in result.stdout
@pytest.mark.include_capsule
def test_positive_health_check_by_tags(sat_maintain):
"""Verify satellite-maintain health check by tags
:id: 518e19af-2dd4-4fb0-8c90-208cbd354107
:parametrized: yes
:steps:
1. Run satellite-maintain health check --tags tag_name
:expectedresults: Health check should pass for listed tags.
"""
result = sat_maintain.cli.Health.list_tags().stdout
output = [tag.strip("[]") for tag in result.strip().split("\n")]
for tag in output:
assert (
sat_maintain.cli.Health.check(
options={'tags': tag, 'assumeyes': True, 'whitelist': 'non-rh-packages'}
).status
== 0
)
@pytest.mark.include_capsule
def test_positive_health_check_pre_upgrade(sat_maintain):
"""Verify pre-upgrade health checks
:id: f52bd43e-79cd-488b-adbb-3c9e5bac32cc
:parametrized: yes
:steps:
1. Run satellite-maintain health check --tags pre-upgrade
:expectedresults: Pre-upgrade health checks should pass.
"""
result = sat_maintain.cli.Health.check(
options={'tags': 'pre-upgrade', 'whitelist': 'non-rh-packages'}
)
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.include_capsule
def test_positive_health_check_server_ping(sat_maintain):
"""Verify server ping check
:id: b1eec8cb-9f94-439a-b5e7-8621cb35501f
:parametrized: yes
:steps:
1. Run satellite-maintain health check --label server-ping
:expectedresults: server-ping health check should pass.
"""
result = sat_maintain.cli.Health.check(options={'label': 'server-ping'})
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.usefixtures('start_satellite_services')
def test_health_check_server_ping(sat_maintain):
"""Verify health check server-ping
:id: ecdc5bfb-2adf-49f6-948d-995dae34bcd3
:steps:
1. Run satellite-maintain health check --label server-ping
2. Run satellite-maintain service stop
3. Run satellite-maintain health check --label server-ping
:expectedresults: server-ping health check should pass
"""
result = sat_maintain.cli.Health.check(options={'label': 'server-ping', 'assumeyes': True})
assert result.status == 0
assert 'FAIL' not in result.stdout
assert sat_maintain.cli.Service.stop().status == 0
result = sat_maintain.cli.Health.check(options={'label': 'server-ping', 'assumeyes': True})
assert result.status == 0
assert 'FAIL' in result.stdout
@pytest.mark.include_capsule
def test_negative_health_check_upstream_repository(sat_maintain, request):
"""Verify upstream repository check
:id: 349fcf33-2d25-4628-a6af-cff53e624b25
:parametrized: yes
:steps:
1. Run satellite-maintain health check --label check-upstream-repository
:expectedresults: check-upstream-repository health check should fail.
"""
@request.addfinalizer
def _finalize():
for name in upstream_url:
sat_maintain.execute(f'rm -fr /etc/yum.repos.d/{name}.repo')
sat_maintain.execute('dnf clean all')
for name, url in upstream_url.items():
sat_maintain.create_custom_repos(**{name: url})
result = sat_maintain.cli.Health.check(
options={'label': 'check-upstream-repository', 'assumeyes': True}
)
assert result.status == 0
assert (
f"System has upstream {','.join(sorted([name for name in upstream_url]))} repositories enabled"
in result.stdout
)
assert 'FAIL' in result.stdout
for name in upstream_url:
result = sat_maintain.execute(f'cat /etc/yum.repos.d/{name}.repo')
assert 'enabled=0' in result.stdout
def test_positive_health_check_available_space(sat_maintain):
"""Verify available-space check
:id: 7d8798ca-3334-4dda-a9b0-dc3d7c0903e9
:parametrized: yes
:steps:
1. Run satellite-maintain health check --label available-space
2. Run satellite-maintain health check --label available-space-cp
:expectedresults: available-space health check should pass.
"""
result = sat_maintain.cli.Health.check(options={'label': 'available-space'})
assert 'FAIL' not in result.stdout
assert result.status == 0
result = sat_maintain.cli.Health.check(options={'label': 'available-space-cp'})
assert 'FAIL' not in result.stdout
assert result.status == 0
def test_positive_hammer_defaults_set(sat_maintain, request):
"""Verify that health check is performed when
hammer on system have defaults set.
:id: 27a8b49b-8cb8-4004-ba41-36ed084c4740
:steps:
1. Setup hammer on system with defaults set
2. Run satellite-maintain health check
:expectedresults: Health check should pass.
:BZ: 1632768
:customerscenario: true
"""
@request.addfinalizer
def _finalize():
sat_maintain.cli.Defaults.delete({'param-name': 'organization_id'})
sat_maintain.cli.Defaults.add({'param-name': 'organization_id', 'param-value': 1})
result = sat_maintain.cli.Health.check(options={'assumeyes': True})
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.include_capsule
def test_positive_health_check_hotfix_installed(sat_maintain, request):
"""Verify check-hotfix-installed check.
:id: d9023293-4173-4223-bbf5-328b41cf87cd
:parametrized: yes
:setup:
1. Modify gems files of a Satellite
2. Install hotfix-package
:steps:
1. Run satellite-maintain health check --label check-hotfix-installed
:expectedresults: check-hotfix-installed check should detect modified file
and installed hotfix.
"""
@request.addfinalizer
def _finalize():
sat_maintain.execute('rm -fr /etc/yum.repos.d/custom_repo.repo')
sat_maintain.execute('dnf remove -y hotfix-package')
assert sat_maintain.execute(f'sed -i "/#modifying_file/d" {fpath.stdout}').status == 0
# Verify check-hotfix-installed without hotfix package.
result = sat_maintain.cli.Health.check(options={'label': 'check-hotfix-installed'})
assert result.status == 0
assert 'WARNING' not in result.stdout
# Verify check-hotfix-installed with hotfix package.
gems_path = '/usr/share/gems/gems/'
fpath = sat_maintain.execute(f"find {gems_path} -type f -name 'self_upgrade.rb'")
sat_maintain.execute(f'sed -i "$ a #modifying_file" {fpath.stdout}')
hotfix_url = f'{settings.robottelo.repos_hosting_url}/hotfix_package/'
sat_maintain.create_custom_repos(custom_repo=hotfix_url)
result = sat_maintain.execute('dnf install -y --disableplugin=foreman-protector hotfix-package')
assert result.status == 0
assert 'FAIL' not in result.stdout
result = sat_maintain.cli.Health.check(options={'label': 'check-hotfix-installed'})
assert result.status == 78
assert 'WARNING' in result.stdout
assert 'hotfix-package' in result.stdout
@pytest.mark.include_capsule
def test_positive_health_check_validate_dnf_config(sat_maintain):
"""Verify validate-dnf-config
:id: b50c8866-6175-4286-8106-561945726023
:parametrized: yes
:steps:
1. configure yum exclude.
2. Run satellite-maintain health check --label validate-dnf-config
3. Assert that excluded packages are listed in output.
4. remove yum exclude configured in step 1.
:expectedresults: validate-dnf-config should work.
:BZ: 1669498
:customerscenario: true
"""
file = '/etc/dnf/dnf.conf'
dnf_exclude = 'exclude=cat*'
failure_message = 'Unset this configuration as it is risky while dnf update or upgrade!'
sat_maintain.execute(f'sed -i "$ a {dnf_exclude}" {file}')
result = sat_maintain.cli.Health.check(options={'label': 'validate-dnf-config'})
assert result.status == 1
assert dnf_exclude in result.stdout
assert failure_message in result.stdout
sat_maintain.execute(f'sed -i "/{dnf_exclude}/d" {file}')
result = sat_maintain.cli.Health.check(options={'label': 'validate-dnf-config'})
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.include_capsule
def test_negative_health_check_epel_repository(request, sat_maintain):
"""Verify check-non-redhat-repository.
:id: ce2d7278-d7b7-4f76-9923-79be831c0368
:parametrized: yes
:steps:
1. Configure epel repository.
2. Run satellite-maintain health check --label check-non-redhat-repository.
3. Assert that EPEL repos are enabled on system.
:BZ: 1755755
:expectedresults: check-non-redhat-repository health check should fail.
"""
@request.addfinalizer
def _finalize():
assert sat_maintain.execute('dnf remove -y epel-release').status == 0
epel_repo = 'https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm'
sat_maintain.execute(f'dnf install -y {epel_repo}')
result = sat_maintain.cli.Health.check(options={'label': 'check-non-redhat-repository'})
assert 'System is subscribed to non Red Hat repositories' in result.stdout
assert result.status == 1
assert 'FAIL' in result.stdout
def test_positive_health_check_old_foreman_tasks(sat_maintain):
"""Verify check-old-foreman-tasks.
:id: 156350c4-b55b-40b3-b8f2-202bd5ed9fb6
:parametrized: yes
:setup:
1. Setup old ForemanTasks using 'foreman-rake console'
:steps:
1. Run satellite-maintain health check --label check-old-foreman-tasks.
2. Assert that old tasks are found on system.
3. Assert that old tasks are deleted from system.
:BZ: 1745489
:expectedresults: check-old-foreman-tasks health check should pass.
"""
error_message = 'paused or stopped task(s) older than 30 days'
delete_message = 'Deleted old tasks:'
rake_command = (
't = ForemanTasks::Task.where(state: "stopped").first;'
't.started_at = t.started_at - 32.day;'
't.save(:validate => false)'
)
sat_maintain.execute(f"foreman-rake console <<< '{rake_command}'")
result = sat_maintain.cli.Health.check(
options={'label': 'check-old-foreman-tasks', 'assumeyes': True}
)
assert result.status == 0
assert "FAIL" in result.stdout
assert error_message in result.stdout
assert delete_message in result.stdout
result = sat_maintain.cli.Health.check(options={'label': 'check-old-foreman-tasks'})
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.include_capsule
def test_positive_health_check_tmout_variable(sat_maintain):
"""Verify check-tmout-variable. Upstream issue #23430.
:id: e0eea928-0ffb-4692-adb9-fc4bf041f301
:parametrized: yes
:steps:
1. Run satellite-maintain health check --label check-tmout-variable.
2. Assert that check-tmout-variable pass.
3. export TMOUT environment variable.
4. Run satellite-maintain health check --label check-tmout-variable.
5. Assert that check-tmout-variable fails.
:expectedresults: check-tmout-variable health check should pass.
"""
error_message = (
"The TMOUT environment variable is set with value 100. "
"Run 'unset TMOUT' command to unset this variable."
)
# Run check without setting TMOUT environment variable.
result = sat_maintain.cli.Health.check(options={'label': 'check-tmout-variable'})
assert result.status == 0
assert 'FAIL' not in result.stdout
# Run check with TMOUT environment variable set.
result = sat_maintain.cli.Health.check(
options={'label': 'check-tmout-variable'},
env_var='TMOUT=100',
)
assert result.status == 1
assert 'FAIL' in result.stdout
assert error_message in result.stdout
def test_positive_health_check_tftp_storage(sat_maintain, request):
"""Verify check-tftp-storage
:id: 9a900bc7-65ff-4280-bf8a-8974a7cb76c6
:steps:
1. Create test files in /var/lib/tftpboot/boot/
2. Run satellite-maintain health check --label check-tftp-storage.
3. Assert that check-tftp-storage fails.
4. Assert that check deletes files older than token_duration setting.
5. Delete all files from /var/lib/tftpboot/boot/
6. Run satellite-maintain health check --label check-tftp-storage.
7. Assert that check-tftp-storage pass.
:BZ: 1827176
:customerscenario: true
:expectedresults: check-tftp-storage health check should pass.
"""
@request.addfinalizer
def _finalize():
sat_maintain.cli.Settings.set({'name': 'token_duration', 'value': '360'})
assert (
sat_maintain.cli.Settings.list({'search': 'name=token_duration'})[0]['value'] == '360'
)
sat_maintain.cli.Settings.set({'name': 'token_duration', 'value': '2'})
assert sat_maintain.cli.Settings.list({'search': 'name=token_duration'})[0]['value'] == '2'
files_to_delete = [
'foreman-discovery-vmlinuz',
'foreman-discovery-initrd.img',
'do-not-delete.yml',
]
files_to_keep = ['keep-discovery-initrd.img']
# Create files for testing check-tftp-storage check.
for file in files_to_delete:
assert sat_maintain.execute(f'touch /var/lib/tftpboot/boot/{file}').status == 0
time.sleep(200)
assert sat_maintain.execute(f'touch /var/lib/tftpboot/boot/{files_to_keep[0]}').status == 0
# Run check-tftp-storage check.
result = sat_maintain.cli.Health.check(
options={'label': 'check-tftp-storage', 'assumeyes': True}
)
assert 'There are old initrd and vmlinuz files present in tftp' in result.stdout
assert 'Rerunning the check after fix procedure' in result.stdout
assert result.status == 0
assert 'FAIL' in result.stdout
# check whether expected files are deleted
for file in files_to_delete[:2]:
assert sat_maintain.execute(f'ls -l /var/lib/tftpboot/boot/{file}').status != 0
# check whether expected files are not deleted.
for file in files_to_keep + files_to_delete[2:]:
assert sat_maintain.execute(f'ls -l /var/lib/tftpboot/boot/{file}').status == 0
sat_maintain.execute(f'rm -fr /var/lib/tftpboot/boot/{file}')
# Re-run check with no files present in /var/lib/tftpboot/boot/
result = sat_maintain.cli.Health.check({'label': 'check-tftp-storage'})
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.include_capsule
def test_positive_health_check_env_proxy(sat_maintain):
"""Verify env-proxy health check.
:id: f8c44b40-3ce5-4179-8d6b-1156c0032450
:parametrized: yes
:steps:
1. export HTTP_PROXY environment variable.
2. Run satellite-maintain health check --label env-proxy.
3. Assert that check env-proxy fail.
4. Run satellite-maintain health check --label env-proxy.
5. Assert that check env-proxy pass.
:expectedresults: check env-proxy health check should pass .
:CaseImportance: Medium
"""
error_message = 'Global HTTP(S) proxy in environment (env) is set. Please unset first!'
# Run check with HTTP_PROXY environment variable set.
result = sat_maintain.cli.Health.check(
options={'label': 'env-proxy'}, env_var='HTTP_PROXY=https://proxy.example.com:5442'
)
assert 'FAIL' in result.stdout
assert result.status == 1
assert error_message in result.stdout
# Run check without setting HTTP_PROXY environment variable.
result = sat_maintain.cli.Health.check(options={'label': 'env-proxy'})
assert result.status == 0
assert 'FAIL' not in result.stdout
@pytest.mark.skipif(
settings.server.network_type == NetworkType.IPV6,
reason='Skipping as DHCPv6 is not managed on IPv6-only setup',
)
def test_positive_health_check_foreman_proxy_verify_dhcp_config_syntax(sat_maintain):
"""Verify foreman-proxy-verify-dhcp-config-syntax
:id: 43ca5cc7-9888-490d-b1ba-f3298e737039
:parametrized: yes
:setup:
1. Satellite instance configured with external DHCP like Infoblox,
which has `:use_provider: dhcp_infoblox` set in /etc/foreman-proxy/settings.d/dhcp.yml
2. Satellite instance which is DHCP enabled and has `:use_provider: dhcp_isc`
set in /etc/foreman-proxy/settings.d/dhcp.yml
:steps:
1. satellite-maintain health list | grep foreman-proxy-verify-dhcp-config-syntax
2. satellite-maintain health check --label foreman-proxy-verify-dhcp-config-syntax
:BZ: 1847889
:expectedresults: Check is not available on the satellite instances where `:use_provider:`
is set other than `dhcp_isc`, and also not on DHCP disabled Satellite.
:CaseImportance: Medium
"""
# Set dhcp.yml to `:use_provider: dhcp_isc`
sat_maintain.execute(
r"sed -i '/:use_provider: dhcp_infoblox/c\:use_provider: dhcp_isc'"
" /etc/foreman-proxy/settings.d/dhcp.yml"
)
result = sat_maintain.execute("cat /etc/foreman-proxy/settings.d/dhcp.yml")
assert ':use_provider: dhcp_isc' in result.stdout
# Run health list and check and verify nothing comes back
result = sat_maintain.cli.Health.list()
assert 'foreman-proxy-verify-dhcp-config-syntax' not in result.stdout
result = sat_maintain.cli.Health.check(
options={'label': 'foreman-proxy-verify-dhcp-config-syntax'}
)
assert result.status == 1
assert 'No scenario matching label [foreman-proxy-verify-dhcp-config-syntax]' in result.stdout
# Enable DHCP
installer = sat_maintain.install(
InstallerCommand('enable-foreman-proxy-plugin-dhcp-remote-isc', 'foreman-proxy-dhcp true')
)
assert 'Success!' in installer.stdout
# Run health list and check and verify check is made
result = sat_maintain.cli.Health.list()
assert 'foreman-proxy-verify-dhcp-config-syntax' in result.stdout
result = sat_maintain.cli.Health.check(
options={'label': 'foreman-proxy-verify-dhcp-config-syntax'}
)
assert result.status == 0
assert 'OK' in result.stdout
# Set dhcp.yml `:use_provider: dhcp_infoblox`
sat_maintain.execute(
r"sed -i '/:use_provider: dhcp_isc/c\:use_provider: dhcp_infoblox'"
" /etc/foreman-proxy/settings.d/dhcp.yml"
)
result = sat_maintain.execute("cat /etc/foreman-proxy/settings.d/dhcp.yml")
assert ':use_provider: dhcp_infoblox' in result.stdout
# Run health list and check and verify nothing comes back
result = sat_maintain.cli.Health.list()
assert 'foreman-proxy-verify-dhcp-config-syntax' not in result.stdout
result = sat_maintain.cli.Health.check(
options={'label': 'foreman-proxy-verify-dhcp-config-syntax'}
)
assert result.status == 1
assert 'No scenario matching label [foreman-proxy-verify-dhcp-config-syntax]' in result.stdout
def test_positive_remove_job_file(sat_maintain):
"""Verify file /var/lib/pulp/job1.0.0 is not present after the following command.
:id: eed224f9-a2ec-4d15-9047-cede0b823866
:steps:
1. Run satellite-maintain health list --tags pre-upgrade
2. Run satellite-maintain health check --label disk-performance
:expectedresults: `disk-performance` shouldn't exist under pre-upgrade tag and
/var/lib/pulp/job1.0.0 file should not exist after check execution
:CaseImportance: Medium
:customerscenario: true
:BZ: 1827219, 1762302
"""
# Verify pre-upgrade checks don't include disk-performance check
result = sat_maintain.cli.Health.list({'tags': 'pre-upgrade'})
assert 'disk-performance' not in result.stdout
# Verify job1.0.0 file not exist after check completion
result = sat_maintain.cli.Health.check(options={'label': 'disk-performance', 'assumeyes': True})
assert 'FAIL' not in result.stdout
assert sat_maintain.execute("ls -l /var/lib/pulp/job1.0.0").status != 0
def test_positive_health_check_corrupted_roles(sat_maintain, request):
"""Verify corrupted-roles check.
:id: 46117c38-edec-462d-83e1-4a5c035500d7
:steps:
1. Run satellite-maintain health check --label corrupted-roles
2. Run "hammer filter list --search role=test_role" again to check if corrupted roles
are fixed and verify if new filter is created for updated resource_type
:expectedresults: corrupted-roles health check should pass and should handle corrupted
roles by splitting filters as per updated values.
:CaseImportance: Medium
:customerscenario: true
:BZ: 1703041, 1908846
"""
role_name = 'test_role'
resource_type = gen_string("alpha")
sat_maintain.cli.Role.create(options={'name': role_name})
@request.addfinalizer
def _finalize():
resource_type = r"'\''Host'\''"
sat_maintain.execute(
f'''sudo su - postgres -c "psql -d foreman -c 'UPDATE permissions SET
resource_type = {resource_type} WHERE name = {permission_name};'"'''
)
sat_maintain.cli.Role.delete(options={'name': role_name})
# Check the filter created to verify the role, resource type, and permissions assigned.
sat_maintain.cli.Filter.create(
options={'role': role_name, 'permissions': ['view_hosts', 'console_hosts']}
)
permission_name = r"'\''console_hosts'\''"
resource_type = rf"'\''{resource_type}'\''"
setup = sat_maintain.execute(
f'''sudo su - postgres -c "psql -d foreman -c 'UPDATE permissions SET
resource_type = {resource_type} WHERE name = {permission_name};'"'''
)
assert setup.status == 0
result = sat_maintain.cli.Filter.list(options={'search': role_name}, output_format='yaml')
# Shows the filter id which comprises of role id hence asserting 2 here
assert result.count('Id') == 2
# Run corrupted-roles check.
result = sat_maintain.cli.Health.check(options={'label': 'corrupted-roles', 'assumeyes': True})
assert result.status == 0
assert 'FAIL' in result.stdout
# Verify corrupted roles are fixed and new filter is created for updated resource_type.
result = sat_maintain.cli.Filter.list(options={'search': role_name}, output_format='yaml')
assert result.count('Id') == 4
@pytest.mark.include_capsule
def test_positive_health_check_non_rh_packages(sat_maintain, request):
"""Verify non-rh-packages health check
:id: 2b7a25bb-902c-4a87-bb71-f460dcce655c
:parametrized: yes
:setup:
1. Configure custom repository and install non-RH/custom package
:steps:
1. Run satellite-maintain health check --label non-rh-packages.
2. Verify presence of non-RH/custom package installed on system.
:BZ: 1869865
:expectedresults: check-non-rh-packages health check should pass.
:customerscenario: true
:CaseImportance: High
"""
@request.addfinalizer
def _finalize():
assert sat_maintain.execute('dnf remove -y walrus').status == 0
assert sat_maintain.execute('rm -fr /etc/yum.repos.d/custom_repo.repo').status == 0
sat_maintain.create_custom_repos(custom_repo=settings.repos.yum_0.url)
assert (
sat_maintain.cli.Packages.install(packages='walrus', options={'assumeyes': True}).status
== 0
)
result = sat_maintain.cli.Health.check({'label': 'non-rh-packages'})
assert 'unexpected non Red Hat Package(s) installed!' in result.stdout
assert 'walrus-5.21-1.noarch' in result.stdout
assert result.status == 78
assert 'WARNING' in result.stdout
def test_positive_health_check_duplicate_permissions(sat_maintain):
"""Verify duplicate-permissions check
:id: 192a5943-43cc-4f89-9949-893c8011831a
:setup:
1. Setup duplicate permissions in the database
:steps:
1. foreman-maintain health check --label duplicate-permissions
:expectedresults: Verify if the check passes and removes duplicate permissions.
:CaseImportance: High
:customerscenario: true
:BZ: 1849110, 1884024
"""
# Verify if check failed because of duplicate permissions
name = r"'\''view_ansible_variables'\''"
resource_type = r"'\''AnsibleVariable'\''"
result = sat_maintain.execute(
f'''sudo su - postgres -c "psql -d foreman -c 'INSERT INTO permissions(name, resource_type)
VALUES({name}, {resource_type});'"'''
)
assert result.status == 0
result = sat_maintain.cli.Health.check({'label': 'duplicate-permissions', 'assumeyes': True})
assert result.status == 0
assert 'FAIL' in result.stdout
assert 'Remove duplicate permissions from database' in result.stdout
# Verify the check passed
result = sat_maintain.cli.Health.check({'label': 'duplicate-permissions'})
assert result.status == 0
assert 'FAIL' not in result.stdout