Skip to content

Commit

Permalink
[6.14.z] Add tests for Facts component (SatelliteQE#15507)
Browse files Browse the repository at this point in the history
  • Loading branch information
Satellite-QE authored and shweta83 committed Jun 26, 2024
1 parent 5a137d9 commit 7c5111e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
60 changes: 60 additions & 0 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 added and removed 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[:2],
}
)
# verify ansible role(s) assigned properly while creating a host group.
assert session.hostgroup.read_role(name, SELECTED_ROLE) == SELECTED_ROLE[:2]

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

session.hostgroup.remove_hostgroup_role(
name, {'ansible_roles.resources': SELECTED_ROLE[0]}
)
# verify ansible role(s) removed properly from the host group.
assert SELECTED_ROLE[0] not in session.hostgroup.read_role(name, SELECTED_ROLE)
assert SELECTED_ROLE[1:] == 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
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/ui/test_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def test_positive_upload_host_facts(
module_target_sat,
rhel_contenthost,
module_sca_manifest_org,
module_entitlement_manifest_org,
module_location,
module_activation_key,
):
Expand All @@ -41,7 +41,7 @@ def test_positive_upload_host_facts(
:customerscenario: true
"""
with module_target_sat.ui_session() as session:
session.organization.select(module_sca_manifest_org.name)
session.organization.select(module_entitlement_manifest_org.name)
session.location.select(module_location.name)
cmd = session.host.get_register_command(
{
Expand Down

0 comments on commit 7c5111e

Please sign in to comment.