Skip to content

Commit

Permalink
ImageUpgradeTask: Fix idempotence for merged state
Browse files Browse the repository at this point in the history
Fix an intermittent idempotence issue found by the integration tests.

have.status was sometimes reported as "Not-In-Sync" which caused upgrade.nxos to be set to True, which cause unnecessary upgrade.  The fix was to remove have.status from consideration.  We now consider only have.reason, have.policy, and have.upgrade.
  • Loading branch information
allenrobel committed Jan 23, 2024
1 parent 6247470 commit a37a01f
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions plugins/modules/dcnm_image_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,25 +599,33 @@ def _build_idempotent_want(self, want) -> None:
# if the image is already validated, don't validate it again
if self.have.validated == "Success":
self.idempotent_want["validate"] = False

msg = f"self.have.reason: {self.have.reason}, "
msg += f"self.have.policy: {self.have.policy}, "
msg += f"idempotent_want[policy]: {self.idempotent_want['policy']}, "
msg += f"self.have.upgrade: {self.have.upgrade}"
self.log.debug(msg)

# if the image is already upgraded, don't upgrade it again
if (
self.have.status == "In-Sync"
and self.have.reason == "Upgrade"
and self.have.policy == want["policy"]
self.have.reason == "Upgrade"
and self.have.policy == self.idempotent_want["policy"]
# If upgrade is other than Success, we need to try to upgrade
# again. So only change upgrade.nxos if upgrade is Success.
and self.have.upgrade == "Success"
):
msg = "Set upgrade nxos to False"
self.log.debug(msg)
self.idempotent_want["upgrade"]["nxos"] = False

# Get relevant install options from the controller
# based on the options in our want item
# based on the options in our idempotent_want item
instance = ImageInstallOptions(self.module)
instance.policy_name = want["policy"]
instance.policy_name = self.idempotent_want["policy"]
instance.serial_number = self.have.serial_number

instance.epld = want.get("upgrade", {}).get("epld", False)
instance.issu = want.get("upgrade", {}).get("nxos", False)
instance.issu = self.idempotent_want.get("upgrade", {}).get("nxos", False)
instance.package_install = (
want.get("options", {}).get("package", {}).get("install", False)
)
Expand Down Expand Up @@ -1306,9 +1314,9 @@ def main():
# For an example configuration, see:
# $ANSIBLE_COLLECTIONS_PATH/cisco/dcnm/plugins/module_utils/common/logging_config.json
log = Log(ansible_module)
collection_path = "/Users/arobel/repos/collections/ansible_collections/cisco/dcnm"
config_file = f"{collection_path}/plugins/module_utils/common/logging_config.json"
log.config = config_file
# collection_path = "/Users/arobel/repos/collections/ansible_collections/cisco/dcnm"
# config_file = f"{collection_path}/plugins/module_utils/common/logging_config.json"
# log.config = config_file
log.commit()

task_module = ImageUpgradeTask(ansible_module)
Expand Down

0 comments on commit a37a01f

Please sign in to comment.