From 490088ac736040bcce318c283421e2127a99c4df Mon Sep 17 00:00:00 2001 From: amol patil Date: Tue, 27 Aug 2024 22:30:10 +0530 Subject: [PATCH] add remove ansible role from host --- tests/foreman/ui/test_ansible.py | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/foreman/ui/test_ansible.py b/tests/foreman/ui/test_ansible.py index 530f9eeeea2..b1a9fd73852 100644 --- a/tests/foreman/ui/test_ansible.py +++ b/tests/foreman/ui/test_ansible.py @@ -11,6 +11,7 @@ from fauxfactory import gen_string import pytest +from wait_for import wait_for import yaml from robottelo import constants @@ -420,6 +421,49 @@ def test_positive_ansible_config_report_changes_notice_and_failed_tasks_errors( assert f'notice Install the {package_name} package' in notice_log['permission_denied'] assert f'Installed: rubygem-{package_name}' in notice_log['permission_denied'] + @pytest.mark.tier2 + def test_positive_assign_and_remove_ansible_role_to_host(self, target_sat, function_host): + """Add and remove the role(s) of a Host + :id: a61b4c05-1395-47c2-b6d9-fcff8b094e0e + :setup: Used pre-defined function_host (component/host) registerd with satellite. + :steps: + 1. Import all roles available by default. + 2. Assign a role to the host. + 3. Navigate to the new UI for the given Host. + 4. Select the 'Ansible' tab + 5. Click the 'Edit Ansible roles' button. + 6. Using the popup, remove the assigned role from the Host. + :expectedresults: The Role is successfully aaded and removed from the Host, and no longer shows + up on the UI + """ + SELECTED_ROLE = 'RedHatInsights.insights-client' + + location = function_host.location.read() + organization = function_host.organization.read() + proxy_id = target_sat.nailgun_smart_proxy.id + target_sat.api.AnsibleRoles().sync( + data={'proxy_id': proxy_id, 'role_names': [SELECTED_ROLE]} + ) + with target_sat.ui_session() as session: + session.location.select(location.name) + session.organization.select(organization.name) + # add ansible role + session.host_new.add_single_ansible_role(function_host.name) + wait_for(lambda: session.browser.refresh(), timeout=5) + # verify ansible role assigned to new UI for the given Host + ansible_roles_table = session.host_new.get_ansible_roles(function_host.name) + assert ansible_roles_table[0]['Name'] == SELECTED_ROLE + # remove ansible role + session.host_new.remove_single_ansible_role(function_host.name) + # verify ansible role removed + result = session.host_new.get_details( + function_host.name, widget_names='ansible.roles.noRoleAssign' + ) + assert ( + result['ansible']['roles']['noRoleAssign'] + == 'No roles assigned directly to the host' + ) + class TestAnsibleREX: """Test class for remote execution via Ansible