Skip to content

Commit

Permalink
Making a discovery component helper module
Browse files Browse the repository at this point in the history
  • Loading branch information
adarshdubey-star committed Oct 11, 2023
1 parent 0beabd4 commit fdea4f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
31 changes: 31 additions & 0 deletions pytest_fixtures/component/discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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).create()
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):
discovery_org = module_target_sat.update_setting('discovery_organization', module_org.name)
yield module_org
module_target_sat.update_setting('discovery_organization', discovery_org)


@pytest.fixture(scope='module')
def discovery_location(module_location, module_target_sat):
discovery_loc = module_target_sat.update_setting('discovery_location', module_location.name)
yield module_location
module_target_sat.update_setting('discovery_location', discovery_loc)
30 changes: 7 additions & 23 deletions tests/foreman/api/test_discoveredhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit fdea4f0

Please sign in to comment.