Skip to content

Commit

Permalink
Discovery Provisioning UI coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
adarshdubey-star committed Oct 27, 2023
1 parent 5912ef2 commit b9f750c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 132 deletions.
11 changes: 11 additions & 0 deletions pytest_fixtures/component/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ 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)


@pytest.fixture(scope='module')
def provisioning_env(module_target_sat, discovery_org, discovery_location):
# Build PXE default template to get default PXE file
module_target_sat.cli.ProvisioningTemplate().build_pxe_default()
return module_target_sat.api_factory.configure_provisioning(
org=discovery_org,
loc=discovery_location,
os='Redhat {}'.format(module_target_sat.cli_factory.RHELRepository().repo_data['version']),
)
208 changes: 76 additions & 132 deletions tests/foreman/ui/test_discoveredhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,19 @@
:Upstream: No
"""
from fauxfactory import gen_ipaddr, gen_string
from nailgun import entities
import pytest
from wait_for import wait_for

from robottelo.utils import ssh

pytestmark = [pytest.mark.run_in_one_thread]


@pytest.fixture(scope='module')
def discovery_org(module_org):
# Update default discovered host organization
discovery_org = entities.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):
# Update default discovered host location
discovery_loc = entities.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'])


@pytest.fixture(scope='module')
def provisioning_env(module_target_sat, discovery_org, discovery_location):
# Build PXE default template to get default PXE file
module_target_sat.cli.ProvisioningTemplate().build_pxe_default()
return module_target_sat.api_factory.configure_provisioning(
org=discovery_org,
loc=discovery_location,
os='Redhat {}'.format(module_target_sat.cli_factory.RHELRepository().repo_data['version']),
)


@pytest.fixture
def discovered_host(target_sat):
return target_sat.api_factory.create_discovered_host()


@pytest.fixture(scope='module')
def module_host_group(discovery_org, discovery_location):
host = entities.Host(organization=discovery_org, location=discovery_location)
host.create_missing()
return entities.HostGroup(
organization=[discovery_org],
location=[discovery_location],
medium=host.medium,
root_pass=gen_string('alpha'),
operatingsystem=host.operatingsystem,
ptable=host.ptable,
domain=host.domain,
architecture=host.architecture,
).create()


def _is_host_reachable(host, retries=12, iteration_sleep=5, expect_reachable=True):
"""Helper to ensure given IP/hostname is reachable or not. The return value
returned depend from expect reachable value.
Expand All @@ -100,53 +49,24 @@ def _is_host_reachable(host, retries=12, iteration_sleep=5, expect_reachable=Tru
return bool(result.status)


@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_pxe_based_discovery(session, provisioning_env):
"""Discover a host via PXE boot by setting "proxy.type=proxy" in
PXE default
:id: 43a8857d-2f08-436e-97fb-ffec6a0c84dd
:Setup: Provisioning should be configured
:Steps: PXE boot a host/VM
:expectedresults: Host should be successfully discovered
:BZ: 1731112
:CaseImportance: Critical
"""


@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_pxe_less_with_dhcp_unattended(session, provisioning_env):
"""Discover a host with dhcp via bootable discovery ISO by setting
"proxy.type=proxy" in PXE default in unattended mode.
:id: fc13167f-6fa0-4fe5-8584-7716292866ce
:Setup: Provisioning should be configured
:Steps: Boot a host/VM using modified discovery ISO.
:expectedresults: Host should be successfully discovered
:BZ: 1731112
:CaseImportance: Critical
"""


@pytest.mark.tier3
@pytest.mark.upgrade
def test_positive_provision_using_quick_host_button(
session, discovery_org, discovery_location, discovered_host, module_host_group
@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')
def test_positive_provision_pxe_host(
session,
discovery_org,
discovery_location,
module_discovery_hostgroup,
module_provisioning_rhel_content,
module_discovery_sat,
provisioning_host,
provisioning_hostgroup,
pxe_loader,
):
"""Associate hostgroup while provisioning a discovered host from
host properties model window and select quick host.
"""Provision a PXE-based discoveredhost
:id: 34c1e9ea-f210-4a1e-aead-421eb962643b
Expand All @@ -155,20 +75,34 @@ def test_positive_provision_using_quick_host_button(
1. Host should already be discovered
2. Hostgroup should already be created with all required entities.
:expectedresults: Host should be quickly provisioned and entry from
:expectedresults: Host should be provisioned and entry from
discovered host should be auto removed.
:BZ: 1728306, 1731112
:CaseImportance: High
"""
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

discovered_host_name = discovered_host['name']
domain_name = module_host_group.domain.read().name
domain_name = module_discovery_hostgroup.domain.read().name
host_name = f'{discovered_host_name}.{domain_name}'
with session:
session.discoveredhosts.provision(
discovered_host_name,
module_host_group.name,
module_discovery_hostgroup.name,
discovery_org.name,
discovery_location.name,
)
Expand All @@ -179,7 +113,7 @@ def test_positive_provision_using_quick_host_button(

@pytest.mark.tier3
def test_positive_update_name(
session, discovery_org, discovery_location, module_host_group, discovered_host
session, discovery_org, discovery_location, module_discovery_hostgroup, discovered_host
):
"""Update the discovered host name and provision it
Expand All @@ -195,15 +129,15 @@ def test_positive_update_name(
:CaseImportance: High
"""
discovered_host_name = discovered_host['name']
domain_name = module_host_group.domain.read().name
domain_name = module_discovery_hostgroup.domain.read().name
new_name = gen_string('alpha').lower()
new_host_name = f'{new_name}.{domain_name}'
with session:
discovered_host_values = session.discoveredhosts.wait_for_entity(discovered_host_name)
assert discovered_host_values['Name'] == discovered_host_name
session.discoveredhosts.provision(
discovered_host_name,
module_host_group.name,
module_discovery_hostgroup.name,
discovery_org.name,
discovery_location.name,
quick=False,
Expand All @@ -217,10 +151,22 @@ def test_positive_update_name(

@pytest.mark.tier3
@pytest.mark.upgrade
@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')
def test_positive_auto_provision_host_with_rule(
session, discovery_org, discovery_location, module_host_group, target_sat
session,
discovery_org,
discovery_location,
module_discovery_hostgroup,
module_provisioning_rhel_content,
module_discovery_sat,
pxeless_discovery_host,
provisioning_hostgroup,
pxe_loader,
):
"""Create a new discovery rule and automatically create host from discovered host using that
"""Create a new discovery rule and automatically provision host from discovered host using that
discovery rule.
Set query as (e.g IP=IP_of_discovered_host)
Expand All @@ -229,25 +175,41 @@ def test_positive_auto_provision_host_with_rule(
:Setup: Host should already be discovered
:expectedresults: Host should reboot and provision
:expectedresults: Host should be successfully provisioned
:BZ: 1665471, 1731112
:CaseImportance: High
"""
sat = module_discovery_sat.sat
pxeless_discovery_host.power_control(ensure=False)
mac = pxeless_discovery_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

discovered_host_name = discovered_host.name
domain_name = module_discovery_hostgroup.domain.read().name
host_name = f'{discovered_host_name}.{domain_name}'

host_ip = gen_ipaddr()
discovered_host_name = target_sat.api_factory.create_discovered_host(ip_address=host_ip)['name']
domain = module_host_group.domain.read()
discovery_rule = entities.DiscoveryRule(
max_count=1,
hostgroup=module_host_group,
search_=f'ip = {host_ip}',
discovery_rule = sat.api.DiscoveryRule(
max_count=10,
hostgroup=module_discovery_hostgroup,
search_=f'name = {discovered_host_name}',
location=[discovery_location],
organization=[discovery_org],
).create()
with session:
session.discoveredhosts.apply_action('Auto Provision', [discovered_host_name])
host_name = f'{discovered_host_name}.{domain.name}'
host_name = f'{discovered_host_name}.{domain_name}'
assert session.host.search(host_name)[0]['Name'] == host_name
host_values = session.host.get_details(host_name)
assert host_values['properties']['properties_table']['Status'] == 'OK'
Expand Down Expand Up @@ -296,10 +258,10 @@ def test_positive_update_default_taxonomies(session, discovery_org, discovery_lo
:CaseImportance: High
"""
host_names = [target_sat.api_factory.create_discovered_host()['name'] for _ in range(2)]
new_org = entities.Organization().create()
new_org = target_sat.api.Organization().create()
discovery_location.organization.append(new_org)
discovery_location.update(['organization'])
new_loc = entities.Location(organization=[discovery_org]).create()
new_loc = target_sat.api.Location(organization=[discovery_org]).create()
with session:
values = session.discoveredhosts.search('name = "{}" or name = "{}"'.format(*host_names))
assert set(host_names) == {value['Name'] for value in values}
Expand All @@ -319,21 +281,3 @@ def test_positive_update_default_taxonomies(session, discovery_org, discovery_lo
assert set(host_names) == {value['Name'] for value in values}
values = session.dashboard.read('DiscoveredHosts')
assert len(values['hosts']) == 2


@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_reboot(session, provisioning_env):
"""Reboot a discovered host.
:id: 5edc6831-bfc8-4e69-9029-b4c0caa3ee32
:Setup: Host should already be discovered
:expectedresults: Discovered host without provision is going to shutdown after reboot command
is passed.
:BZ: 1731112
:CaseImportance: Medium
"""

0 comments on commit b9f750c

Please sign in to comment.