Skip to content

Commit

Permalink
Cleanup between parameterized runs
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Nov 8, 2023
1 parent effe759 commit c2d21c2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 15 deletions.
5 changes: 3 additions & 2 deletions robottelo/cli/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,9 +1692,10 @@ 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})
lce_promoted = cv_info['lifecycle-environments']
assert len(cv_info['versions']) > 0
cvv = sorted(cvv['id'] for cvv in cv_info['versions'])[-1]
cv_info['versions'].sort(key=lambda version: version['id'])
cvv = cv_info['versions'][-1]
lce_promoted = cv_info['lifecycle-environments']
# Promote version to next env
try:
if env_id not in [int(lce['id']) for lce in lce_promoted]:
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 @@ -631,14 +631,15 @@ def setup_org_for_a_custom_repo(self, options=None):
# 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]
cv_info['versions'].sort(key=lambda version: version['id'])
cvv = cv_info['versions'][-1]
lce_promoted = cv_info['lifecycle-environments']
# 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
62 changes: 51 additions & 11 deletions tests/foreman/ui/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def registered_contenthost(
rhel_contenthost,
module_org,
module_lce,
module_cv,
module_published_cv,
module_target_sat,
request,
repos=[CUSTOM_REPO_URL],
Expand All @@ -185,8 +185,6 @@ def registered_contenthost(
:param repos: list of upstream URLs for custom repositories,
default to CUSTOM_REPO_URL
"""
module_cv.environment = [module_lce]
module_cv.update(['environment'])
activation_key = module_target_sat.api.ActivationKey(
organization=module_org,
environment=module_lce,
Expand All @@ -196,20 +194,25 @@ def registered_contenthost(
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:
# Publishes a new cvv, associates org, ak, cv, with custom repo:
custom_repo_info = 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': module_cv.id,
'content-view-id': module_published_cv.id,
}
)
custom_products.append(custom_repo_info['product-id'])
custom_repos.append(custom_repo_info['repository-id'])

# Promote newest version with all content
module_published_cv = module_published_cv.read()
module_published_cv.version.sort(key=lambda version: version.id)
module_published_cv.version[-1].promote(data={'environment_ids': module_lce.id})
module_published_cv = module_published_cv.read()

result = rhel_contenthost.register(
activation_keys=activation_key.name,
target=module_target_sat,
Expand All @@ -227,9 +230,47 @@ def registered_contenthost(
len(result['errors']) == 0
), f'Failed to sync custom repository [id: {custom_repo_id}]:\n{str(result["errors"])}'

# TODO: @request.addfinalizer: Cleanup to remove created ak,
# contentview versions, products & repositories.
return rhel_contenthost
yield rhel_contenthost

@request.addfinalizer
# Cleanup for in between parameterized runs
def cleanup():
nonlocal rhel_contenthost, module_published_cv, custom_repos, custom_products, activation_key
rhel_contenthost.unregister()
activation_key.delete()
# Remove CV from all lifecycle-environments
module_target_sat.cli.ContentView.remove_from_environment(
{
'id': module_published_cv.id,
'organization-id': module_org.id,
'lifecycle-environment-id': module_lce.id,
}
)
module_target_sat.cli.ContentView.remove_from_environment(
{
'id': module_published_cv.id,
'organization-id': module_org.id,
'lifecycle-environment': 'Library',
}
)
# Delete all CV versions
module_published_cv = module_published_cv.read()
for version in module_published_cv.version:
version.delete()
# Remove repos from CV, delete all custom repos and products
for repo_id in custom_repos:
module_target_sat.cli.ContentView.remove_repository(
{
'id': module_published_cv.id,
'repository-id': repo_id,
}
)
module_target_sat.api.Repository(id=repo_id).delete()
for product_id in custom_products:
module_target_sat.api.Product(id=product_id).delete()
# Publish a new CV version with no content
module_published_cv = module_published_cv.read()
module_published_cv.publish()


@pytest.mark.e2e
Expand All @@ -241,7 +282,7 @@ def test_end_to_end(
request,
module_org,
module_lce,
module_cv,
module_published_cv,
module_target_sat,
registered_contenthost,
):
Expand Down Expand Up @@ -291,7 +332,6 @@ def test_end_to_end(
assert len(product_list) > 0
product_list.sort(key=lambda product: product.id)
_product = product_list[-1].read()
# _product = module_target_sat.api.Product(id=product_id).read()
assert len(_product.repository) == 1
_repository = _product.repository[0].read()
# Remove custom package if present, install outdated version
Expand Down

0 comments on commit c2d21c2

Please sign in to comment.