diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index 57f22955805..aeb57536265 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -210,10 +210,21 @@ def _publish_and_wait(sat, org, cv): @pytest.fixture -def errata_host_ak(module_target_sat, module_org, module_lce): - """New activation key created in module_org and module_lce""" +def errata_host_ak(module_target_sat, module_sca_manifest_org, module_lce): + """New activation key created in module SCA org and module lce, + if the same ak was created prior for this org and lce, return the existing one. + """ + search_result = module_target_sat.api.ActivationKey( + organization=module_sca_manifest_org, + environment=module_lce, + ).search(query={'search': 'name="errata_host_ak"'}) + # only one existing ak was found, return it + if len(search_result) == 1: + return search_result[0].read() + # no matching aks found, or multiple exist, create a new one ak = module_target_sat.api.ActivationKey( - organization=module_org, + name='errata_host_ak', + organization=module_sca_manifest_org, environment=module_lce, ).create() return ak.read() @@ -221,10 +232,10 @@ def errata_host_ak(module_target_sat, module_org, module_lce): @pytest.fixture def registered_contenthost( + module_sca_manifest_org, module_target_sat, rhel_contenthost, errata_host_ak, - module_org, module_lce, module_cv, request, @@ -261,7 +272,7 @@ def registered_contenthost( custom_repo_info = module_target_sat.cli_factory.setup_org_for_a_custom_repo( { 'url': repo_url, - 'organization-id': module_org.id, + 'organization-id': module_sca_manifest_org.id, 'lifecycle-environment-id': module_lce.id, 'activationkey-id': errata_host_ak.id, 'content-view-id': module_cv.id, @@ -271,17 +282,22 @@ def registered_contenthost( custom_repos.append(custom_repo_info['repository-id']) # Publish new version and promote with all content - cv_publish_promote(module_target_sat, module_org, module_cv, module_lce) + cv_publish_promote(module_target_sat, module_sca_manifest_org, module_cv, module_lce) result = rhel_contenthost.register( activation_keys=errata_host_ak.name, target=module_target_sat, - org=module_org, + org=module_sca_manifest_org, loc=None, ) assert result.status == 0, f'Failed to register host:\n{result.stderr}' - assert rhel_contenthost.subscribed + assert rhel_contenthost.subscribed, ( + f'Failed to subscribe host to content, host: {rhel_contenthost.hostname}' + f' Attempting to subscribe to content-view id: {module_cv.id}' + f' Using activation-key id: {errata_host_ak.id}' + ) for custom_repo_id in custom_repos: + # custom repos setup and successfully sync custom_repo = module_target_sat.api.Repository(id=custom_repo_id).read() assert custom_repo result = custom_repo.sync()['humanized'] @@ -292,23 +308,23 @@ def registered_contenthost( yield rhel_contenthost @request.addfinalizer - # Cleanup for in between parameterized runs + # Cleanup for in-between parameterized sessions def cleanup(): - nonlocal rhel_contenthost, module_cv, custom_repos, custom_products, errata_host_ak + nonlocal rhel_contenthost, module_cv, custom_repos, custom_products, errata_host_ak, module_sca_manifest_org rhel_contenthost.unregister() errata_host_ak.delete() # Remove CV from all lifecycle-environments module_target_sat.cli.ContentView.remove_from_environment( { 'id': module_cv.id, - 'organization-id': module_org.id, + 'organization-id': module_sca_manifest_org.id, 'lifecycle-environment-id': module_lce.id, } ) module_target_sat.cli.ContentView.remove_from_environment( { 'id': module_cv.id, - 'organization-id': module_org.id, + 'organization-id': module_sca_manifest_org.id, 'lifecycle-environment': 'Library', } ) @@ -327,9 +343,6 @@ def cleanup(): 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_cv = module_cv.read() - module_cv.publish() @pytest.mark.e2e @@ -499,7 +512,6 @@ def test_host_content_errata_tab_pagination( module_target_sat, registered_contenthost, module_sca_manifest_org, - errata_host_ak, module_lce, module_cv, ): @@ -725,12 +737,12 @@ def test_host_content_errata_tab_pagination( @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') def test_positive_list( module_sca_manifest_org, + errata_host_ak, function_org, function_lce, target_sat, module_lce, module_cv, - module_ak, session, ): """View all errata in an Org @@ -757,7 +769,7 @@ def test_positive_list( 'url': CUSTOM_REPO_URL, 'organization-id': _org_module.id, 'lifecycle-environment-id': module_lce.id, - 'activationkey-id': module_ak.id, + 'activationkey-id': errata_host_ak.id, 'content-view-id': module_cv.id, }, ) @@ -1119,7 +1131,7 @@ def test_positive_check_errata(session, module_org_with_parameter, registered_co [[CUSTOM_REPO_URL]], indirect=True, ) -def test_positive_errata_search_type(session, registered_contenthost): +def test_positive_errata_search_type(session, module_sca_manifest_org, registered_contenthost): """Search for errata on a host's page content-errata tab by type. :id: f278f0e8-3b64-4dbf-a0c8-b9b289474a76 @@ -1292,7 +1304,7 @@ def test_positive_show_count_on_host_pages(session, module_org, registered_conte ) def test_positive_check_errata_counts_by_type_on_host_details_page( session, - module_org, + module_sca_manifest_org, registered_contenthost, ): """Errata count on host page