From 4f04f93145e2dc8a7e685b83c172f2057d84e227 Mon Sep 17 00:00:00 2001 From: Shweta Singh Date: Wed, 13 Nov 2024 20:22:34 +0530 Subject: [PATCH] Fix Discovery Tests (#16605) (cherry picked from commit 41ec8b6c020f44f27d2ec1645f2a5c4412ac315f) --- pytest_fixtures/component/provision_pxe.py | 3 ++- tests/foreman/api/test_discoveredhost.py | 16 +++++++++------- tests/foreman/api/test_provisioning.py | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pytest_fixtures/component/provision_pxe.py b/pytest_fixtures/component/provision_pxe.py index 8cef98f3dec..8c1f2bc833f 100644 --- a/pytest_fixtures/component/provision_pxe.py +++ b/pytest_fixtures/component/provision_pxe.py @@ -216,7 +216,7 @@ def module_ssh_key_file(): @pytest.fixture -def provisioning_host(module_ssh_key_file, pxe_loader): +def provisioning_host(module_ssh_key_file, pxe_loader, module_provisioning_sat): """Fixture to check out blank VM""" vlan_id = settings.provisioning.vlan_id cd_iso = ( @@ -234,6 +234,7 @@ def provisioning_host(module_ssh_key_file, pxe_loader): ) as prov_host: yield prov_host # Set host as non-blank to run teardown of the host + assert module_provisioning_sat.sat.execute('systemctl restart dhcpd').status == 0 prov_host.blank = getattr(prov_host, 'blank', False) diff --git a/tests/foreman/api/test_discoveredhost.py b/tests/foreman/api/test_discoveredhost.py index 45cda857130..476687e436c 100644 --- a/tests/foreman/api/test_discoveredhost.py +++ b/tests/foreman/api/test_discoveredhost.py @@ -28,7 +28,7 @@ class HostNotDiscoveredException(Exception): def _read_log(ch, pattern): """Read the first line from the given channel buffer and return the matching line""" # read lines until the buffer is empty - for log_line in ch.stdout().splitlines(): + for log_line in ch.result.stdout.splitlines(): logger.debug(f'foreman-tail: {log_line}') if re.search(pattern, log_line): return log_line @@ -179,6 +179,7 @@ def test_positive_provision_pxe_host( provisioning_host, provisioning_hostgroup, pxe_loader, + request, ): """Provision a pxe-based discovered host @@ -214,9 +215,9 @@ def test_positive_provision_pxe_host( host = discovered_host.update(['hostgroup', 'build', 'location', 'organization']) host = sat.api.Host().search(query={"search": f'name={host.name}'})[0] assert host - assert_discovered_host_provisioned(shell, module_provisioning_rhel_content.ksrepo) - sat.provisioning_cleanup(host.name) - provisioning_host.blank = True + shell.close() + assert_discovered_host_provisioned(shell, module_provisioning_rhel_content.ksrepo) + request.addfinalizer(lambda: sat.provisioning_cleanup(host.name)) @pytest.mark.upgrade @pytest.mark.e2e @@ -231,6 +232,7 @@ def test_positive_provision_pxe_less_host( pxeless_discovery_host, module_provisioning_rhel_content, provisioning_hostgroup, + request, ): """Provision a pxe-less discovered hosts @@ -263,9 +265,9 @@ def test_positive_provision_pxe_less_host( host = discovered_host.update(['hostgroup', 'build', 'location', 'organization']) host = sat.api.Host().search(query={"search": f'name={host.name}'})[0] assert host - assert_discovered_host_provisioned(shell, module_provisioning_rhel_content.ksrepo) - sat.provisioning_cleanup(host.name) - pxeless_discovery_host.blank = True + shell.close() + assert_discovered_host_provisioned(shell, module_provisioning_rhel_content.ksrepo) + request.addfinalizer(lambda: sat.provisioning_cleanup(host.name)) @pytest.mark.tier3 def test_positive_auto_provision_pxe_host( diff --git a/tests/foreman/api/test_provisioning.py b/tests/foreman/api/test_provisioning.py index 481041ee412..86252b61c03 100644 --- a/tests/foreman/api/test_provisioning.py +++ b/tests/foreman/api/test_provisioning.py @@ -27,7 +27,7 @@ def _read_log(ch, pattern): """Read the first line from the given channel buffer and return the matching line""" # read lines until the buffer is empty - for log_line in ch.stdout().splitlines(): + for log_line in ch.result.stdout.splitlines(): logger.debug(f'foreman-tail: {log_line}') if re.search(pattern, log_line): return log_line @@ -384,6 +384,7 @@ def test_rhel_httpboot_provisioning( # check for proper HTTP requests shell = module_provisioning_sat.session.shell() shell.send('foreman-tail') + shell.close() assert_host_logs(shell, f'GET /httpboot/grub2/grub.cfg-{host_mac_addr} with 200') # Host should do call back to the Satellite reporting # the result of the installation. Wait until Satellite reports that the host is installed.