From df380fb919a3eaef2b6cab2883cce687943df546 Mon Sep 17 00:00:00 2001 From: shwsingh Date: Tue, 6 Feb 2024 23:50:22 +0530 Subject: [PATCH] UI test fixes --- tests/foreman/ui/test_host.py | 57 ++++++++++++++++++++++++++- tests/foreman/ui/test_registration.py | 43 ++++++++++---------- 2 files changed, 76 insertions(+), 24 deletions(-) diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index afae39593d5..3a72762a228 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -992,6 +992,62 @@ def test_positive_validate_inherited_cv_lce_ansiblerole(session, target_sat, mod assert host.name in [host.name for host in matching_hosts] + +@pytest.mark.tier2 +@pytest.mark.rhel_ver_match('[^6].*') +def test_global_registration_upgrade_subscription_manager( + session, module_activation_key, module_os, rhel_contenthost +): + """Host registration form produces a correct registration command and + subscription-manager can be updated from a custom repository before + registration is completed. + + :id: b7a44f32-90b2-4fd6-b65b-5a3d2a5c5deb + + :customerscenario: true + + :expectedresults: Host is successfully registered, repo is enabled + on advanced tab and subscription-manager is updated. + + :steps: + 1. Create activation-key + 2. Open the global registration form, add repo and activation key + 3. Add 'subscription-manager' to install packages field + 4. Check subscription-manager was installed from repo_name + + :parametrized: yes + + :BZ: 1923320 + """ + client = rhel_contenthost + repo_name = 'foreman_register' + rhel_ver = rhel_contenthost.os_version.major + repo_url = settings.repos.get(f'rhel{rhel_ver}_os') + if isinstance(repo_url, dict): + repo_url = repo_url['baseos'] + # Ensure subs-man is installed from repo_name by removing existing package. + result = client.execute('rpm --erase --nodeps subscription-manager') + assert result.status == 0 + with session: + cmd = session.host.get_register_command( + { + 'general.operating_system': module_os.title, + 'general.activation_keys': module_activation_key.name, + 'general.insecure': True, + 'advanced.force': True, + 'advanced.install_packages': 'subscription-manager', + 'advanced.repository': repo_url, + } + ) + + # run curl + result = client.execute(cmd) + assert result.status == 0 + result = client.execute('yum repolist') + assert repo_name in result.stdout + assert result.status == 0 + + @pytest.mark.tier4 @pytest.mark.upgrade def test_positive_bulk_delete_host(session, smart_proxy_location, target_sat, function_org): @@ -1740,7 +1796,6 @@ def test_positive_tracer_enable_reload(tracer_install_host, target_sat): tracer = session.host_new.get_tracer(tracer_install_host.hostname) assert tracer['title'] == "No applications to restart" - @pytest.mark.tier2 def test_all_hosts_delete(target_sat, function_org, function_location, new_host_ui): """Create a host and delete it through All Hosts UI diff --git a/tests/foreman/ui/test_registration.py b/tests/foreman/ui/test_registration.py index d9b8ee288b8..a7555596371 100644 --- a/tests/foreman/ui/test_registration.py +++ b/tests/foreman/ui/test_registration.py @@ -21,6 +21,7 @@ from robottelo import constants from robottelo.config import settings from robottelo.constants import FAKE_1_CUSTOM_PACKAGE, FAKE_7_CUSTOM_PACKAGE, REPO_TYPE +from robottelo.utils.datafactory import gen_string pytestmark = pytest.mark.tier1 @@ -64,7 +65,7 @@ def test_positive_verify_default_values_for_global_registration( @pytest.mark.tier2 def test_positive_org_loc_change_for_registration( module_activation_key, - module_org, + module_sca_manifest_org, module_location, target_sat, ): @@ -76,15 +77,16 @@ def test_positive_org_loc_change_for_registration( :CaseImportance: Medium """ + org = module_sca_manifest_org new_org = target_sat.api.Organization().create() new_loc = target_sat.api.Location().create() target_sat.api.ActivationKey(organization=new_org).create() with target_sat.ui_session() as session: - session.organization.select(org_name=module_org.name) + session.organization.select(org_name=org.name) session.location.select(loc_name=module_location.name) cmd = session.host.get_register_command() expected_pairs = [ - f'organization_id={module_org.id}', + f'organization_id={org.id}', f'location_id={module_location.id}', ] for pair in expected_pairs: @@ -101,20 +103,16 @@ def test_positive_org_loc_change_for_registration( assert pair in cmd -def test_negative_global_registration_without_ak( - module_target_sat, - module_org, - module_location, -): +def test_negative_global_registration_without_ak(target_sat, function_org, function_location): """Attempt to register a host without ActivationKey :id: 34122bf3-ae23-47ca-ba3d-da0653d8fd36 :expectedresults: Generate command is disabled without ActivationKey """ - with module_target_sat.ui_session() as session: - session.organization.select(org_name=module_org.name) - session.location.select(loc_name=module_location.name) + with target_sat.ui_session() as session: + session.organization.select(org_name=function_org.name) + session.location.select(loc_name=function_location.name) with pytest.raises(DisabledWidgetError) as context: session.host.get_register_command() assert 'Generate registration command button is disabled' in str(context.value) @@ -172,6 +170,8 @@ def test_positive_global_registration_end_to_end( cmd = session.host.get_register_command( { 'general.operating_system': default_os.title, + 'general.organization': module_org.name, + 'general.location': smart_proxy_location.name, 'general.activation_keys': module_activation_key.name, 'advanced.update_packages': True, 'advanced.rex_interface': iface, @@ -329,6 +329,7 @@ def test_global_registration_form_populate( { 'general.organization': new_org.name, 'general.operating_system': default_os.title, + 'general.activation_keys': new_ak.name, 'general.insecure': True, }, full_read=True, @@ -341,7 +342,7 @@ def test_global_registration_form_populate( @pytest.mark.usefixtures('enable_capsule_for_registration') @pytest.mark.no_containers def test_global_registration_with_gpg_repo_and_default_package( - session, module_activation_key, default_os, default_smart_proxy, rhel8_contenthost + session, module_activation_key, rhel8_contenthost ): """Host registration form produces a correct registration command and host is registered successfully with gpg repo enabled and have default package @@ -369,8 +370,6 @@ def test_global_registration_with_gpg_repo_and_default_package( with session: cmd = session.host.get_register_command( { - 'general.operating_system': default_os.title, - 'general.capsule': default_smart_proxy.name, 'general.activation_keys': module_activation_key.name, 'general.insecure': True, 'advanced.force': True, @@ -405,7 +404,7 @@ def test_global_registration_with_gpg_repo_and_default_package( @pytest.mark.tier3 @pytest.mark.usefixtures('enable_capsule_for_registration') def test_global_re_registration_host_with_force_ignore_error_options( - session, module_activation_key, default_os, default_smart_proxy, rhel7_contenthost + session, module_activation_key, rhel7_contenthost ): """If the ignore_error and force checkbox is checked then registered host can get re-registered without any error. @@ -427,8 +426,6 @@ def test_global_re_registration_host_with_force_ignore_error_options( with session: cmd = session.host.get_register_command( { - 'general.operating_system': default_os.title, - 'general.capsule': default_smart_proxy.name, 'general.activation_keys': module_activation_key.name, 'general.insecure': True, 'advanced.force': True, @@ -447,7 +444,7 @@ def test_global_re_registration_host_with_force_ignore_error_options( @pytest.mark.tier2 @pytest.mark.usefixtures('enable_capsule_for_registration') def test_global_registration_token_restriction( - session, module_activation_key, rhel8_contenthost, default_os, default_smart_proxy, target_sat + session, module_activation_key, rhel8_contenthost, module_target_sat ): """Global registration token should be only used for registration call, it should be restricted for any other api calls. @@ -467,8 +464,6 @@ def test_global_registration_token_restriction( with session: cmd = session.host.get_register_command( { - 'general.operating_system': default_os.title, - 'general.capsule': default_smart_proxy.name, 'general.activation_keys': module_activation_key.name, 'general.insecure': True, } @@ -478,8 +473,8 @@ def test_global_registration_token_restriction( auth_header = re.search(pattern, cmd).group() # build curl - curl_users = f'curl -X GET -k -H {auth_header} -i {target_sat.url}/api/users/' - curl_hosts = f'curl -X GET -k -H {auth_header} -i {target_sat.url}/api/hosts/' + curl_users = f'curl -X GET -k -H {auth_header} -i {module_target_sat.url}/api/users/' + curl_hosts = f'curl -X GET -k -H {auth_header} -i {module_target_sat.url}/api/hosts/' for curl_cmd in (curl_users, curl_hosts): result = client.execute(curl_cmd) assert result.status == 0 @@ -522,7 +517,7 @@ def test_positive_host_registration_with_non_admin_user( role = target_sat.cli.Role.info({'name': 'Register hosts'}) target_sat.cli.User.add_role({'id': user.id, 'role-id': role['id']}) - with Session(test_name, user=user.login, password=user_password) as session: + with target_sat.ui_session(test_name, user=user.login, password=user_password) as session: cmd = session.host_new.get_register_command( { @@ -570,6 +565,8 @@ def test_positive_global_registration_form( ).create() iface = 'eth0' with session: + session.organization.select(org_name=module_org.name) + session.location.select(loc_name=smart_proxy_location.name) cmd = session.host.get_register_command( { 'advanced.setup_insights': 'Yes (override)' if insights_value else 'No (override)',