From 8b28a906214ed7d5ec0d36d37e72fc64d1f89b02 Mon Sep 17 00:00:00 2001 From: Ladislav Vasina Date: Wed, 7 Feb 2024 09:00:51 +0100 Subject: [PATCH] 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 580c64fb3ef..24df9203f50 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 d59eb3bb403..f928a4f1b77 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -38,6 +38,7 @@ PERMISSIONS, REPO_TYPE, ) +from robottelo.constants.repos import CUSTOM_FILE_REPO from robottelo.utils.datafactory import gen_string from robottelo.utils.issue_handlers import is_open @@ -2404,3 +2405,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]