diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index bfb85012766..ad6ec0551fb 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -64,31 +64,27 @@ def _generate_errata_applicability(hostname): host.errata_applicability(synchronous=False) -def _install_client_package(client, package, errata_applicability=False): +def _install_client_package(client, package): """Install a package in virtual machine client. + Errata applicability regenerated after successful yum execution. :param client: The Virtual machine client. :param package: the package to install in virtual machine client. - :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}') - if errata_applicability: - _generate_errata_applicability(client.hostname) return result.status == 0 -def _remove_client_package(client, package, errata_applicability=False): +def _remove_client_package(client, package): """Remove a package in virtual machine client. + Errata applicability regenerated after successful yum execution. :param client: The Virtual machine client. :param package: the package (full version, or name) to remove from virtual machine client. - :param errata_applicability: If True, force host to generate errata applicability. :returns: True if a package was removed successfully, False otherwise. """ result = client.execute(f'yum remove -y {package}') - if errata_applicability: - _generate_errata_applicability(client.hostname) return result.status == 0 @@ -215,7 +211,6 @@ def registered_contenthost( result = rhel_contenthost.register( activation_keys=activation_key.name, - lifecycle_environment=module_lce, target=module_target_sat, org=module_org, loc=None, @@ -286,6 +281,7 @@ 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 _product = product_list[-1].read() @@ -293,12 +289,12 @@ def test_end_to_end( _repository = _product.repository[-1].read() # Remove custom package if present, then install outdated version _remove_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE_NAME) - assert _install_client_package( - registered_contenthost, FAKE_1_CUSTOM_PACKAGE, errata_applicability=True - ) + assert _install_client_package(registered_contenthost, FAKE_1_CUSTOM_PACKAGE) assert ( - registered_contenthost.applicable_errata_count == 1 - ), 'Expected only one applicable errata after setup.' + appl_errata := registered_contenthost.applicable_errata_count + ) == 1, ( + f'Expected one applicable errata: {CUSTOM_REPO_ERRATA_ID}, after setup. Got {appl_errata}' + ) with session: @@ -326,7 +322,7 @@ def test_end_to_end( == ERRATA_PACKAGES['module_stream_packages'] ) - # Install Errata, find and assert REX task + # Apply Errata, find REX install task session.host_new.apply_erratas( entity_name=registered_contenthost.hostname, search=f"errata_id == {CUSTOM_REPO_ERRATA_ID}", @@ -346,12 +342,30 @@ def test_end_to_end( assert ( registered_contenthost.applicable_errata_count == 0 ), 'Unexpected applicable errata found after install.' + # Check 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( + 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() + assert ( + task_status['result'] == 'success' + ), f'Bulk Generate Errata Applicability task failed:\n{task_status}' + # Check 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 + assert (bulk_gen_end - bulk_gen_start).total_seconds() <= 60 - task_start = datetime.strptime(task_status['started_at'], '%Y-%m-%d %H:%M:%S UTC') - task_end = datetime.strptime(task_status['ended_at'], '%Y-%m-%d %H:%M:%S UTC') - # Checking UTC timing for install task and session - assert (task_end - task_start).total_seconds() <= 60 - assert (task_end - datetime_utc_start).total_seconds() <= 600 # Errata should still be visible on satellite, but not on contenthost assert session.errata.read(CUSTOM_REPO_ERRATA_ID) assert not session.errata.search_content_hosts(