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 26, 2023
1 parent 5a4dcdb commit 7f03f7d
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 38 deletions.
7 changes: 3 additions & 4 deletions pytest_fixtures/component/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,10 @@ def repos_collection(request, target_sat):
repos = getattr(request, 'param', [])
repo_distro, repos = _simplify_repos(request, repos)
_repos_collection = target_sat.cli_factory.RepositoryCollection(
distro=repo_distro or request.getfixturevalue('distro'),
distro=repo_distro,
repositories=[
getattr(target_sat.cli_factory, repo_name)(**repo_params)
for repo in repos
for repo_name, repo_params in repo.items()
target_sat.cli_factory.SatelliteToolsRepository(),
target_sat.cli_factory.YumRepository(url=repos.url),
],
)
return _repos_collection
Expand Down
1 change: 1 addition & 0 deletions robottelo/cli/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,7 @@ 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 = sorted(cvv['id'] for cvv in cv_info['versions'])[-1]
cvv = cv_info['versions'][-1]
# Promote version to next env
try:
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
143 changes: 111 additions & 32 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,116 @@ def vm(module_repos_collection_with_setup, rhel7_contenthost, target_sat):
yield rhel7_contenthost


@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()
content_view.publish()
latest_cvv_id = sorted(cvv.id for cvv in content_view.read().version)[-1]
latest_cv_version = [
version for version in content_view.read().version if version.id == latest_cvv_id
][-1]
latest_cv_version.promote(data={'environment_ids': module_lce.id})
content_view = content_view.read()

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

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']
rhel_contenthost.create_custom_repos(repo=repo_url)
rhel_contenthost.execute(r'subscription-manager repos --enable \*')
rhel_contenthost.execute(r'yum-config-manager --enable \*')
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"])}'
rhel_contenthost.execute(r'subscription-manager refresh')
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.stderr}'
rhel_contenthost.execute(r'subscription-manager refresh')
rhel_contenthost.execute(f'yum-config-manager --enable {custom_repo_id}')
result = rhel_contenthost.execute(f'subscription-manager repos --enable {custom_repo_id}')
assert (
result.status == 0
), f'Failed to enable custom repo with subscription-manager: {result.stderr}'
assert rhel_contenthost.subscribed, f'Failed to subscribe the registered host: {result.stderr}'
yield rhel_contenthost


@pytest.mark.e2e
@pytest.mark.tier3
@pytest.mark.parametrize('setting_update', ['remote_execution_by_default'], indirect=True)
@pytest.mark.rhel_ver_match('8')
@pytest.mark.parametrize(
'module_repos_collection_with_setup',
'repos_collection',
[
{
'distro': 'rhel7',
'SatelliteToolsRepository': {},
'RHELAnsibleEngineRepository': {},
'distro': 'rhel8',
'YumRepository': {'url': CUSTOM_REPO_URL},
'FileRepository': {'url': CUSTOM_FILE_REPO},
'DockerRepository': {
'url': CONTAINER_REGISTRY_HUB,
'upstream_name': CONTAINER_UPSTREAM_NAME,
},
'AnsibleRepository': {
'url': ANSIBLE_GALAXY,
'requirements': [
{'name': 'theforeman.foreman', 'version': '2.1.0'},
{'name': 'theforeman.operations', 'version': '0.1.0'},
],
},
}
],
indirect=True,
)
@pytest.mark.no_containers
def test_end_to_end(
session,
module_org_with_parameter,
module_repos_collection_with_setup,
vm,
target_sat,
setting_update,
function_registered_contenthost,
module_entitlement_manifest_org,
module_lce,
module_cv,
module_target_sat,
repos_collection,
):
"""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 +290,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,10 +312,10 @@ def test_end_to_end(
],
'module_stream_packages': [],
}
assert _install_client_package(vm, FAKE_1_CUSTOM_PACKAGE)
assert _install_client_package(function_registered_contenthost, FAKE_1_CUSTOM_PACKAGE)
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
session.location.select(loc_name=DEFAULT_LOC)
assert session.errata.search(CUSTOM_REPO_ERRATA_ID, applicable=True)[0]['Errata ID']
Expand All @@ -247,20 +338,20 @@ def test_end_to_end(
)
assert (
errata['repositories']['table'][-1]['Name']
== module_repos_collection_with_setup.custom_repos_info[-1]['name']
== repos_collection.custom_repos_info[-1]['name']
)
assert (
errata['repositories']['table'][-1]['Product']
== module_repos_collection_with_setup.custom_product['name']
== repos_collection.custom_product['name']
)
status = session.contenthost.install_errata(
vm.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex'
function_registered_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
function_registered_contenthost = function_registered_contenthost.nailgun_host.read()
assert function_registered_contenthost.applicable_errata_count == 0


@pytest.mark.tier2
Expand Down Expand Up @@ -679,18 +770,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 7f03f7d

Please sign in to comment.