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

fix test which addresses katello-host-tools & entitlement_manifest is… #13161

Merged
Merged
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
107 changes: 48 additions & 59 deletions tests/foreman/longrun/test_inc_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from robottelo.config import settings
from robottelo.constants import (
DEFAULT_ARCHITECTURE,
DEFAULT_SUBSCRIPTION_NAME,
ENVIRONMENT,
FAKE_4_CUSTOM_PACKAGE,
PRDS,
Expand All @@ -36,109 +35,104 @@


@pytest.fixture(scope='module')
def module_lce_library(module_entitlement_manifest_org):
def module_lce_library(module_sca_manifest_org):
"""Returns the Library lifecycle environment from chosen organization"""
return (
entities.LifecycleEnvironment()
.search(
query={
'search': f'name={ENVIRONMENT} and '
f'organization_id={module_entitlement_manifest_org.id}'
'search': f'name={ENVIRONMENT} and ' f'organization_id={module_sca_manifest_org.id}'
}
)[0]
.read()
)


@pytest.fixture(scope='module')
def dev_lce(module_entitlement_manifest_org):
return entities.LifecycleEnvironment(
name='DEV', organization=module_entitlement_manifest_org
).create()
def dev_lce(module_sca_manifest_org):
return entities.LifecycleEnvironment(name='DEV', organization=module_sca_manifest_org).create()


@pytest.fixture(scope='module')
def qe_lce(module_entitlement_manifest_org, dev_lce):
def qe_lce(module_sca_manifest_org, dev_lce):
qe_lce = entities.LifecycleEnvironment(
name='QE', prior=dev_lce, organization=module_entitlement_manifest_org
name='QE', prior=dev_lce, organization=module_sca_manifest_org
).create()
return qe_lce


@pytest.fixture(scope='module')
def rhel7_sat6tools_repo(module_entitlement_manifest_org, module_target_sat):
def sat_client_repo(module_sca_manifest_org, module_target_sat):
"""Enable Sat tools repository"""
rhel7_sat6tools_repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid(
sat_client_repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid(
basearch=DEFAULT_ARCHITECTURE,
org_id=module_entitlement_manifest_org.id,
org_id=module_sca_manifest_org.id,
product=PRDS['rhel'],
repo=REPOS['rhst7']['name'],
reposet=REPOSET['rhst7'],
repo=REPOS['rhsclient7']['name'],
reposet=REPOSET['rhsclient7'],
releasever=None,
)
rhel7_sat6tools_repo = entities.Repository(id=rhel7_sat6tools_repo_id).read()
assert rhel7_sat6tools_repo.sync()['result'] == 'success'
return rhel7_sat6tools_repo
sat_client_repo = module_target_sat.api.Repository(id=sat_client_repo_id).read()
assert sat_client_repo.sync()['result'] == 'success'
return sat_client_repo


@pytest.fixture(scope='module')
def custom_repo(module_entitlement_manifest_org):
def custom_repo(module_sca_manifest_org, module_target_sat):
"""Enable custom errata repository"""
custom_repo = entities.Repository(
custom_repo = module_target_sat.api.Repository(
url=settings.repos.yum_9.url,
product=entities.Product(organization=module_entitlement_manifest_org).create(),
product=module_target_sat.api.Product(organization=module_sca_manifest_org).create(),
).create()
assert custom_repo.sync()['result'] == 'success'
return custom_repo


@pytest.fixture(scope='module')
def module_cv(module_entitlement_manifest_org, rhel7_sat6tools_repo, custom_repo):
def module_cv(module_sca_manifest_org, sat_client_repo, custom_repo):
"""Publish both repos into module CV"""
module_cv = entities.ContentView(
organization=module_entitlement_manifest_org,
repository=[rhel7_sat6tools_repo.id, custom_repo.id],
organization=module_sca_manifest_org,
repository=[sat_client_repo.id, custom_repo.id],
).create()
module_cv.publish()
module_cv = module_cv.read()
return module_cv


@pytest.fixture(scope='module')
def module_ak(module_entitlement_manifest_org, module_cv, custom_repo, module_lce_library):
def module_ak(
module_sca_manifest_org, module_cv, custom_repo, module_lce_library, module_target_sat
):
"""Create a module AK in Library LCE"""
ak = entities.ActivationKey(
content_view=module_cv,
environment=module_lce_library,
organization=module_entitlement_manifest_org,
organization=module_sca_manifest_org,
).create()
# Fetch available subscriptions
subs = entities.Subscription(organization=module_entitlement_manifest_org).search()
subs = module_target_sat.api.Subscription(organization=module_sca_manifest_org).search()
assert len(subs) > 0
# Add default subscription to activation key
sub_found = False
for sub in subs:
if sub.name == DEFAULT_SUBSCRIPTION_NAME:
ak.add_subscriptions(data={'subscription_id': sub.id})
sub_found = True
assert sub_found
# Enable RHEL product content in activation key
# Enable rhclient7 client repo in activation key
ak.content_override(
data={'content_overrides': [{'content_label': REPOS['rhst7']['id'], 'value': '1'}]}
data={'content_overrides': [{'content_label': REPOS['rhsclient7']['id'], 'value': '1'}]}
)
# Add custom subscription to activation key
prod = custom_repo.product.read()
custom_sub = entities.Subscription(organization=module_entitlement_manifest_org).search(
query={'search': f'name={prod.name}'}

# Enable custom repo in activation key
all_content = ak.product_content(data={'content_access_mode_all': '1'})['results']
for content in all_content:
if content['name'] == custom_repo.name:
content_label = content['label']
ak.content_override(
data={'content_overrides': [{'content_label': content_label, 'value': '1'}]}
)
ak.add_subscriptions(data={'subscription_id': custom_sub[0].id})
return ak


@pytest.fixture(scope='module')
def host(
rhel7_contenthost_module,
module_entitlement_manifest_org,
module_sca_manifest_org,
dev_lce,
qe_lce,
custom_repo,
Expand All @@ -147,18 +141,16 @@ def host(
module_target_sat,
):
# Create client machine and register it to satellite with rhel_7_partial_ak
rhel7_contenthost_module.install_katello_ca(module_target_sat)
# Register, enable tools repo and install katello-host-tools.
rhel7_contenthost_module.register_contenthost(
module_entitlement_manifest_org.label, module_ak.name
rhel7_contenthost_module.register(
module_sca_manifest_org, None, module_ak.name, module_target_sat
)
rhel7_contenthost_module.enable_repo(REPOS['rhst7']['id'])
rhel7_contenthost_module.install_katello_host_tools()
rhel7_contenthost_module.enable_repo(REPOS['rhsclient7']['id'])
# make a note of time for later wait_for_tasks, and include 4 mins margin of safety.
timestamp = (datetime.utcnow() - timedelta(minutes=4)).strftime('%Y-%m-%d %H:%M')
# AK added custom repo for errata package, just install it.
rhel7_contenthost_module.execute(f'yum install -y {FAKE_4_CUSTOM_PACKAGE}')
rhel7_contenthost_module.execute('katello-package-upload')
rhel7_contenthost_module.execute('subscription-manager repos')
# Wait for applicability update event (in case Satellite system slow)
module_target_sat.wait_for_tasks(
search_query='label = Actions::Katello::Applicability::Hosts::BulkGenerate'
Expand Down Expand Up @@ -186,7 +178,7 @@ def get_applicable_errata(repo):
@pytest.mark.tier4
@pytest.mark.upgrade
def test_positive_noapply_api(
module_entitlement_manifest_org, module_cv, custom_repo, host, dev_lce
module_sca_manifest_org, module_cv, custom_repo, host, dev_lce, module_target_sat
):
"""Check if api incremental update can be done without
actually applying it
Expand All @@ -207,28 +199,25 @@ def test_positive_noapply_api(
versions = sorted(module_cv.read().version, key=lambda ver: ver.id)
cvv = versions[-1].read()
cvv.promote(data={'environment_ids': dev_lce.id})
# Read CV to pick up LCE ID and next_version
module_cv = module_cv.read()

# Get the content view versions and use the recent one. API always
# returns the versions in ascending order (last in the list is most recent)
cv_versions = module_cv.version
# Get the applicable errata
errata_list = get_applicable_errata(custom_repo)
assert len(errata_list) > 0

# Apply incremental update using the first applicable errata
entities.ContentViewVersion().incremental_update(
outval = module_target_sat.api.ContentViewVersion().incremental_update(
data={
'content_view_version_environments': [
{
'content_view_version_id': cv_versions[-1].id,
'content_view_version_id': cvv.id,
'environment_ids': [dev_lce.id],
}
],
'add_content': {'errata_ids': [errata_list[0].id]},
}
)
# Re-read the content view to get the latest versions
module_cv = module_cv.read()
assert len(module_cv.version) > len(cv_versions)
assert outval['result'] == 'success'
assert (
outval['action']
== 'Incremental Update of 1 Content View Version(s) with 1 Package(s), and 1 Errata'
)