From c180aa10475736d23d27e38d167430c17c2c4f51 Mon Sep 17 00:00:00 2001 From: Gaurav Talreja Date: Thu, 15 Feb 2024 18:57:03 +0530 Subject: [PATCH] Add extended for OS version check in VMware provisioning tests Signed-off-by: Gaurav Talreja --- robottelo/hosts.py | 26 +++++++++---- .../cli/test_computeresource_vmware.py | 39 ++++++++++++++++--- 2 files changed, 52 insertions(+), 13 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 57dec9e9f04..b0d16a6031f 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -449,14 +449,24 @@ def power_control(self, state=VmState.RUNNING, ensure=True): def wait_for_connection(self, timeout=180): try: - wait_for( - self.connect, - fail_condition=lambda res: res is not None, - handle_exception=True, - raise_original=True, - timeout=timeout, - delay=1, - ) + if self.key_filename: + wait_for( + lambda: self.connect(key_filename=self.key_filename), + fail_condition=lambda res: res is not None, + handle_exception=True, + raise_original=True, + timeout=timeout, + delay=1, + ) + else: + wait_for( + self.connect, + fail_condition=lambda res: res is not None, + handle_exception=True, + raise_original=True, + timeout=timeout, + delay=1, + ) except (ConnectionRefusedError, ConnectionAbortedError, TimedOutError) as err: raise ContentHostError( f'Unable to establsh SSH connection to host {self} after {timeout} seconds' diff --git a/tests/foreman/cli/test_computeresource_vmware.py b/tests/foreman/cli/test_computeresource_vmware.py index da69418eecd..912af09eebe 100644 --- a/tests/foreman/cli/test_computeresource_vmware.py +++ b/tests/foreman/cli/test_computeresource_vmware.py @@ -17,6 +17,7 @@ from robottelo.config import settings from robottelo.constants import FOREMAN_PROVIDERS +from robottelo.hosts import ContentHost @pytest.mark.tier1 @@ -77,10 +78,10 @@ def test_positive_vmware_cr_end_to_end(target_sat, module_org, module_location, @pytest.mark.e2e @pytest.mark.on_premises_provisioning @pytest.mark.parametrize('setting_update', ['destroy_vm_on_host_delete=True'], indirect=True) -@pytest.mark.parametrize('vmware', ['vmware7', 'vmware8'], indirect=True) -@pytest.mark.parametrize('pxe_loader', ['bios', 'uefi'], indirect=True) -@pytest.mark.parametrize('provision_method', ['build', 'bootdisk']) -@pytest.mark.rhel_ver_match('[^6]') +@pytest.mark.parametrize('vmware', ['vmware8'], indirect=True) +@pytest.mark.parametrize('pxe_loader', ['uefi'], indirect=True) +@pytest.mark.parametrize('provision_method', ['build']) +@pytest.mark.rhel_ver_match('[8, 9]') @pytest.mark.tier3 def test_positive_provision_end_to_end( request, @@ -94,6 +95,7 @@ def test_positive_provision_end_to_end( provision_method, vmware, vmwareclient, + module_ssh_key_file, ): """Provision a host on vmware compute resource with the help of hostgroup. @@ -101,7 +103,6 @@ def test_positive_provision_end_to_end( :id: ff9963fc-a2a7-4392-aa9a-190d5d1c8357 :steps: - 1. Configure provisioning setup. 2. Create VMware CR 3. Configure host group setup. @@ -146,6 +147,34 @@ def test_positive_provision_end_to_end( != 'Pending installation', timeout=1800, delay=30, + silent_failure=True, + handle_exception=True, ) host_info = sat.cli.Host.info({'id': host['id']}) assert host_info['status']['build-status'] == 'Installed' + + # Perform OS version check and check if root password is properly updated + provisioning_host = ContentHost( + host_info['network-interfaces'][0]['ipv4-address'], auth=module_ssh_key_file + ) + expected_rhel_version = host_info['operating-system']['operating-system'][-3:] + + # Wait for the host to be rebooted and SSH daemon to be started. + provisioning_host.wait_for_connection() + + if int(expected_rhel_version.split('.')[0]) >= 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}'