Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pytest_fixtures/component/provision_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def module_provisioning_sat(
It calls a workflow using broker to set up the network and to run satellite-installer.
It uses the artifacts from the workflow to create all the necessary Satellite entities
that are later used by the tests.
For IPv4, it clears DHCP leases and restarts dhcpd to ensure provisioning can obtain addresses.
"""
provisioning_type = getattr(request, 'param', '')
sat = module_target_sat
Expand Down Expand Up @@ -208,6 +209,9 @@ def module_provisioning_sat(
remote_execution_proxy=[module_provisioning_capsule.id],
domain=[domain.id],
).create()
if sat.network_type == NetworkType.IPV4:
assert sat.execute('cat /dev/null > /var/lib/dhcpd/dhcpd.leases').status == 0
assert sat.execute('systemctl restart dhcpd').status == 0
return Box(sat=sat, domain=domain, subnet=subnet, provisioning_type=provisioning_type)


Expand Down
15 changes: 12 additions & 3 deletions tests/foreman/cli/test_computeresource_libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from robottelo.exceptions import CLIReturnCodeError
from robottelo.hosts import ContentHost
from robottelo.utils.datafactory import parametrized
from robottelo.utils.issue_handlers import is_open

LIBVIRT_URL = LIBVIRT_RESOURCE_URL % settings.libvirt.libvirt_hostname

Expand Down Expand Up @@ -408,6 +409,10 @@ def test_positive_provision_end_to_end(

:customerscenario: true
"""
# Skip test for UEFI and SecureBoot loaders
if is_open('SAT-41340') and pxe_loader.vm_firmware in ['uefi', 'uefi_secure_boot']:
pytest.skip(f"Test not supported for {pxe_loader.vm_firmware} firmware")

sat = module_libvirt_provisioning_sat.sat
cr_name = gen_string('alpha')
hostname = gen_string('alpha').lower()
Expand Down Expand Up @@ -450,12 +455,16 @@ def test_positive_provision_end_to_end(
f'su foreman -s /bin/bash -c "virsh -c {LIBVIRT_URL} list --state-running"'
)
assert hostname in result.stdout

wait_for(
lambda: sat.cli.Host.info({'name': hostname})['status']['build-status']
!= 'Pending installation',
lambda: (
sat.cli.Host.info({'name': hostname})
.get('status', {})
.get('build-status', 'Pending installation')
!= 'Pending installation'
),
timeout=1800,
delay=30,
handle_exception=True,
)
host_info = sat.cli.Host.info({'id': host['id']})
assert host_info['status']['build-status'] == 'Installed'
Expand Down
6 changes: 3 additions & 3 deletions tests/foreman/ui/test_computeresource_libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def test_positive_provision_end_to_end(
)
name = f'{hostname}.{module_libvirt_provisioning_sat.domain.name}'
request.addfinalizer(lambda: sat.provisioning_cleanup(name))
assert session.host.search(name)[0]['Name'] == name

Comment on lines 183 to -185

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Guard against empty search results before indexing to improve test failure messages.

session.host_new.search(name)[0] will raise IndexError if no host is found, instead of a clear assertion failure. Capture the results first and assert they are non-empty (e.g. results = session.host_new.search(name); assert results, 'Expected host ...'; result = results[0]) before asserting result['Name'] == name.

Suggested change
request.addfinalizer(lambda: sat.provisioning_cleanup(name))
assert session.host.search(name)[0]['Name'] == name
request.addfinalizer(lambda: sat.provisioning_cleanup(name))
results = session.host_new.search(name)
assert results, f"Expected host '{name}' to be present in session.host_new.search results"
result = results[0]
assert result['Name'] == name

result = session.host_new.search(name)[0]
assert result['Name'] == name
# Check on Libvirt, if VM exists
result = sat.execute(
f'su foreman -s /bin/bash -c "virsh -c {LIBVIRT_URL} list --state-running"'
Expand All @@ -203,7 +203,7 @@ def test_positive_provision_end_to_end(

# Verify SecureBoot is enabled on host after provisioning is completed successfully
if pxe_loader.vm_firmware == 'uefi_secure_boot':
host = sat.api.Host().search(query={'host': hostname})[0].read()
host = sat.api.Host().search(query={"search": f'name={name}'})[0].read()
provisioning_host = ContentHost(host.ip)
# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
Expand Down