From 7703aab662db2de8e8fd75d739a923637c3d111f Mon Sep 17 00:00:00 2001 From: Bob Fournier Date: Sun, 4 Nov 2018 19:22:54 -0500 Subject: [PATCH] Handle validation failure if not all switch fields received The Ironic API has a validation on the LocalLinkConnectionType to ensure all mandatory values are included. Handle failures which could occur if the switch does not send all mandatory fields. Change-Id: I8716a69586265a58520cc2c6bc0bbc00a7c159da Story: 2004238 Task: 27761 --- .../plugins/local_link_connection.py | 8 +++++++- .../unit/test_plugins_local_link_connection.py | 18 ++++++++++++++++++ ...le-patch-port-failure-9a8b85749104506f.yaml | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml diff --git a/ironic_inspector/plugins/local_link_connection.py b/ironic_inspector/plugins/local_link_connection.py index bb86ba08a..aea9faa7d 100644 --- a/ironic_inspector/plugins/local_link_connection.py +++ b/ironic_inspector/plugins/local_link_connection.py @@ -16,6 +16,7 @@ import binascii from construct import core +from ironicclient import exceptions import netaddr from oslo_config import cfg from oslo_utils import netutils @@ -157,4 +158,9 @@ class GenericLocalLinkConnectionHook(base.ProcessingHook): if patch is not None: patches.append(patch) - node_info.patch_port(port, patches) + try: + node_info.patch_port(port, patches) + except exceptions.BadRequest as e: + LOG.warning("Failed to update port %(uuid)s: %(error)s", + {'uuid': port.uuid, 'error': e}, + node_info=node_info) diff --git a/ironic_inspector/test/unit/test_plugins_local_link_connection.py b/ironic_inspector/test/unit/test_plugins_local_link_connection.py index a57481633..b0687203d 100644 --- a/ironic_inspector/test/unit/test_plugins_local_link_connection.py +++ b/ironic_inspector/test/unit/test_plugins_local_link_connection.py @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ironicclient import exceptions import mock from oslo_config import cfg @@ -211,3 +212,20 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest): ] self.hook.before_update(self.data, self.node_info) self.assertCalledWithPatch(patches, mock_patch) + + @mock.patch('ironic_inspector.plugins.local_link_connection.LOG') + @mock.patch.object(node_cache.NodeInfo, 'patch_port') + def test_patch_port_exception(self, mock_patch, mock_log): + self.data['all_interfaces'] = { + 'em1': {"ip": self.ips[0], "mac": self.macs[0], + "lldp_processed": { + "switch_chassis_id": "192.0.2.1", + "switch_port_id": "Ethernet2/66"} + } + } + + mock_patch.side_effect = exceptions.BadRequest('invalid data') + self.hook.before_update(self.data, self.node_info) + log_msg = ("Failed to update port %(uuid)s: %(error)s") + mock_log.warning.assert_called_with(log_msg, mock.ANY, + node_info=mock.ANY) diff --git a/releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml b/releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml new file mode 100644 index 000000000..41393fa38 --- /dev/null +++ b/releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - Fixes issue that can result in introspection failure when a network switch + sends incomplete information for LLDP switch_id or port_id. The validation + expects these fields when a port is updated, this fix now handles the + validation exception.