From c044ebd19826e825132434ff4f1010c213fb136b Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 14 May 2020 16:08:34 +0200 Subject: [PATCH] extra_hardware: stop storing raw data in swift The same information can be fetched from unprocessed introspection data, which has an advantage of working without swift. Change-Id: Id65644c27c78bb2c476166eb9095ef6acd94db7b --- ironic_inspector/plugins/extra_hardware.py | 19 ----- .../test/unit/test_plugins_extra_hardware.py | 73 +------------------ .../extra-hardware-data-2346f0163e4b7699.yaml | 7 ++ 3 files changed, 11 insertions(+), 88 deletions(-) create mode 100644 releasenotes/notes/extra-hardware-data-2346f0163e4b7699.yaml diff --git a/ironic_inspector/plugins/extra_hardware.py b/ironic_inspector/plugins/extra_hardware.py index d00dda62a..b73650f6c 100644 --- a/ironic_inspector/plugins/extra_hardware.py +++ b/ironic_inspector/plugins/extra_hardware.py @@ -18,9 +18,6 @@ string in a Swift object. The object is named 'extra_hardware-' and is stored in the 'inspector' container. """ -import json - -from ironic_inspector.common import swift from ironic_inspector.plugins import base from ironic_inspector import utils @@ -31,11 +28,6 @@ EDEPLOY_ITEM_SIZE = 4 class ExtraHardwareHook(base.ProcessingHook): """Processing hook for saving extra hardware information in Swift.""" - def _store_extra_hardware(self, name, data): - """Handles storing the extra hardware data from the ramdisk""" - swift_api = swift.SwiftAPI() - swift_api.create_object(name, data) - def before_update(self, introspection_data, node_info, **kwargs): """Stores the 'data' key from introspection_data in Swift. @@ -52,17 +44,6 @@ class ExtraHardwareHook(base.ProcessingHook): return 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']. # Delete introspection_data['data'], it is assumed unusable diff --git a/ironic_inspector/test/unit/test_plugins_extra_hardware.py b/ironic_inspector/test/unit/test_plugins_extra_hardware.py index d102fc9ea..73faa2069 100644 --- a/ironic_inspector/test/unit/test_plugins_extra_hardware.py +++ b/ironic_inspector/test/unit/test_plugins_extra_hardware.py @@ -11,38 +11,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json -from unittest 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) -@mock.patch.object(node_cache.NodeInfo, 'patch', autospec=True) class TestExtraHardware(test_base.NodeTest): hook = extra_hardware.ExtraHardwareHook() - def test_data_recieved(self, patch_mock, swift_mock): + def test_data_recieved(self): introspection_data = { 'data': [['memory', 'total', 'size', '4294967296'], ['cpu', 'physical', 'number', '1'], ['cpu', 'logical', 'number', '1']]} - data = json.dumps(introspection_data['data']) self.hook.before_processing(introspection_data) self.hook.before_update(introspection_data, self.node_info) - swift_conn = swift_mock.return_value - name = 'extra_hardware-%s' % self.uuid - swift_conn.create_object.assert_called_once_with(name, data) - patch_mock.assert_called_once_with( - self.node_info, - [{'op': 'add', 'path': '/extra/hardware_swift_object', - 'value': name}]) - expected = { 'memory': { 'total': { @@ -61,34 +44,22 @@ class TestExtraHardware(test_base.NodeTest): self.assertEqual(expected, introspection_data['extra']) - def test_data_not_in_edeploy_format(self, patch_mock, swift_mock): + def test_data_not_in_edeploy_format(self): introspection_data = { 'data': [['memory', 'total', 'size', '4294967296'], ['cpu', 'physical', 'number', '1'], {'interface': 'eth1'}]} - data = json.dumps(introspection_data['data']) self.hook.before_processing(introspection_data) self.hook.before_update(introspection_data, self.node_info) - swift_conn = swift_mock.return_value - name = 'extra_hardware-%s' % self.uuid - swift_conn.create_object.assert_called_once_with(name, data) - patch_mock.assert_called_once_with( - self.node_info, - [{'op': 'add', 'path': '/extra/hardware_swift_object', - 'value': name}]) - self.assertNotIn('data', introspection_data) - def test_no_data_recieved(self, patch_mock, swift_mock): + def test_no_data_recieved(self): introspection_data = {'cats': 'meow'} - swift_conn = swift_mock.return_value self.hook.before_processing(introspection_data) 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): + def test__convert_edeploy_data(self): introspection_data = [['Sheldon', 'J.', 'Plankton', '123'], ['Larry', 'the', 'Lobster', None], ['Eugene', 'H.', 'Krabs', 'The cashier']] @@ -98,39 +69,3 @@ 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']) diff --git a/releasenotes/notes/extra-hardware-data-2346f0163e4b7699.yaml b/releasenotes/notes/extra-hardware-data-2346f0163e4b7699.yaml new file mode 100644 index 000000000..b5d2fdd31 --- /dev/null +++ b/releasenotes/notes/extra-hardware-data-2346f0163e4b7699.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + The raw data from the ``extra_hardware`` processing hook is no longer + stored in Swift in an object named ``extra_hardware-``. + The same information is already available as part of the unprocessed + introspection data without a hard dependency on Swift.