updated output

This commit is contained in:
sean-m-sullivan
2020-08-28 08:22:44 -05:00
parent 7bd3f9d63c
commit fd77a8aca5
2 changed files with 20 additions and 17 deletions

View File

@@ -594,25 +594,32 @@ class TowerAPIModule(TowerModule):
# Grab our start time to compare against for the timeout # Grab our start time to compare against for the timeout
start = time.time() start = time.time()
result = self.get_endpoint(url) result = self.get_endpoint(url)
if result['json']['finished'] is None: while not result['json']['finished']:
self.json_output['msg'] = 'Finished was not returned in the request of {0}'.format(url) # If we are past our time out fail with a message
self.fail_json(**self.json_output) if timeout and timeout < time.time() - start:
else: self.json_output['msg'] = 'Monitoring of {0} "{1}" aborted due to timeout'.format(object_type, object_name)
while not result['json']['finished']: # Format data to keep legacy compatability.
# If we are past our time out fail with a message self.wait_output(result)
if timeout and timeout < time.time() - start: self.fail_json(**self.json_output)
self.json_output['msg'] = 'Monitoring of {0} "{1}" aborted due to timeout'.format(object_type, object_name)
self.fail_json(**self.json_output)
# Put the process to sleep for our interval # Put the process to sleep for our interval
time.sleep(interval) time.sleep(interval)
result = self.get_endpoint(url) result = self.get_endpoint(url)
self.json_output['status'] = result['json']['status'] self.json_output['status'] = result['json']['status']
# If the job has failed, we want to raise a task failure for that so we get a non-zero response. # If the job has failed, we want to raise a task failure for that so we get a non-zero response.
if result['json']['failed']: if result['json']['failed']:
self.json_output['msg'] = 'The {0} "{1}" failed'.format(object_type, object_name) self.json_output['msg'] = 'The {0} "{1}" failed'.format(object_type, object_name)
# Format data to keep legacy compatability.
self.wait_output(result)
self.fail_json(**self.json_output) self.fail_json(**self.json_output)
self.wait_output(result)
return result return result
def wait_output(self, response):
# Format data to keep legacy compatability.
for k in ('id', 'status', 'elapsed', 'started', 'finished'):
self.json_output[k] = response['json'].get(k)

View File

@@ -147,10 +147,6 @@ def main():
timeout=timeout, interval=interval timeout=timeout, interval=interval
) )
# Format data to keep legacy compatability.
for k in ('id', 'status', 'elapsed', 'started', 'finished'):
module.json_output[k] = result['json'].get(k)
module.exit_json(**module.json_output) module.exit_json(**module.json_output)
if __name__ == '__main__': if __name__ == '__main__':