From 8f66cfa2c0fe6728bf5a74928d10adfe8388f5e9 Mon Sep 17 00:00:00 2001 From: Donald Picard Date: Wed, 7 Oct 2020 11:00:17 -0400 Subject: [PATCH] related #8344 add support for wait of project_updates jobs, inventory_update, and workflow_job. Signed-off-by: Donald Picard --- .../plugins/modules/tower_job_wait.py | 14 ++++-- .../targets/tower_job_wait/tasks/main.yml | 46 +++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/awx_collection/plugins/modules/tower_job_wait.py b/awx_collection/plugins/modules/tower_job_wait.py index 6f71a1be5b..9bbcd096ca 100644 --- a/awx_collection/plugins/modules/tower_job_wait.py +++ b/awx_collection/plugins/modules/tower_job_wait.py @@ -30,7 +30,7 @@ options: interval: description: - The interval in sections, to request an update from Tower. - - For backwards compatability if unset this will be set to the average of min and max intervals + - For backwards compatibility if unset this will be set to the average of min and max intervals required: False default: 1 type: float @@ -48,6 +48,12 @@ options: description: - Maximum time in seconds to wait for a job to finish. type: int + job_type: + description: + - Job type to wait for + choices: ['project_updates', 'jobs', 'inventory_updates', 'workflow_jobs'] + default: 'jobs' + type: str extends_documentation_fragment: awx.awx.auth ''' @@ -99,6 +105,7 @@ def main(): # Any additional arguments that are not fields of the item can be added here argument_spec = dict( job_id=dict(type='int', required=True), + job_type=dict(choices=['project_updates', 'jobs', 'inventory_updates', 'workflow_jobs'], default='jobs'), timeout=dict(type='int'), min_interval=dict(type='float'), max_interval=dict(type='float'), @@ -110,6 +117,7 @@ def main(): # Extract our parameters job_id = module.params.get('job_id') + job_type = module.params.get('job_type') timeout = module.params.get('timeout') min_interval = module.params.get('min_interval') max_interval = module.params.get('max_interval') @@ -130,14 +138,14 @@ def main(): ) # Attempt to look up job based on the provided id - job = module.get_one('jobs', **{ + job = module.get_one(job_type, **{ 'data': { 'id': job_id, } }) if job is None: - module.fail_json(msg='Unable to wait on job {0}; that ID does not exist in Tower.'.format(job_id)) + module.fail_json(msg='Unable to wait on ' + job_type.rstrip("s") + ' {0}; that ID does not exist in Tower.'.format(job_id)) # Invoke wait function result = module.wait_on_url( diff --git a/awx_collection/tests/integration/targets/tower_job_wait/tasks/main.yml b/awx_collection/tests/integration/targets/tower_job_wait/tasks/main.yml index b04fa62ff8..2b3b8e4536 100644 --- a/awx_collection/tests/integration/targets/tower_job_wait/tasks/main.yml +++ b/awx_collection/tests/integration/targets/tower_job_wait/tasks/main.yml @@ -135,3 +135,49 @@ name: "{{ proj_name }}" organization: Default state: absent + +# tower workflow wait test +- name: Generate a random string for test + set_fact: + test_id1: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" + when: test_id1 is not defined + +- name: Generate names + set_fact: + wfjt_name2: "AWX-Collection-tests-tower_workflow_launch--wfjt1-{{ test_id1 }}" + +- name: Create our workflow + tower_workflow_job_template: + name: "{{ wfjt_name2 }}" + state: present + +- name: Add a node + tower_workflow_job_template_node: + workflow_job_template: "{{ wfjt_name2 }}" + unified_job_template: "Demo Job Template" + identifier: leaf + register: new_node + +- name: Kick off a workflow + tower_workflow_launch: + workflow_template: "{{ wfjt_name2 }}" + ignore_errors: true + register: workflow + +- name: Wait for the Workflow Job to finish + tower_job_wait: + job_id: "{{ workflow.job_info.id }}" + job_type: "workflow_jobs" + register: wait_workflow_results + +# Make sure it worked and that we have some data in our results +- assert: + that: + - wait_workflow_results is successful + - "'elapsed' in wait_workflow_results" + - "'id' in wait_workflow_results" + +- name: Clean up test workflow + tower_workflow_job_template: + name: "{{ wfjt_name2 }}" + state: absent