From 398ae70bdc0844dd2c97dac2dbacd8f0599a1a5f Mon Sep 17 00:00:00 2001 From: David Moore Date: Mon, 6 May 2024 09:14:51 -0400 Subject: [PATCH] fixup --- tests/foreman/ui/test_errata.py | 96 +++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index 397be2d47e4..e047efffce1 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -364,22 +364,22 @@ def test_end_to_end( ): """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, contains some outdated packages applicable errata. - + :expectedresults: Errata details are the same as expected, errata installation is successful. - + :parametrized: yes - + :BZ: 2029192 - + :customerscenario: true """ - + ERRATA_DETAILS = { 'advisory': 'RHSA-2012:0055', 'cves': 'N/A', @@ -401,25 +401,28 @@ def test_end_to_end( 'module_stream_packages': [], } # create custom repo, sync, add to content view - custom_repo = module_target_sat.api.Repository(url=CUSTOM_REPO_URL, product=module_product).create() + custom_repo = module_target_sat.api.Repository( + url=CUSTOM_REPO_URL, product=module_product + ).create() custom_repo.sync() module_cv.repository = [custom_repo] module_cv.update(['repository']) module_cv = module_cv.read() - + # associate needed entities, prepare content view, register the host client: client = module_target_sat.api_factory.register_host_and_needed_setup( - organization = module_sca_manifest_org, - client = rhel_contenthost, - activation_key = module_ak, - environment = module_lce, - content_view = module_cv, + organization=module_sca_manifest_org, + client=rhel_contenthost, + activation_key=module_ak, + environment=module_lce, + content_view=module_cv, + rex_key=True, )['client'] - + # nothing applicable to start - assert 0 == client.applicable_errata_count == client.applicable_package_count, ( - f'Expected no applicable erratum or packages to start, on host: {client.hostname}' - ) + assert ( + 0 == client.applicable_errata_count == client.applicable_package_count + ), f'Expected no applicable erratum or packages to start, on host: {client.hostname}' # enable all repositories enable_repos = client.execute(r'subscription-manager repos --enable \*') assert enable_repos.status == 0, ( @@ -435,7 +438,7 @@ def test_end_to_end( assert ( applicable_errata == 1 ), f'Expected 1 applicable errata: {CUSTOM_REPO_ERRATA_ID}, after setup. Got {applicable_errata}' - + with session: datetime_utc_start = datetime.utcnow() # Check selection box function for BZ#1688636 @@ -448,19 +451,38 @@ def test_end_to_end( assert len(results) == 1 assert results[0]['Name'] == client.hostname errata = session.errata.read(CUSTOM_REPO_ERRATA_ID) - # errata is present in expected product and custom repo - assert errata['repositories']['table'][-1]['Name'] == custom_repo.name, 'Repo containing Errata in UI does not match.' - assert errata['repositories']['table'][-1]['Product'] == module_product.name, 'Product containing Errata in UI does not match.' + assert errata['repositories']['table'], ( + f'There are no repositories listed for errata ({CUSTOM_REPO_ERRATA_ID}),', + f' expected to find at least one repository, name: {custom_repo.name}.', + ) + # repo/product entry in table match expected + # find the first table entry with the custom repository's name + errata_repo = next( + ( + repo + for repo in errata['repositories']['table'] + if 'Name' in repo and repo['Name'] == custom_repo.name + ), + None, + ) + # assert custom repo found and product name + assert ( + errata_repo + ), f'Could not find the errata repository in UI by name: {custom_repo.name}.' + assert errata_repo['Name'] == custom_repo.name + assert ( + errata_repo['Product'] == module_product.name + ), 'The product name for the errata repository in UI does not match.' # Check all tabs of Errata Details page assert ( not ERRATA_DETAILS.items() - errata['details'].items() ), 'Errata details do not match expected values.' - assert parse(errata['details']['issued']) == parse(ERRATA_DETAILS['issued']), ( - 'Errata issued date in UI does not match.' - ) - assert parse(errata['details']['last_updated_on']) == parse(ERRATA_DETAILS['last_updated_on']), ( - 'Errata last updated date in UI does not match.' - ) + assert parse(errata['details']['issued']) == parse( + ERRATA_DETAILS['issued'] + ), 'Errata issued date in UI does not match.' + assert parse(errata['details']['last_updated_on']) == parse( + ERRATA_DETAILS['last_updated_on'] + ), 'Errata last updated date in UI does not match.' assert set(errata['packages']['independent_packages']) == set( ERRATA_PACKAGES['independent_packages'] ), 'Set of errata packages in UI does not match.' @@ -472,12 +494,10 @@ def test_end_to_end( session.host_new.apply_erratas( entity_name=client.hostname, search=f"errata_id == {CUSTOM_REPO_ERRATA_ID}", - ignore_error=True, ) results = module_target_sat.wait_for_tasks( search_query=( - f'"Install errata errata_id == {CUSTOM_REPO_ERRATA_ID}' - f' on {client.hostname}"' + f'"Install errata errata_id == {CUSTOM_REPO_ERRATA_ID}' f' on {client.hostname}"' ), search_rate=2, max_tries=60, @@ -490,20 +510,18 @@ def test_end_to_end( ), f'Errata Installation task failed:\n{task_status}' assert ( client.applicable_errata_count == 0 - ), 'Unexpected applicable errata found after install.' + ), f'Unexpected applicable errata found after install of {CUSTOM_REPO_ERRATA_ID}.' # UTC timing for install task and session _UTC_format = '%Y-%m-%d %H:%M:%S UTC' install_start = datetime.strptime(task_status['started_at'], _UTC_format) install_end = datetime.strptime(task_status['ended_at'], _UTC_format) - # install task duration did not exceed 1 minute, + # install task duration did not exceed 1 minute, # duration since start of session did not exceed 10 minutes. assert (install_end - install_start).total_seconds() <= 60 assert (install_end - datetime_utc_start).total_seconds() <= 600 # Find bulk generate applicability task results = module_target_sat.wait_for_tasks( - search_query=( - f'Bulk generate applicability for host {client.hostname}' - ), + search_query=(f'Bulk generate applicability for host {client.hostname}'), search_rate=2, max_tries=60, ) @@ -517,7 +535,7 @@ def test_end_to_end( bulk_gen_end = datetime.strptime(task_status['ended_at'], _UTC_format) assert (bulk_gen_start - install_end).total_seconds() <= 30 assert (bulk_gen_end - bulk_gen_start).total_seconds() <= 60 - + # Errata should still be visible on satellite, but not on contenthost assert session.errata.read(CUSTOM_REPO_ERRATA_ID) results = session.errata.search_content_hosts( @@ -527,9 +545,7 @@ def test_end_to_end( ) assert len(results) == 0 # Check package version was updated on contenthost - _package_version = client.execute( - f'rpm -q {FAKE_1_CUSTOM_PACKAGE_NAME}' - ).stdout + _package_version = client.execute(f'rpm -q {FAKE_1_CUSTOM_PACKAGE_NAME}').stdout assert FAKE_2_CUSTOM_PACKAGE in _package_version