mirror of
https://github.com/ansible/awx.git
synced 2026-03-15 16:07:30 -02:30
Merge pull request #5195 from AlanCoding/job_fail_json
In tower_job_wait intentionally fail module for failure Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -136,6 +136,12 @@ def main():
|
|||||||
json_output['timeout'] = True
|
json_output['timeout'] = True
|
||||||
except exc.NotFound as excinfo:
|
except exc.NotFound as excinfo:
|
||||||
fail_json = dict(msg='Unable to wait, no job_id {0} found: {1}'.format(job_id, excinfo), changed=False)
|
fail_json = dict(msg='Unable to wait, no job_id {0} found: {1}'.format(job_id, excinfo), changed=False)
|
||||||
|
except exc.JobFailure as excinfo:
|
||||||
|
fail_json = dict(msg='Job with id={} failed, error: {}'.format(job_id, excinfo))
|
||||||
|
fail_json['success'] = False
|
||||||
|
result = job.get(job_id)
|
||||||
|
for k in ('id', 'status', 'elapsed', 'started', 'finished'):
|
||||||
|
fail_json[k] = result.get(k)
|
||||||
except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo:
|
except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo:
|
||||||
fail_json = dict(msg='Unable to wait for job: {0}'.format(excinfo), changed=False)
|
fail_json = dict(msg='Unable to wait for job: {0}'.format(excinfo), changed=False)
|
||||||
|
|
||||||
|
|||||||
53
awx_collection/test/awx/test_job.py
Normal file
53
awx_collection/test/awx/test_job.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import pytest
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
from awx.main.models import Job
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_job_wait_successful(run_module, admin_user):
|
||||||
|
job = Job.objects.create(status='successful', started=now(), finished=now())
|
||||||
|
result = run_module('tower_job_wait', dict(
|
||||||
|
job_id=job.id
|
||||||
|
), admin_user)
|
||||||
|
result.pop('invocation', None)
|
||||||
|
assert result.pop('finished', '')[:10] == str(job.finished)[:10]
|
||||||
|
assert result.pop('started', '')[:10] == str(job.started)[:10]
|
||||||
|
assert result == {
|
||||||
|
"status": "successful",
|
||||||
|
"success": True,
|
||||||
|
"elapsed": str(job.elapsed),
|
||||||
|
"id": job.id
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_job_wait_failed(run_module, admin_user):
|
||||||
|
job = Job.objects.create(status='failed', started=now(), finished=now())
|
||||||
|
result = run_module('tower_job_wait', dict(
|
||||||
|
job_id=job.id
|
||||||
|
), admin_user)
|
||||||
|
result.pop('invocation', None)
|
||||||
|
assert result.pop('finished', '')[:10] == str(job.finished)[:10]
|
||||||
|
assert result.pop('started', '')[:10] == str(job.started)[:10]
|
||||||
|
assert result == {
|
||||||
|
"status": "failed",
|
||||||
|
"failed": True,
|
||||||
|
"success": False,
|
||||||
|
"elapsed": str(job.elapsed),
|
||||||
|
"id": job.id,
|
||||||
|
"msg": "Job with id=1 failed, error: Job failed."
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_job_wait_not_found(run_module, admin_user):
|
||||||
|
result = run_module('tower_job_wait', dict(
|
||||||
|
job_id=42
|
||||||
|
), admin_user)
|
||||||
|
result.pop('invocation', None)
|
||||||
|
assert result == {
|
||||||
|
"changed": False,
|
||||||
|
"failed": True,
|
||||||
|
"msg": "Unable to wait, no job_id 42 found: The requested object could not be found."
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user