From ece3411029af39126d77ec1d8bf6cb7f7a68666b Mon Sep 17 00:00:00 2001 From: shwsingh Date: Thu, 7 Sep 2023 11:48:34 +0530 Subject: [PATCH] Component Audit Part-2 --- pytest_fixtures/component/activationkey.py | 11 +++- tests/foreman/api/test_registration.py | 39 +++++++++++- tests/foreman/ui/test_host.py | 72 ++++++++++++---------- 3 files changed, 84 insertions(+), 38 deletions(-) diff --git a/pytest_fixtures/component/activationkey.py b/pytest_fixtures/component/activationkey.py index 05c479c65b7..9981d60f13d 100644 --- a/pytest_fixtures/component/activationkey.py +++ b/pytest_fixtures/component/activationkey.py @@ -6,8 +6,15 @@ @pytest.fixture(scope='module') -def module_activation_key(module_org, module_target_sat): - return module_target_sat.api.ActivationKey(organization=module_org).create() +def module_activation_key(module_entitlement_manifest_org, module_target_sat): + """Create activation key using default CV and library environment.""" + activation_key = module_target_sat.api.ActivationKey( + auto_attach=True, + content_view=module_entitlement_manifest_org.default_content_view.id, + environment=module_entitlement_manifest_org.library.id, + organization=module_entitlement_manifest_org, + ).create() + return activation_key @pytest.fixture(scope='module') diff --git a/tests/foreman/api/test_registration.py b/tests/foreman/api/test_registration.py index d9267bb5d2f..26172f6ae34 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 @@ -125,3 +126,35 @@ 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, + rhel8_contenthost, + module_activation_key, +): + """Test package update on host post registration + + :id: 3d0a3252-ab81-4acf-bca6-253b746f26bb + + :expectedresults: Package update is successful on host post registration. + + :CaseLevel: Component + """ + org = module_entitlement_manifest_org + command = module_target_sat.api.RegistrationCommand( + organization=org, + location=module_location, + activation_keys=[module_activation_key.name], + update_packages=True, + ).create() + result = rhel8_contenthost.execute(command) + 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 12470963e7d..d480ddf5d9b 100644 --- a/tests/foreman/ui/test_host.py +++ b/tests/foreman/ui/test_host.py @@ -34,7 +34,6 @@ ANY_CONTEXT, DEFAULT_CV, DEFAULT_LOC, - DEFAULT_SUBSCRIPTION_NAME, ENVIRONMENT, FAKE_1_CUSTOM_PACKAGE, FAKE_7_CUSTOM_PACKAGE, @@ -97,28 +96,28 @@ def module_global_params(module_target_sat): global_parameter.delete() -@pytest.fixture(scope='module') -def module_activation_key(module_entitlement_manifest_org, module_target_sat): - """Create activation key using default CV and library environment.""" - activation_key = module_target_sat.api.ActivationKey( - auto_attach=True, - content_view=module_entitlement_manifest_org.default_content_view.id, - environment=module_entitlement_manifest_org.library.id, - organization=module_entitlement_manifest_org, - ).create() - - # Find the 'Red Hat Employee Subscription' and attach it to the activation key. - for subs in module_target_sat.api.Subscription( - organization=module_entitlement_manifest_org - ).search(): - if subs.name == DEFAULT_SUBSCRIPTION_NAME: - # 'quantity' must be 1, not subscription['quantity']. Greater - # values produce this error: 'RuntimeError: Error: Only pools - # with multi-entitlement product subscriptions can be added to - # the activation key with a quantity greater than one.' - activation_key.add_subscriptions(data={'quantity': 1, 'subscription_id': subs.id}) - break - return activation_key +# @pytest.fixture(scope='module') +# def module_activation_key(module_entitlement_manifest_org, module_target_sat): +# """Create activation key using default CV and library environment.""" +# activation_key = module_target_sat.api.ActivationKey( +# auto_attach=True, +# content_view=module_entitlement_manifest_org.default_content_view.id, +# environment=module_entitlement_manifest_org.library.id, +# organization=module_entitlement_manifest_org, +# ).create() +# +# # Find the 'Red Hat Employee Subscription' and attach it to the activation key. +# for subs in module_target_sat.api.Subscription( +# organization=module_entitlement_manifest_org +# ).search(): +# if subs.name == DEFAULT_SUBSCRIPTION_NAME: +# # 'quantity' must be 1, not subscription['quantity']. Greater +# # values produce this error: 'RuntimeError: Error: Only pools +# # with multi-entitlement product subscriptions can be added to +# # the activation key with a quantity greater than one.' +# activation_key.add_subscriptions(data={'quantity': 1, 'subscription_id': subs.id}) +# break +# return activation_key @pytest.fixture @@ -510,7 +509,7 @@ def test_positive_view_hosts_with_non_admin_user( :expectedresults: user with only view_hosts, edit_hosts and view_organization permissions is able to read content hosts and hosts - :CaseLevel: System + :CaseLevel: Component """ user_password = gen_string('alpha') role = target_sat.api.Role(organization=[module_org]).create() @@ -2418,16 +2417,19 @@ def test_positive_host_registration_with_non_admin_user( :id: 35458bbc-4556-41b9-ba26-ae0b15179731 - :expectedresults: User with register hosts permission able to do it. + :expectedresults: User with register hosts permission able to register hosts. - :CaseLevel: System + :CaseLevel: Component """ 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_permissions = { + 'Organization': ['view_organizations'], + 'Host': ['view_hosts'], + } + target_sat.api_factory.create_role_permissions(role, user_permissions) user = target_sat.api.User( role=[role], admin=False, @@ -2437,12 +2439,12 @@ def test_positive_host_registration_with_non_admin_user( default_organization=org, default_location=module_location, ).create() - # created_host = target_sat.api.Host(location=module_location, organization=org).create() + 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: - host = session.host.get_details(rhel8_contenthost.name, widget_names='breadcrumb') - assert host['breadcrumb'] == rhel8_contenthost.name - cmd = session.host.get_register_command( + cmd = session.host_new.get_register_command( { 'general.insecure': True, 'general.activation_keys': module_activation_key.name, @@ -2451,3 +2453,7 @@ def test_positive_host_registration_with_non_admin_user( result = rhel8_contenthost.execute(cmd) assert result.status == 0, f'Failed to register host: {result.stderr}' + + # Verify server.hostname and server.port from subscription-manager config + assert target_sat.hostname == rhel8_contenthost.subscription_config['server']['hostname'] + assert constants.CLIENT_PORT == rhel8_contenthost.subscription_config['server']['port']