diff --git a/conftest.py b/conftest.py index 91eb0d54ae9..cba26ace014 100644 --- a/conftest.py +++ b/conftest.py @@ -37,6 +37,7 @@ 'pytest_fixtures.component.computeprofile', 'pytest_fixtures.component.contentview', 'pytest_fixtures.component.domain', + 'pytest_fixtures.component.discovery', 'pytest_fixtures.component.host', 'pytest_fixtures.component.hostgroup', 'pytest_fixtures.component.http_proxy', diff --git a/pytest_fixtures/component/discovery.py b/pytest_fixtures/component/discovery.py new file mode 100644 index 00000000000..693c51c9994 --- /dev/null +++ b/pytest_fixtures/component/discovery.py @@ -0,0 +1,46 @@ +from fauxfactory import gen_string +import pytest + + +@pytest.fixture(scope='module') +def module_discovery_hostgroup(module_org, module_location, module_target_sat): + host = module_target_sat.api.Host(organization=module_org, location=module_location) + host.create_missing() + return module_target_sat.api.HostGroup( + organization=[module_org], + location=[module_location], + medium=host.medium, + root_pass=gen_string('alpha'), + operatingsystem=host.operatingsystem, + ptable=host.ptable, + domain=host.domain, + architecture=host.architecture, + ).create() + + +@pytest.fixture(scope='module') +def discovery_org(module_org, module_target_sat): + # Update default discovered host organization + discovery_org = module_target_sat.api.Setting().search( + query={'search': 'name="discovery_organization"'} + )[0] + default_discovery_org = discovery_org.value + discovery_org.value = module_org.name + discovery_org.update(['value']) + yield module_org + discovery_org.value = default_discovery_org + discovery_org.update(['value']) + + +@pytest.fixture(scope='module') +def discovery_location(module_location, module_target_sat): + # Update default discovered host location + discovery_loc = module_target_sat.api.Setting().search( + query={'search': 'name="discovery_location"'} + )[0] + default_discovery_loc = discovery_loc.value + discovery_loc.value = module_location.name + discovery_loc.update(['value']) + yield module_location + discovery_loc.value = default_discovery_loc + discovery_loc.update(['value']) diff --git a/tests/foreman/api/test_discoveredhost.py b/tests/foreman/api/test_discoveredhost.py index 3fafd1cc423..773175812cf 100644 --- a/tests/foreman/api/test_discoveredhost.py +++ b/tests/foreman/api/test_discoveredhost.py @@ -25,22 +25,6 @@ from robottelo.utils.datafactory import valid_data_list -@pytest.fixture(scope='module') -def module_discovery_hostgroup(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""" @@ -290,7 +274,7 @@ def test_positive_provision_pxe_less_host( @pytest.mark.tier3 def test_positive_auto_provision_pxe_host( - self, module_discovery_hostgroup, module_target_sat, default_org, default_location + self, module_discovery_hostgroup, module_target_sat, discovery_org, discovery_location ): """Auto provision a pxe-based host by executing discovery rules @@ -313,15 +297,15 @@ def test_positive_auto_provision_pxe_host( max_count=1, hostgroup=module_discovery_hostgroup, search_=f'name = {discovered_host["name"]}', - location=[default_location], - organization=[default_org], + location=[discovery_location], + organization=[discovery_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.tier3 def test_positive_auto_provision_all( - self, module_discovery_hostgroup, module_target_sat, default_org, default_location + self, module_discovery_hostgroup, module_target_sat, discovery_org, discovery_location ): """Auto provision all host by executing discovery rules @@ -342,9 +326,9 @@ def test_positive_auto_provision_all( module_target_sat.api.DiscoveryRule( max_count=25, hostgroup=module_discovery_hostgroup, - search_='location = "Default Location"', - location=[default_location], - organization=[default_org], + search_=f'location = "{discovery_location.name}"', + location=[discovery_location], + organization=[discovery_org], ).create() for _ in range(2):