From 84d99361dc5db5d98ea6eea7f1c8a04e1f83c2a1 Mon Sep 17 00:00:00 2001 From: shwsingh Date: Thu, 7 Sep 2023 11:48:34 +0530 Subject: [PATCH] Component Audit Part-2 --- tests/foreman/api/test_registration.py | 51 ++++++++++++++++++++++++-- tests/foreman/ui/test_host.py | 49 +++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/tests/foreman/api/test_registration.py b/tests/foreman/api/test_registration.py index 9d184f029f5..5121f6eeafc 100644 --- a/tests/foreman/api/test_registration.py +++ b/tests/foreman/api/test_registration.py @@ -20,7 +20,8 @@ import pytest -from robottelo.constants import CLIENT_PORT +from robottelo import constants +from robottelo.config import settings pytestmark = pytest.mark.tier1 @@ -60,7 +61,7 @@ def test_host_registration_end_to_end( # Verify server.hostname and server.port from subscription-manager config assert module_target_sat.hostname == rhel_contenthost.subscription_config['server']['hostname'] - assert CLIENT_PORT == rhel_contenthost.subscription_config['server']['port'] + assert constants.CLIENT_PORT == rhel_contenthost.subscription_config['server']['port'] # Update module_capsule_configured to include module_org/module_location nc = module_capsule_configured.nailgun_smart_proxy @@ -84,7 +85,7 @@ def test_host_registration_end_to_end( module_capsule_configured.hostname == rhel_contenthost.subscription_config['server']['hostname'] ) - assert CLIENT_PORT == rhel_contenthost.subscription_config['server']['port'] + assert constants.CLIENT_PORT == rhel_contenthost.subscription_config['server']['port'] @pytest.mark.tier3 @@ -126,3 +127,47 @@ def test_positive_allow_reregistration_when_dmi_uuid_changed( ).create() result = rhel_contenthost.execute(command) assert result.status == 0 + + +def test_positive_update_packages_post_registration( + module_target_sat, + module_entitlement_manifest_org, + module_location, + module_ak, + rhel8_contenthost, +): + """Test package update on host post registration + + :id: 3d0a3252-ab81-4acf-bca6-253b746f26bb + + :expectedresults: Package update is successful on host post registration. + + :CaseLevel: Integration + """ + org = module_entitlement_manifest_org + + rh_repo_id = module_target_sat.api_factory.enable_rhrepo_and_fetchid( + basearch=constants.DEFAULT_ARCHITECTURE, + org_id=module_entitlement_manifest_org.id, + product=constants.PRDS['rhel8'], + repo=constants.REPOS['rhst8']['name'], + reposet=constants.REPOSET['rhst8'], + releasever=None, + ) + rh_repo = module_target_sat.api.Repository(id=rh_repo_id).read() + rh_repo.sync() + + result = rhel8_contenthost.register( + org, + module_location, + module_ak.name, + module_target_sat, + update_packages=True, + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' + + package = constants.FAKE_7_CUSTOM_PACKAGE + repo_url = settings.repos.yum_3['url'] + rhel8_contenthost.create_custom_repos(fake_yum=repo_url) + result = rhel8_contenthost.execute(f"yum install -y {package}") + assert result.status == 0 diff --git a/tests/foreman/ui/test_host.py b/tests/foreman/ui/test_host.py index 413a0398107..15d80de5375 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -2387,3 +2387,52 @@ 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" + + +def test_positive_host_registration_with_non_admin_user( + test_name, + module_entitlement_manifest_org, + module_location, + target_sat, + rhel8_contenthost, + module_ak, +): + """Register hosts from a non-admin user with only register_hosts, edit_hosts + and view_organization permissions + + :id: 35458bbc-4556-41b9-ba26-ae0b15179731 + + :expectedresults: User with register hosts permission able to do it. + + :CaseLevel: System + """ + + user_password = gen_string('alpha') + org = module_entitlement_manifest_org + role = target_sat.api.Role(organization=[org]).create() + target_sat.api_factory.create_role_permissions( + role, {'Organization': ['view_organizations'], 'Host': ['view_hosts', 'register_hosts']} + ) + user = target_sat.api.User( + role=[role], + admin=False, + password=user_password, + organization=[org], + location=[module_location], + default_organization=org, + default_location=module_location, + ).create() + created_host = target_sat.api.Host(location=module_location, organization=org).create() + with Session(test_name, user=user.login, password=user_password) as session: + host = session.host.get_details(created_host.name, widget_names='breadcrumb') + assert host['breadcrumb'] == created_host.name + + cmd = session.host.get_register_command( + { + 'general.insecure': True, + 'general.activation_keys': module_activation_key.name, + } + ) + + result = rhel8_contenthost.execute(cmd) + assert result.status == 0, f'Failed to register host: {result.stderr}'