mirror of
https://github.com/ansible/awx.git
synced 2026-02-01 01:28:09 -03:30
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:
@@ -743,3 +743,37 @@ class TowerAPIModule(TowerModule):
|
||||
def wait_output(self, response):
|
||||
for k in ('id', 'status', 'elapsed', 'started', 'finished'):
|
||||
self.json_output[k] = response['json'].get(k)
|
||||
|
||||
def wait_on_workflow_node_url(self, url, object_name, object_type, timeout=30, interval=10, **kwargs):
|
||||
# Grab our start time to compare against for the timeout
|
||||
start = time.time()
|
||||
result = self.get_endpoint(url, **kwargs)
|
||||
|
||||
while result["json"]["count"] == 0:
|
||||
# If we are past our time out fail with a message
|
||||
if timeout and timeout < time.time() - start:
|
||||
# Account for Legacy messages
|
||||
self.json_output["msg"] = "Monitoring of {0} - {1} aborted due to timeout, {2}".format(object_type, object_name, url)
|
||||
self.wait_output(result)
|
||||
self.fail_json(**self.json_output)
|
||||
|
||||
# Put the process to sleep for our interval
|
||||
time.sleep(interval)
|
||||
result = self.get_endpoint(url, **kwargs)
|
||||
|
||||
if object_type == "Workflow Approval":
|
||||
# Approval jobs have no elapsed time so return
|
||||
return result["json"]["results"][0]
|
||||
else:
|
||||
# Removed time so far from timeout.
|
||||
revised_timeout = timeout - (time.time() - start)
|
||||
# Now that Job has been found, wait for it to finish
|
||||
result = self.wait_on_url(
|
||||
url=result["json"]["results"][0]["related"]["job"],
|
||||
object_name=object_name,
|
||||
object_type=object_type,
|
||||
timeout=revised_timeout,
|
||||
interval=interval,
|
||||
)
|
||||
self.json_output["job_data"] = result["json"]
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user