From 50e97805ae0a86cf89561768ab7f0c6facd84fec Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 17 Feb 2025 17:19:16 -0600 Subject: [PATCH] ironic: fix logging of validation errors When validation of the node fails, since switching to the SDK the address of the ValidationResult object is displayed instead of the actual message. This has been broken since patch Ibb5b168ee0944463b996e96f033bd3dfb498e304. Closes-Bug: 2100009 Change-Id: I8fbdaadd125ece6a3050b2fbb772a7bd5d7e5304 Signed-off-by: Doug Goldstein (cherry picked from commit 37888e875f0cef8350991b6a9cb81da9dacc1bac) (cherry picked from commit 3242cde34232d0c65629f8c6866d0f2ddef7cda3) --- nova/tests/unit/virt/ironic/test_driver.py | 11 +++++++---- nova/virt/ironic/driver.py | 12 +++++++++--- ...ronic-validate-node-message-6a8b1eedbddd06fd.yaml | 7 +++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/ironic-validate-node-message-6a8b1eedbddd06fd.yaml diff --git a/nova/tests/unit/virt/ironic/test_driver.py b/nova/tests/unit/virt/ironic/test_driver.py index e696a24c00b2..711de8df6359 100644 --- a/nova/tests/unit/virt/ironic/test_driver.py +++ b/nova/tests/unit/virt/ironic/test_driver.py @@ -1582,15 +1582,18 @@ class IronicDriverTestCase(test.NoDBTestCase): self.mock_conn.validate_node.return_value = \ ironic_utils.get_test_validation( - power=_node.ValidationResult(result=False, reason=None), + power=_node.ValidationResult(result=False, reason='OVERVOLT'), deploy=_node.ValidationResult(result=False, reason=None), - storage=_node.ValidationResult(result=False, reason=None), + storage=_node.ValidationResult(result=True, reason=None), ) self.mock_conn.get_node.return_value = node image_meta = ironic_utils.get_test_image_meta() - self.assertRaises(exception.ValidationError, self.driver.spawn, - self.ctx, instance, image_meta, [], None, {}) + msgre = '.*deploy: None, power: OVERVOLT, storage: No Error.*' + + self.assertRaisesRegex(exception.ValidationError, msgre, + self.driver.spawn, self.ctx, instance, image_meta, + [], None, {}) self.mock_conn.get_node.assert_called_once_with( node_id, fields=ironic_driver._NODE_FIELDS) mock_avti.assert_called_once_with(self.ctx, instance, None) diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index 271728d989ec..4468a365e96f 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -1211,14 +1211,20 @@ class IronicDriver(virt_driver.ComputeDriver): ): # something is wrong. undo what we have done self._cleanup_deploy(node, instance, network_info) + deploy_msg = ("No Error" if validate_chk['deploy'].result + else validate_chk['deploy'].reason) + power_msg = ("No Error" if validate_chk['power'].result + else validate_chk['power'].reason) + storage_msg = ("No Error" if validate_chk['storage'].result + else validate_chk['storage'].reason) raise exception.ValidationError(_( "Ironic node: %(id)s failed to validate. " "(deploy: %(deploy)s, power: %(power)s, " "storage: %(storage)s)") % {'id': node.id, - 'deploy': validate_chk['deploy'], - 'power': validate_chk['power'], - 'storage': validate_chk['storage']}) + 'deploy': deploy_msg, + 'power': power_msg, + 'storage': storage_msg}) # Config drive configdrive_value = None diff --git a/releasenotes/notes/ironic-validate-node-message-6a8b1eedbddd06fd.yaml b/releasenotes/notes/ironic-validate-node-message-6a8b1eedbddd06fd.yaml new file mode 100644 index 000000000000..2ac2e8940116 --- /dev/null +++ b/releasenotes/notes/ironic-validate-node-message-6a8b1eedbddd06fd.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fix displaying the reason messages from the Ironic validate node operation that + is called just before the instance is deployed on the bare metal node. The + message from Ironic is now correctly logged. + Fixes `bug 2100009 _`.