Skip to content

Commit

Permalink
Modify test_positive_assign_ansible_role_variable_on_host to verify r…
Browse files Browse the repository at this point in the history
…oles (SatelliteQE#15477)

Signed-off-by: Gaurav Talreja <[email protected]>
  • Loading branch information
Gauravtalreja1 authored Jun 25, 2024
1 parent 08f5b26 commit 1c52ab5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 6 additions & 0 deletions robottelo/cli/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def variables_create(cls, options=None):
cls.command_sub = 'variables create'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def variables_delete(cls, options=None):
"""Delete ansible variables"""
cls.command_sub = 'variables delete'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def variables_info(cls, options=None):
"""Information about ansible variables"""
Expand Down
32 changes: 19 additions & 13 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,16 @@ def test_positive_assign_ansible_role_variable_on_host(

@request.addfinalizer
def _finalize():
result = target_sat.cli.Ansible.roles_delete({'name': SELECTED_ROLE})
assert f'Ansible role [{SELECTED_ROLE}] was deleted.' in result[0]['message']
result = target_sat.cli.Ansible.variables_delete({'name': key})
assert f'Ansible variable [{key}] was deleted.' in result[0]['message']
for role in SELECTED_ROLE:
result = target_sat.cli.Ansible.roles_delete({'name': role})
assert f'Ansible role [{role}] was deleted.' in result[0]['message']

key = gen_string('alpha')
SELECTED_ROLE = 'redhat.satellite.activation_keys'
SELECTED_ROLE = ['redhat.satellite.activation_keys', 'RedHatInsights.insights-client']
proxy_id = target_sat.nailgun_smart_proxy.id
target_sat.api.AnsibleRoles().sync(
data={'proxy_id': proxy_id, 'role_names': [SELECTED_ROLE]}
)
target_sat.api.AnsibleRoles().sync(data={'proxy_id': proxy_id, 'role_names': SELECTED_ROLE})
result = rhel_contenthost.api_register(
target_sat,
organization=module_org,
Expand All @@ -191,7 +192,7 @@ def _finalize():
session.ansiblevariables.create_with_overrides(
{
'key': key,
'ansible_role': SELECTED_ROLE,
'ansible_role': SELECTED_ROLE[0],
'override': 'true',
'parameter_type': parameter_type,
'default_value': default_value,
Expand All @@ -208,14 +209,19 @@ def _finalize():
}
)
result = target_sat.cli.Host.ansible_roles_assign(
{'id': target_host.id, 'ansible-roles': SELECTED_ROLE}
{'id': target_host.id, 'ansible-roles': ','.join(SELECTED_ROLE)}
)
assert 'Ansible roles were assigned' in result[0]['message']
values = session.host_new.get_details(rhel_contenthost.hostname, 'ansible')['ansible'][
'variables'
]['table']
assert (key, SELECTED_ROLE, default_value, parameter_type) in [
(var['Name'], var['Ansible role'], var['Value'], var['Type']) for var in values

values = session.host_new.get_details(rhel_contenthost.hostname, 'ansible')['ansible']
roles_table = values['roles']['table']
variable_table = values['variables']['table']
for role in SELECTED_ROLE:
var_count = str(len([v for v in variable_table if v['Ansible role'] == role]))
assert (role, var_count) in [(r['Name'], r['Variables']) for r in roles_table]

assert (key, SELECTED_ROLE[0], parameter_type, default_value) in [
(v['Name'], v['Ansible role'], v['Type'], v['Value']) for v in variable_table
]

@pytest.mark.stubbed
Expand Down

0 comments on commit 1c52ab5

Please sign in to comment.