Improve error handling of extra_hardware
extra_hardware plugin saves data to Swift, if Swift is not available or accessible, the collected information will not be processed and consumed. Change-Id: I6cae8d84ac73ea656f0e305bc408c4788aefa1fa Story: 2005691 Task: 31011
This commit is contained in:
parent
b8d1bda4c6
commit
09938a3975
@ -53,7 +53,15 @@ class ExtraHardwareHook(base.ProcessingHook):
|
||||
data = introspection_data['data']
|
||||
|
||||
name = 'extra_hardware-%s' % node_info.uuid
|
||||
try:
|
||||
self._store_extra_hardware(name, json.dumps(data))
|
||||
except utils.Error as e:
|
||||
LOG.error("Failed to save extra hardware information in "
|
||||
"Swift: %s", e, node_info=node_info)
|
||||
else:
|
||||
node_info.patch([{'op': 'add',
|
||||
'path': '/extra/hardware_swift_object',
|
||||
'value': name}])
|
||||
|
||||
# NOTE(sambetts) If data is edeploy format, convert to dicts for rules
|
||||
# processing, store converted data in introspection_data['extra'].
|
||||
@ -76,9 +84,6 @@ class ExtraHardwareHook(base.ProcessingHook):
|
||||
node_info=node_info, data=introspection_data)
|
||||
del introspection_data['data']
|
||||
|
||||
node_info.patch([{'op': 'add', 'path': '/extra/hardware_swift_object',
|
||||
'value': name}])
|
||||
|
||||
def _is_edeploy_data(self, data):
|
||||
return all(isinstance(item, list) and len(item) == EDEPLOY_ITEM_SIZE
|
||||
for item in data)
|
||||
|
@ -18,6 +18,7 @@ import mock
|
||||
from ironic_inspector import node_cache
|
||||
from ironic_inspector.plugins import extra_hardware
|
||||
from ironic_inspector.test import base as test_base
|
||||
from ironic_inspector import utils
|
||||
|
||||
|
||||
@mock.patch.object(extra_hardware.swift, 'SwiftAPI', autospec=True)
|
||||
@ -95,3 +96,39 @@ class TestExtraHardware(test_base.NodeTest):
|
||||
'Larry': {'the': {'Lobster': None}},
|
||||
'Eugene': {'H.': {'Krabs': 'The cashier'}}}
|
||||
self.assertEqual(expected_data, data)
|
||||
|
||||
def test_swift_access_failed(self, patch_mock, swift_mock):
|
||||
introspection_data = {
|
||||
'data': [['memory', 'total', 'size', '4294967296'],
|
||||
['cpu', 'physical', 'number', '1'],
|
||||
['cpu', 'logical', 'number', '1']]}
|
||||
data = json.dumps(introspection_data['data'])
|
||||
name = 'extra_hardware-%s' % self.uuid
|
||||
|
||||
swift_conn = swift_mock.return_value
|
||||
swift_conn.create_object.side_effect = utils.Error('no one')
|
||||
|
||||
self.hook.before_processing(introspection_data)
|
||||
self.hook.before_update(introspection_data, self.node_info)
|
||||
|
||||
swift_conn.create_object.assert_called_once_with(name, data)
|
||||
patch_mock.assert_not_called()
|
||||
|
||||
expected = {
|
||||
'memory': {
|
||||
'total': {
|
||||
'size': 4294967296
|
||||
}
|
||||
},
|
||||
'cpu': {
|
||||
'physical': {
|
||||
'number': 1
|
||||
},
|
||||
'logical': {
|
||||
'number': 1
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
self.assertNotIn('data', introspection_data)
|
||||
self.assertEqual(expected, introspection_data['extra'])
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes an issue when extra_hardware plugin failed to save extra hardware
|
||||
information to Swift, the collected information is not processed and
|
||||
consumed.
|
Loading…
Reference in New Issue
Block a user