Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend VMware provisioning tests for OS version check #14094

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions robottelo/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Comment on lines +461 to +469
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this actually necessary?
isn't
lambda: self.connect(key_filename=self.key_filename), universal for both cases?
you could still pass key_filename=None if it is not specified and it should work, shouldn't it?
https://github.com/SatelliteQE/broker/blob/master/broker/hosts.py#L117

except (ConnectionRefusedError, ConnectionAbortedError, TimedOutError) as err:
raise ContentHostError(
f'Unable to establsh SSH connection to host {self} after {timeout} seconds'
Expand Down
39 changes: 34 additions & 5 deletions tests/foreman/cli/test_computeresource_vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from robottelo.config import settings
from robottelo.constants import FOREMAN_PROVIDERS
from robottelo.hosts import ContentHost


@pytest.mark.tier1
Expand Down Expand Up @@ -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]')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i noticed you have a hardcoded rhel8 here:
https://github.com/SatelliteQE/robottelo/pull/14094/files#diff-f5876fe03942ff6e50c18a8f2c95255cdca6f84b9956721a587abf7322fb73abR130
mind changing that, so it reflects the current rhel_ver parameter?

@pytest.mark.tier3
def test_positive_provision_end_to_end(
request,
Expand All @@ -94,14 +95,14 @@ 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.

:id: ff9963fc-a2a7-4392-aa9a-190d5d1c8357

:steps:

1. Configure provisioning setup.
2. Create VMware CR
3. Configure host group setup.
Expand Down Expand Up @@ -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:]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are setting yourself for a failure with this kind of version parsing

In [1]: '8.10'[-3:]
Out[1]: '.10'

also, that field might contain os name + version + some suffix, like beta or possibly eus.
I'd suggest to use nailgun to get the host info, which should resolve the os entity where you can directly access major and minor versions.


# Wait for the host to be rebooted and SSH daemon to be started.
provisioning_host.wait_for_connection()
Gauravtalreja1 marked this conversation as resolved.
Show resolved Hide resolved

if int(expected_rhel_version.split('.')[0]) >= 9:
assert (
provisioning_host.execute(
'echo -e "\nPermitRootLogin yes" >> /etc/ssh/sshd_config; systemctl restart sshd'
lhellebr marked this conversation as resolved.
Show resolved Hide resolved
).status
== 0
)
host_ssh_os = sat.execute(
lhellebr marked this conversation as resolved.
Show resolved Hide resolved
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}'