Skip to content

Commit

Permalink
created new proxy for non-admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
amolpati30 committed Jan 24, 2025
1 parent b5562ba commit 34e63a7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tests/foreman/cli/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def test_positive_install_ansible_collection(
@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version])
@pytest.mark.parametrize('auth_type', ['admin', 'non-admin'])
def test_positive_ansible_variables_imported_with_roles(
self, request, auth_type, target_sat, module_org, module_ak_with_cv, rhel_contenthost
self, request, auth_type, target_sat, module_org, module_ak_with_cv, content_hosts
):
"""Verify that when Ansible roles are imported, their variables are imported simultaneously
Expand All @@ -651,6 +651,7 @@ def test_positive_ansible_variables_imported_with_roles(
:verifies: SAT-28198
"""
vm1, vm2 = content_hosts
username = settings.server.admin_username
password = settings.server.admin_password
if auth_type == 'non-admin':
Expand All @@ -666,6 +667,15 @@ def test_positive_ansible_variables_imported_with_roles(
target_sat.cli.User.add_role(
{'id': user['id'], 'login': username, 'role': 'Ansible Roles Manager'}
)
result = vm2.register(
module_org,
None,
module_ak_with_cv.name,
target_sat,
auth_username=username,
auth_password=password,
)
assert result.status == 0, f'Failed to register host: {result.stderr}'

@request.addfinalizer
def _finalize():
Expand Down Expand Up @@ -700,7 +710,7 @@ def _finalize():
target_sat.put(playbook, tasks_file)
target_sat.put(vars, vars_file)

result = rhel_contenthost.register(
result = vm1.register(
module_org,
None,
module_ak_with_cv.name,
Expand All @@ -710,7 +720,7 @@ def _finalize():
)
assert result.status == 0, f'Failed to register host: {result.stderr}'
proxy_id = target_sat.nailgun_smart_proxy.id
target_host = rhel_contenthost.nailgun_host
target_host = vm1.nailgun_host if auth_type == 'admin' else vm2.nailgun_host
target_sat.cli.Ansible.with_user(username, password).roles_sync(
{'role-names': SELECTED_ROLE, 'proxy-id': proxy_id}
)
Expand All @@ -729,9 +739,8 @@ def _finalize():
)
assert result[0]['variable'] == 'ssh_keys'

job_id = target_sat.cli.Host.ansible_roles_play({'name': rhel_contenthost.hostname})[0].get(
'id'
)
hostname = vm1.hostname if auth_type == 'admin' else vm2.hostname
job_id = target_sat.cli.Host.ansible_roles_play({'name': hostname})[0].get('id')
target_sat.wait_for_tasks(
f'resource_type = JobInvocation and resource_id = {job_id} and action ~ "hosts job"'
)
Expand Down

0 comments on commit 34e63a7

Please sign in to comment.