Browse Source

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
Bob Fournier 5 months ago
parent
commit
7703aab662

+ 7
- 1
ironic_inspector/plugins/local_link_connection.py View File

@@ -16,6 +16,7 @@
16 16
 import binascii
17 17
 
18 18
 from construct import core
19
+from ironicclient import exceptions
19 20
 import netaddr
20 21
 from oslo_config import cfg
21 22
 from oslo_utils import netutils
@@ -157,4 +158,9 @@ class GenericLocalLinkConnectionHook(base.ProcessingHook):
157 158
                     if patch is not None:
158 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)

+ 18
- 0
ironic_inspector/test/unit/test_plugins_local_link_connection.py View File

@@ -11,6 +11,7 @@
11 11
 # See the License for the specific language governing permissions and
12 12
 # limitations under the License.
13 13
 
14
+from ironicclient import exceptions
14 15
 import mock
15 16
 from oslo_config import cfg
16 17
 
@@ -211,3 +212,20 @@ class TestGenericLocalLinkConnectionHook(test_base.NodeTest):
211 212
         ]
212 213
         self.hook.before_update(self.data, self.node_info)
213 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)

+ 6
- 0
releasenotes/notes/handle-patch-port-failure-9a8b85749104506f.yaml View File

@@ -0,0 +1,6 @@
1
+---
2
+fixes:
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.

Loading…
Cancel
Save