forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_provisioning.py
More file actions
866 lines (752 loc) · 32.9 KB
/
Copy pathtest_provisioning.py
File metadata and controls
866 lines (752 loc) · 32.9 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
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
"""Provisioning tests
:Requirement: Provisioning
:CaseAutomation: Automated
:CaseComponent: Provisioning
:Team: Rocket
:CaseImportance: Critical
"""
import time
from fauxfactory import gen_string
import pytest
from wait_for import wait_for
from wrapanapi.systems.virtualcenter import VMWareVirtualMachine
from robottelo.config import settings
from robottelo.enums import NetworkType
from robottelo.utils.installer import InstallerCommand
from robottelo.utils.issue_handlers import is_open
@pytest.mark.e2e
@pytest.mark.upgrade
@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True)
@pytest.mark.on_premises_provisioning
@pytest.mark.ipv6_provisioning
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_rhel_pxe_provisioning(
request,
module_provisioning_sat,
module_sca_manifest_org,
module_location,
provisioning_host,
pxe_loader,
module_provisioning_rhel_content,
provisioning_hostgroup,
module_lce_library,
module_default_org_view,
configure_kea_dhcp6_server,
):
"""Simulate baremetal provisioning of a RHEL system via PXE on RHV provider
:id: 8b33f545-c4a8-428d-8fd8-a5e402c8cd10
:steps:
1. Provision RHEL system via PXE on RHV
2. Check that resulting host is registered to Satellite
3. Check host is subscribed to Satellite
:expectedresults:
1. Host installs right version of RHEL
2. Satellite is able to run REX job on the host
3. Host is registered to Satellite and subscription status is 'Success'
:BZ: 2105441, 1955861, 1784012
:Verifies:SAT-20739,SAT-27869
:customerscenario: true
:parametrized: yes
"""
if (
pxe_loader.vm_firmware == 'bios'
and module_provisioning_sat.sat.network_type == NetworkType.IPV6
):
pytest.skip('Test cannot be run on BIOS as its not supported')
host_mac_addr = provisioning_host.provisioning_nic_mac_addr
sat = module_provisioning_sat.sat
# Configure the grubx64.efi image to setup the interface and use TFTP to load the configuration
if module_provisioning_sat.sat.network_type == NetworkType.IPV6:
sat.execute("echo -e 'net_bootp6\nset root=tftp\nset prefix=(tftp)/grub2' > pre.cfg")
sat.execute(
'grub2-mkimage -c pre.cfg -o /var/lib/tftpboot/grub2/grubx64.efi -p /grub2/ -O x86_64-efi efinet efi_netfs efienv efifwsetup efi_gop tftp net normal chain configfile loadenv procfs romfs'
)
host = sat.api.Host(
hostgroup=provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
name=gen_string('alpha').lower(),
mac=host_mac_addr,
operatingsystem=module_provisioning_rhel_content.os,
host_parameters_attributes=[
{'name': 'remote_execution_connect_by_ip', 'value': 'true', 'parameter_type': 'boolean'}
],
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
# Start the VM, do not ensure that we can connect to SSHD
provisioning_host.power_control(ensure=False)
# TODO: Implement Satellite log capturing logic to verify that
# all the events are captured in the logs.
# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
# The label checked above is generated dynamically and may not necessarily
# represent the exact value that is stored in the database
assert (
len(sat.api.Host().search(query={'search': f'name="{host.name}" and build_status = built'}))
== 1
)
# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
if is_open('SAT-30601') and module_provisioning_sat.sat.network_type == NetworkType.IPV4:
provisioning_host.hostname = host.ip
# Host is not blank anymore
provisioning_host.blank = False
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'
if int(host_os.major) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert expected_rhel_version in host_ssh_os.stdout, (
'Different than the expected OS version was installed'
)
# Verify provisioning log exists on host at correct path
assert provisioning_host.execute('test -s /root/install.post.log').status == 0
assert provisioning_host.execute('test -s /mnt/sysimage/root/install.post.log').status == 1
# Run a command on the host using REX to verify that Satellite's SSH key is present on the host
# Add workaround for SAT-32007 and SAT-32006
if is_open('SAT-32007') and is_open('SAT-32006'):
assert (
sat.execute('cat /dev/null > /usr/share/foreman-proxy/.ssh/known_hosts').status == 0
)
template_id = (
sat.api.JobTemplate()
.search(query={'search': 'name="Run Command - Script Default"'})[0]
.id
)
job = sat.api.JobInvocation().run(
data={
'job_template_id': template_id,
'inputs': {
'command': f'subscription-manager config | grep "hostname = {sat.hostname}"'
},
'search_query': f"name = {host.name}",
'targeting_type': 'static_query',
},
)
assert job['result'] == 'success', 'Job invocation failed'
# check if katello-ca-consumer is not used while host registration
assert provisioning_host.execute('rpm -qa |grep katello-ca-consumer').status == 1
assert (
'katello-ca-consumer'
not in provisioning_host.execute('cat /root/install.post.log').stdout
)
# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'
@pytest.mark.e2e
@pytest.mark.upgrade
@pytest.mark.parametrize('pxe_loader', ['ipxe'], indirect=True)
@pytest.mark.on_premises_provisioning
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_rhel_ipxe_provisioning(
request,
module_provisioning_sat,
module_sca_manifest_org,
module_location,
provisioning_host,
pxe_loader,
module_provisioning_rhel_content,
provisioning_hostgroup,
module_lce_library,
module_default_org_view,
):
"""Provision a host using iPXE workflow
:id: 9e016e1d-757a-48e7-9159-131bb65dc4ed
:steps:
1. Configure satellite for provisioning
2. provision a host
3. Check that resulting host is registered to Satellite
4. Check host is subscribed to Satellite
:expectedresults:
1. Provisioning via iPXE is successful
2. Host installs right version of RHEL
3. Satellite is able to run REX job on the host
4. Host is registered to Satellite and subscription status is 'Success'
:parametrized: yes
"""
# TODO: parametrize iPXE Chain BIOS as pxe loader after #BZ:2171172 is fixed
sat = module_provisioning_sat.sat
# set http url
ipxe_http_url = sat.install(
InstallerCommand(
f'foreman-proxy-dhcp-ipxefilename "http://{sat.hostname}/unattended/iPXE?bootstrap=1"'
)
)
assert ipxe_http_url.status == 0
host_mac_addr = provisioning_host.provisioning_nic_mac_addr
host = sat.api.Host(
hostgroup=provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
name=gen_string('alpha').lower(),
mac=host_mac_addr,
operatingsystem=module_provisioning_rhel_content.os,
subnet=module_provisioning_sat.subnet,
host_parameters_attributes=[
{'name': 'remote_execution_connect_by_ip', 'value': 'true', 'parameter_type': 'boolean'}
],
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
# Start the VM, do not ensure that we can connect to SSHD
provisioning_host.power_control(ensure=False)
# TODO: Implement Satellite log capturing logic to verify that
# all the events are captured in the logs.
# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
provisioning_host.hostname = host.ip
# Host is not blank anymore
provisioning_host.blank = False
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'
if int(host_os.major) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert expected_rhel_version in host_ssh_os.stdout, (
f'The installed OS version differs from the expected version {expected_rhel_version}'
)
# Run a command on the host using REX to verify that Satellite's SSH key is present on the host
# Add workaround for SAT-32007 and SAT-32006
if is_open('SAT-32007') and is_open('SAT-32006'):
assert sat.execute('cat /dev/null > /usr/share/foreman-proxy/.ssh/known_hosts').status == 0
template_id = (
sat.api.JobTemplate().search(query={'search': 'name="Run Command - Script Default"'})[0].id
)
job = sat.api.JobInvocation().run(
data={
'job_template_id': template_id,
'inputs': {
'command': f'subscription-manager config | grep "hostname = {sat.hostname}"'
},
'search_query': f"name = {host.name}",
'targeting_type': 'static_query',
},
)
assert job['result'] == 'success', 'Job invocation failed'
# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'
@pytest.mark.e2e
@pytest.mark.upgrade
@pytest.mark.parametrize('pxe_loader', ['http_uefi'], indirect=True)
@pytest.mark.on_premises_provisioning
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_rhel_httpboot_provisioning(
request,
module_provisioning_sat,
module_sca_manifest_org,
module_location,
provisioning_host,
pxe_loader,
module_provisioning_rhel_content,
provisioning_hostgroup,
module_lce_library,
module_default_org_view,
):
"""Provision a host using httpboot workflow
:id: 98c2865e-5d21-402e-ad01-c474b7fc4eee
:steps:
1. Configure satellite for provisioning
2. provision a host using pxe loader as Grub2 UEFI HTTP
3. Check that resulting host is registered to Satellite
4. Check host is subscribed to Satellite
:expectedresults:
1. Provisioning via HTTP is successful
2. Host installs right version of RHEL
3. Satellite is able to run REX job on the host
4. Host is registered to Satellite and subscription status is 'Success'
:parametrized: yes
:BlockedBy: SAT-20684
:Verifies: SAT-20684
"""
sat = module_provisioning_sat.sat
# Configure the grubx64.efi image to setup the interface and use TFTP to load the configuration
# update grub2-efi package
sat.cli.Packages.update(packages='grub2-efi', options={'assumeyes': True})
sat.execute("echo -e 'set root=tftp\nset prefix=(tftp)/grub2' > pre.cfg")
sat.execute(
'grub2-mkimage -c pre.cfg -o /var/lib/tftpboot/grub2/grubx64.efi -p /grub2/ -O x86_64-efi efinet efi_netfs efienv efifwsetup efi_gop tftp net normal chain configfile loadenv procfs romfs'
)
host_mac_addr = provisioning_host.provisioning_nic_mac_addr
host = sat.api.Host(
hostgroup=provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
name=gen_string('alpha').lower(),
mac=host_mac_addr,
operatingsystem=module_provisioning_rhel_content.os,
subnet=module_provisioning_sat.subnet,
host_parameters_attributes=[
{'name': 'remote_execution_connect_by_ip', 'value': 'true', 'parameter_type': 'boolean'}
],
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
# Start the VM, do not ensure that we can connect to SSHD
provisioning_host.power_control(ensure=False)
host_mac_addr = host_mac_addr.replace(":", "-")
shell = sat.session.shell()
shell.send('foreman-tail')
time.sleep(20)
shell.close()
assert f'GET /httpboot/host-config/{host_mac_addr}/grub2/boot.efi with 200' in str(shell.read())
# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
provisioning_host.hostname = host.ip
# Host is not blank anymore
provisioning_host.blank = False
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'
if int(host_os.major) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert expected_rhel_version in host_ssh_os.stdout, (
f'The installed OS version differs from the expected version {expected_rhel_version}'
)
# Run a command on the host using REX to verify that Satellite's SSH key is present on the host
# Add workaround for SAT-32007 and SAT-32006
if is_open('SAT-32007') and is_open('SAT-32006'):
assert sat.execute('cat /dev/null > /usr/share/foreman-proxy/.ssh/known_hosts').status == 0
template_id = (
sat.api.JobTemplate().search(query={'search': 'name="Run Command - Script Default"'})[0].id
)
job = sat.api.JobInvocation().run(
data={
'job_template_id': template_id,
'inputs': {
'command': f'subscription-manager config | grep "hostname = {sat.hostname}"'
},
'search_query': f"name = {host.name}",
'targeting_type': 'static_query',
},
)
assert job['result'] == 'success', 'Job invocation failed'
# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'
@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True)
@pytest.mark.on_premises_provisioning
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_rhel_pxe_provisioning_fips_enabled(
request,
module_provisioning_sat,
module_sca_manifest_org,
module_location,
provisioning_host,
pxe_loader,
module_provisioning_rhel_content,
provisioning_hostgroup,
module_lce_library,
module_default_org_view,
):
"""Provision a host with host param fips_enabled set to true
:id: 9e016e1d-757a-48e7-9159-131bb65dc4ef
:steps:
1. Configure satellite for provisioning
2. Provision a host with host param fips_enabled
3. Check that resulting host is registered to Satellite
4. Check host is subscribed to Satellite
:expectedresults:
1. Provisioning with host param fips_enabled is successful
2. Host installs right version of RHEL
3. Satellite is able to run REX job on the fips_enabled host
4. Host is registered to Satellite and subscription status is 'Success'
:parametrized: yes
:BZ: 2240076
:Verifies: SAT-26071
"""
# Skip RHEL7 UEFI test due to known issue SAT-41340
if (
is_open('SAT-41340')
and pxe_loader.vm_firmware in ['uefi']
and module_provisioning_rhel_content.os.major == '7'
):
pytest.skip(
f"Test not supported for rhel{module_provisioning_rhel_content.os.major} {pxe_loader.vm_firmware} firmware"
)
sat = module_provisioning_sat.sat
host_mac_addr = provisioning_host.provisioning_nic_mac_addr
# Verify password hashing algorithm SHA512 is set in OS used for provisioning
assert module_provisioning_rhel_content.os.password_hash == 'SHA512'
host = sat.api.Host(
hostgroup=provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
name=gen_string('alpha').lower(),
mac=host_mac_addr,
operatingsystem=module_provisioning_rhel_content.os,
subnet=module_provisioning_sat.subnet,
host_parameters_attributes=[
{
'name': 'remote_execution_connect_by_ip',
'value': 'true',
'parameter_type': 'boolean',
},
{'name': 'fips_enabled', 'value': 'true', 'parameter_type': 'boolean'},
],
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
# Start the VM, do not ensure that we can connect to SSHD
provisioning_host.power_control(ensure=False)
# TODO: Implement Satellite log capturing logic to verify that
# all the events are captured in the logs.
# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
provisioning_host.hostname = host.ip
# Host is not blank anymore
provisioning_host.blank = False
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'
if int(host_os.major) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert expected_rhel_version in host_ssh_os.stdout, (
f'The installed OS version differs from the expected version {expected_rhel_version}'
)
# Verify FIPS is enabled on host after provisioning is completed successfully
result = provisioning_host.execute('cat /proc/sys/crypto/fips_enabled')
assert int(result.stdout) == 1
# Run a command on the host using REX to verify that Satellite's SSH key is present on the host
# Add workaround for SAT-32007 and SAT-32006
if is_open('SAT-32007') and is_open('SAT-32006'):
assert sat.execute('cat /dev/null > /usr/share/foreman-proxy/.ssh/known_hosts').status == 0
template_id = (
sat.api.JobTemplate().search(query={'search': 'name="Run Command - Script Default"'})[0].id
)
job = sat.api.JobInvocation().run(
data={
'job_template_id': template_id,
'inputs': {
'command': f'subscription-manager config | grep "hostname = {sat.hostname}"'
},
'search_query': f"name = {host.name}",
'targeting_type': 'static_query',
},
)
assert job['result'] == 'success', 'Job invocation failed'
# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'
@pytest.mark.e2e
@pytest.mark.upgrade
@pytest.mark.on_premises_provisioning
@pytest.mark.parametrize('pxe_loader', ['secureboot'], indirect=True)
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_rhel_pxe_provisioning_secureboot_enabled(
request,
module_provisioning_sat,
vmwareclient,
provisioning_vmware_host,
pxe_loader,
module_sca_manifest_org,
module_location,
module_provisioning_rhel_content,
provisioning_hostgroup,
):
"""Simulate Secureboot baremetal provisioning of a RHEL system via PXE on vCenter provider
:id: 8b33f545-c4a8-428d-8fd8-a5e402c8cd23
:steps:
1. Provision RHEL system via PXE on vCenter provider
2. Check that resulting host is registered to Satellite
3. Check host is subscribed to Satellite
:expectedresults:
1. Host installs right version of RHEL
2. Host is registered to Satellite and subscription status is 'Success'
3. Secureboot is enabled on the host
:Verifies: SAT-25809
:customerscenario: true
:parametrized: yes
"""
host_mac_addr = provisioning_vmware_host.provisioning_nic_mac_addr
sat = module_provisioning_sat.sat
host = sat.api.Host(
hostgroup=provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
name=gen_string('alpha').lower(),
mac=host_mac_addr,
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
# start the provisioning host on VMware, do not ensure that we can connect to SSHD
vmware_host = VMWareVirtualMachine(vmwareclient, name=provisioning_vmware_host.name)
vmware_host.start()
# TODO: Implement Satellite log capturing logic to verify that
# all the events are captured in the logs.
# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
provisioning_vmware_host.hostname = host.ip
# Host is not blank anymore
provisioning_vmware_host.blank = False
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_vmware_host.wait_for_connection()
# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'
if int(host_os.major) >= 9:
assert (
provisioning_vmware_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_vmware_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert expected_rhel_version in host_ssh_os.stdout, (
'Different than the expected OS version was installed'
)
# Verify host is subscribed and consumes subsctiption provided by the activation key
assert provisioning_vmware_host.subscribed, 'Host is not subscribed'
# Verify SecureBoot is enabled on host after provisioning is completed successfully
assert 'SecureBoot enabled' in provisioning_vmware_host.execute('mokutil --sb-state').stdout
@pytest.mark.e2e
@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True)
@pytest.mark.skip(reason='Skipping till we have destructive support')
@pytest.mark.on_premises_provisioning
@pytest.mark.rhel_ver_match(r'^(?!.*fips).*$')
def test_capsule_pxe_provisioning(
request,
capsule_provisioning_sat,
module_capsule_configured,
capsule_provisioning_rhel_content,
module_sca_manifest_org,
module_location,
provisioning_host,
pxe_loader,
capsule_provisioning_hostgroup,
module_lce_library,
module_default_org_view,
capsule_provisioning_lce_sync_setup,
):
"""Provision a host using external capsule
:id: d76cd326-af4e-4bd5-b20c-128348e042d3
:steps:
1. Configure satellite and capsule for provisioning
2. Provision a host using capsule as the content source
3. Check that resulting host is registered to Satellite
:expectedresults:
1. Provisioning using external capsule is successful.
1. Host installs right version of RHEL
2. Satellite is able to run REX job on the host
3. Host is registered to Satellite and subscription status is 'Success'
:parametrized: yes
"""
host_mac_addr = provisioning_host.provisioning_nic_mac_addr
sat = capsule_provisioning_sat.sat
cap = module_capsule_configured
host = sat.api.Host(
hostgroup=capsule_provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
content_facet_attributes={
'content_view_id': capsule_provisioning_rhel_content.cv.id,
'lifecycle_environment_id': module_lce_library.id,
},
name=gen_string('alpha').lower(),
mac=host_mac_addr,
operatingsystem=capsule_provisioning_rhel_content.os,
subnet=capsule_provisioning_sat.subnet,
host_parameters_attributes=[
{
'name': 'remote_execution_connect_by_ip',
'value': 'true',
'parameter_type': 'boolean',
},
],
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(lambda: sat.provisioning_cleanup(host.name))
# Start the VM, do not ensure that we can connect to SSHD
provisioning_host.power_control(ensure=False)
# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
provisioning_host.hostname = host.ip
# Host is not blank anymore
provisioning_host.blank = False
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'
if int(host_os.major) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert expected_rhel_version in host_ssh_os.stdout, (
f'The installed OS version differs from the expected version {expected_rhel_version}'
)
# Run a command on the host using REX to verify that Satellite's SSH key is present on the host
# Add workaround for SAT-32007 and SAT-32006
if is_open('SAT-32007') and is_open('SAT-32006'):
assert sat.execute('cat /dev/null > /usr/share/foreman-proxy/.ssh/known_hosts').status == 0
template_id = (
sat.api.JobTemplate().search(query={'search': 'name="Run Command - Script Default"'})[0].id
)
job = sat.api.JobInvocation().run(
data={
'job_template_id': template_id,
'inputs': {
'command': f'subscription-manager config | grep "hostname = {cap.hostname}"'
},
'search_query': f"name = {host.name}",
'targeting_type': 'static_query',
},
)
assert job['result'] == 'success', 'Job invocation failed'
# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'
@pytest.mark.stubbed
def test_rhel_provisioning_using_realm():
"""Provision a host using realm
:id: 687e7d71-7e46-46d5-939b-4562f88c4598
:steps:
1. Configure satellite for provisioning
2. Configure Satellite for Realm support
3. Provision a Host
4. Check host is subscribed to Satellite
:expectedresults:
1. Provisioning via Realm is successful
2. Check if the provisioned host is automatically registered to IdM
3. Host installs right version of RHEL
4. Satellite is able to run REX job on the host
5. Host is registered to Satellite and subscription status is 'Success'
:CaseAutomation: NotAutomated
"""