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,154 +9,156 @@
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:
project: - name: Create a project
name: "{{ proj_name }}" project:
scm_type: 'git' name: "{{ proj_name }}"
scm_url: 'https://github.com/ansible/test-playbooks.git' scm_type: 'git'
scm_update_on_launch: true scm_url: 'https://github.com/ansible/test-playbooks.git'
organization: Default scm_update_on_launch: true
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"
job_type: run job_type: run
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
job_template: - name: Generate a random string for test
name: "{{ jt_name }}" set_fact:
playbook: "sleep.yml" test_id1: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
job_type: run when: test_id1 is not defined
project: "{{ proj_name }}"
inventory: "Demo Inventory"
state: absent
- name: Delete the project - name: Generate names
project: set_fact:
name: "{{ proj_name }}" wfjt_name2: "AWX-Collection-tests-workflow_launch--wfjt1-{{ test_id1 }}"
organization: Default
state: absent
# workflow wait test - name: Create our workflow
- name: Generate a random string for test workflow_job_template:
set_fact: name: "{{ wfjt_name2 }}"
test_id1: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" state: present
when: test_id1 is not defined
- name: Generate names - name: Add a node
set_fact: workflow_job_template_node:
wfjt_name2: "AWX-Collection-tests-workflow_launch--wfjt1-{{ test_id1 }}" workflow_job_template: "{{ wfjt_name2 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
register: new_node
- name: Create our workflow - name: Kick off a workflow
workflow_job_template: workflow_launch:
name: "{{ wfjt_name2 }}" workflow_template: "{{ wfjt_name2 }}"
state: present ignore_errors: true
register: workflow
- name: Add a node - name: Wait for the Workflow Job to finish
workflow_job_template_node: job_wait:
workflow_job_template: "{{ wfjt_name2 }}" job_id: "{{ workflow.job_info.id }}"
unified_job_template: "Demo Job Template" job_type: "workflow_jobs"
identifier: leaf register: wait_workflow_results
register: new_node
- name: Kick off a workflow # Make sure it worked and that we have some data in our results
workflow_launch: - assert:
workflow_template: "{{ wfjt_name2 }}" that:
ignore_errors: true - wait_workflow_results is successful
register: workflow - "'elapsed' in wait_workflow_results"
- "'id' in wait_workflow_results"
- name: Wait for the Workflow Job to finish always:
job_wait: - name: Clean up test workflow
job_id: "{{ workflow.job_info.id }}" workflow_job_template:
job_type: "workflow_jobs" name: "{{ wfjt_name2 }}"
register: wait_workflow_results state: absent
# Make sure it worked and that we have some data in our results - name: Delete the job template
- assert: job_template:
that: name: "{{ jt_name }}"
- wait_workflow_results is successful playbook: "sleep.yml"
- "'elapsed' in wait_workflow_results" job_type: run
- "'id' in wait_workflow_results" project: "{{ proj_name }}"
inventory: "Demo Inventory"
state: absent
- name: Clean up test workflow - name: Delete the project
workflow_job_template: project:
name: "{{ wfjt_name2 }}" name: "{{ proj_name }}"
state: absent organization: Default
state: absent