Merge pull request #9896 from sean-m-sullivan/approval_node

Add workflow approval and node wait modules

SUMMARY
Please see #9878 this is a clean PR after redoing my fork.
Add a module to find a workflow approval node and approve or deny it, based on Issue #8013.
Add a module to wait for a specific workflow node to complete and return information on it.
Both of these are based on tests I have been creating for testing workflows.
Scenario
Launch workflow
Wait for A node in the workflow to finish, compare output to expected output.
If it matches, approve the approval node, otherwise deny the approval node.
Workflow completes.
Even used in concert I've added the wait feature to both of these so a user can wait on either to appear.
This does require a workflow to use unique names on the job nodes they are waiting on, As the job # is created on the fly, it would be difficult for user to specify, A future update could explore searching for a specific identifier among a workflow template and then finding that job created by that identifier.
Currently without the modules this depends on generous use of the uri module, with until and retry coupled together.
ISSUE TYPE
Feature Pull Request

COMPONENT NAME
awx-collection
AWX VERSION
19.0.0

Reviewed-by: Bianca Henderson <beeankha@gmail.com>
This commit is contained in:
softwarefactory-project-zuul[bot]
2021-04-24 22:52:50 +00:00
committed by GitHub
5 changed files with 494 additions and 127 deletions

View File

@@ -7,146 +7,237 @@
- name: Generate names
set_fact:
wfjt_name1: "AWX-Collection-tests-tower_workflow_launch--wfjt1-{{ test_id }}"
wfjt_name2: "AWX-Collection-tests-tower_workflow_launch--wfjt1-{{ test_id }}-2"
approval_node_name: "AWX-Collection-tests-tower_workflow_launch_approval_node-{{ test_id }}"
- name: Create our workflow
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
- block:
- name: Add a node
tower_workflow_job_template_node:
workflow_job_template: "{{ wfjt_name1 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
register: new_node
- name: Create our workflow
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
- name: Connect to Tower server but request an invalid workflow
tower_workflow_launch:
workflow_template: "Does Not Exist"
ignore_errors: true
register: result
- name: Add a node
tower_workflow_job_template_node:
workflow_job_template: "{{ wfjt_name1 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
register: new_node
- assert:
that:
- result is failed
- "'Unable to find workflow job template' in result.msg"
- name: Connect to Tower server but request an invalid workflow
tower_workflow_launch:
workflow_template: "Does Not Exist"
ignore_errors: true
register: result
- name: Run the workflow without waiting (this should just give us back a job ID)
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
wait: false
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'Unable to find workflow job template' in result.msg"
- assert:
that:
- result is not failed
- "'id' in result['job_info']"
- name: Run the workflow without waiting (this should just give us back a job ID)
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
wait: false
ignore_errors: true
register: result
- name: Kick off a workflow and wait for it, but only for a second
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
timeout: 1
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- "'id' in result['job_info']"
- assert:
that:
- result is failed
- "'Monitoring of Workflow Job - {{ wfjt_name1 }} aborted due to timeout' in result.msg"
- name: Kick off a workflow and wait for it, but only for a second
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
timeout: 1
ignore_errors: true
register: result
- name: Kick off a workflow and wait for it
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
ignore_errors: true
register: result
- assert:
that:
- result is failed
- "'Monitoring of Workflow Job - {{ wfjt_name1 }} aborted due to timeout' in result.msg"
- assert:
that:
- result is not failed
- "'id' in result['job_info']"
- name: Kick off a workflow and wait for it
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
ignore_errors: true
register: result
- name: Kick off a workflow with extra_vars but not enabled
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- assert:
that:
- result is not failed
- "'id' in result['job_info']"
- assert:
that:
- result is failed
- "'The field extra_vars was specified but the workflow job template does not allow for it to be overridden' in result.errors"
- name: Kick off a workflow with extra_vars but not enabled
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- name: Prompt the workflow's with survey
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
survey_enabled: true
ask_variables_on_launch: false
survey:
name: ''
description: ''
spec:
- question_name: Basic Name
question_description: Name
required: true
type: text
variable: basic_name
min: 0
max: 1024
default: ''
choices: ''
new_question: true
- question_name: Choose yes or no?
question_description: Choosing yes or no.
required: false
type: multiplechoice
variable: option_true_false
min:
max:
default: 'yes'
choices: |-
yes
no
new_question: true
- assert:
that:
- result is failed
- "'The field extra_vars was specified but the workflow job template does not allow for it to be overridden' in result.errors"
- name: Kick off a workflow with survey
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
basic_name: My First Variable
option_true_false: 'no'
ignore_errors: true
register: result
- name: Prompt the workflow's with survey
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
survey_enabled: true
ask_variables_on_launch: false
survey:
name: ''
description: ''
spec:
- question_name: Basic Name
question_description: Name
required: true
type: text
variable: basic_name
min: 0
max: 1024
default: ''
choices: ''
new_question: true
- question_name: Choose yes or no?
question_description: Choosing yes or no.
required: false
type: multiplechoice
variable: option_true_false
min:
max:
default: 'yes'
choices: |-
yes
no
new_question: true
- assert:
that:
- result is not failed
- name: Kick off a workflow with survey
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
basic_name: My First Variable
option_true_false: 'no'
ignore_errors: true
register: result
- name: Prompt the workflow's extra_vars on launch
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
ask_variables_on_launch: true
- assert:
that:
- result is not failed
- name: Kick off a workflow with extra_vars
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
basic_name: My First Variable
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- name: Prompt the workflow's extra_vars on launch
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: present
ask_variables_on_launch: true
- assert:
that:
- result is not failed
- name: Kick off a workflow with extra_vars
tower_workflow_launch:
workflow_template: "{{ wfjt_name1 }}"
extra_vars:
basic_name: My First Variable
var1: My First Variable
var2: My Second Variable
ignore_errors: true
register: result
- name: Clean up test workflow
tower_workflow_job_template:
name: "{{ wfjt_name1 }}"
state: absent
- assert:
that:
- result is not failed
- name: Test waiting for an approval node that doesn't exit on the last workflow for failure.
tower_workflow_approval:
workflow_job_id: "{{ result.id }}"
name: Test workflow approval
interval: 1
timeout: 2
action: deny
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Monitoring of Workflow Approval - Test workflow approval aborted due to timeout' in result.msg"
- name: Create new Workflow
tower_workflow_job_template:
name: "{{ wfjt_name2 }}"
state: present
- name: Add a job node
tower_workflow_job_template_node:
workflow_job_template: "{{ wfjt_name2 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
# Test tower_workflow_approval and tower_workflow_node_wait
- name: Create approval node
tower_workflow_job_template_node:
identifier: approval_test
approval_node:
name: "{{ approval_node_name }}"
timeout: 900
workflow: "{{ wfjt_name2 }}"
- name: Create link for approval node
tower_workflow_job_template_node:
identifier: approval_test
workflow: "{{ wfjt_name2 }}"
always_nodes:
- leaf
- name: Run the workflow without waiting This should pause waiting for approval
tower_workflow_launch:
workflow_template: "{{ wfjt_name2 }}"
wait: false
ignore_errors: true
register: wfjt_info
- name: Wait for Job node wait to fail as it is waiting on approval
awx.awx.tower_workflow_node_wait:
workflow_job_id: "{{ wfjt_info.id }}"
name: Demo Job Template
interval: 1
timeout: 5
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'Monitoring of Workflow Node - Demo Job Template aborted due to timeout' in result.msg"
- name: Wait for approval node to activate and approve
awx.awx.tower_workflow_approval:
workflow_job_id: "{{ wfjt_info.id }}"
name: "{{ approval_node_name }}"
interval: 1
timeout: 10
action: deny
register: result
- assert:
that:
- result is not failed
- result is changed
- name: Wait for workflow job to finish max 120s
tower_job_wait:
job_id: "{{ wfjt_info.id }}"
timeout: 120
job_type: "workflow_jobs"
always:
- name: Clean up test workflow
tower_workflow_job_template:
name: "{{ item }}"
state: absent
with_items:
- "{{ wfjt_name1 }}"
- "{{ wfjt_name2 }}"