mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 12:20:45 -03:30
clean up and tests added
This commit is contained in:
parent
9bcb5ef0c9
commit
a2c8e3d87e
@ -93,6 +93,24 @@ options:
|
||||
- Can be a job template, project, inventory source, etc.
|
||||
- Omit if creating an approval node (not yet implemented).
|
||||
type: str
|
||||
approval_node:
|
||||
description:
|
||||
- A dictionary of Name, description, and timeout values for the approval node.
|
||||
type: dict
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
- Name of this workflow approval template.
|
||||
type: str
|
||||
required: True
|
||||
description:
|
||||
description:
|
||||
- Optional description of this workflow approval template.
|
||||
type: str
|
||||
timeout:
|
||||
description:
|
||||
- The amount of time (in seconds) before the approval node expires and fails.
|
||||
type: int
|
||||
all_parents_must_converge:
|
||||
description:
|
||||
- If enabled then the node will only run if all of the parent nodes have met the criteria to reach this node
|
||||
@ -166,10 +184,6 @@ def main():
|
||||
identifier=dict(required=True),
|
||||
workflow_job_template=dict(required=True, aliases=['workflow']),
|
||||
organization=dict(),
|
||||
approval_node=dict(type='bool'),
|
||||
name=dict(),
|
||||
description=dict(),
|
||||
timeout=dict(type='int'),
|
||||
extra_data=dict(type='dict'),
|
||||
inventory=dict(),
|
||||
scm_branch=dict(),
|
||||
@ -180,11 +194,11 @@ def main():
|
||||
diff_mode=dict(type='bool'),
|
||||
verbosity=dict(choices=['0', '1', '2', '3', '4', '5']),
|
||||
unified_job_template=dict(),
|
||||
approval_node=dict(type='dict'),
|
||||
all_parents_must_converge=dict(type='bool'),
|
||||
success_nodes=dict(type='list', elements='str'),
|
||||
always_nodes=dict(type='list', elements='str'),
|
||||
failure_nodes=dict(type='list', elements='str'),
|
||||
approval_nodes=dict(type='list', elements='str'),
|
||||
credentials=dict(type='list', elements='str'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
)
|
||||
@ -196,9 +210,6 @@ def main():
|
||||
identifier = module.params.get('identifier')
|
||||
state = module.params.get('state')
|
||||
approval_node = module.params.get('approval_node')
|
||||
name = module.params.get('name')
|
||||
description = module.params.get('description')
|
||||
timeout = module.params.get('timeout')
|
||||
new_fields = {}
|
||||
search_fields = {'identifier': identifier}
|
||||
|
||||
@ -245,7 +256,7 @@ def main():
|
||||
new_fields[field_name] = field_val
|
||||
|
||||
association_fields = {}
|
||||
for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'approval_nodes', 'credentials'):
|
||||
for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'credentials'):
|
||||
name_list = module.params.get(association)
|
||||
if name_list is None:
|
||||
continue
|
||||
@ -275,23 +286,31 @@ def main():
|
||||
endpoint='workflow_job_template_nodes', item_type='workflow_job_template_node', on_continue=approval_node,
|
||||
associations=association_fields
|
||||
)
|
||||
|
||||
# Create approval node unified template or update existing
|
||||
if approval_node:
|
||||
# Set Approval Fields
|
||||
new_fields = {}
|
||||
if name is not None:
|
||||
new_fields['name'] = name
|
||||
if description is not None:
|
||||
new_fields['description'] = description
|
||||
if timeout is not None:
|
||||
new_fields['timeout'] = timeout
|
||||
# Find created approval node ID
|
||||
|
||||
# Extract Parameters
|
||||
if approval_node.get('name') is None:
|
||||
module.fail_json(msg="Approval node name is required to create approval node.")
|
||||
if approval_node.get('name') is not None:
|
||||
new_fields['name'] = approval_node['name']
|
||||
if approval_node.get('description') is not None:
|
||||
new_fields['description'] = approval_node['description']
|
||||
if approval_node.get('timeout') is not None:
|
||||
new_fields['timeout'] = approval_node['timeout']
|
||||
|
||||
# Find created workflow node ID
|
||||
search_fields = {'identifier': identifier}
|
||||
search_fields['workflow_job_template'] = workflow_job_template_id
|
||||
workflow_job_template_node = module.get_one('workflow_job_template_nodes', **{'data': search_fields})
|
||||
workflow_job_template_node_id = workflow_job_template_node['id']
|
||||
# Due to not able to lookup workflow_approval_templates, none existing item
|
||||
existing_item = {}
|
||||
# module.fail_json(msg="workflow_job_template_nodes/{0}/create_approval_template/".format(workflow_job_template_node_id))
|
||||
module.json_output['workflow_node_id'] = workflow_job_template_node_id
|
||||
# Due to not able to lookup workflow_approval_templates, find the existing item in another place
|
||||
if workflow_job_template_node['related'].get('unified_job_template') is not None:
|
||||
existing_item = module.get_endpoint(workflow_job_template_node['related']['unified_job_template'])['json']
|
||||
module.create_or_update_if_needed(
|
||||
existing_item, new_fields,
|
||||
endpoint='workflow_job_template_nodes/' + str(workflow_job_template_node_id) + '/create_approval_template/', item_type='workflow_job_template_approval_node', on_continue=approval_node,
|
||||
|
||||
@ -100,7 +100,7 @@
|
||||
# Make sure that we failed and that we have some data in our results
|
||||
- assert:
|
||||
that:
|
||||
- "wait_results.msg == 'Monitoring aborted due to timeout' or 'Timeout waiting for job to finish.'"
|
||||
- "wait_results.msg == 'Approval node name is required to create approval node.'"
|
||||
- "'id' in wait_results"
|
||||
|
||||
- name: Async cancel the long running job
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
demo_project_name: "AWX-Collection-tests-tower_workflow_job_template-proj-{{ test_id }}"
|
||||
jt1_name: "AWX-Collection-tests-tower_workflow_job_template-jt1-{{ test_id }}"
|
||||
jt2_name: "AWX-Collection-tests-tower_workflow_job_template-jt2-{{ test_id }}"
|
||||
approval_node_name: "AWX-Collection-tests-tower_workflow_approval_node-{{ test_id }}"
|
||||
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ test_id }}"
|
||||
wfjt_name: "AWX-Collection-tests-tower_workflow_job_template-wfjt-{{ test_id }}"
|
||||
email_not: "AWX-Collection-tests-tower_job_template-email-not-{{ test_id }}"
|
||||
@ -145,6 +146,36 @@
|
||||
unified_job_template: "{{ jt1_name }}"
|
||||
workflow: "{{ wfjt_name }}"
|
||||
|
||||
- name: Fail if no name is set for approval
|
||||
tower_workflow_job_template_node:
|
||||
identifier: approval_test
|
||||
approval_node:
|
||||
description: "{{ approval_node_name }}"
|
||||
workflow: "{{ wfjt_name }}"
|
||||
register: no_name_results
|
||||
ignore_errors: true
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "no_name_results.msg == 'Approval node name is required to create approval node.'"
|
||||
|
||||
- name: Create approval node
|
||||
awx.awx.tower_workflow_job_template_node:
|
||||
identifier: approval_test
|
||||
approval_node:
|
||||
name: "{{ approval_node_name }}"
|
||||
timeout: 900
|
||||
workflow: test
|
||||
|
||||
- name: Create link for root node
|
||||
tower_workflow_job_template_node:
|
||||
identifier: root
|
||||
workflow: "{{ wfjt_name }}"
|
||||
success_nodes:
|
||||
- approval_test
|
||||
always_nodes:
|
||||
- leaf
|
||||
|
||||
- name: Add started notifications to workflow job template
|
||||
tower_workflow_job_template:
|
||||
name: "{{ wfjt_name }}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user