From 0f65bcf699681af7d566eaa9355cb0ace334b9eb Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 28 Jul 2020 14:12:41 +0200 Subject: [PATCH] Support retrieving unprocessed data Change-Id: Id8d2d3621385e0ef982a531609ce8c02739987a5 Depends-On: https://review.opendev.org/743504 --- doc/source/cli/index.rst | 4 +++- ironic_inspector_client/shell.py | 5 ++++- ironic_inspector_client/test/test_shell.py | 21 +++++++++++++++++-- ironic_inspector_client/test/test_v1.py | 9 ++++++++ ironic_inspector_client/v1.py | 8 +++++-- .../notes/unprocessed-7ebb1c48427bfee4.yaml | 6 ++++++ 6 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/unprocessed-7ebb1c48427bfee4.yaml diff --git a/doc/source/cli/index.rst b/doc/source/cli/index.rst index 5b9d248..149e8e0 100644 --- a/doc/source/cli/index.rst +++ b/doc/source/cli/index.rst @@ -116,11 +116,13 @@ Retrieving introspection data :: - $ openstack baremetal introspection data save [--file file_name] NODE_ID + $ openstack baremetal introspection data save [--file file_name] [--unprocessed] NODE_ID * ``NODE_ID`` - Ironic node UUID or name; * ``file_name`` - file name to save data to. If file name is not provided, the data is dumped to stdout. +* ``--unprocessed`` - if set, retrieves the unprocessed data received from the + ramdisk. .. note:: This feature requires Swift support to be enabled in **Ironic Inspector** diff --git a/ironic_inspector_client/shell.py b/ironic_inspector_client/shell.py index 797bb37..5109e29 100644 --- a/ironic_inspector_client/shell.py +++ b/ironic_inspector_client/shell.py @@ -287,13 +287,16 @@ class DataSaveCommand(command.Command): parser.add_argument("--file", metavar="", help="downloaded introspection data filename " "(default: stdout)") + parser.add_argument('--unprocessed', action='store_true', + help="download the unprocessed data") parser.add_argument('node', help='baremetal node UUID or name') return parser def take_action(self, parsed_args): client = self.app.client_manager.baremetal_introspection data = client.get_data(parsed_args.node, - raw=bool(parsed_args.file)) + raw=bool(parsed_args.file), + processed=not parsed_args.unprocessed) if parsed_args.file: with open(parsed_args.file, 'wb') as fp: fp.write(data) diff --git a/ironic_inspector_client/test/test_shell.py b/ironic_inspector_client/test/test_shell.py index 756638a..a75d575 100644 --- a/ironic_inspector_client/test/test_shell.py +++ b/ironic_inspector_client/test/test_shell.py @@ -371,7 +371,23 @@ class TestDataSave(BaseTest): with mock.patch.object(sys, 'stdout', buf): cmd.take_action(parsed_args) self.assertEqual('{"answer": 42}', buf.getvalue()) - self.client.get_data.assert_called_once_with('uuid1', raw=False) + self.client.get_data.assert_called_once_with('uuid1', raw=False, + processed=True) + + def test_unprocessed(self): + self.client.get_data.return_value = {'answer': 42} + buf = io.StringIO() + + arglist = ['uuid1', '--unprocessed'] + verifylist = [('node', 'uuid1'), ('unprocessed', True)] + + cmd = shell.DataSaveCommand(self.app, None) + parsed_args = self.check_parser(cmd, arglist, verifylist) + with mock.patch.object(sys, 'stdout', buf): + cmd.take_action(parsed_args) + self.assertEqual('{"answer": 42}', buf.getvalue()) + self.client.get_data.assert_called_once_with('uuid1', raw=False, + processed=False) def test_file(self): self.client.get_data.return_value = b'{"answer": 42}' @@ -387,7 +403,8 @@ class TestDataSave(BaseTest): content = fp.read() self.assertEqual(b'{"answer": 42}', content) - self.client.get_data.assert_called_once_with('uuid1', raw=True) + self.client.get_data.assert_called_once_with('uuid1', raw=True, + processed=True) class TestInterfaceCmds(BaseTest): diff --git a/ironic_inspector_client/test/test_v1.py b/ironic_inspector_client/test/test_v1.py index a20576a..5cfd225 100644 --- a/ironic_inspector_client/test/test_v1.py +++ b/ironic_inspector_client/test/test_v1.py @@ -262,6 +262,15 @@ class TestGetData(BaseTest): mock_req.assert_called_once_with( mock.ANY, 'get', '/introspection/%s/data' % self.uuid) + def test_unprocessed(self, mock_req): + mock_req.return_value.json.return_value = 'json' + + self.assertEqual('json', self.get_client().get_data(self.uuid, + processed=False)) + + mock_req.assert_called_once_with( + mock.ANY, 'get', '/introspection/%s/data/unprocessed' % self.uuid) + def test_deprecated_uuid(self, mock_req): mock_req.return_value.json.return_value = 'json' diff --git a/ironic_inspector_client/v1.py b/ironic_inspector_client/v1.py index 7edff37..071dda0 100644 --- a/ironic_inspector_client/v1.py +++ b/ironic_inspector_client/v1.py @@ -262,7 +262,7 @@ class ClientV1(http.BaseClient): raise WaitTimeoutError(_("Timeout while waiting for introspection " "of nodes %s") % new_active_node_ids) - def get_data(self, node_id=None, raw=False, uuid=None): + def get_data(self, node_id=None, raw=False, uuid=None, processed=True): """Get introspection data from the last introspection of a node. If swift support is disabled, introspection data won't be stored, @@ -271,6 +271,8 @@ class ClientV1(http.BaseClient): :param uuid: node UUID or name, deprecated :param node_id: node node_id or name :param raw: whether to return raw binary data or parsed JSON data + :param processed: whether to return the final processed data or the + raw unprocessed data received from the ramdisk. :returns: bytes or a dict depending on the 'raw' argument :raises: :py:class:`ironic_inspector_client.ClientError` on error reported from a server @@ -281,7 +283,9 @@ class ClientV1(http.BaseClient): """ node_id = self._check_parameters(node_id, uuid) - resp = self.request('get', '/introspection/%s/data' % node_id) + url = ('/introspection/%s/data' if processed + else '/introspection/%s/data/unprocessed') + resp = self.request('get', url % node_id) if raw: return resp.content else: diff --git a/releasenotes/notes/unprocessed-7ebb1c48427bfee4.yaml b/releasenotes/notes/unprocessed-7ebb1c48427bfee4.yaml new file mode 100644 index 0000000..fb67537 --- /dev/null +++ b/releasenotes/notes/unprocessed-7ebb1c48427bfee4.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Adds support for retrieving unprocessed introspection data via the new + ``processed`` boolean argument to ``get_data``, as well as the new + ``--unprocessed`` CLI flag.