From 070bdd8a685a4ddb34117010485038948ba1ba95 Mon Sep 17 00:00:00 2001 From: Adarsh Dubey Date: Wed, 4 Oct 2023 19:20:38 +0530 Subject: [PATCH] Coverage for autoprovision and reboot of discovered host --- tests/foreman/api/test_discoveredhost.py | 63 ++++++++++++++++++++++-- tests/foreman/api/test_repositories.py | 4 +- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/tests/foreman/api/test_discoveredhost.py b/tests/foreman/api/test_discoveredhost.py index 9b4a5ae5e22..7a4d1f757ed 100644 --- a/tests/foreman/api/test_discoveredhost.py +++ b/tests/foreman/api/test_discoveredhost.py @@ -25,6 +25,22 @@ from robottelo.utils.datafactory import valid_data_list +@pytest.fixture(scope='module') +def module_hg(default_org, default_location, module_target_sat): + host = module_target_sat.api.Host(organization=default_org, location=default_location) + host.create_missing() + return module_target_sat.api.HostGroup( + organization=[default_org], + location=[default_location], + medium=host.medium, + root_pass=gen_string('alpha'), + operatingsystem=host.operatingsystem, + ptable=host.ptable, + domain=host.domain, + architecture=host.architecture, + ).create() + + class HostNotDiscoveredException(Exception): """Raised when host is not discovered""" @@ -274,9 +290,11 @@ def test_positive_provision_pxe_less_host( assert not sat.api.Host().search(query={"search": f'name={host.name}'}) pxeless_discovery_host.blank = True - @pytest.mark.stubbed + @pytest.mark.tier3 - def test_positive_auto_provision_pxe_host(self): + def test_positive_auto_provision_pxe_host( + self, module_hg, module_target_sat, default_org, default_location + ): """Auto provision a pxe-based host by executing discovery rules :id: c93fd7c9-41ef-4eb5-8042-f72e87e67e10 @@ -294,8 +312,18 @@ def test_positive_auto_provision_pxe_host(self): :CaseImportance: Critical """ + discovered_host = module_target_sat.api_factory.create_discovered_host() + + rule = module_target_sat.api.DiscoveryRule( + max_count=1, + hostgroup=module_hg, + search_=f"name = {discovered_host['name']}", + location=[default_location], + organization=[default_org], + ).create() + result = module_target_sat.api.DiscoveredHost(id=discovered_host['id']).auto_provision() + assert f"provisioned with rule {rule.name}" in result['message'] - @pytest.mark.stubbed @pytest.mark.tier3 def test_positive_auto_provision_all(self): """Auto provision all host by executing discovery rules @@ -337,9 +365,19 @@ def test_positive_refresh_facts_pxe_host(self): :CaseImportance: High """ - @pytest.mark.stubbed + @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_match('9') @pytest.mark.tier3 - def test_positive_reboot_pxe_host(self): + def test_positive_reboot_pxe_host( + self, + module_provisioning_rhel_content, + module_discovery_sat, + provisioning_host, + provisioning_hostgroup, + pxe_loader, + ): """Rebooting a pxe based discovered host :id: 69c807f8-5646-4aa6-8b3c-5ecab69560fc @@ -356,6 +394,21 @@ def test_positive_reboot_pxe_host(self): :CaseImportance: Medium """ + sat = module_discovery_sat.sat + provisioning_host.power_control(ensure=False) + mac = provisioning_host._broker_args['provisioning_nic_mac_addr'] + wait_for( + lambda: sat.api.DiscoveredHost().search(query={'mac': mac}) != [], + timeout=240, + delay=20, + ) + discovered_host = sat.api.DiscoveredHost().search(query={'mac': mac})[0] + discovered_host.hostgroup = provisioning_hostgroup + discovered_host.location = provisioning_hostgroup.location[0] + discovered_host.organization = provisioning_hostgroup.organization[0] + discovered_host.build = True + result = sat.api.DiscoveredHost(id=discovered_host.id).reboot() + assert 'Unable to perform reboot' not in result @pytest.mark.stubbed @pytest.mark.tier3 diff --git a/tests/foreman/api/test_repositories.py b/tests/foreman/api/test_repositories.py index a7c4b1a5340..58cbd9792b2 100644 --- a/tests/foreman/api/test_repositories.py +++ b/tests/foreman/api/test_repositories.py @@ -25,9 +25,7 @@ from robottelo import constants from robottelo.cli.base import CLIReturnCodeError from robottelo.config import settings -from robottelo.constants import DEFAULT_ARCHITECTURE -from robottelo.constants import MIRRORING_POLICIES -from robottelo.constants import REPOS +from robottelo.constants import DEFAULT_ARCHITECTURE, MIRRORING_POLICIES, REPOS from robottelo.utils.datafactory import parametrized