Skip to content

Commit

Permalink
Adding coverage for Discovery provisioning via CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Adarsh Dubey <[email protected]>
  • Loading branch information
adarshdubey-star committed Sep 20, 2023
1 parent a63fbac commit 32cc275
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 81 deletions.
22 changes: 20 additions & 2 deletions robottelo/cli/discoveredhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@ class DiscoveredHost(Base):
def provision(cls, options=None):
"""Manually provision discovered host"""
cls.command_sub = 'provision'
return cls.execute(cls._construct_command(options))
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def facts(cls, options=None):
"""Get all the facts associated with discovered host"""
cls.command_sub = 'facts'
return cls.execute(cls._construct_command(options))
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def auto_provision(cls, options=None):
"""Auto provision discovered host"""
cls.command_sub = 'auto-provision'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def reboot(cls, options=None):
"""Reboot discovered host"""
cls.command_sub = 'reboot'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def refresh_facts(cls, options=None):
"""Refresh facts associated with discovered host"""
cls.command_sub = 'refresh-facts'
return cls.execute(cls._construct_command(options), output_format='csv')
2 changes: 1 addition & 1 deletion tests/foreman/api/test_discoveredhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_positive_provision_pxe_less_host(
):
"""Provision a pxe-less discovered hosts
:id: 91bb254b-3c30-4608-b1ba-e18bcc22efb5
:id: 9fd9eb9c-75c7-4c2c-b65e-e2a5e9849086
:Setup: Provisioning should be configured and a host should be
discovered
Expand Down
190 changes: 112 additions & 78 deletions tests/foreman/cli/test_discoveredhost.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,135 @@
:Upstream: No
"""
from time import sleep

import pytest
from wait_for import wait_for

from robottelo.cli.base import CLIReturnCodeError
from robottelo.cli.discoveredhost import DiscoveredHost

pytestmark = [pytest.mark.run_in_one_thread]


def _assertdiscoveredhost(hostname):
"""Check if host is discovered and information about it can be
retrieved back
@pytest.mark.e2e
@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('8')
def test_positive_provision_pxe_host_cli(
module_provisioning_rhel_content,
module_discovery_sat,
provisioning_host,
provisioning_hostgroup,
):
"""Provision a pxe-based discovered host from CLI
Introduced a delay of 300secs by polling every 10 secs to get expected
host
"""
for _ in range(30):
try:
discovered_host = DiscoveredHost.info({'name': hostname})
except CLIReturnCodeError:
sleep(10)
continue
return discovered_host
:id: 91bb254b-3c30-4608-b1ba-e18bcc22efb5
:parametrized: yes
@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_pxe_based_discovery():
"""Discover a host via PXE boot by setting "proxy.type=proxy" in
PXE default
:Setup: Provisioning and discovery should be configured
:id: 25e935fe-18f4-477e-b791-7ea5a395b4f6
:Setup: Provisioning should be configured
:Steps:
:Steps: PXE boot a host/VM
1. Boot up the host to discover
2. Provision the host
:expectedresults: Host should be successfully discovered
:expectedresults: Host should be provisioned successfully from CLI
:CaseImportance: Critical
:BZ: 1731112
"""
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.cli.DiscoveredHost.provision(
{
'id': discovered_host.id,
'hostgroup-id': discovered_host.hostgroup.id,
'organization-id': discovered_host.organization.id,
'location-id': discovered_host.location.id,
}
)
assert 'Host created' in result[0]['message']
host = sat.api.Host().search(query={"search": f'id={discovered_host.id}'})[0]
assert host
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
host.delete()
assert not sat.api.Host().search(query={"search": f'id={discovered_host.id}'})


@pytest.mark.e2e
@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('8')
def test_positive_provision_pxe_less_host_cli(
module_discovery_sat,
pxeless_discovery_host,
module_provisioning_rhel_content,
provisioning_hostgroup,
):
"""Provision a pxe-less discovered hosts with cli
:id: e75ee13a-9edc-4182-b02a-6b106a459751
:Setup: Provisioning should be configured and a host should be
discovered via cli
:expectedresults: Host should be provisioned successfully
:CaseImportance: Critical
"""
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
result = sat.cli.DiscoveredHost.provision(
{
'id': discovered_host.id,
'hostgroup-id': discovered_host.hostgroup.id,
'organization-id': discovered_host.organization.id,
'location-id': discovered_host.location.id,
}
)
assert 'Host created' in result[0]['message']
host = sat.api.Host().search(query={"search": f'id={discovered_host.id}'})[0]
assert host
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'
host.delete()
assert not sat.api.Host().search(query={"search": f'id={discovered_host.id}'})


@pytest.mark.stubbed
Expand Down Expand Up @@ -149,57 +234,6 @@ def test_positive_provision_pxe_host_with_bios_syslinux():
"""


@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_provision_pxe_host_with_uefi_grub2():
"""Provision the pxe-based UEFI discovered host from cli using PXEGRUB2
loader
:id: 0002af1b-6f4b-40e2-8f2f-343387be6f72
:Setup:
1. Create an UEFI VM and set it to boot from a network
2. Synchronize RHEL7 kickstart repo (rhel6 kernel too old for GRUB)
3. for getting more detailed info from FDI, remaster the image to
have ssh enabled
:steps:
1. Build a default PXE template
2. Run assertion step #1
3. Boot the VM (from NW)
4. Run assertion steps #2-4
5. Provision the discovered host
6. Run assertion steps #5-9
:expectedresults: Host should be provisioned successfully
1. Ensure the tftpboot files are updated
1.1 Ensure fdi-image files have been placed under tftpboot/boot/
1.2 Ensure the 'default' pxelinux config has been placed under
tftpboot/pxelinux.cfg/
1.3 Ensure the discovery section exists inside pxelinux config,
it leads to the FDI kernel and the ONTIMEOUT is set to discovery
2. Ensure PXE handoff goes as expected (tcpdump -p tftp)
3. Ensure FDI loaded and successfully sent out facts
3.1 ping vm
3.2 ssh to the VM and read the logs (if ssh enabled)
3.3 optionally sniff the HTTP traffic coming from the host
4. Ensure host appeared in Discovered Hosts on satellite
5. Ensure the tftpboot files are updated for the hosts mac
6. Ensure PXE handoff goes as expected (tcpdump -p tftp)
7. Optionally ensure anaconda loaded and the installation finished
8. Ensure the host is provisioned with correct attributes
9. Ensure the entry from discovered host list disappeared
:CaseAutomation: NotAutomated
:CaseImportance: High
"""


@pytest.mark.stubbed
@pytest.mark.tier3
def test_positive_delete():
Expand Down

0 comments on commit 32cc275

Please sign in to comment.