From a12d1af6805de8525258c83fd95e803cba78617a Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Mon, 21 Mar 2016 14:40:35 +0000 Subject: [PATCH] Better error handling when converting eDeploy data When attempting to convert some eDeploy data to integer, inspector will handle the ValueError exception which works fine for strings that are not interger-like. But, when this data is None a TypeError exception will be raised which wasn't handlded before, this patch is fixing it. Closes-Bug: #1560050 Change-Id: I830a1a88c765c6471c457e383c7e859fd7f93ef9 --- ironic_inspector/plugins/extra_hardware.py | 2 +- ironic_inspector/test/test_plugins_extra_hardware.py | 11 +++++++++++ .../notes/edeploy-typeerror-6486e31923d91666.yaml | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/edeploy-typeerror-6486e31923d91666.yaml diff --git a/ironic_inspector/plugins/extra_hardware.py b/ironic_inspector/plugins/extra_hardware.py index e9fa6d955..9a65dfc5d 100644 --- a/ironic_inspector/plugins/extra_hardware.py +++ b/ironic_inspector/plugins/extra_hardware.py @@ -96,7 +96,7 @@ class ExtraHardwareHook(base.ProcessingHook): try: item[3] = int(item[3]) - except ValueError: + except (ValueError, TypeError): pass converted_1[item[2]] = item[3] diff --git a/ironic_inspector/test/test_plugins_extra_hardware.py b/ironic_inspector/test/test_plugins_extra_hardware.py index 84c44371b..54fcf2f2b 100644 --- a/ironic_inspector/test/test_plugins_extra_hardware.py +++ b/ironic_inspector/test/test_plugins_extra_hardware.py @@ -84,3 +84,14 @@ class TestExtraHardware(test_base.NodeTest): self.hook.before_update(introspection_data, self.node_info) self.assertFalse(patch_mock.called) self.assertFalse(swift_conn.create_object.called) + + def test__convert_edeploy_data(self, patch_mock, swift_mock): + introspection_data = [['Sheldon', 'J.', 'Plankton', '123'], + ['Larry', 'the', 'Lobster', None], + ['Eugene', 'H.', 'Krabs', 'The cashier']] + + data = self.hook._convert_edeploy_data(introspection_data) + expected_data = {'Sheldon': {'J.': {'Plankton': 123}}, + 'Larry': {'the': {'Lobster': None}}, + 'Eugene': {'H.': {'Krabs': 'The cashier'}}} + self.assertEqual(expected_data, data) diff --git a/releasenotes/notes/edeploy-typeerror-6486e31923d91666.yaml b/releasenotes/notes/edeploy-typeerror-6486e31923d91666.yaml new file mode 100644 index 000000000..f51af3180 --- /dev/null +++ b/releasenotes/notes/edeploy-typeerror-6486e31923d91666.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - Fixes a problem which caused an unhandled TypeError exception to + bubble up when inspector was attempting to convert some eDeploy data + to integer.