From 1c52ab574042a9eaeedee57f89b5c3e2e0799203 Mon Sep 17 00:00:00 2001 From: Gaurav Talreja Date: Tue, 25 Jun 2024 18:38:32 +0530 Subject: [PATCH] Modify test_positive_assign_ansible_role_variable_on_host to verify roles (#15477) Signed-off-by: Gaurav Talreja --- robottelo/cli/ansible.py | 6 ++++++ tests/foreman/ui/test_ansible.py | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/robottelo/cli/ansible.py b/robottelo/cli/ansible.py index d717f8cd4d6..7182f3892d2 100644 --- a/robottelo/cli/ansible.py +++ b/robottelo/cli/ansible.py @@ -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""" diff --git a/tests/foreman/ui/test_ansible.py b/tests/foreman/ui/test_ansible.py index 23cd7fa6fc9..ea2cb1f4c8f 100644 --- a/tests/foreman/ui/test_ansible.py +++ b/tests/foreman/ui/test_ansible.py @@ -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, @@ -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, @@ -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