diff --git a/tests/foreman/ui/test_ansible.py b/tests/foreman/ui/test_ansible.py index 0b29d2c2c17..511b0c9dde0 100644 --- a/tests/foreman/ui/test_ansible.py +++ b/tests/foreman/ui/test_ansible.py @@ -11,7 +11,6 @@ from fauxfactory import gen_string import pytest -from wait_for import wait_for import yaml from robottelo import constants @@ -21,6 +20,7 @@ settings, user_nailgun_config, ) +from wait_for import wait_for class TestAnsibleCfgMgmt: @@ -455,6 +455,66 @@ def test_positive_assign_and_remove_ansible_role_to_host(self, target_sat, funct == 'No roles assigned directly to the host' ) + @pytest.mark.tier2 + def test_positive_assign_and_remove_ansible_role_to_hostgroup( + self, + target_sat, + module_org, + module_location, + ): + """Add and remove functionality for ansible roles in hostgroup + + :id: 5d94a484-92c1-4387-ab92-0649e4c4f907 + + :steps: + 1. Import all roles available by default. + 2. Assign ansible role while creating the hostgroup + 3. Assign ansible role after creating the hostgroup + 4. Remove previously added ansible roles from the hostgroup + + :expectedresults: The Ansible Role is successfully add and remove from the hostgroup + """ + SELECTED_ROLE = [ + 'RedHatInsights.insights-client', + 'redhat.satellite.hostgroups', + 'redhat.satellite.compute_profiles', + ] + name = gen_string('alpha').lower() + with target_sat.ui_session() as session: + synced_all_role = session.ansibleroles.import_all_roles() + total_imported_roles = session.ansibleroles.imported_roles_count + # verify all roles are synced + assert synced_all_role == total_imported_roles + + session.location.select(module_location.name) + session.organization.select(module_org.name) + # Assign Ansible role(s) while creating the hostgroup. + session.hostgroup.create( + { + 'host_group.name': name, + 'ansible_roles.resources': SELECTED_ROLE[0:2], + } + ) + # verify ansible role(s) assigned properly while creating a host group. + result = session.hostgroup.read_role(name, SELECTED_ROLE) + assert 'RedHatInsights.insights-client' in result + assert 'redhat.satellite.hostgroups' in result + + session.hostgroup.assign_role_to_hostgroup(name, SELECTED_ROLE[2]) + # verify ansible role(s) assigned properly after creating the hostgroup. + assert 'redhat.satellite.compute_profiles' in session.hostgroup.read_role( + name, SELECTED_ROLE + ) + + session.hostgroup.remove_hostgroup_role(name, SELECTED_ROLE[0]) + # verify ansible role(s) removed properly from the hostgroup. + assert 'RedHatInsights.insights-client' not in session.hostgroup.read_role( + name, SELECTED_ROLE + ) + # Delete host group + session.hostgroup.delete(name) + assert not target_sat.api.HostGroup().search(query={'search': f'name={name}'}) + class TestAnsibleREX: """Test class for remote execution via Ansible