diff --git a/plugins/module_utils/image_mgmt/image_stage.py b/plugins/module_utils/image_mgmt/image_stage.py index 86647d34c..8c2f26d5f 100644 --- a/plugins/module_utils/image_mgmt/image_stage.py +++ b/plugins/module_utils/image_mgmt/image_stage.py @@ -186,11 +186,11 @@ def commit(self): 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." - } + msg = "No serial numbers to stage." + self.properties["response"] = {"response": msg} + self.properties["response_data"] = {"response": msg} self.properties["result"] = {"success": True} return @@ -215,25 +215,30 @@ def commit(self): ) self.properties["result"] = self._handle_response(self.response, self.verb) + msg = f"payload: {self.payload}" + self.log.debug(msg) + msg = f"response: {self.response}" + self.log.debug(msg) + msg = f"result: {self.result}" + self.log.debug(msg) + if not self.result["success"]: msg = f"{self.class_name}.{method_name}: " msg = f"failed: {self.result}. " msg += f"Controller response: {self.response}" self.module.fail_json(msg, **self.failed_result) - 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() for serial_number in self.serial_numbers_done: self.issu_detail.filter = serial_number - self.issu_detail.refresh() diff = {} - diff["serial_number"] = serial_number diff["action"] = "stage" - diff["logical_name"] = self.issu_detail.device_name diff["ip_address"] = self.issu_detail.ip_address + diff["logical_name"] = self.issu_detail.device_name + diff["policy"] = self.issu_detail.policy + diff["serial_number"] = serial_number self.diff = copy.deepcopy(diff) def _wait_for_current_actions_to_complete(self): diff --git a/plugins/module_utils/image_mgmt/image_validate.py b/plugins/module_utils/image_mgmt/image_validate.py index 548b3c46c..2f5eff5b2 100644 --- a/plugins/module_utils/image_mgmt/image_validate.py +++ b/plugins/module_utils/image_mgmt/image_validate.py @@ -154,15 +154,25 @@ def commit(self) -> None: Commit the image validation request to the controller and wait for the images to be validated. """ - self.method_name = inspect.stack()[0][3] + method_name = inspect.stack()[0][3] + + msg = "ENTERED commit()" + self.log.debug(msg) if self.serial_numbers is None: - msg = f"{self.class_name}.{self.method_name}: " - msg += "call instance.serial_numbers before " - msg += "calling commit." + 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: + msg = "No serial numbers to validate." + self.properties["response"] = {"response": msg} + self.properties["response_data"] = {"response": msg} + self.properties["result"] = {"success": True} return self.prune_serial_numbers() @@ -183,7 +193,7 @@ def commit(self) -> None: self.log.debug(msg) if not self.result["success"]: - msg = f"{self.class_name}.{self.method_name}: " + msg = f"{self.class_name}.{method_name}: " msg = f"failed: {self.result}. " msg += f"Controller response: {self.response}" self.module.fail_json(msg, **self.failed_result) @@ -191,6 +201,16 @@ def commit(self) -> None: self.properties["response_data"] = self.response self._wait_for_image_validate_to_complete() + for serial_number in self.serial_numbers_done: + self.issu_detail.filter = serial_number + diff = {} + diff["action"] = "validate" + diff["ip_address"] = self.issu_detail.ip_address + diff["logical_name"] = self.issu_detail.device_name + diff["policy"] = self.issu_detail.policy + diff["serial_number"] = serial_number + self.diff = copy.deepcopy(diff) + def _wait_for_current_actions_to_complete(self) -> None: """ The controller will not validate an image if there are any actions in diff --git a/plugins/modules/dcnm_image_upgrade.py b/plugins/modules/dcnm_image_upgrade.py index 72d741bde..33f0cfae0 100644 --- a/plugins/modules/dcnm_image_upgrade.py +++ b/plugins/modules/dcnm_image_upgrade.py @@ -1076,7 +1076,8 @@ def _stage_images(self, serial_numbers) -> None: instance = ImageStage(self.module) instance.serial_numbers = serial_numbers instance.commit() - self.result.diff_stage = instance.response + for diff in instance.diff: + self.result.diff_stage = copy.deepcopy(diff) instance.response.pop("DATA", None) self.result.response_stage = instance.response @@ -1093,7 +1094,8 @@ def _validate_images(self, serial_numbers) -> None: instance = ImageValidate(self.module) instance.serial_numbers = serial_numbers instance.commit() - self.result.diff_validate = instance.payload + for diff in instance.diff: + self.result.diff_validate = copy.deepcopy(diff) self.result.response_validate = instance.response def _verify_install_options(self, devices) -> None: diff --git a/tests/unit/modules/dcnm/dcnm_image_upgrade/test_image_upgrade_image_validate.py b/tests/unit/modules/dcnm/dcnm_image_upgrade/test_image_upgrade_image_validate.py index 1774118ab..2e8a20224 100644 --- a/tests/unit/modules/dcnm/dcnm_image_upgrade/test_image_upgrade_image_validate.py +++ b/tests/unit/modules/dcnm/dcnm_image_upgrade/test_image_upgrade_image_validate.py @@ -494,8 +494,8 @@ def test_image_mgmt_validate_00022(image_validate) -> None: instance = image_validate instance.serial_numbers = [] instance.commit() - assert instance.response == {} - assert instance.result == {} + assert instance.response == {'response': 'No serial numbers to validate.'} + assert instance.result == {'success': True} def test_image_mgmt_validate_00023(monkeypatch, image_validate) -> None: