Skip to content

Commit

Permalink
Merge branch 'master' into ui_utils_mod_depr
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare authored Sep 15, 2023
2 parents 9ad33da + 2525b64 commit 874c978
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 2 deletions.
1 change: 1 addition & 0 deletions pytest_fixtures/component/provision_pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def pxe_loader(request):
PXE_LOADER_MAP = {
'bios': {'vm_firmware': 'bios', 'pxe_loader': 'PXELinux BIOS'},
'uefi': {'vm_firmware': 'uefi', 'pxe_loader': 'Grub2 UEFI'},
'ipxe': {'vm_firmware': 'bios', 'pxe_loader': 'iPXE Embedded'},
}
return Box(PXE_LOADER_MAP[getattr(request, 'param', 'bios')])

Expand Down
131 changes: 130 additions & 1 deletion tests/foreman/api/test_provisioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from wait_for import wait_for

from robottelo.config import settings
from robottelo.utils.installer import InstallerCommand


@pytest.mark.e2e
Expand Down Expand Up @@ -114,7 +115,7 @@ def test_rhel_pxe_provisioning(
).status
== 0
)
host_ssh_os = module_provisioning_sat.sat.execute(
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
Expand Down Expand Up @@ -147,3 +148,131 @@ def test_rhel_pxe_provisioning(
# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'


@pytest.mark.e2e
@pytest.mark.parametrize('pxe_loader', ['ipxe'], indirect=True)
@pytest.mark.on_premises_provisioning
@pytest.mark.rhel_ver_match('[^6]')
def test_rhel_ipxe_provisioning(
request,
module_provisioning_sat,
module_sca_manifest_org,
module_location,
provisioning_host,
pxe_loader,
module_provisioning_rhel_content,
provisioning_hostgroup,
module_lce_library,
module_default_org_view,
):
"""Provision a host using iPXE workflow
:id: 9e016e1d-757a-48e7-9159-131bb65dc4ed
:steps:
1. Configure satellite for provisioning
2. provision a host
3. Check that resulting host is registered to Satellite
4. Check host is subscribed to Satellite
:expectedresults:
1. Provisioning via iPXE is successful
2. Host installs right version of RHEL
3. Satellite is able to run REX job on the host
4. Host is registered to Satellite and subscription status is 'Success'
:parametrized: yes
"""
# TODO: parametrize iPXE Chain BIOS as pxe loader after #BZ:2171172 is fixed
sat = module_provisioning_sat.sat
# set http url
ipxe_http_url = sat.install(
InstallerCommand(
f'foreman-proxy-dhcp-ipxefilename "http://{sat.hostname}/unattended/iPXE?bootstrap=1"'
)
)
assert ipxe_http_url.status == 0
host_mac_addr = provisioning_host._broker_args['provisioning_nic_mac_addr']
host = sat.api.Host(
hostgroup=provisioning_hostgroup,
organization=module_sca_manifest_org,
location=module_location,
name=gen_string('alpha').lower(),
mac=host_mac_addr,
operatingsystem=module_provisioning_rhel_content.os,
subnet=module_provisioning_sat.subnet,
host_parameters_attributes=[
{'name': 'remote_execution_connect_by_ip', 'value': 'true', 'parameter_type': 'boolean'}
],
build=True, # put the host in build mode
).create(create_missing=False)
# Clean up the host to free IP leases on Satellite.
# broker should do that as a part of the teardown, putting here just to make sure.
request.addfinalizer(host.delete)
# Start the VM, do not ensure that we can connect to SSHD
provisioning_host.power_control(ensure=False)

# TODO: Implement Satellite log capturing logic to verify that
# all the events are captured in the logs.

# Host should do call back to the Satellite reporting
# the result of the installation. Wait until Satellite reports that the host is installed.
wait_for(
lambda: host.read().build_status_label != 'Pending installation',
timeout=1500,
delay=10,
)
host = host.read()
assert host.build_status_label == 'Installed'

# Change the hostname of the host as we know it already.
# In the current infra environment we do not support
# addressing hosts using FQDNs, falling back to IP.
provisioning_host.hostname = host.ip
# Host is not blank anymore
provisioning_host.blank = False

# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()

# Perform version check and check if root password is properly updated
host_os = host.operatingsystem.read()
expected_rhel_version = f'{host_os.major}.{host_os.minor}'

if int(host_os.major) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
).status
== 0
)
host_ssh_os = sat.execute(
f'sshpass -p {settings.provisioning.host_root_password} '
'ssh -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -o PasswordAuthentication=yes '
f'-o UserKnownHostsFile=/dev/null root@{provisioning_host.hostname} cat /etc/redhat-release'
)
assert host_ssh_os.status == 0
assert (
expected_rhel_version in host_ssh_os.stdout
), f'The installed OS version differs from the expected version {expected_rhel_version}'

# Run a command on the host using REX to verify that Satellite's SSH key is present on the host
template_id = (
sat.api.JobTemplate().search(query={'search': 'name="Run Command - Script Default"'})[0].id
)
job = sat.api.JobInvocation().run(
data={
'job_template_id': template_id,
'inputs': {
'command': f'subscription-manager config | grep "hostname = {sat.hostname}"'
},
'search_query': f"name = {host.name}",
'targeting_type': 'static_query',
},
)
assert job['result'] == 'success', 'Job invocation failed'

# assert that the host is subscribed and consumes
# subsctiption provided by the activation key
assert provisioning_host.subscribed, 'Host is not subscribed'
5 changes: 4 additions & 1 deletion tests/foreman/cli/test_hammer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

HAMMER_COMMANDS = json.loads(DataFile.HAMMER_COMMANDS_JSON.read_text())

pytestmark = [pytest.mark.tier1, pytest.mark.upgrade]
pytestmark = [pytest.mark.tier1]


def fetch_command_info(command):
Expand Down Expand Up @@ -127,6 +127,7 @@ def test_positive_all_options(target_sat):
pytest.fail(format_commands_diff(differences))


@pytest.mark.upgrade
def test_positive_disable_hammer_defaults(request, function_product, target_sat):
"""Verify hammer disable defaults command.
Expand Down Expand Up @@ -166,6 +167,7 @@ def _finalize():
assert str(function_product.organization.id) not in result.stdout


@pytest.mark.upgrade
def test_positive_check_debug_log_levels(target_sat):
"""Enabling debug log level in candlepin via hammer logging
Expand Down Expand Up @@ -193,6 +195,7 @@ def test_positive_check_debug_log_levels(target_sat):


@pytest.mark.e2e
@pytest.mark.upgrade
def test_positive_hammer_shell(target_sat):
"""Verify that hammer shell runs a command when input is provided via interactive/bash
Expand Down

0 comments on commit 874c978

Please sign in to comment.