Skip to content

Commit

Permalink
Component Audit Part-2 (SatelliteQE#12519)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2e46f7e)
  • Loading branch information
shweta83 authored and Gauravtalreja1 committed Nov 22, 2023
1 parent 8e5c51b commit 15bd38c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 6 deletions.
11 changes: 9 additions & 2 deletions pytest_fixtures/component/activationkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
39 changes: 36 additions & 3 deletions tests/foreman/api/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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_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
57 changes: 56 additions & 1 deletion tests/foreman/ui/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,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()
Expand Down Expand Up @@ -2385,3 +2385,58 @@ 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_activation_key,
):
"""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 register hosts.
:CaseLevel: Component
"""
user_password = gen_string('alpha')
org = module_entitlement_manifest_org
role = target_sat.api.Role(organization=[org]).create()

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,
password=user_password,
organization=[org],
location=[module_location],
default_organization=org,
default_location=module_location,
).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:

cmd = session.host_new.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}'

# 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']

0 comments on commit 15bd38c

Please sign in to comment.