Skip to content

Commit

Permalink
Parameterized fixes in-between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
damoore044 committed Nov 6, 2023
1 parent 742a49a commit 83cc4bc
Showing 1 changed file with 40 additions and 27 deletions.
67 changes: 40 additions & 27 deletions tests/foreman/ui/test_errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _remove_client_package(client, package):
:param package: the package (full version, or name) to remove from virtual machine client.
:returns: True if a package was removed successfully, False otherwise.
"""
result = client.execute(f'yum remove -y {package}')
result = client.execute(f'yum erase -y {package}')
return result.status == 0


Expand Down Expand Up @@ -174,7 +174,9 @@ def registered_contenthost(
rhel_contenthost,
module_org,
module_lce,
module_cv,
module_target_sat,
request,
repos=[CUSTOM_REPO_URL],
):
"""RHEL ContentHost registered in satellite,
Expand All @@ -183,31 +185,30 @@ def registered_contenthost(
: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()

module_cv.environment = [module_lce]
module_cv.update(['environment'])
activation_key = module_target_sat.api.ActivationKey(
organization=module_org,
environment=module_lce,
).create()

custom_products = []
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(
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': content_view.id,
'content-view-id': module_cv.id,
}
)['repository-id']
custom_repos.append(custom_repo_id)
)
custom_products.append(custom_repo_info['product-id'])
custom_repos.append(custom_repo_info['repository-id'])

result = rhel_contenthost.register(
activation_keys=activation_key.name,
Expand All @@ -226,6 +227,8 @@ 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


Expand All @@ -235,6 +238,7 @@ def registered_contenthost(
@pytest.mark.no_containers
def test_end_to_end(
session,
request,
module_org,
module_lce,
module_cv,
Expand Down Expand Up @@ -282,19 +286,21 @@ def test_end_to_end(
'module_stream_packages': [],
}
_UTC_format = '%Y-%m-%d %H:%M:%S UTC'
# Capture product and repository with the desired content
assert len(product_list := module_target_sat.api.Product(organization=module_org).search()) > 0
# Capture newest product and repository with the desired content
product_list = module_target_sat.api.Product(organization=module_org).search()
assert len(product_list) > 0
product_list.sort(key=lambda product: product.id)
_product = product_list[-1].read()
assert len(_product.repository) > 0
_repository = _product.repository[-1].read()
# Remove custom package if present, then install outdated version
# _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
_remove_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE_NAME)
assert _install_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE)
applicable_errata = registered_contenthost.applicable_errata_count
assert (
appl_errata := registered_contenthost.applicable_errata_count
) == 1, (
f'Expected one applicable errata: {CUSTOM_REPO_ERRATA_ID}, after setup. Got {appl_errata}'
)
applicable_errata == 1
), f'Expected 1 applicable errata: {CUSTOM_REPO_ERRATA_ID}, after setup. Got {applicable_errata}'

with session:

Expand All @@ -305,10 +311,10 @@ def test_end_to_end(
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)
assert errata['repositories']['table'][-1]['Name'] == _repository.name
assert errata['repositories']['table'][-1]['Product'] == _product.name
# Check all tabs of Errata Details page
assert (
not ERRATA_DETAILS.items() - errata['details'].items()
), 'Errata details do not match expected values.'
Expand All @@ -327,40 +333,42 @@ def test_end_to_end(
entity_name=registered_contenthost.hostname,
search=f"errata_id == {CUSTOM_REPO_ERRATA_ID}",
)
result = module_target_sat.wait_for_tasks(
results = 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,
)
task_status = module_target_sat.api.ForemanTask(id=result[0].id).poll()
results.sort(key=lambda res: res.id)
task_status = module_target_sat.api.ForemanTask(id=results[-1].id).poll()
assert (
task_status['result'] == 'success'
), f'Errata Installation task failed:\n{task_status}'
assert (
registered_contenthost.applicable_errata_count == 0
), 'Unexpected applicable errata found after install.'
# Check UTC timing for install task and session
# UTC timing for install task and session
install_start = datetime.strptime(task_status['started_at'], _UTC_format)
install_end = datetime.strptime(task_status['ended_at'], _UTC_format)
assert (install_end - install_start).total_seconds() <= 60
assert (install_end - datetime_utc_start).total_seconds() <= 600

# Find bulk generate applicability task
result = module_target_sat.wait_for_tasks(
results = module_target_sat.wait_for_tasks(
search_query=(
f'"Bulk generate applicability for host {registered_contenthost.hostname}"'
),
search_rate=2,
max_tries=60,
)
task_status = module_target_sat.api.ForemanTask(id=result[0].id).poll()
results.sort(key=lambda res: res.id)
task_status = module_target_sat.api.ForemanTask(id=results[-1].id).poll()
assert (
task_status['result'] == 'success'
), f'Bulk Generate Errata Applicability task failed:\n{task_status}'
# Check UTC timing for generate applicability task
# UTC timing for generate applicability task
bulk_gen_start = datetime.strptime(task_status['started_at'], _UTC_format)
bulk_gen_end = datetime.strptime(task_status['ended_at'], _UTC_format)
assert (bulk_gen_start - install_end).total_seconds() <= 30
Expand All @@ -371,6 +379,11 @@ def test_end_to_end(
assert not session.errata.search_content_hosts(
CUSTOM_REPO_ERRATA_ID, registered_contenthost.hostname, environment=module_lce.name
)
# Check package version was updated on contenthost
_package_version = registered_contenthost.execute(
f'rpm -q {FAKE_1_CUSTOM_PACKAGE_NAME}'
).stdout
assert FAKE_2_CUSTOM_PACKAGE in _package_version


@pytest.mark.tier2
Expand Down

0 comments on commit 83cc4bc

Please sign in to comment.