summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Fournier <bfournie@redhat.com>2018-11-04 19:22:54 -0500
committerBob Fournier <bfournie@redhat.com>2018-11-13 08:19:14 -0500
commit7703aab662db2de8e8fd75d739a923637c3d111f (patch)
tree175e21d7d2558997e192e5a16384b2c9e24c93b7
parent054f300290c45035bb1cc1b222b2cc8cf26c3002 (diff)
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
Notes
Notes (review): Code-Review+2: Kaifeng Wang <kaifeng.w@gmail.com> Code-Review+2: Dmitry Tantsur <divius.inside@gmail.com> Workflow+1: Dmitry Tantsur <divius.inside@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 15 Nov 2018 14:00:02 +0000 Reviewed-on: https://review.openstack.org/615456 Project: openstack/ironic-inspector Branch: refs/heads/master
-rw-r--r--ironic_inspector/plugins/local_link_connection.py8
-rw-r--r--ironic_inspector/test/unit/test_plugins_local_link_connection.py18
-rw-r--r--releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml6
3 files changed, 31 insertions, 1 deletions
diff --git a/ironic_inspector/plugins/local_link_connection.py b/ironic_inspector/plugins/local_link_connection.py
index bb86ba0..aea9faa 100644
--- a/ironic_inspector/plugins/local_link_connection.py
+++ b/ironic_inspector/plugins/local_link_connection.py
@@ -16,6 +16,7 @@
16import binascii 16import binascii
17 17
18from construct import core 18from construct import core
19from ironicclient import exceptions
19import netaddr 20import netaddr
20from oslo_config import cfg 21from oslo_config import cfg
21from oslo_utils import netutils 22from oslo_utils import netutils
@@ -157,4 +158,9 @@ class GenericLocalLinkConnectionHook(base.ProcessingHook):
157 if patch is not None: 158 if patch is not None:
158 patches.append(patch) 159 patches.append(patch)
159 160
160 node_info.patch_port(port, patches) 161 try:
162 node_info.patch_port(port, patches)
163 except exceptions.BadRequest as e:
164 LOG.warning("Failed to update port %(uuid)s: %(error)s",
165 {'uuid': port.uuid, 'error': e},
166 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 a574816..b068720 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 @@
11# See the License for the specific language governing permissions and 11# See the License for the specific language governing permissions and
12# limitations under the License. 12# limitations under the License.
13 13
14from ironicclient import exceptions
14import mock 15import mock
15from oslo_config import cfg 16from oslo_config import cfg
16 17
@@ -211,3 +212,20 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
211 ] 212 ]
212 self.hook.before_update(self.data, self.node_info) 213 self.hook.before_update(self.data, self.node_info)
213 self.assertCalledWithPatch(patches, mock_patch) 214 self.assertCalledWithPatch(patches, mock_patch)
215
216 @mock.patch('ironic_inspector.plugins.local_link_connection.LOG')
217 @mock.patch.object(node_cache.NodeInfo, 'patch_port')
218 def test_patch_port_exception(self, mock_patch, mock_log):
219 self.data['all_interfaces'] = {
220 'em1': {"ip": self.ips[0], "mac": self.macs[0],
221 "lldp_processed": {
222 "switch_chassis_id": "192.0.2.1",
223 "switch_port_id": "Ethernet2/66"}
224 }
225 }
226
227 mock_patch.side_effect = exceptions.BadRequest('invalid data')
228 self.hook.before_update(self.data, self.node_info)
229 log_msg = ("Failed to update port %(uuid)s: %(error)s")
230 mock_log.warning.assert_called_with(log_msg, mock.ANY,
231 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 0000000..41393fa
--- /dev/null
+++ b/releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml
@@ -0,0 +1,6 @@
1---
2fixes:
3 - Fixes issue that can result in introspection failure when a network switch
4 sends incomplete information for LLDP switch_id or port_id. The validation
5 expects these fields when a port is updated, this fix now handles the
6 validation exception.