Adding tower_workflow_launch (#42701)

This commit is contained in:
John Westcott IV
2019-01-18 06:08:04 -05:00
committed by John R Barker
parent 9722254618
commit e1b7acde87
5 changed files with 389 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
cloud/tower
shippable/tower/group1

View File

@@ -0,0 +1,46 @@
[
{
"asset_relation": {
"workflow_nodes": [
{
"name": "node0",
"unified_job_type": "job",
"success_nodes": [
"node1"
],
"failure_nodes": [],
"unified_job_name": "Demo Job Template",
"always_nodes": []
},
{
"name": "node1",
"unified_job_type": "job",
"success_nodes": [],
"failure_nodes": [],
"unified_job_name": "Demo Job Template",
"always_nodes": []
}
],
"roles": [
{
"team": [],
"name": "Execute",
"user": []
},
{
"team": [],
"name": "Admin",
"user": []
},
{
"team": [],
"name": "Read",
"user": []
}
],
"survey_spec": {}
},
"asset_type": "workflow",
"name": "Success Workflow"
},
]

View File

@@ -0,0 +1,78 @@
- name: Get unified job template ID for Demo Job Template"
uri:
url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/unified_job_templates/?name=Demo+Job+Template"
method: GET
password: "{{ lookup('env', 'TOWER_PASSWORD') }}"
user: "{{ lookup('env', 'TOWER_USERNAME') }}"
validate_certs: False
register: unified_job
- name: Build workflow
uri:
url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/workflow_job_templates/"
body:
name: "Success Template"
variables: "---"
extra_vars: ""
body_format: 'json'
method: 'POST'
password: "{{ lookup('env', 'TOWER_PASSWORD') }}"
status_code: 201
user: "{{ lookup('env', 'TOWER_USERNAME') }}"
validate_certs: False
register: workflow
- name: Add a node
uri:
url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/workflow_job_templates/{{ workflow.json.id }}/workflow_nodes/"
body:
credential: null
diff_mode: null
extra_data: {}
inventory: null
job_tags: null
job_type: null
limit: null
skip_tags: null
unified_job_template: "{{ unified_job.json.results[0].id }}"
verbosity: null
body_format: 'json'
method: 'POST'
password: "{{ lookup('env', 'TOWER_PASSWORD') }}"
status_code: 201
user: "{{ lookup('env', 'TOWER_USERNAME') }}"
validate_certs: False
register: node1
- name: Add a node
uri:
url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/workflow_job_templates/{{ workflow.json.id }}/workflow_nodes/"
body:
credential: null
diff_mode: null
extra_data: {}
inventory: null
job_tags: null
job_type: null
limit: null
skip_tags: null
unified_job_template: "{{ unified_job.json.results[0].id }}"
verbosity: null
body_format: 'json'
method: 'POST'
password: "{{ lookup('env', 'TOWER_PASSWORD') }}"
status_code: 201
user: "{{ lookup('env', 'TOWER_USERNAME') }}"
validate_certs: False
register: node2
- name: "Link nodes {{ node2.json.id }} to {{ node1.json.id }}"
uri:
url: "https://{{ lookup('env', 'TOWER_HOST') }}/api/v2/workflow_job_template_nodes/{{ node1.json.id }}/success_nodes/"
body: '{ "id": {{ node2.json.id }} }'
body_format: 'json'
method: 'POST'
password: "{{ lookup('env', 'TOWER_PASSWORD') }}"
status_code: 204
user: "{{ lookup('env', 'TOWER_USERNAME') }}"
validate_certs: False

View File

@@ -0,0 +1,99 @@
- name: Run a workflow with no parameters
tower_workflow_launch:
tower_verify_ssl: False
ignore_errors: true
register: result1
- assert:
that:
- result1.failed
- "'missing required arguments' in result1.msg"
- name: Fail no connect to Tower server
tower_workflow_launch:
tower_host: 127.0.0.1:22
tower_verify_ssl: False
workflow_template: "Here"
ignore_errors: True
register: result2
- assert:
that:
- result2.failed
- "'Failed to reach Tower' in result2.msg"
- name: Connect to Tower server but request an invalid workflow
tower_workflow_launch:
tower_verify_ssl: False
workflow_template: "Does Not Exist"
ignore_errors: true
register: result3
- assert:
that:
- result3.failed
- "'The requested object could not be found' in result3.msg"
- name: Connect to Tower in check_mode with a valid workflow name
tower_workflow_launch:
tower_verify_ssl: False
workflow_template: "Success Workflow"
check_mode: True
ignore_errors: true
register: result4
- assert:
that:
- not result4.failed
- "'Check mode passed' in result4.msg"
- name: Connect to Tower in check_mode with a valid workflow id
tower_workflow_launch:
tower_verify_ssl: False
workflow_template: 9999999
check_mode: True
ignore_errors: true
register: result5
- assert:
that:
- result5.failed
- "'The requested object could not be found' in result5.msg"
- name: Run the workflow without waiting (this should just give us back a job ID)
tower_workflow_launch:
tower_verify_ssl: False
workflow_template: "Success Workflow"
wait: False
ignore_errors: True
register: result6
- assert:
that:
- not result6.failed
- "'id' in result6['job_info']"
- name: Kick off a workflow and wait for it
tower_workflow_launch:
tower_verify_ssl: False
workflow_template: "Success Workflow"
ignore_errors: True
register: result7
- assert:
that:
- not result7.failed
- "'id' in result7['job_info']"
- name: Kick off a workflow and wait for it, but only for a second
tower_workflow_launch:
tower_verify_ssl: False
workflow_template: "Success Workflow"
timeout: 1
ignore_errors: True
register: result8
- assert:
that:
- result8.failed
- "'Monitoring aborted due to timeout' in result8.msg"