Skip to content

Commit

Permalink
steps added for hostgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
amolpati30 committed Jun 21, 2024
1 parent a7ede10 commit 85a1dd1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
- id: check-yaml
- id: debug-statements
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
rev: v0.4.10
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
64 changes: 64 additions & 0 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,70 @@ 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 added and removed from the hostgroup
"""
SELECTED_ROLE = [
'RedHatInsights.insights-client',
'redhat.satellite.hostgroups',
'redhat.satellite.compute_profiles',
]
name = gen_string('alpha').lower()
RedHatInsights = 'RedHatInsights.insights-client'
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],
}
)
result = session.hostgroup.read_role(name, SELECTED_ROLE)
# verify ansible role(s) assigned properly while creating a host group.
assert RedHatInsights in result
assert 'redhat.satellite.hostgroups' in result

session.hostgroup.assign_role_to_hostgroup(
name, {'ansible_roles.resources': SELECTED_ROLE[2]}
)
result = session.hostgroup.read_role(name, SELECTED_ROLE)
# verify ansible role(s) assigned properly after creating the hostgroup.
assert 'redhat.satellite.compute_profiles' in result

session.hostgroup.remove_hostgroup_role(
name, {'ansible_roles.resources': SELECTED_ROLE[0]}
)
result = session.hostgroup.read_role(name, SELECTED_ROLE)
# verify ansible role(s) removed properly from the host group.
assert RedHatInsights not in result

# 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
Expand Down

0 comments on commit 85a1dd1

Please sign in to comment.