baremetal-introspection: allow fetching unprocessed data

Depends-On: https://review.opendev.org/743504
Change-Id: I5b42527a10ca93aff98abb62abf3026e107c549e
This commit is contained in:
Dmitry Tantsur
2020-07-28 14:03:19 +02:00
parent 6f9cd3f7a7
commit 707839e29d
4 changed files with 26 additions and 4 deletions

View File

@@ -86,17 +86,19 @@ class Proxy(proxy.Proxy):
"""
return self._get(_introspect.Introspection, introspection)
def get_introspection_data(self, introspection):
def get_introspection_data(self, introspection, processed=True):
"""Get introspection data.
:param introspection: The value can be the name or ID of an
introspection (matching bare metal node name or ID) or
an :class:`~.introspection.Introspection` instance.
:param processed: Whether to fetch the final processed data (the
default) or the raw unprocessed data as received from the ramdisk.
:returns: introspection data from the most recent successful run.
:rtype: dict
"""
res = self._get_resource(_introspect.Introspection, introspection)
return res.get_data(self)
return res.get_data(self, processed=processed)
def abort_introspection(self, introspection, ignore_missing=True):
"""Abort an introspection.

View File

@@ -73,7 +73,7 @@ class Introspection(resource.Resource):
.format(id=self.id))
exceptions.raise_from_response(response, error_message=msg)
def get_data(self, session):
def get_data(self, session, processed=True):
"""Get introspection data.
Note that the introspection data format is not stable and can vary
@@ -81,14 +81,20 @@ class Introspection(resource.Resource):
:param session: The session to use for making this request.
:type session: :class:`~keystoneauth1.adapter.Adapter`
:param processed: Whether to fetch the final processed data (the
default) or the raw unprocessed data as received from the ramdisk.
:type processed: bool
:returns: introspection data from the most recent successful run.
:rtype: dict
"""
session = self._get_session(session)
version = self._get_microversion_for(session, 'fetch')
version = (self._get_microversion_for(session, 'fetch')
if processed else '1.17')
request = self._prepare_request(requires_id=True)
request.url = utils.urljoin(request.url, 'data')
if not processed:
request.url = utils.urljoin(request.url, 'unprocessed')
response = session.get(
request.url, headers=request.headers, microversion=version)
msg = ("Failed to fetch introspection data for node {id}"

View File

@@ -163,3 +163,12 @@ class TestGetData(base.TestCase):
self.proxy, 'introspection/1234/data', 'GET',
headers=mock.ANY, microversion=mock.ANY)
self.assertIs(data, mock_request.return_value.json.return_value)
def test_get_unprocessed_data(self, mock_request):
mock_request.return_value.status_code = 200
data = self.proxy.get_introspection_data(self.introspection,
processed=False)
mock_request.assert_called_once_with(
self.proxy, 'introspection/1234/data/unprocessed', 'GET',
headers=mock.ANY, microversion='1.17')
self.assertIs(data, mock_request.return_value.json.return_value)

View File

@@ -0,0 +1,5 @@
---
features:
- |
Supports fetching raw (unprocessed) introspection data from the bare metal
introspection service.