Skip to content

Commit

Permalink
Updates for UI errata e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Nov 1, 2023
1 parent df42f4b commit 5c7dbee
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 52 deletions.
9 changes: 7 additions & 2 deletions robottelo/cli/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,12 +1693,17 @@ def setup_org_for_a_custom_repo(options=None):
# Get the content view info
cv_info = ContentView.info({'id': cv_id})
lce_promoted = cv_info['lifecycle-environments']
cvv = cv_info['versions'][-1]
assert len(cv_info['versions']) > 0
cvv = sorted(cvv['id'] for cvv in cv_info['versions'])[-1]
# Promote version to next env
try:
if env_id not in [int(lce['id']) for lce in lce_promoted]:
ContentView.version_promote(
{'id': cvv['id'], 'organization-id': org_id, 'to-lifecycle-environment-id': env_id}
{
'id': cvv['id'],
'organization-id': org_id,
'to-lifecycle-environment-id': env_id,
}
)
except CLIReturnCodeError as err:
raise CLIFactoryError(f'Failed to promote version to next environment\n{err.msg}')
Expand Down
5 changes: 3 additions & 2 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,15 @@ def setup_org_for_a_custom_repo(self, options=None):
raise CLIFactoryError(f'Failed to publish new version of content view\n{err.msg}')
# Get the version id
cv_info = self._satellite.cli.ContentView.info({'id': cv_id})
assert len(cv_info['versions']) > 0
cvv_id = sorted(cvv['id'] for cvv in cv_info['versions'])[-1]
lce_promoted = cv_info['lifecycle-environments']
cvv = cv_info['versions'][-1]
# Promote version to next env
try:
if env_id not in [int(lce['id']) for lce in lce_promoted]:
self._satellite.cli.ContentView.version_promote(
{
'id': cvv['id'],
'id': cvv_id,
'organization-id': org_id,
'to-lifecycle-environment-id': env_id,
}
Expand Down
182 changes: 134 additions & 48 deletions tests/foreman/ui/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
:Upstream: No
"""
from datetime import datetime

from airgun.session import Session
from broker import Broker
from fauxfactory import gen_string
Expand All @@ -27,6 +29,7 @@
from robottelo.constants import (
DEFAULT_LOC,
FAKE_1_CUSTOM_PACKAGE,
FAKE_1_CUSTOM_PACKAGE_NAME,
FAKE_2_CUSTOM_PACKAGE,
FAKE_3_YUM_OUTDATED_PACKAGES,
FAKE_4_CUSTOM_PACKAGE,
Expand Down Expand Up @@ -75,6 +78,20 @@ def _install_client_package(client, package, errata_applicability=False):
return result.status == 0


def _remove_client_package(client, package, errata_applicability=False):
"""Delete a package in virtual machine client.
:param client: The Virtual machine client.
:param package: the package (general name, or version) to remove from virtual machine client.
:param errata_applicability: If True, force host to generate errata applicability.
:returns: True if a package was removed successfully, False otherwise.
"""
result = client.execute(f'yum remove -y {package}')
if errata_applicability:
_generate_errata_applicability(client.hostname)
return result.status == 0


def _set_setting_value(setting_entity, value):
"""Set setting value.
Expand Down Expand Up @@ -124,13 +141,6 @@ def function_org_with_parameter(target_sat, function_manifest):
return org


@pytest.fixture(scope='module')
def module_lce(module_target_sat, module_org_with_parameter):
return module_target_sat.api.LifecycleEnvironment(
organization=module_org_with_parameter
).create()


@pytest.fixture
def lce(target_sat, function_org_with_parameter):
return target_sat.api.LifecycleEnvironment(organization=function_org_with_parameter).create()
Expand Down Expand Up @@ -163,35 +173,87 @@ def vm(module_repos_collection_with_setup, rhel7_contenthost, target_sat):
yield rhel7_contenthost


@pytest.fixture(scope='function')
def registered_contenthost(
rhel_contenthost,
module_org,
module_lce,
module_target_sat,
repos=[CUSTOM_REPO_URL],
):
"""RHEL ContentHost registered in satellite,
Using SCA and global registration.
:param repos: list of upstream URLs for custom repositories,
default to CUSTOM_REPO_URL
"""
content_view = module_target_sat.api.ContentView(
organization=module_org,
environment=[module_lce],
).create()

activation_key = module_target_sat.api.ActivationKey(
organization=module_org,
environment=module_lce,
).create()

custom_repos = []
for repo_url in repos:
rhel_contenthost.create_custom_repos(custom_repo=repo_url)
# Publishes and promotes a new cvv to lce
# Associate org, ak, cv, with custom repo:
custom_repo_id = module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'url': repo_url,
'organization-id': module_org.id,
'lifecycle-environment-id': module_lce.id,
'activationkey-id': activation_key.id,
'content-view-id': content_view.id,
}
)['repository-id']
custom_repos.append(custom_repo_id)

result = rhel_contenthost.register(
activation_keys=activation_key.name,
lifecycle_environment=module_lce,
target=module_target_sat,
org=module_org,
loc=None,
)
assert result.status == 0, f'Failed to register host: {result.stdout}'
assert rhel_contenthost.subscribed

for custom_repo_id in custom_repos:
custom_repo = module_target_sat.api.Repository(id=custom_repo_id).read()
assert custom_repo
result = custom_repo.sync()['humanized']
assert (
len(result['errors']) == 0
), f'Failed to sync custom repository, id: {custom_repo_id}:\n{str(result["errors"])}'

yield rhel_contenthost


@pytest.mark.e2e
@pytest.mark.tier3
@pytest.mark.parametrize('setting_update', ['remote_execution_by_default'], indirect=True)
@pytest.mark.parametrize(
'module_repos_collection_with_setup',
[
{
'distro': 'rhel7',
'SatelliteToolsRepository': {},
'RHELAnsibleEngineRepository': {},
'YumRepository': {'url': CUSTOM_REPO_URL},
}
],
indirect=True,
)
@pytest.mark.rhel_ver_match('8')
@pytest.mark.no_containers
def test_end_to_end(
session,
module_org_with_parameter,
module_repos_collection_with_setup,
vm,
target_sat,
setting_update,
module_org,
module_lce,
module_cv,
module_target_sat,
registered_contenthost,
):
"""Create all entities required for errata, set up applicable host,
read errata details and apply it to host
:id: a26182fc-f31a-493f-b094-3f5f8d2ece47
:setup: A host with content from a custom repo collection,
contains some applicable errata
:expectedresults: Errata details are the same as expected, errata
installation is successful
Expand All @@ -203,11 +265,14 @@ def test_end_to_end(
:CaseLevel: System
"""

ERRATA_DETAILS = {
'advisory': 'RHSA-2012:0055',
'cves': 'N/A',
'type': 'Security Advisory',
'severity': 'N/A',
'issued': 'January 27, 2012 at 12:00 AM',
'last_updated_on': 'January 27, 2012 at 12:00 AM',
'reboot_suggested': 'No',
'topic': '',
'description': 'Sea_Erratum',
Expand All @@ -221,20 +286,28 @@ def test_end_to_end(
],
'module_stream_packages': [],
}
assert _install_client_package(vm, FAKE_1_CUSTOM_PACKAGE)
assert len(product_list := module_target_sat.api.Product(organization=module_org).search()) == 1
_product = product_list[0]
assert len(repo_list := module_target_sat.api.Repository(organization=module_org).search()) == 1
_repository = repo_list[0]

_remove_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE_NAME)
assert _install_client_package(
registered_contenthost, FAKE_1_CUSTOM_PACKAGE, errata_applicability=True
)
assert registered_contenthost.applicable_errata_count == 1

with session:
property_value = 'Yes'
session.settings.update(f'name = {setting_update.name}', property_value) # BZ 2029192

datetime_utc_start = datetime.utcnow()
# Check selection box function for BZ#1688636
session.location.select(loc_name=DEFAULT_LOC)
assert session.errata.search(CUSTOM_REPO_ERRATA_ID, applicable=True)[0]['Errata ID']
assert session.errata.search(CUSTOM_REPO_ERRATA_ID, installable=True)[0]['Errata ID']
session.organization.select(org_name=module_org.name)
assert session.errata.search_content_hosts(
CUSTOM_REPO_ERRATA_ID, registered_contenthost.hostname, environment=module_lce.name
), 'Errata ID not found on registered contenthost or the host lifecycle-environment.'
assert (errata := session.errata.read(CUSTOM_REPO_ERRATA_ID))
# Check all tabs of Errata Details page
errata = session.errata.read(CUSTOM_REPO_ERRATA_ID)
# We ignore issued date and updated date in ERRATA_DETAILS, so we don't perform an
# equality check here.
# TODO: Find a way to account for browser time zone, so that the errata dates displayed
# in the UI can be compared to the UTC values in ERRATA_DETAILS.
assert (
not ERRATA_DETAILS.items() - errata['details'].items()
), 'Errata details do not match expected values.'
Expand All @@ -245,22 +318,35 @@ def test_end_to_end(
errata['packages']['module_stream_packages']
== ERRATA_PACKAGES['module_stream_packages']
)
assert (
errata['repositories']['table'][-1]['Name']
== module_repos_collection_with_setup.custom_repos_info[-1]['name']
assert errata['repositories']['table'][-1]['Name'] == _repository.name
assert errata['repositories']['table'][-1]['Product'] == _product.name

session.host_new.apply_erratas(
entity_name=registered_contenthost.hostname,
search=f"errata_id == {CUSTOM_REPO_ERRATA_ID}",
)
assert (
errata['repositories']['table'][-1]['Product']
== module_repos_collection_with_setup.custom_product['name']

result = module_target_sat.wait_for_tasks(
search_query=(
f'"Install errata errata_id == {CUSTOM_REPO_ERRATA_ID}'
f' on {registered_contenthost.hostname}"'
),
search_rate=2,
max_tries=60,
)
status = session.contenthost.install_errata(
vm.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex'
task_status = module_target_sat.api.ForemanTask(id=result[0].id).poll()
assert task_status['result'] == 'success'
assert registered_contenthost.applicable_errata_count == 0
task_start = datetime.strptime(task_status['started_at'], '%Y-%m-%d %H:%M:%S UTC')
task_end = datetime.strptime(task_status['ended_at'], '%Y-%m-%d %H:%M:%S UTC')

assert (task_end - task_start).total_seconds() <= 60
assert (task_end - datetime_utc_start).total_seconds() <= 600

assert session.errata.read(CUSTOM_REPO_ERRATA_ID)
assert not session.errata.search_content_hosts(
CUSTOM_REPO_ERRATA_ID, registered_contenthost.hostname, environment=module_lce.name
)
assert status['overview']['job_status'] == 'Success'
assert status['overview']['job_status_progress'] == '100%'
_generate_errata_applicability(vm.hostname)
vm = vm.nailgun_host.read()
assert vm.applicable_errata_count == 0


@pytest.mark.tier2
Expand Down

0 comments on commit 5c7dbee

Please sign in to comment.