Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the maximum timeout for checking the execution of task id and execution id #278

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions plugins/module_utils/dnac.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def __init__(self, module):
'parsed': self.verify_diff_parsed
}
self.dnac_log = dnac_params.get("dnac_log")
self.max_timeout = self.params.get('dnac_api_task_timeout')

if self.dnac_log and not DnacBase.__is_log_init:
self.dnac_log_level = dnac_params.get("dnac_log_level") or 'WARNING'
Expand Down Expand Up @@ -331,7 +332,14 @@ def check_task_response_status(self, response, validation_string, data=False):
return self

task_id = response.get("taskId")
start_time = time.time()
while True:
end_time = time.time()
if (end_time - start_time) >= self.max_timeout:
self.log("Max timeout of {0} sec has reached for the execution id '{1}'. Exiting the loop due to unexpected API status."
.format(self.max_timeout, task_id), "WARNING")
break

task_details = self.get_task_details(task_id)
self.log('Getting task details from task ID {0}: {1}'.format(task_id, task_details), "DEBUG")
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -350,7 +358,7 @@ def check_task_response_status(self, response, validation_string, data=False):
self.status = "success"
break

self.log("progress set to {0} for taskid: {1}".format(task_details.get('progress'), task_id), "DEBUG")
self.log("Progress is {0} for task ID: {1}".format(task_details.get('progress'), task_id), "DEBUG")

return self

Expand Down Expand Up @@ -401,9 +409,16 @@ def check_execution_response_status(self, response):
self.status = "failed"
return self

executionid = response.get("executionId")
execution_id = response.get("executionId")
start_time = time.time()
while True:
execution_details = self.get_execution_details(executionid)
end_time = time.time()
if (end_time - start_time) >= self.max_timeout:
self.log("Max timeout of {0} sec has reached for the execution id '{1}'. Exiting the loop due to unexpected API status."
MUTHU-RAKESH-27 marked this conversation as resolved.
Show resolved Hide resolved
.format(self.max_timeout, execution_id), "WARNING")
break

execution_details = self.get_execution_details(execution_id)
if execution_details.get("status") == "SUCCESS":
self.result['changed'] = True
self.msg = "Successfully executed"
Expand Down Expand Up @@ -529,15 +544,14 @@ def check_status_api_events(self, status_execution_id):
response from the API. If the timeout is reached first, the method logs a warning and returns None.
"""

max_timeout = self.params.get('dnac_api_task_timeout')
events_response = None
start_time = time.time()

while True:
end_time = time.time()
if (end_time - start_time) >= max_timeout:
if (end_time - start_time) >= self.max_timeout:
self.log("""Max timeout of {0} sec has reached for the execution id '{1}' for the event and unexpected
api status so moving out of the loop.""".format(max_timeout, status_execution_id), "WARNING")
api status so moving out of the loop.""".format(self.max_timeout, status_execution_id), "WARNING")
break
# Now we check the status of API Events for configuring destination and notifications
response = self.dnac._exec(
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/network_settings_workflow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ def get_have_network(self, network_details):

site_id = self.get_site_id(site_name)
if site_id is None:
self.msg = "Failed to get site id from {0}".format(site_name)
self.msg = "The site with the name '{0}' is not available in the Catalyst Center".format(site_name)
self.status = "failed"
return self

Expand Down