From 65d44b5355c7541eb19565b5755d7c93d6efc5a7 Mon Sep 17 00:00:00 2001 From: shwsingh Date: Fri, 22 Mar 2024 00:40:39 +0530 Subject: [PATCH] Verify a variable created and added to the host --- tests/foreman/ui/test_ansible.py | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/foreman/ui/test_ansible.py b/tests/foreman/ui/test_ansible.py index 89eba62ff56..d706e1ed438 100644 --- a/tests/foreman/ui/test_ansible.py +++ b/tests/foreman/ui/test_ansible.py @@ -275,6 +275,71 @@ def test_positive_host_role_information(target_sat, function_host): assert all_assigned_roles_table[0]["Name"] == SELECTED_ROLE +@pytest.mark.rhel_ver_match('8') +def test_positive_verify_ansible_variable_on_host( + target_sat, rhel_contenthost, module_activation_key, module_org, module_location +): + """Verify ansible variable is added to the role and attached to the host. + + :id: 7ec4fe19-5a08-4b10-bb4e-7327dd68699a + + :BZ: 2170727 + + :customerscenario: true + + :steps: + + 1. Create an Ansible variable with array type and set the default value. + 2. Enable both 'Merge Overrides' and 'Merge Default'. + 3. Add the variable to a role and attach the role to the host. + 4. Verify that ansible variable is added to the host. + + :expectedresults: The variable is successfully added to the host. + """ + key = gen_string('alpha') + SELECTED_ROLE = 'redhat.satellite.activation_keys' + proxy_id = target_sat.nailgun_smart_proxy.id + target_sat.api.AnsibleRoles().sync(data={'proxy_id': proxy_id, 'role_names': [SELECTED_ROLE]}) + command = target_sat.api.RegistrationCommand( + organization=module_org, + location=module_location, + activation_keys=[module_activation_key.name], + ).create() + result = rhel_contenthost.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' + target_host = rhel_contenthost.nailgun_host + with target_sat.ui_session() as session: + session.organization.select(org_name=module_org.name) + session.location.select(loc_name=module_location.name) + session.ansiblevariables.create_with_overrides( + { + 'key': key, + 'ansible_role': SELECTED_ROLE, + 'override': 'true', + 'parameter_type': 'array', + 'default_value': '[\'test\']', + 'validator_type': None, + 'attribute_order': 'domain \n fqdn \n hostgroup \n os', + 'merge_default': 'true', + 'merge_overrides': 'true', + 'matcher_section.params': [ + { + 'attribute_type': {'matcher_key': 'os', 'matcher_value': 'fedora'}, + 'value': '[\'13\']', + } + ], + } + ) + target_sat.cli.Host.ansible_roles_assign( + {'id': target_host.id, 'ansible-roles': SELECTED_ROLE} + ) + values = session.host_new.get_details(rhel_contenthost.hostname, 'ansible')['ansible'][ + 'variables' + ]['table'] + result = [ansible_var for ansible_var in values if ansible_var['Name'] == key] + assert result != [] + + @pytest.mark.stubbed @pytest.mark.tier2 def test_positive_role_variable_information(self):