Skip to content

Commit

Permalink
[6.11.z] Add Libvirt CR setup helper to fix UI E2E tests (#12393)
Browse files Browse the repository at this point in the history
  • Loading branch information
Satellite-QE authored Aug 29, 2023
1 parent a4a7e60 commit 4eacd92
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
5 changes: 4 additions & 1 deletion robottelo/host_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from robottelo.host_helpers.satellite_mixins import ContentInfo
from robottelo.host_helpers.satellite_mixins import EnablePluginsSatellite
from robottelo.host_helpers.satellite_mixins import Factories
from robottelo.host_helpers.satellite_mixins import ProvisioningSetup
from robottelo.host_helpers.satellite_mixins import SystemInfo


Expand All @@ -17,5 +18,7 @@ class CapsuleMixins(CapsuleInfo, EnablePluginsCapsule):
pass


class SatelliteMixins(ContentInfo, Factories, SystemInfo, EnablePluginsSatellite):
class SatelliteMixins(
ContentInfo, Factories, SystemInfo, EnablePluginsSatellite, ProvisioningSetup
):
pass
27 changes: 27 additions & 0 deletions robottelo/host_helpers/satellite_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,33 @@ def validate_pulp_filepath(
return result.stdout


class ProvisioningSetup:
"""Provisioning tests setup helper methods"""

def configure_libvirt_cr(self, server_fqdn=settings.libvirt.libvirt_hostname):
"""Configures Libvirt ComputeResource to communicate with Satellite
:param server_fqdn: Libvirt server FQDN
:return: None
"""
# Geneate SSH key-pair for foreman user and copy public key to libvirt server
self.execute('sudo -u foreman ssh-keygen -q -t rsa -f ~foreman/.ssh/id_rsa -N "" <<< y')
self.execute(f'ssh-keyscan -t ecdsa {server_fqdn} >> ~foreman/.ssh/known_hosts')
self.execute(
f'sshpass -p {settings.server.ssh_password} ssh-copy-id -o StrictHostKeyChecking=no '
f'-i ~foreman/.ssh/id_rsa root@{server_fqdn}'
)
# Install libvirt-client, and verify foreman user is able to communicate with Libvirt server
self.register_to_cdn()
self.execute('dnf -y --disableplugin=foreman-protector install libvirt-client')
assert (
self.execute(
f'su foreman -s /bin/bash -c "virsh -c qemu+ssh://root@{server_fqdn}/system list"'
).status
== 0
)


class Factories:
"""Mixin that provides attributes for each factory type"""

Expand Down
25 changes: 12 additions & 13 deletions tests/foreman/ui/test_computeresource_libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import pytest
from fauxfactory import gen_string
from nailgun import entities

from robottelo.config import settings
from robottelo.constants import COMPUTE_PROFILE_SMALL
Expand All @@ -29,14 +28,12 @@

pytestmark = [pytest.mark.skip_if_not_set('libvirt')]


@pytest.fixture(scope='module')
def module_libvirt_url():
return LIBVIRT_RESOURCE_URL % settings.libvirt.libvirt_hostname
LIBVIRT_URL = LIBVIRT_RESOURCE_URL % settings.libvirt.libvirt_hostname


@pytest.mark.tier2
def test_positive_end_to_end(session, module_org, module_location, module_libvirt_url):
@pytest.mark.e2e
def test_positive_end_to_end(session, module_target_sat, module_org, module_location):
"""Perform end to end testing for compute resource Libvirt component.
:id: 7ef925ac-5aec-4e9d-b786-328a9b219c01
Expand All @@ -53,17 +50,18 @@ def test_positive_end_to_end(session, module_org, module_location, module_libvir
cr_description = gen_string('alpha')
new_cr_name = gen_string('alpha')
new_cr_description = gen_string('alpha')
new_org = entities.Organization().create()
new_loc = entities.Location().create()
new_org = module_target_sat.api.Organization().create()
new_loc = module_target_sat.api.Location().create()
display_type = choice(('VNC', 'SPICE'))
console_passwords = choice((True, False))
module_target_sat.configure_libvirt_cr()
with session:
session.computeresource.create(
{
'name': cr_name,
'description': cr_description,
'provider': FOREMAN_PROVIDERS['libvirt'],
'provider_content.url': module_libvirt_url,
'provider_content.url': LIBVIRT_URL,
'provider_content.display_type': display_type,
'provider_content.console_passwords': console_passwords,
'organizations.resources.assigned': [module_org.name],
Expand All @@ -73,7 +71,7 @@ def test_positive_end_to_end(session, module_org, module_location, module_libvir
cr_values = session.computeresource.read(cr_name)
assert cr_values['name'] == cr_name
assert cr_values['description'] == cr_description
assert cr_values['provider_content']['url'] == module_libvirt_url
assert cr_values['provider_content']['url'] == LIBVIRT_URL
assert cr_values['provider_content']['display_type'] == display_type
assert cr_values['provider_content']['console_passwords'] == console_passwords
assert cr_values['organizations']['resources']['assigned'] == [module_org.name]
Expand Down Expand Up @@ -102,7 +100,7 @@ def test_positive_end_to_end(session, module_org, module_location, module_libvir
# check that the compute resource is listed in one of the default compute profiles
profile_cr_values = session.computeprofile.list_resources(COMPUTE_PROFILE_SMALL)
profile_cr_names = [cr['Compute Resource'] for cr in profile_cr_values]
assert '{} ({})'.format(new_cr_name, FOREMAN_PROVIDERS['libvirt']) in profile_cr_names
assert f'{new_cr_name} ({FOREMAN_PROVIDERS["libvirt"]})' in profile_cr_names
session.computeresource.update_computeprofile(
new_cr_name,
COMPUTE_PROFILE_SMALL,
Expand All @@ -112,8 +110,9 @@ def test_positive_end_to_end(session, module_org, module_location, module_libvir
new_cr_name, COMPUTE_PROFILE_SMALL
)
assert cr_profile_values['compute_profile'] == COMPUTE_PROFILE_SMALL
assert cr_profile_values['compute_resource'] == '{} ({})'.format(
new_cr_name, FOREMAN_PROVIDERS['libvirt']
assert (
cr_profile_values['compute_resource']
== f'{new_cr_name} ({FOREMAN_PROVIDERS["libvirt"]})'
)
assert cr_profile_values['provider_content']['cpus'] == '16'
assert cr_profile_values['provider_content']['memory'] == '8192 MB'
Expand Down

0 comments on commit 4eacd92

Please sign in to comment.