Skip to content

Commit

Permalink
Update Ansible tests to reflect the new split Ansible components (#14302
Browse files Browse the repository at this point in the history
)

Signed-off-by: Gaurav Talreja <[email protected]>
  • Loading branch information
Gauravtalreja1 committed Mar 12, 2024
1 parent 5e1a1ba commit 48feefe
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 72 deletions.
3 changes: 2 additions & 1 deletion testimony.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ CaseComponent:
# No spaces allowed
- ActivationKeys
- AlternateContentSources
- Ansible
- Ansible-ConfigurationManagement
- Ansible-RemoteExecution
- AnsibleCollection
- API
- AuditLog
Expand Down
156 changes: 117 additions & 39 deletions tests/foreman/api/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
:CaseAutomation: Automated
:CaseComponent: Ansible
:CaseComponent: Ansible-ConfigurationManagement
:Team: Rocket
:CaseImportance: High
:CaseImportance: Critical
"""
from fauxfactory import gen_string
Expand All @@ -19,6 +19,46 @@
from robottelo.utils.issue_handlers import is_open


@pytest.fixture
def filtered_user(target_sat, module_org, module_location):
"""
:steps:
1. Create a role with a host view filtered
2. Create a user with that role
3. Setup a host
"""
role = target_sat.api.Role(
name=gen_string('alpha'), location=[module_location], organization=[module_org]
).create()
# assign view_hosts (with a filter, to test BZ 1699188),
# view_hostgroups, view_facts permissions to the role
permission_hosts = target_sat.api.Permission().search(query={'search': 'name="view_hosts"'})
permission_hostgroups = target_sat.api.Permission().search(
query={'search': 'name="view_hostgroups"'}
)
permission_facts = target_sat.api.Permission().search(query={'search': 'name="view_facts"'})
target_sat.api.Filter(
permission=permission_hosts, search='name != nonexistent', role=role
).create()
target_sat.api.Filter(permission=permission_hostgroups, role=role).create()
target_sat.api.Filter(permission=permission_facts, role=role).create()

password = gen_string('alpha')
user = target_sat.api.User(
role=[role], password=password, location=[module_location], organization=[module_org]
).create()

return user, password


@pytest.fixture
def rex_host_in_org_and_loc(target_sat, module_org, module_location, rex_contenthost):
host = target_sat.api.Host().search(query={'search': f'name={rex_contenthost.hostname}'})[0]
target_sat.api.Host(id=host.id, organization=[module_org.id]).update(['organization'])
target_sat.api.Host(id=host.id, location=module_location.id).update(['location'])
return host


@pytest.mark.e2e
def test_fetch_and_sync_ansible_playbooks(target_sat):
"""
Expand All @@ -39,8 +79,6 @@ def test_fetch_and_sync_ansible_playbooks(target_sat):
1. Playbooks should be fetched and synced successfully.
:BZ: 2115686
:CaseAutomation: Automated
"""
target_sat.execute(
"ansible-galaxy collection install -p /usr/share/ansible/collections "
Expand Down Expand Up @@ -84,9 +122,9 @@ def test_positive_ansible_job_on_host(target_sat, module_org, rhel_contenthost):
1. Host should be assigned the proper role.
2. Job execution must be successful.
:CaseAutomation: Automated
:BZ: 2164400
:CaseImportance: Critical
:CaseComponent: Ansible-RemoteExecution
"""
SELECTED_ROLE = 'RedHatInsights.insights-client'
if rhel_contenthost.os_version.major <= 7:
Expand Down Expand Up @@ -152,7 +190,7 @@ def test_positive_ansible_job_on_multiple_host(
:BZ: 2167396, 2190464, 2184117
:CaseAutomation: Automated
:CaseComponent: Ansible-RemoteExecution
"""
hosts = [rhel9_contenthost, rhel8_contenthost, rhel7_contenthost]
SELECTED_ROLE = 'RedHatInsights.insights-client'
Expand Down Expand Up @@ -195,43 +233,83 @@ def test_positive_ansible_job_on_multiple_host(
assert result.status_label == 'failed'


@pytest.fixture
def filtered_user(target_sat, module_org, module_location):
"""
:steps:
1. Create a role with a host view filtered
2. Create a user with that role
3. Setup a host
@pytest.mark.e2e
@pytest.mark.tier2
@pytest.mark.upgrade
def test_add_and_remove_ansible_role_hostgroup(target_sat):
"""
api = target_sat.api
role = api.Role(
name=gen_string('alpha'), location=[module_location], organization=[module_org]
).create()
# assign view_hosts (with a filter, to test BZ 1699188),
# view_hostgroups, view_facts permissions to the role
permission_hosts = api.Permission().search(query={'search': 'name="view_hosts"'})
permission_hostgroups = api.Permission().search(query={'search': 'name="view_hostgroups"'})
permission_facts = api.Permission().search(query={'search': 'name="view_facts"'})
api.Filter(permission=permission_hosts, search='name != nonexistent', role=role).create()
api.Filter(permission=permission_hostgroups, role=role).create()
api.Filter(permission=permission_facts, role=role).create()
Test add and remove functionality for ansible roles in hostgroup via API
password = gen_string('alpha')
user = api.User(
role=[role], password=password, location=[module_location], organization=[module_org]
).create()
:id: 7672cf86-fa31-11ed-855a-0fd307d2d66b
return user, password
:steps:
1. Create a hostgroup and a nested hostgroup
2. Sync a few ansible roles
3. Assign a few ansible roles with the host group
4. Add some ansible role with the host group
5. Add some ansible roles to the nested hostgroup
6. Remove the added ansible roles from the parent and nested hostgroup
:expectedresults:
1. Ansible role assign/add/remove functionality should work as expected in API
@pytest.fixture
def rex_host_in_org_and_loc(target_sat, module_org, module_location, rex_contenthost):
api = target_sat.api
host = api.Host().search(query={'search': f'name={rex_contenthost.hostname}'})[0]
host_id = host.id
api.Host(id=host_id, organization=[module_org.id]).update(['organization'])
api.Host(id=host_id, location=module_location.id).update(['location'])
return host
:BZ: 2164400
"""
ROLE_NAMES = [
'theforeman.foreman_scap_client',
'redhat.satellite.hostgroups',
'RedHatInsights.insights-client',
'redhat.satellite.compute_resources',
]
hg = target_sat.api.HostGroup(name=gen_string('alpha')).create()
hg_nested = target_sat.api.HostGroup(name=gen_string('alpha'), parent=hg).create()
proxy_id = target_sat.nailgun_smart_proxy.id
target_sat.api.AnsibleRoles().sync(data={'proxy_id': proxy_id, 'role_names': ROLE_NAMES})
ROLES = [
target_sat.api.AnsibleRoles().search(query={'search': f'name={role}'})[0].id
for role in ROLE_NAMES
]
# Assign first 2 roles to HG and verify it
target_sat.api.HostGroup(id=hg.id).assign_ansible_roles(data={'ansible_role_ids': ROLES[:2]})
for r1, r2 in zip(
target_sat.api.HostGroup(id=hg.id).list_ansible_roles(), ROLE_NAMES[:2], strict=True
):
assert r1['name'] == r2

# Add next role from list to HG and verify it
target_sat.api.HostGroup(id=hg.id).add_ansible_role(data={'ansible_role_id': ROLES[2]})
for r1, r2 in zip(
target_sat.api.HostGroup(id=hg.id).list_ansible_roles(), ROLE_NAMES[:3], strict=True
):
assert r1['name'] == r2

# Add next role to nested HG, and verify roles are also nested to HG along with assigned role
# Also, ensure the parent HG does not contain the roles assigned to nested HGs
target_sat.api.HostGroup(id=hg_nested.id).add_ansible_role(data={'ansible_role_id': ROLES[3]})
for r1, r2 in zip(
target_sat.api.HostGroup(id=hg_nested.id).list_ansible_roles(),
[ROLE_NAMES[-1]] + ROLE_NAMES[:-1],
strict=True,
):
assert r1['name'] == r2

for r1, r2 in zip(
target_sat.api.HostGroup(id=hg.id).list_ansible_roles(), ROLE_NAMES[:3], strict=True
):
assert r1['name'] == r2

# Remove roles assigned one by one from HG and nested HG
for role in ROLES[:3]:
target_sat.api.HostGroup(id=hg.id).remove_ansible_role(data={'ansible_role_id': role})
hg_roles = target_sat.api.HostGroup(id=hg.id).list_ansible_roles()
assert len(hg_roles) == 0

for role in ROLES:
target_sat.api.HostGroup(id=hg_nested.id).remove_ansible_role(
data={'ansible_role_id': role}
)
hg_nested_roles = target_sat.api.HostGroup(id=hg_nested.id).list_ansible_roles()
assert len(hg_nested_roles) == 0


@pytest.mark.rhel_ver_match('[78]')
Expand Down
12 changes: 4 additions & 8 deletions tests/foreman/cli/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:CaseAutomation: Automated
:CaseComponent: Ansible
:CaseComponent: Ansible-ConfigurationManagement
:Team: Rocket
Expand Down Expand Up @@ -41,8 +41,6 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
2. Job execution must be successful.
3. Operations performed with hammer must be successful.
:CaseAutomation: Automated
:BZ: 2154184
:customerscenario: true
Expand All @@ -53,7 +51,7 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
SELECTED_ROLE_1 = 'theforeman.foreman_scap_client'
SELECTED_VAR = gen_string('alpha')
# disable batch tasks to test BZ#2154184
target_sat.cli.Settings.set({'name': "foreman_tasks_proxy_batch_trigger", 'value': "false"})
target_sat.cli.Settings.set({'name': 'foreman_tasks_proxy_batch_trigger', 'value': 'false'})
if rhel_contenthost.os_version.major <= 7:
rhel_contenthost.create_custom_repos(rhel7=settings.repos.rhel7_os)
assert rhel_contenthost.execute('yum install -y insights-client').status == 0
Expand Down Expand Up @@ -121,7 +119,7 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
@pytest.mark.tier2
def test_add_and_remove_ansible_role_hostgroup(target_sat):
"""
Test add and remove functionality for ansible roles in hostgroup via cli
Test add and remove functionality for ansible roles in hostgroup via CLI
:id: 2c6fda14-4cd2-490a-b7ef-7a08f8164fad
Expand All @@ -135,11 +133,9 @@ def test_add_and_remove_ansible_role_hostgroup(target_sat):
5. Remove the added ansible roles from the host group
:expectedresults:
1. Ansible role assign/add/remove functionality should work as expected in cli
1. Ansible role assign/add/remove functionality should work as expected in CLI
:BZ: 2029402
:CaseAutomation: Automated
"""
ROLES = [
'theforeman.foreman_scap_client',
Expand Down
2 changes: 1 addition & 1 deletion tests/foreman/cli/test_remoteexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def test_positive_install_ansible_collection(
:id: ad25aee5-4ea3-4743-a301-1c6271856f79
:CaseComponent: Ansible
:CaseComponent: Ansible-RemoteExecution
:Team: Rocket
"""
Expand Down
11 changes: 5 additions & 6 deletions tests/foreman/destructive/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:CaseAutomation: Automated
:CaseComponent: Ansible
:CaseComponent: Ansible-ConfigurationManagement
:Team: Rocket
Expand All @@ -21,10 +21,6 @@ def test_positive_persistent_ansible_cfg_change(target_sat):
:id: c22fcd47-8627-4230-aa1f-7d4fc8517a0e
:BZ: 1786358
:customerscenario: true
:steps:
1. Update value in ansible.cfg.
2. Verify value is updated in the file.
Expand All @@ -33,6 +29,10 @@ def test_positive_persistent_ansible_cfg_change(target_sat):
:expectedresults: Changes in ansible.cfg are persistent after running
"satellite-installer".
:BZ: 1786358
:customerscenario: true
"""
ansible_cfg = '/etc/ansible/ansible.cfg'
param = 'local_tmp = /tmp'
Expand All @@ -49,7 +49,6 @@ def test_positive_import_all_roles(target_sat):
:id: 53fe3857-a08f-493d-93c7-3fed331ed391
:steps:
1. Navigate to the Configure > Roles page.
2. Click the `Import from [hostname]` button.
3. Get total number of importable roles from pagination.
Expand Down
8 changes: 4 additions & 4 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
:CaseAutomation: Automated
:CaseComponent: Ansible
:CaseComponent: Ansible-ConfigurationManagement
:Team: Rocket
:CaseImportance: High
:CaseImportance: Critical
"""
from fauxfactory import gen_string
Expand Down Expand Up @@ -111,7 +111,7 @@ def test_positive_config_report_ansible(session, target_sat, module_org, rhel_co
1. Host should be assigned the proper role.
2. Job report should be created.
:CaseImportance: Critical
:CaseComponent: Ansible-RemoteExecution
"""
SELECTED_ROLE = 'RedHatInsights.insights-client'
if rhel_contenthost.os_version.major <= 7:
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_positive_ansible_custom_role(target_sat, session, module_org, rhel_cont
:BZ: 2155392
:CaseAutomation: Automated
:CaseComponent: Ansible-RemoteExecution
"""
SELECTED_ROLE = 'custom_role'
playbook = f'{robottelo_tmp_dir}/playbook.yml'
Expand Down
4 changes: 2 additions & 2 deletions tests/foreman/ui/test_jobinvocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_positive_schedule_recurring_host_job(self):
:id: 5052be04-28ab-4349-8bee-851ef76e4ffa
:caseComponent: Ansible
:caseComponent: Ansible-RemoteExecution
:Team: Rocket
Expand All @@ -152,7 +152,7 @@ def test_positive_schedule_recurring_hostgroup_job(self):
:id: c65db99b-11fe-4a32-89d0-0a4692b07efe
:caseComponent: Ansible
:caseComponent: Ansible-RemoteExecution
:Team: Rocket
Expand Down
Loading

0 comments on commit 48feefe

Please sign in to comment.