From 52a9b81df30b30b2e71036686c9d60bf51096794 Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Wed, 7 Feb 2024 09:00:51 +0100 Subject: [PATCH 1/7] Test for change hosts content source --- robottelo/hosts.py | 2 +- tests/foreman/ui/test_host.py | 161 ++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 1 deletion(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index d89b3db2c63..2ff72bbe367 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -719,10 +719,10 @@ def register( """Registers content host to the Satellite or Capsule server using a global registration template. - :param target: Satellite or Capusle object to register to, required. :param org: Organization to register content host to. Previously required, pass None to omit :param loc: Location to register content host for, Previously required, pass None to omit. :param activation_keys: Activation key name to register content host with, required. + :param target: Satellite or Capsule object to register to, required. :param setup_insights: Install and register Insights client, requires OS repo. :param setup_remote_execution: Copy remote execution SSH key. :param setup_remote_execution_pull: Deploy pull provider client on host diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index afae39593d5..1991ea5ede7 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -33,6 +33,7 @@ OSCAP_WEEKDAY, PERMISSIONS, ) +from robottelo.constants.repos import CUSTOM_FILE_REPO from robottelo.utils.datafactory import gen_string from robottelo.utils.issue_handlers import is_open @@ -1778,3 +1779,163 @@ def test_all_hosts_bulk_delete(target_sat, function_org, function_location, new_ session.organization.select(function_org.name) session.location.select(function_location.name) assert session.all_hosts.bulk_delete_all() + + +@pytest.fixture +def change_content_source_prep( + target_sat, + module_sca_manifest_org, + module_capsule_configured, + module_location, + rhel_contenthost, +): + """ + This fixture sets up all necessary stuff for tests excercising the Change of the hosts's content source. + + It creates a new product in the organization, + creates a new repository in the product, + enables the specified repositories, + creates a new lce, + creates a new CV in the organization, adds the repository to the CV, publishes the CV, and promotes the published version to the lifecycle environment, + creates a new activation key for the CV in the lce, + registers the RHEL content host with the activation key, + updates the capsule's taxonomies + adds the lifecycle environment to the capsule's content. + + Fixture returns target_sat, rhel_contenthost, org, lce, capsule, content_view + """ + product_name, lce_name = (gen_string('alpha') for _ in range(2)) + repos_to_enable = ['rhae2.9_el8'] + + org = module_sca_manifest_org + loc = module_location + + product = target_sat.api.Product( + name=product_name, + organization=org.id, + ).create() + + repository = target_sat.api.Repository( + product=product, + content_type=REPO_TYPE['file'], + url=CUSTOM_FILE_REPO, + ).create() + + for repo in repos_to_enable: + target_sat.cli.RepositorySet.enable( + { + 'organization-id': org.id, + 'name': constants.REPOS[repo]['reposet'], + 'product': constants.REPOS[repo]['product'], + 'releasever': constants.REPOS[repo]['version'], + 'basearch': constants.DEFAULT_ARCHITECTURE, + } + ) + + lce = target_sat.cli_factory.make_lifecycle_environment( + {'name': lce_name, 'organization-id': org.id} + ) + + # Create CV + content_view = target_sat.api.ContentView(organization=org.id).create() + # Add repos to CV + content_view.repository = [repository] + content_view = content_view.update(['repository']) + # Publish that CV and promote it + content_view.publish() + content_view.read().version[0].promote(data={'environment_ids': lce.id}) + + ak = target_sat.api.ActivationKey( + content_view=content_view, organization=org.id, environment=lce.id + ).create() + + rhel_contenthost.register(org, loc, ak.name, target_sat) + + # Edit capsule's taxonomies + capsule = target_sat.cli.Capsule.update( + { + 'name': module_capsule_configured.hostname, + 'organization-ids': org.id, + 'location-ids': loc.id, + } + ) + + target_sat.cli.Capsule.content_add_lifecycle_environment( + { + 'id': module_capsule_configured.nailgun_capsule.id, + 'organization-id': org.id, + 'lifecycle-environment': lce.name, + } + ) + + return target_sat, rhel_contenthost, org, lce, capsule, content_view + + +@pytest.mark.no_containers +@pytest.mark.rhel_ver_match('[78]') +def test_change_content_source(session, change_content_source_prep): + """ + This test excercises different ways to change host's content source + + :id: 5add68c3-16b1-496d-9b24-f5388013351d + + :expectedresults: Job invocation page should be correctly generated by the change content source action, + generated script should also be correct + + :CaseComponent:Hosts-Content + + :Team: Phoenix-content + + :CaseLevel: Component + """ + + target_sat, rhel_contenthost, org, lce, capsule, content_view = change_content_source_prep + + with target_sat.ui_session() as session: + session.organization.select(org_name=org.name) + session.location.select(loc_name=ANY_CONTEXT['location']) + + # STEP 1: Test the part where you use "Update hosts manually" button + # Set the content source to the checked-out capsule + # Check that generated script contains correct name of new content source + rhel_contenthost_pre_values = rhel_contenthost.nailgun_host.content_facet_attributes + generated_script = session.host.change_content_source_get_script( + entities_list=[ + rhel_contenthost.hostname, + ], + content_source=capsule[0]['name'], + lce=lce.name, + content_view=content_view.name, + ) + rhel_contenthost_post_values = rhel_contenthost.nailgun_host.content_facet_attributes + content_source_from_script = re.search(r'--server.hostname=\"(.*?)\"', generated_script) + + assert content_source_from_script.group(1) == capsule[0]['name'] + assert rhel_contenthost_post_values['content_source']['name'] == capsule[0]['name'] + assert rhel_contenthost_post_values['content_view']['name'] == content_view.name + assert rhel_contenthost_post_values['lifecycle_environment']['name'] == lce.name + + session.browser.refresh() + + # Step 2: Test the part where you use "Run job invocation" button + # Change the rhel_contenthost's content source back to what it was before STEP 1 + # Check the prefilled job invocation page + session.host.change_content_source( + entities_list=[ + rhel_contenthost.hostname, + ], + content_source=rhel_contenthost_pre_values['content_source']['name'], + lce=rhel_contenthost_pre_values['lifecycle_environment']['name'], + content_view=rhel_contenthost_pre_values['content_view']['name'], + run_job_invocation=True, + ) + + selected_category_and_template = session.jobinvocation.get_job_category_and_template() + selected_targeted_hosts = session.jobinvocation.get_targeted_hosts() + + assert selected_category_and_template['job_category'] == 'Katello' + assert ( + selected_category_and_template['job_template'] + == 'Configure host for new content source' + ) + assert selected_targeted_hosts['selected_hosts'] == [rhel_contenthost.hostname] From 403f1e8b6f31fa66da0c892e0dbf1e6e2c95b8b5 Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Wed, 7 Feb 2024 09:22:26 +0100 Subject: [PATCH 2/7] Fix comment --- tests/foreman/ui/test_host.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index 1991ea5ede7..8457e44dbae 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -1879,14 +1879,11 @@ def test_change_content_source(session, change_content_source_prep): :id: 5add68c3-16b1-496d-9b24-f5388013351d - :expectedresults: Job invocation page should be correctly generated by the change content source action, - generated script should also be correct + :expectedresults: Job invocation page should be correctly generated by the change content source action, generated script should also be correct :CaseComponent:Hosts-Content :Team: Phoenix-content - - :CaseLevel: Component """ target_sat, rhel_contenthost, org, lce, capsule, content_view = change_content_source_prep From decbcd1eda83c03fef5fd7986ab613d4012da404 Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Wed, 7 Feb 2024 14:24:43 +0100 Subject: [PATCH 3/7] Set fixture to module scope --- tests/foreman/ui/test_host.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index 8457e44dbae..900d6e8000a 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -1781,13 +1781,12 @@ def test_all_hosts_bulk_delete(target_sat, function_org, function_location, new_ assert session.all_hosts.bulk_delete_all() -@pytest.fixture +@pytest.fixture(scope='module') def change_content_source_prep( - target_sat, + module_target_sat, module_sca_manifest_org, module_capsule_configured, module_location, - rhel_contenthost, ): """ This fixture sets up all necessary stuff for tests excercising the Change of the hosts's content source. @@ -1802,7 +1801,7 @@ def change_content_source_prep( updates the capsule's taxonomies adds the lifecycle environment to the capsule's content. - Fixture returns target_sat, rhel_contenthost, org, lce, capsule, content_view + Fixture returns module_target_sat, org, lce, capsule, content_view, loc, ak """ product_name, lce_name = (gen_string('alpha') for _ in range(2)) repos_to_enable = ['rhae2.9_el8'] @@ -1810,19 +1809,19 @@ def change_content_source_prep( org = module_sca_manifest_org loc = module_location - product = target_sat.api.Product( + product = module_target_sat.api.Product( name=product_name, organization=org.id, ).create() - repository = target_sat.api.Repository( + repository = module_target_sat.api.Repository( product=product, content_type=REPO_TYPE['file'], url=CUSTOM_FILE_REPO, ).create() for repo in repos_to_enable: - target_sat.cli.RepositorySet.enable( + module_target_sat.cli.RepositorySet.enable( { 'organization-id': org.id, 'name': constants.REPOS[repo]['reposet'], @@ -1832,12 +1831,12 @@ def change_content_source_prep( } ) - lce = target_sat.cli_factory.make_lifecycle_environment( + lce = module_target_sat.cli_factory.make_lifecycle_environment( {'name': lce_name, 'organization-id': org.id} ) # Create CV - content_view = target_sat.api.ContentView(organization=org.id).create() + content_view = module_target_sat.api.ContentView(organization=org.id).create() # Add repos to CV content_view.repository = [repository] content_view = content_view.update(['repository']) @@ -1845,14 +1844,12 @@ def change_content_source_prep( content_view.publish() content_view.read().version[0].promote(data={'environment_ids': lce.id}) - ak = target_sat.api.ActivationKey( + ak = module_target_sat.api.ActivationKey( content_view=content_view, organization=org.id, environment=lce.id ).create() - rhel_contenthost.register(org, loc, ak.name, target_sat) - # Edit capsule's taxonomies - capsule = target_sat.cli.Capsule.update( + capsule = module_target_sat.cli.Capsule.update( { 'name': module_capsule_configured.hostname, 'organization-ids': org.id, @@ -1860,7 +1857,7 @@ def change_content_source_prep( } ) - target_sat.cli.Capsule.content_add_lifecycle_environment( + module_target_sat.cli.Capsule.content_add_lifecycle_environment( { 'id': module_capsule_configured.nailgun_capsule.id, 'organization-id': org.id, @@ -1868,12 +1865,12 @@ def change_content_source_prep( } ) - return target_sat, rhel_contenthost, org, lce, capsule, content_view + return module_target_sat, org, lce, capsule, content_view, loc, ak @pytest.mark.no_containers @pytest.mark.rhel_ver_match('[78]') -def test_change_content_source(session, change_content_source_prep): +def test_change_content_source(session, change_content_source_prep, rhel_contenthost): """ This test excercises different ways to change host's content source @@ -1886,9 +1883,11 @@ def test_change_content_source(session, change_content_source_prep): :Team: Phoenix-content """ - target_sat, rhel_contenthost, org, lce, capsule, content_view = change_content_source_prep + module_target_sat, org, lce, capsule, content_view, loc, ak = change_content_source_prep - with target_sat.ui_session() as session: + rhel_contenthost.register(org, loc, ak.name, module_target_sat) + + with module_target_sat.ui_session() as session: session.organization.select(org_name=org.name) session.location.select(loc_name=ANY_CONTEXT['location']) From 30372d0fedd0843c665a8bf399139e597251067b Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Tue, 13 Feb 2024 09:52:37 +0100 Subject: [PATCH 4/7] Fix comments --- tests/foreman/ui/test_host.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index 900d6e8000a..7633621334b 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -1789,19 +1789,21 @@ def change_content_source_prep( module_location, ): """ - This fixture sets up all necessary stuff for tests excercising the Change of the hosts's content source. - - It creates a new product in the organization, - creates a new repository in the product, - enables the specified repositories, - creates a new lce, - creates a new CV in the organization, adds the repository to the CV, publishes the CV, and promotes the published version to the lifecycle environment, - creates a new activation key for the CV in the lce, - registers the RHEL content host with the activation key, - updates the capsule's taxonomies - adds the lifecycle environment to the capsule's content. - - Fixture returns module_target_sat, org, lce, capsule, content_view, loc, ak + This fixture sets up all the necessary entities for tests + exercising the Change of the hosts's content source. + + It creates a new product in the organization, + creates a new repository in the product, + enables the specified repositories, + creates a new lce, + creates a new CV in the organization, adds the repository to the CV, + publishes the CV, and promotes the published version to the lifecycle environment, + creates a new activation key for the CV in the lce, + registers the RHEL content host with the activation key, + updates the capsule's taxonomies + adds the lifecycle environment to the capsule's content. + + Fixture returns module_target_sat, org, lce, capsule, content_view, loc, ak """ product_name, lce_name = (gen_string('alpha') for _ in range(2)) repos_to_enable = ['rhae2.9_el8'] @@ -1876,7 +1878,8 @@ def test_change_content_source(session, change_content_source_prep, rhel_content :id: 5add68c3-16b1-496d-9b24-f5388013351d - :expectedresults: Job invocation page should be correctly generated by the change content source action, generated script should also be correct + :expectedresults: Job invocation page should be correctly generated + by the change content source action, generated script should also be correct :CaseComponent:Hosts-Content @@ -1925,7 +1928,7 @@ def test_change_content_source(session, change_content_source_prep, rhel_content content_view=rhel_contenthost_pre_values['content_view']['name'], run_job_invocation=True, ) - + # Getting the data from the prefilled job invocation form selected_category_and_template = session.jobinvocation.get_job_category_and_template() selected_targeted_hosts = session.jobinvocation.get_targeted_hosts() From 37ef5c910ecab6781786b5a6bdc42be1d7cbc1b6 Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Thu, 15 Feb 2024 08:03:02 +0100 Subject: [PATCH 5/7] Add some asserts --- tests/foreman/ui/test_host.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index 7633621334b..be78f3955d9 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -1806,7 +1806,6 @@ def change_content_source_prep( Fixture returns module_target_sat, org, lce, capsule, content_view, loc, ak """ product_name, lce_name = (gen_string('alpha') for _ in range(2)) - repos_to_enable = ['rhae2.9_el8'] org = module_sca_manifest_org loc = module_location @@ -1822,17 +1821,6 @@ def change_content_source_prep( url=CUSTOM_FILE_REPO, ).create() - for repo in repos_to_enable: - module_target_sat.cli.RepositorySet.enable( - { - 'organization-id': org.id, - 'name': constants.REPOS[repo]['reposet'], - 'product': constants.REPOS[repo]['product'], - 'releasever': constants.REPOS[repo]['version'], - 'basearch': constants.DEFAULT_ARCHITECTURE, - } - ) - lce = module_target_sat.cli_factory.make_lifecycle_environment( {'name': lce_name, 'organization-id': org.id} ) @@ -1938,3 +1926,18 @@ def test_change_content_source(session, change_content_source_prep, rhel_content == 'Configure host for new content source' ) assert selected_targeted_hosts['selected_hosts'] == [rhel_contenthost.hostname] + + session.jobinvocation.submit_prefilled_view() + rhel_contenthost_post_values = rhel_contenthost.nailgun_host.content_facet_attributes + assert ( + rhel_contenthost_post_values['content_source']['name'] + == rhel_contenthost_pre_values['content_source']['name'] + ) + assert ( + rhel_contenthost_post_values['content_view']['name'] + == rhel_contenthost_post_values['content_view']['name'] + ) + assert ( + rhel_contenthost_post_values['lifecycle_environment']['name'] + == rhel_contenthost_post_values['lifecycle_environment']['name'] + ) From 883eeae260f78948d45462d9b10efa4b198f05d7 Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Thu, 15 Feb 2024 08:13:25 +0100 Subject: [PATCH 6/7] Add imports --- tests/foreman/ui/test_host.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index be78f3955d9..f4b31d2242c 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -14,6 +14,7 @@ import copy import csv import os +import re from airgun.exceptions import DisabledWidgetError, NoSuchElementException import pytest @@ -32,6 +33,7 @@ OSCAP_PERIOD, OSCAP_WEEKDAY, PERMISSIONS, + REPO_TYPE, ) from robottelo.constants.repos import CUSTOM_FILE_REPO from robottelo.utils.datafactory import gen_string From ca2ea9b78381c0113aafa5d5f96b42f8daa19c8c Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Thu, 15 Feb 2024 08:21:06 +0100 Subject: [PATCH 7/7] Remove comment --- tests/foreman/ui/test_host.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index f4b31d2242c..b3564fb04b1 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -1796,7 +1796,6 @@ def change_content_source_prep( It creates a new product in the organization, creates a new repository in the product, - enables the specified repositories, creates a new lce, creates a new CV in the organization, adds the repository to the CV, publishes the CV, and promotes the published version to the lifecycle environment,