Skip to content

Commit

Permalink
Ansible_Job api test coverage [e2e] (#10497)
Browse files Browse the repository at this point in the history
Signed-off-by: Adarsh Dubey <[email protected]>

Signed-off-by: Adarsh Dubey <[email protected]>
  • Loading branch information
adarshdubey-star authored Jan 19, 2023
1 parent 83b3ee3 commit a435528
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/foreman/api/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
:Upstream: No
"""
import pytest

from robottelo.config import settings


def test_fetch_and_sync_ansible_playbooks(target_sat):
Expand Down Expand Up @@ -59,3 +62,61 @@ def test_fetch_and_sync_ansible_playbooks(target_sat):
)
assert task_details[0].result == 'success'
assert len(task_details[0].output['result']['created']) == playbooks_count


@pytest.mark.e2e
@pytest.mark.no_containers
@pytest.mark.rhel_ver_match('[^6].*')
def test_positive_ansible_job_on_host(target_sat, module_org, rhel_contenthost):
"""
Test successful execution of Ansible Job on host.
:id: c8dcdc54-cb98-4b24-bff9-049a6cc36acb
:Steps:
1. Register a content host with satellite
2. Import a role into satellite
3. Assign that role to a host
4. Assert that the role was assigned to the host successfully
5. Run the Ansible playbook associated with that role
6. Check if the job is executed.
:expectedresults:
1. Host should be assigned the proper role.
2. Job execution must be successful.
:CaseAutomation: Automated
"""
SELECTED_ROLE = 'RedHatInsights.insights-client'
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
rhel_contenthost.install_katello_ca(target_sat)
rhel_contenthost.register_contenthost(module_org.label, force=True)
assert rhel_contenthost.subscribed
rhel_contenthost.add_rex_key(satellite=target_sat)
id = target_sat.nailgun_smart_proxy.id
target_host = rhel_contenthost.nailgun_host
target_sat.api.AnsibleRoles().sync(data={'proxy_id': id, 'role_names': [SELECTED_ROLE]})
target_host.assign_ansible_roles(data={'ansible_role_ids': [1]})
host_roles = target_host.list_ansible_roles()
assert host_roles[0]['name'] == SELECTED_ROLE
assert target_host.name == rhel_contenthost.hostname
template_id = (
target_sat.api.JobTemplate()
.search(query={'search': 'name="Ansible Roles - Ansible Default"'})[0]
.id
)
job = target_sat.api.JobInvocation().run(
synchronous=False,
data={
'job_template_id': template_id,
'targeting_type': 'static_query',
'search_query': f'name = {rhel_contenthost.hostname}',
},
)
target_sat.wait_for_tasks(
f'resource_type = JobInvocation and resource_id = {job["id"]}', poll_timeout=1000
)
result = target_sat.api.JobInvocation(id=job['id']).read()
assert result.succeeded == 1

0 comments on commit a435528

Please sign in to comment.