Change job_wait collection test to always try and delete created objects

This commit is contained in:
John Westcott IV
2023-05-10 11:08:50 -04:00
parent a66acd87e6
commit cf091d7836

View File

@@ -9,7 +9,8 @@
jt_name: "AWX-Collection-tests-job_wait-long_running-{{ test_id }}" jt_name: "AWX-Collection-tests-job_wait-long_running-{{ test_id }}"
proj_name: "AWX-Collection-tests-job_wait-long_running-{{ test_id }}" proj_name: "AWX-Collection-tests-job_wait-long_running-{{ test_id }}"
- name: Assure that the demo project exists - block:
- name: Create a project
project: project:
name: "{{ proj_name }}" name: "{{ proj_name }}"
scm_type: 'git' scm_type: 'git'
@@ -17,7 +18,7 @@
scm_update_on_launch: true scm_update_on_launch: true
organization: Default organization: Default
- name: Create a job template - name: Create a job template
job_template: job_template:
name: "{{ jt_name }}" name: "{{ jt_name }}"
playbook: "sleep.yml" playbook: "sleep.yml"
@@ -25,82 +26,129 @@
project: "{{ proj_name }}" project: "{{ proj_name }}"
inventory: "Demo Inventory" inventory: "Demo Inventory"
extra_vars: extra_vars:
sleep_interval: 300 sleep_interval: 600
- name: Check module fails with correct msg - name: Check module fails with correct msg
job_wait: job_wait:
job_id: "99999999" job_id: "99999999"
register: result register: result
ignore_errors: true ignore_errors: true
- assert: - assert:
that: that:
- result is failed - result is failed
- "result.msg =='Unable to wait, no job_id 99999999 found: The requested object could not be found.' or - "result.msg =='Unable to wait, no job_id 99999999 found: The requested object could not be found.' or
'Unable to wait on job 99999999; that ID does not exist.'" 'Unable to wait on job 99999999; that ID does not exist.'"
- name: Launch Demo Job Template (take happy path) - name: Launch Demo Job Template (take happy path)
job_launch: job_launch:
job_template: "Demo Job Template" job_template: "Demo Job Template"
register: job register: job
- assert: - assert:
that: that:
- job is changed - job is changed
- name: Wait for the Job to finish - name: Wait for the Job to finish
job_wait: job_wait:
job_id: "{{ job.id }}" job_id: "{{ job.id }}"
register: wait_results register: wait_results
# Make sure it worked and that we have some data in our results # Make sure it worked and that we have some data in our results
- assert: - assert:
that: that:
- wait_results is successful - wait_results is successful
- "'elapsed' in wait_results" - "'elapsed' in wait_results"
- "'id' in wait_results" - "'id' in wait_results"
- name: Launch a long running job - name: Launch a long running job
job_launch: job_launch:
job_template: "{{ jt_name }}" job_template: "{{ jt_name }}"
register: job register: job
- assert: - assert:
that: that:
- job is changed - job is changed
- name: Timeout waiting for the job to complete - name: Timeout waiting for the job to complete
job_wait: job_wait:
job_id: "{{ job.id }}" job_id: "{{ job.id }}"
timeout: 5 timeout: 5
ignore_errors: true ignore_errors: true
register: wait_results register: wait_results
# Make sure that we failed and that we have some data in our results # Make sure that we failed and that we have some data in our results
- assert: - assert:
that: that:
- "wait_results.msg == 'Monitoring aborted due to timeout' or 'Timeout waiting for job to finish.'" - "wait_results.msg == 'Monitoring aborted due to timeout' or 'Timeout waiting for job to finish.'"
- "'id' in wait_results" - "'id' in wait_results"
- name: Async cancel the long running job - name: Async cancel the long running job
job_cancel: job_cancel:
job_id: "{{ job.id }}" job_id: "{{ job.id }}"
async: 3600 async: 3600
poll: 0 poll: 0
- name: Wait for the job to exit on cancel - name: Wait for the job to exit on cancel
job_wait: job_wait:
job_id: "{{ job.id }}" job_id: "{{ job.id }}"
register: wait_results register: wait_results
ignore_errors: true ignore_errors: true
- assert: - assert:
that: that:
- wait_results is failed - wait_results is failed
- 'wait_results.status == "canceled"' - 'wait_results.status == "canceled"'
- "wait_results.msg == 'Job with id {{ job.id }} failed' or 'Job with id={{ job.id }} failed, error: Job failed.'" - "wait_results.msg == 'Job with id {{ job.id }} failed' or 'Job with id={{ job.id }} failed, error: Job failed.'"
- name: Delete the job template # 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-workflow_launch--wfjt1-{{ test_id1 }}"
- name: Create our workflow
workflow_job_template:
name: "{{ wfjt_name2 }}"
state: present
- name: Add a node
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
workflow_launch:
workflow_template: "{{ wfjt_name2 }}"
ignore_errors: true
register: workflow
- name: Wait for the Workflow Job to finish
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"
always:
- name: Clean up test workflow
workflow_job_template:
name: "{{ wfjt_name2 }}"
state: absent
- name: Delete the job template
job_template: job_template:
name: "{{ jt_name }}" name: "{{ jt_name }}"
playbook: "sleep.yml" playbook: "sleep.yml"
@@ -109,54 +157,8 @@
inventory: "Demo Inventory" inventory: "Demo Inventory"
state: absent state: absent
- name: Delete the project - name: Delete the project
project: project:
name: "{{ proj_name }}" name: "{{ proj_name }}"
organization: Default organization: Default
state: absent state: absent
# 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-workflow_launch--wfjt1-{{ test_id1 }}"
- name: Create our workflow
workflow_job_template:
name: "{{ wfjt_name2 }}"
state: present
- name: Add a node
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
workflow_launch:
workflow_template: "{{ wfjt_name2 }}"
ignore_errors: true
register: workflow
- name: Wait for the Workflow Job to finish
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
workflow_job_template:
name: "{{ wfjt_name2 }}"
state: absent