From cae48cfb779ef44dd1125f5043cb203ff095cd0e Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 8 Sep 2016 13:04:56 -0400 Subject: [PATCH] instantiate db with sample workflows --- awx/main/tests/manual/workflows/linear.py | 41 +++++++++++++++++ awx/main/tests/manual/workflows/linear.svg | 1 + awx/main/tests/manual/workflows/parallel.py | 46 ++++++++++++++++++++ awx/main/tests/manual/workflows/parallel.svg | 1 + 4 files changed, 89 insertions(+) create mode 100644 awx/main/tests/manual/workflows/linear.py create mode 100644 awx/main/tests/manual/workflows/linear.svg create mode 100644 awx/main/tests/manual/workflows/parallel.py create mode 100644 awx/main/tests/manual/workflows/parallel.svg diff --git a/awx/main/tests/manual/workflows/linear.py b/awx/main/tests/manual/workflows/linear.py new file mode 100644 index 0000000000..dd9918a933 --- /dev/null +++ b/awx/main/tests/manual/workflows/linear.py @@ -0,0 +1,41 @@ +# AWX +from awx.main.models import ( + WorkflowNode, + WorkflowJobTemplate, + WorkflowJob, +) +from awx.main.models.jobs import JobTemplate + +def do_init_workflow(job_template_success, job_template_fail, job_template_never): + wfjt, created = WorkflowJobTemplate.objects.get_or_create(name="linear workflow") + wfjt.delete() + wfjt, created = WorkflowJobTemplate.objects.get_or_create(name="linear workflow") + print(wfjt.id) + WorkflowNode.objects.all().delete() + if created: + nodes_success = [] + nodes_fail = [] + nodes_never = [] + for i in range(0, 2): + nodes_success.append(WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=job_template_success)) + nodes_fail.append(WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=job_template_fail)) + nodes_never.append(WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=job_template_never)) + nodes_never.append(WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=job_template_never)) + nodes_fail[1].delete() + + nodes_success[0].success_nodes.add(nodes_fail[0]) + nodes_success[0].failure_nodes.add(nodes_never[0]) + + nodes_fail[0].failure_nodes.add(nodes_success[1]) + nodes_fail[0].success_nodes.add(nodes_never[1]) + + nodes_success[1].failure_nodes.add(nodes_never[2]) + +def do_init(): + jt_success = JobTemplate.objects.get(id=5) + jt_fail= JobTemplate.objects.get(id=9) + jt_never= JobTemplate.objects.get(id=11) + do_init_workflow(jt_success, jt_fail, jt_never) + +if __name__ == "__main__": + do_init() diff --git a/awx/main/tests/manual/workflows/linear.svg b/awx/main/tests/manual/workflows/linear.svg new file mode 100644 index 0000000000..521cc0a9f2 --- /dev/null +++ b/awx/main/tests/manual/workflows/linear.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/awx/main/tests/manual/workflows/parallel.py b/awx/main/tests/manual/workflows/parallel.py new file mode 100644 index 0000000000..bd33f350ba --- /dev/null +++ b/awx/main/tests/manual/workflows/parallel.py @@ -0,0 +1,46 @@ +# AWX +from awx.main.models import ( + WorkflowNode, + WorkflowJobTemplate, + WorkflowJob, +) +from awx.main.models.jobs import JobTemplate + +def do_init_workflow(job_template_success, job_template_fail, job_template_never, jts_parallel): + wfjt, created = WorkflowJobTemplate.objects.get_or_create(name="parallel workflow") + wfjt.delete() + wfjt, created = WorkflowJobTemplate.objects.get_or_create(name="parallel workflow") + print(wfjt.id) + WorkflowNode.objects.all().delete() + if created: + node_success = WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=job_template_success) + + nodes_never = [] + for x in range(0, 3): + nodes_never.append(WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=job_template_never)) + + nodes_parallel = [] + for jt in jts_parallel: + nodes_parallel.append(WorkflowNode.objects.create(workflow_job_template=wfjt, unified_job_template=jt)) + + node_success.success_nodes.add(nodes_parallel[0]) + node_success.success_nodes.add(nodes_parallel[1]) + node_success.success_nodes.add(nodes_parallel[2]) + + # Add a failure node for each paralell node + for i, n in enumerate(nodes_parallel): + n.failure_nodes.add(nodes_never[i]) + +def do_init(): + jt_success = JobTemplate.objects.get(id=5) + jt_fail= JobTemplate.objects.get(id=9) + jt_never= JobTemplate.objects.get(id=11) + + jt_parallel = [] + jt_parallel.append(JobTemplate.objects.get(id=16)) + jt_parallel.append(JobTemplate.objects.get(id=17)) + jt_parallel.append(JobTemplate.objects.get(id=18)) + do_init_workflow(jt_success, jt_fail, jt_never, jt_parallel) + +if __name__ == "__main__": + do_init() diff --git a/awx/main/tests/manual/workflows/parallel.svg b/awx/main/tests/manual/workflows/parallel.svg new file mode 100644 index 0000000000..7d480f7308 --- /dev/null +++ b/awx/main/tests/manual/workflows/parallel.svg @@ -0,0 +1 @@ + \ No newline at end of file