Skip to content

Commit

Permalink
Modified returned result not to use ansible state names
Browse files Browse the repository at this point in the history
In preparation for writing integration tests, I realized that the returned results weren't very good.

There wasn't a clean way to categorize the result sections by Ansible state (at least I couldn't think of one).

1. Deleted state detaches image policies from switches
2. Merged state attaches policies, stages and validates images, and upgrades switches.
3. Query state simply returns the current ISSU state of the switch(es).

Given that the above don't really fix neatly into similar per-state actions, I removed Ansible state names from result section names and, instead, used names that describe what is being returned.

So, we have the following subsections in both the "diff" and "response" sections:

attach_policy
detach_policy
issu_status
stage
upgrade
validate
  • Loading branch information
allenrobel committed Jan 12, 2024
1 parent 4dc4cfd commit 06c673e
Show file tree
Hide file tree
Showing 7 changed files with 472 additions and 44 deletions.
21 changes: 20 additions & 1 deletion plugins/module_utils/image_mgmt/image_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,23 @@ def commit(self):
"""
method_name = inspect.stack()[0][3]

msg = "ENTERED commit()"
self.log.debug(msg)

if self.serial_numbers is None:
msg = f"{self.class_name}.{method_name}: "
msg += "call instance.serial_numbers "
msg += "before calling commit."
self.module.fail_json(msg, **self.failed_result)

msg = f"self.serial_numbers: {self.serial_numbers}"
self.log.debug(msg)
if len(self.serial_numbers) == 0:
self.properties["response"] = {"response": "No serial numbers to stage."}
self.properties["response_data"] = {
"response": "No serial numbers to stage."
}
self.properties["result"] = {"success": True}
return

self.prune_serial_numbers()
Expand Down Expand Up @@ -211,7 +221,9 @@ def commit(self):
msg += f"Controller response: {self.response}"
self.module.fail_json(msg, **self.failed_result)

self.properties["response_data"] = self.response.get("DATA")
msg = f"self.response: {self.response}"
self.log.debug(msg)
self.properties["response_data"] = self.response.get("DATA", "No Stage DATA")
self._wait_for_image_stage_to_complete()

def _wait_for_current_actions_to_complete(self):
Expand Down Expand Up @@ -284,6 +296,13 @@ def _wait_for_image_stage_to_complete(self):
if staged_status == "Success":
self.serial_numbers_done.add(serial_number)

msg = f"seconds remaining {timeout}"
self.log.debug(msg)
msg = f"serial_numbers_todo: {serial_numbers_todo}"
self.log.debug(msg)
msg = f"serial_numbers_done: {self.serial_numbers_done}"
self.log.debug(msg)

if self.serial_numbers_done != serial_numbers_todo:
msg = f"{self.class_name}.{method_name}: "
msg += "Timed out waiting for image stage to complete. "
Expand Down
6 changes: 6 additions & 0 deletions plugins/module_utils/image_mgmt/image_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ def _wait_for_image_upgrade_to_complete(self):

if upgrade_status == "Success":
self.ipv4_done.add(ipv4)
msg = f"seconds remaining {timeout}"
self.log.debug(msg)
msg = f"ipv4_done: {self.ipv4_done}"
self.log.debug(msg)
msg = f"ipv4_todo: {self.ipv4_todo}"
self.log.debug(msg)

if self.ipv4_done != self.ipv4_todo:
msg = f"{self.class_name}.{method_name}: "
Expand Down
28 changes: 24 additions & 4 deletions plugins/module_utils/image_mgmt/image_upgrade_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import inspect
import logging
# Using only for its failed_result property
from ansible_collections.cisco.dcnm.plugins.module_utils.image_mgmt.image_upgrade_task_result import \
ImageUpgradeTaskResult as Result


class ImageUpgradeCommon:
Expand All @@ -43,6 +46,7 @@ def __init__(self, module):

self.module = module
self.params = module.params

self.properties = {}
self.properties["changed"] = False
self.properties["diff"] = []
Expand Down Expand Up @@ -156,10 +160,26 @@ def failed_result(self):
"""
return a result for a failed task with no changes
"""
result = {}
result["changed"] = False
result["diff"] = []
return result
result = Result(self.module)
return result.failed_result

# @property
# def failed_result(self):
# """
# return a result for a failed task with no changes
# """
# result = {}
# result["changed"] = False
# result["diff"] = {
# "deleted": [],
# "merged": [],
# "overridden": [],
# "query": [],
# "replaced": [],
# }
# result["failed"] = True
# result["response"] = []
# return result

@property
def changed(self):
Expand Down
Loading

0 comments on commit 06c673e

Please sign in to comment.