Support retrieving unprocessed data

Change-Id: Id8d2d3621385e0ef982a531609ce8c02739987a5
Depends-On: https://review.opendev.org/743504
This commit is contained in:
Dmitry Tantsur 2020-07-28 14:12:41 +02:00
parent 89a30e2bef
commit 0f65bcf699
6 changed files with 47 additions and 6 deletions

View File

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

View File

@ -287,13 +287,16 @@ class DataSaveCommand(command.Command):
parser.add_argument("--file", metavar="<filename>",
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)

View File

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

View File

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

View File

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

View File

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