diff --git a/tests/foreman/api/test_reporttemplates.py b/tests/foreman/api/test_reporttemplates.py index c1e9e89006b..05c65d74831 100644 --- a/tests/foreman/api/test_reporttemplates.py +++ b/tests/foreman/api/test_reporttemplates.py @@ -13,7 +13,6 @@ """ import re -from time import time from broker import Broker from fauxfactory import gen_string @@ -342,81 +341,6 @@ def test_positive_export_report(): """ -@pytest.mark.tier2 -@pytest.mark.rhel_ver_match('[^6]') -@pytest.mark.no_containers -def test_positive_applied_errata_by_search( - function_org, function_lce, rhel_contenthost, target_sat -): - """Generate an Applied Errata report - :id: 0f7d2772-47a4-4215-b555-dd8ee675372f - :setup: A Host with some applied errata. - :steps: - 1. Generate an Applied Errata report - :expectedresults: A report is generated with all applied errata listed - :CaseImportance: Medium - """ - activation_key = target_sat.api.ActivationKey( - environment=function_lce, organization=function_org - ).create() - cv = target_sat.api.ContentView(organization=function_org).create() - ERRATUM_ID = str(settings.repos.yum_6.errata[2]) - target_sat.cli_factory.setup_org_for_a_custom_repo( - { - 'url': settings.repos.yum_9.url, - 'organization-id': function_org.id, - 'content-view-id': cv.id, - 'lifecycle-environment-id': function_lce.id, - 'activationkey-id': activation_key.id, - } - ) - errata_name = ( - target_sat.api.Errata() - .search(query={'search': f'errata_id="{ERRATUM_ID}"'})[0] - .read() - .description - ) - result = rhel_contenthost.register(function_org, None, activation_key.name, target_sat) - assert f'The registered system name is: {rhel_contenthost.hostname}' in result.stdout - assert rhel_contenthost.subscribed - epoch_timestamp = int(time() - 1) - rhel_contenthost.execute(r'subscription-manager repos --enable \*') - assert rhel_contenthost.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0 - assert rhel_contenthost.execute(f'rpm -q {FAKE_1_CUSTOM_PACKAGE}').status == 0 - rhel_contenthost.execute('subscription-manager repos') - task_id = target_sat.api.JobInvocation().run( - data={ - 'feature': 'katello_errata_install_by_search', - 'inputs': {'Errata search query': errata_name}, - 'targeting_type': 'static_query', - 'search_query': f'name = {rhel_contenthost.hostname}', - 'organization_id': function_org.id, - }, - )['id'] - target_sat.wait_for_tasks( - search_query=(f'label = Actions::RemoteExecution::RunHostsJob and id = {task_id}'), - search_rate=15, - ) - rt = ( - target_sat.api.ReportTemplate() - .search(query={'search': 'name="Host - Applied Errata"'})[0] - .read() - ) - res = rt.generate( - data={ - 'organization_id': function_org.id, - 'report_format': 'json', - 'input_values': { - 'Filter Errata Type': 'all', - 'Include Last Reboot': 'no', - 'Status': 'all', - }, - } - ) - assert res[0]['erratum_id'] == ERRATUM_ID - assert res[0]['issued'] - - @pytest.mark.tier2 @pytest.mark.stubbed def test_positive_generate_report_sanitized(): diff --git a/tests/foreman/ui/test_errata.py b/tests/foreman/ui/test_errata.py index ab6eb81ce9d..c771f4af836 100644 --- a/tests/foreman/ui/test_errata.py +++ b/tests/foreman/ui/test_errata.py @@ -163,6 +163,7 @@ def cv_publish_promote(sat, org, cv, lce=None, needs_publish=True): :param lce: if None, default to 'Library', pass a single instance of lce, or list of instances. + do not pass the Library environment :param bool needs_publish: if False, skip publish of a new version :return dictionary: 'content-view': instance of updated cv @@ -203,7 +204,7 @@ def _publish_and_wait(sat, org, cv, timeout=60): """Synchrnous publish of a new version of content-view to organization, wait for task completion. - return: the polled task, if success or failed. + return: the polled task, success or fail. """ task_id = sat.api.ContentView(id=cv.id).publish({'id': cv.id, 'organization': org})['id'] assert task_id, f'No task was invoked to publish the Content-View: {cv.id}.' @@ -216,16 +217,6 @@ def _publish_and_wait(sat, org, cv, timeout=60): return sat.api.ForemanTask(id=task_id).poll(must_succeed=False) -@pytest.fixture -def errata_host_ak(module_target_sat, module_sca_manifest_org, module_lce): - """New activation key created in module SCA org and module lce""" - ak = module_target_sat.api.ActivationKey( - organization=module_sca_manifest_org, - environment=module_lce, - ).create() - return ak.read() - - @pytest.fixture def registered_contenthost( module_sca_manifest_org, @@ -330,7 +321,7 @@ def registered_contenthost( # found index (repo) with matching name, grab sub-manager repo-id: assert repo.name in repo_ids_names['names'] sub_man_repo_id = repo_ids_names['ids'][repo_ids_names['names'].index(repo.name)] - # repo present, and can be enabled without error + # repo can be enabled by id without error enable_repo = client.execute(f'subscription-manager repos --enable {sub_man_repo_id}') assert enable_repo.status == 0, ( f'Failed to enable a repository with subscription-manager, on client: {client.hostname}.' @@ -357,6 +348,7 @@ def cleanup(): @pytest.mark.e2e @pytest.mark.tier3 @pytest.mark.rhel_ver_match('[^6]') +@pytest.mark.parametrize('registered_contenthost', [[CUSTOM_REPO_URL]], indirect=True) @pytest.mark.no_containers def test_end_to_end( registered_contenthost, @@ -366,7 +358,7 @@ def test_end_to_end( module_cv, session, ): - """Create all entities required for errata, set up applicable host, + """Create all entities required for errata, register an applicable host, read errata details and apply it to host. :id: a26182fc-f31a-493f-b094-3f5f8d2ece47 @@ -408,21 +400,7 @@ def test_end_to_end( client = registered_contenthost hostname = client.hostname assert client.subscribed - # create new custom repo, sync, add to content view - 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']) - # publish new version with the newly added content, promote. - # once promoted, the new version with content - # will be available to host. - module_cv.read().publish() - module_cv = module_cv.read() - module_cv.version.sort(key=lambda version: version.id) - content_view_version = module_cv.version[-1].read() - content_view_version.promote(data={'environment_ids': module_lce.id}) + custom_repo = module_cv.read().repository[0].read() # nothing applicable to start result = client.execute('subscription-manager repos') assert ( @@ -460,9 +438,9 @@ def test_end_to_end( # BZ 2265095: Check all columns in table of applicable host: # from ContentTypes > Errata > Details > Content Hosts tab assert results[0]['Name'] == hostname - #assert str(client.deploy_rhel_version) in results[0]['OS'] - #assert results[0]['Environment'] == module_lce.name - #assert results[0]['Content View'] == module_cv.name + # assert str(client.deploy_rhel_version) in results[0]['OS'] + # assert results[0]['Environment'] == module_lce.name + # assert results[0]['Content View'] == module_cv.name # Check errata details errata = session.errata.read(CUSTOM_REPO_ERRATA_ID) assert errata['repositories']['table'], ( @@ -573,12 +551,12 @@ def test_end_to_end( @pytest.mark.parametrize('registered_contenthost', [[CUSTOM_REPO_3_URL]], indirect=True) @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') def test_host_content_errata_tab_pagination( - session, - module_target_sat, - registered_contenthost, module_sca_manifest_org, + registered_contenthost, + module_target_sat, module_lce, module_cv, + session, ): """ # Test per-page pagination for BZ#1662254 @@ -621,7 +599,7 @@ def test_host_content_errata_tab_pagination( # custom_repo was created & added to cv, in registered_contenthost fixture # search for the instance custom_repo = [repo for repo in all_repos if repo.url == CUSTOM_REPO_3_URL] - assert len(custom_repo) == 1 + assert len(custom_repo) > 0 custom_repo = custom_repo[0].read() custom_repo.sync() # Set up rh_repo @@ -738,7 +716,7 @@ def test_host_content_errata_tab_pagination( item_count = pf4_pagination.total_items assert item_count == _prior_app_count - 1 - # Install all available from errata tab, we pass no search filter, + # Install All available from errata tab, we pass no search filter, # so that all errata are selected, on all pages. session.host_new.apply_erratas(_chost_name) # find host's errata install job non-pending, timeout is 120s @@ -803,12 +781,12 @@ def test_host_content_errata_tab_pagination( @pytest.mark.tier2 @pytest.mark.skipif((not settings.robottelo.REPOS_HOSTING_URL), reason='Missing repos_hosting_url') def test_positive_list( + function_sca_manifest_org, module_sca_manifest_org, - errata_host_ak, - function_org, function_lce, - target_sat, module_lce, + target_sat, + module_ak, module_cv, session, ): @@ -828,15 +806,14 @@ def test_positive_list( :customerscenario: true """ _org_module = module_sca_manifest_org - _org_function = function_org - module_cv = module_cv.read() # for module sca org + _org_function = function_sca_manifest_org # create and sync repository, for module org's errata target_sat.cli_factory.setup_org_for_a_custom_repo( { 'url': CUSTOM_REPO_URL, 'organization-id': _org_module.id, 'lifecycle-environment-id': module_lce.id, - 'activationkey-id': errata_host_ak.id, + 'activationkey-id': module_ak.id, 'content-view-id': module_cv.id, }, ) @@ -907,7 +884,9 @@ def test_positive_list_permission( ) rh_repo = module_target_sat.api.Repository(id=rh_repo_id).read() rh_repo.sync() - custom_repo = module_target_sat.api.Repository(url=CUSTOM_REPO_URL, product=function_product).create() + custom_repo = module_target_sat.api.Repository( + url=CUSTOM_REPO_URL, product=function_product + ).create() custom_repo.sync() # create role with access only to 'RHEL8' RedHat product role = module_target_sat.api.Role().create() @@ -972,15 +951,20 @@ def test_positive_apply_for_all_hosts( :expectedresults: Check that the erratum is applied in all the content hosts. """ + num_hosts = 4 + distro = 'rhel9' # one custom repo on satellite, for all hosts to use custom_repo = target_sat.api.Repository(url=CUSTOM_REPO_URL, product=module_product).create() custom_repo.sync() module_cv.repository = [custom_repo] module_cv.update(['repository']) with Broker( - nick='rhel9', workflow='deploy-rhel', host_class=ContentHost, _count=4, + nick=distro, + workflow='deploy-rhel', + host_class=ContentHost, + _count=num_hosts, ) as hosts: - if not isinstance(hosts, list) or len(hosts) != 4: + if not isinstance(hosts, list) or len(hosts) != num_hosts: pytest.fail('Failed to provision the expected number of hosts.') for client in hosts: # setup/register all hosts to same ak, content-view, and the one custom repo @@ -995,22 +979,38 @@ def test_positive_apply_for_all_hosts( assert setup['result'] != 'error', f'{setup["message"]}' assert (client := setup['client']) assert client.subscribed - assert client.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0 + pkgs = ' '.join(FAKE_9_YUM_OUTDATED_PACKAGES) + assert client.execute(f'yum install -y {pkgs}').status == 0 assert client.execute('subscription-manager repos').status == 0 with session: session.location.select(loc_name=DEFAULT_LOC) + # for first errata, install in each chost and check, one at a time. + # from Legacy Chost UI > details > Errata tab for client in hosts: status = session.contenthost.install_errata( client.hostname, CUSTOM_REPO_ERRATA_ID, install_via='rex' ) assert status['overview']['job_status'] == 'Success' assert status['overview']['job_status_progress'] == '100%' + # check updated package in chost details + assert client.execute('subscription-manager repos').status == 0 packages_rows = session.contenthost.search_package( client.hostname, FAKE_2_CUSTOM_PACKAGE ) assert packages_rows[0]['Installed Package'] == FAKE_2_CUSTOM_PACKAGE + # for second errata, apply to all chosts at once + # from Content > Errata > info > ContentHosts tab + errata_id = settings.repos.yum_9.errata[4] # RHBA-2012:1030 + session.errata.install( + entity_name=errata_id, + host_names="All", + ) + # bulk action task for expected hosts + # Actions::RemoteExecution::RunHostsJob + # check each task's status, and each chost's package version + @pytest.mark.tier2 @pytest.mark.upgrade @@ -1267,6 +1267,7 @@ def test_positive_host_content_library( assert client.applicable_errata_count == 0 assert client.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0 + assert client.execute('subscription-manager repos').status == 0 assert client.applicable_errata_count == 1 assert client.applicable_package_count == 1 @@ -1587,12 +1588,14 @@ def test_positive_filtered_errata_status_installable_param( """ client = registered_contenthost assert client.execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0 + assert client.execute('subscription-manager repos').status == 0 # Adding content view filter and content view filter rule to exclude errata, # for the installed package above. cv_filter = target_sat.api.ErratumContentViewFilter( content_view=module_cv, inclusion=False ).create() module_cv = module_cv.read() + module_cv.version.sort(key=lambda version: version.id) errata = target_sat.api.Errata(content_view_version=module_cv.version[-1]).search( query={'search': f'errata_id="{CUSTOM_REPO_ERRATA_ID}"'} )[0] @@ -1644,12 +1647,12 @@ def test_positive_filtered_errata_status_installable_param( @pytest.mark.tier3 def test_content_host_errata_search_commands( - session, - target_sat, module_product, + target_sat, module_org, module_ak, module_cv, + session, ): """View a list of affected content hosts for security (RHSA) and bugfix (RHBA) errata, filtered with errata status and applicable flags. Applicability is calculated using the @@ -1658,7 +1661,9 @@ def test_content_host_errata_search_commands( :id: 45114f8e-0fc8-4c7c-85e0-f9b613530dac - :Setup: Two Content Hosts, one with RHSA and one with RHBA errata. + :Setup: + 1. Two content views, one for each host's repo for errata. + 2. Two registered Content Hosts, one with RHSA and one with RHBA errata. :customerscenario: true @@ -1669,38 +1674,48 @@ def test_content_host_errata_search_commands( 4. host list --search "applicable_errata = RHBA-2012:1030" 5. host list --search "applicable_rpms = walrus-5.21-1.noarch" 6. host list --search "applicable_rpms = kangaroo-0.2-1.noarch" - 7. host list --search "installable_errata = RHSA-2012:0055" - 8. host list --search "installable_errata = RHBA-2012:1030" + 7. host list --search installable=True "errata_id = RHSA-2012:0055" + 8. host list --search installable=True "errata_id = RHBA-2012:1030" :expectedresults: The hosts are correctly listed for RHSA and RHBA errata. :BZ: 1707335 """ - yum_9_repo = target_sat.api.Repository(url=CUSTOM_REPO_URL, product=module_product).create() - yum_6_repo = target_sat.api.Repository(url=settings.repos.yum_6.url, product=module_product).create() - yum_9_repo.sync() - yum_6_repo.sync() - module_cv.repository = [yum_6_repo, yum_9_repo] + content_view = target_sat.api.ContentView(organization=module_org).create() + RHSA_repo = target_sat.api.Repository( + url=settings.repos.yum_9.url, product=module_product + ).create() + RHBA_repo = target_sat.api.Repository( + url=settings.repos.yum_6.url, product=module_product + ).create() + RHSA_repo.sync() + RHBA_repo.sync() + module_cv.repository = [RHSA_repo] module_cv.update(['repository']) - + content_view.repository = [RHBA_repo] + content_view.update(['repository']) + cvs = [module_cv.read(), content_view.read()] # client0, client1 + # walrus-0.71-1.noarch (RHSA), kangaroo-0.1-1.noarch (RHBA) + packages = [FAKE_1_CUSTOM_PACKAGE, FAKE_4_CUSTOM_PACKAGE] with Broker(nick='rhel8', host_class=ContentHost, _count=2) as clients: - for client in clients: - # register all hosts to the same AK, CV: + for ( + client, + cv, + pkg, + ) in zip(clients, cvs, packages, strict=True): setup = target_sat.api_factory.register_host_and_needed_setup( organization=module_org, client=client, activation_key=module_ak, environment='Library', - content_view=module_cv, + content_view=cv, enable_repos=True, ) assert setup['result'] != 'error', f'{setup["message"]}' assert (client := setup['client']) assert client.subscribed - # Install pkg walrus-0.71-1.noarch to create need for RHSA on client 1 - assert clients[0].execute(f'yum install -y {FAKE_1_CUSTOM_PACKAGE}').status == 0 - # Install pkg kangaroo-0.1-1.noarch to create need for RHBA on client 2 - assert clients[1].execute(f'yum install -y {FAKE_4_CUSTOM_PACKAGE}').status == 0 + assert client.execute(f'yum install -y {pkg}').status == 0 + assert client.execute('subscription-manager repos').status == 0 with session: session.location.select(loc_name=DEFAULT_LOC) @@ -1732,15 +1747,34 @@ def test_content_host_errata_search_commands( result = session.contenthost.search(f'applicable_rpms = {FAKE_5_CUSTOM_PACKAGE}') result = [item['Name'] for item in result] assert clients[1].hostname in result - # Search for installable RHSA errata by Errata ID - result = session.contenthost.search( - f'installable_errata = {settings.repos.yum_6.errata[2]}' + + # Search chost for installable RHSA errata by Errata ID + result = session.contenthost.search_errata( + entity_name=clients[0].hostname, + errata_id=settings.repos.yum_6.errata[2], ) - result = [item['Name'] for item in result] - assert clients[0].hostname in result - # Search for installable RHBA errata by Errata ID - result = session.contenthost.search( - f'installable_errata = {settings.repos.yum_6.errata[0]}' + assert len(result) > 0, ( + f'Found no matching entries in chost errata table, for host: {clients[0].hostname}' + f' for search by that hostname, and errata_id: {settings.repos.yum_6.errata[2]}.' ) - result = [item['Name'] for item in result] - assert clients[1].hostname in result + breakpoint() + for row in result: + # all rows show expected client and errata details + assert row['Id'] == settings.repos.yum_6.errata[2] + assert row['Title'] == 'Sea_Erratum' + assert row['Type'] == 'Security Advisory' + + # Search chost for installable RHBA errata by Errata ID + result = session.contenthost.search_errata( + entity_name=clients[1].hostname, + errata_id=settings.repos.yum_6.errata[0], + ) + assert len(result) > 0, ( + f'Found no matching entries in chost errata table, for host: {clients[1].hostname}' + f' for search by that hostname, and errata_id: {settings.repos.yum_6.errata[0]}.' + ) + for row in result: + # all rows show expected client and errata details + assert row['Id'] == settings.repos.yum_6.errata[0] + assert row['Title'] == 'Kangaroo_Erratum' + assert row['Type'] == 'Bug Fix Advisory - low'