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
This commit is contained in:
Lucas Alvares Gomes 2016-03-21 14:40:35 +00:00
parent 7b7fba72de
commit a12d1af680
3 changed files with 17 additions and 1 deletions

View File

@ -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]

View File

@ -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)

View File

@ -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.