Skip to content

Commit

Permalink
Testing setup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Oct 31, 2023
1 parent df42f4b commit 37fb921
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 54 deletions.
10 changes: 8 additions & 2 deletions robottelo/cli/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,13 +1692,19 @@ def setup_org_for_a_custom_repo(options=None):
raise CLIFactoryError(f'Failed to publish new version of content view\n{err.msg}')
# Get the content view info
cv_info = ContentView.info({'id': cv_id})
assert len(cv_info['versions']) > 0
lce_promoted = cv_info['lifecycle-environments']
cvv = cv_info['versions'][-1]
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'],
'content-view-id': cv_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
6 changes: 4 additions & 2 deletions robottelo/host_helpers/cli_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,14 +630,16 @@ 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,
'content-view-id': cv_id,
'organization-id': org_id,
'to-lifecycle-environment-id': env_id,
}
Expand Down
173 changes: 123 additions & 50 deletions tests/foreman/ui/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

from robottelo.config import settings
from robottelo.constants import (
CONTAINER_REGISTRY_HUB,
CONTAINER_UPSTREAM_NAME,
DEFAULT_LOC,
FAKE_1_CUSTOM_PACKAGE,
FAKE_2_CUSTOM_PACKAGE,
Expand All @@ -43,6 +45,10 @@
REAL_4_ERRATA_CVES,
REAL_4_ERRATA_ID,
)
from robottelo.constants.repos import (
ANSIBLE_GALAXY,
CUSTOM_FILE_REPO,
)
from robottelo.hosts import ContentHost

CUSTOM_REPO_URL = settings.repos.yum_9.url
Expand All @@ -69,7 +75,7 @@ def _install_client_package(client, package, errata_applicability=False):
:param errata_applicability: If True, force host to generate errata applicability.
:returns: True if package installed successfully, False otherwise.
"""
result = client.execute(f'yum install -y {package}')
result = client.run(f'yum install -y {package}')
if errata_applicability:
_generate_errata_applicability(client.hostname)
return result.status == 0
Expand Down Expand Up @@ -125,7 +131,7 @@ def function_org_with_parameter(target_sat, function_manifest):


@pytest.fixture(scope='module')
def module_lce(module_target_sat, module_org_with_parameter):
def module_lce_with_param(module_target_sat, module_org_with_parameter):
return module_target_sat.api.LifecycleEnvironment(
organization=module_org_with_parameter
).create()
Expand Down Expand Up @@ -163,35 +169,82 @@ def vm(module_repos_collection_with_setup, rhel7_contenthost, target_sat):
yield rhel7_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',
[
@pytest.fixture(scope='function')
def function_registered_contenthost(
rhel_contenthost,
module_org,
module_lce,
module_target_sat,
repo_url=CUSTOM_REPO_URL,
):
"""RHEL ContentHost registered in satellite,
Using SCA and global registration.
Associate custom repository from URL, enable."""
# TODO: Impliment global registration through SCA
"""Publish and promote content view,
Create and associate activation key."""
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()

rhel_contenthost.create_custom_repos(custom_repo=repo_url)
custom_repo_id = module_target_sat.cli_factory.setup_org_for_a_custom_repo(
{
'distro': 'rhel7',
'SatelliteToolsRepository': {},
'RHELAnsibleEngineRepository': {},
'YumRepository': {'url': CUSTOM_REPO_URL},
'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,
}
],
indirect=True,
)
)['repository-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

rhel_contenthost.create_custom_repos(custom_repo=repo_url)
rhel_contenthost.execute(r'subscription-manager refresh')
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: {str(result["errors"])}'
yield rhel_contenthost

from time import time, localtime

@pytest.mark.e2e
@pytest.mark.tier3
@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,
function_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,6 +256,10 @@ def test_end_to_end(
:CaseLevel: System
"""
#for repo in repos_collection:
# function_registered_contenthost.create_custom_repos(repo=repo.url)
# repo.sync()
# function_registered_contenthost.execute(f'subscription-manager repos --enable {repo.id}')
ERRATA_DETAILS = {
'advisory': 'RHSA-2012:0055',
'cves': 'N/A',
Expand All @@ -221,19 +278,38 @@ def test_end_to_end(
],
'module_stream_packages': [],
}
assert _install_client_package(vm, FAKE_1_CUSTOM_PACKAGE)
contenthost = function_registered_contenthost
assert _install_client_package(contenthost, FAKE_1_CUSTOM_PACKAGE)
contenthost.execute('subscription-manager repos')
module_target_sat.cli.Host.errata_recalculate(
{'host-id': contenthost.nailgun_host.id}
)
assert contenthost.applicable_errata_count > 0
_UTC_time_epoch = time()
_local_time_epoch = localtime()
_local_timezone = _local_time_epoch.tm_zone


with session:
property_value = 'Yes'
session.settings.update(f'name = {setting_update.name}', property_value) # BZ 2029192
# TODO: Update setting per BZ 2029192 without setting_update fixture
# TODO: FIX -- session.settings.update(f'name = {setting_update.name}', property_value) # BZ 2029192
# Check selection box function for BZ#1688636
breakpoint()
#session.organization.select(org_name=module_org.name)
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']
assert session.errata.search_content_hosts(
CUSTOM_REPO_ERRATA_ID, contenthost.hostname, environment=module_lce.name
)

#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']
# Check all tabs of Errata Details page
errata = session.errata.read(CUSTOM_REPO_ERRATA_ID)
breakpoint()
assert errata
# 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
# DONE: 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()
Expand All @@ -245,22 +321,31 @@ 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]['Product']
== module_repos_collection_with_setup.custom_product['name']
)
#assert (
# errata['repositories']['table'][-1]['Name']
# == repos_collection.custom_repos_info[-1]['name']
#)
#assert (
# errata['repositories']['table'][-1]['Product']
# == repos_collection.custom_product['name']
#)
status = session.contenthost.install_errata(
vm.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex'
contenthost.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex'
)
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
_generate_errata_applicability(contenthost.hostname)
contenthost.execute('subscription-manager repos')
module_target_sat.cli.Host.errata_recalculate(
{'host-id': contenthost.nailgun_host.id}
)
breakpoint()
install_time_UTC = session.errata.read(CUSTOM_REPO_ERRATA_ID)['install_date']
#install_time_local = time.convert_from_utc(install_time_UTC, browser_time_zone)

#assert

assert contenthost.applicable_errata_count == 0


@pytest.mark.tier2
Expand Down Expand Up @@ -679,18 +764,6 @@ def test_positive_content_host_previous_env(


@pytest.mark.tier3
@pytest.mark.parametrize(
'module_repos_collection_with_setup',
[
{
'distro': 'rhel7',
'SatelliteToolsRepository': {},
'RHELAnsibleEngineRepository': {'cdn': True},
'YumRepository': {'url': CUSTOM_REPO_URL},
}
],
indirect=True,
)
def test_positive_content_host_library(session, module_org_with_parameter, vm):
"""Check if the applicable errata are available from the content
host's Library
Expand Down

0 comments on commit 37fb921

Please sign in to comment.