From 0a7ef4a26cd903138ae7b37f62ee2781ceb33cf7 Mon Sep 17 00:00:00 2001 From: shwsingh Date: Tue, 8 Oct 2024 09:50:16 +0530 Subject: [PATCH] Fix Discovery Tests --- pytest_fixtures/component/provision_pxe.py | 3 ++- tests/foreman/api/test_discoveredhost.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pytest_fixtures/component/provision_pxe.py b/pytest_fixtures/component/provision_pxe.py index 6ab04d036e1..3efa0035a4c 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..2fe4e0a51fa 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 @@ -167,7 +167,7 @@ class TestDiscoveredHost: @pytest.mark.upgrade @pytest.mark.e2e - @pytest.mark.on_premises_provisioning + # @pytest.mark.on_premises_provisioning @pytest.mark.parametrize('module_provisioning_sat', ['discovery'], indirect=True) @pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True) @pytest.mark.rhel_ver_list([8, 9]) @@ -179,6 +179,7 @@ def test_positive_provision_pxe_host( provisioning_host, provisioning_hostgroup, pxe_loader, + request, ): """Provision a pxe-based discovered host @@ -201,7 +202,7 @@ def test_positive_provision_pxe_host( mac = provisioning_host._broker_args['provisioning_nic_mac_addr'] wait_for( lambda: sat.api.DiscoveredHost().search(query={'mac': mac}) != [], - timeout=1500, + timeout=1800, delay=40, ) discovered_host = sat.api.DiscoveredHost().search(query={'mac': mac})[0] @@ -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 @@ -263,9 +264,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) + sat.provisioning_cleanup(host.name) @pytest.mark.tier3 def test_positive_auto_provision_pxe_host(