From 707839e29daf72c28b2bbeae5e39a784fae86c66 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Tue, 28 Jul 2020 14:03:19 +0200 Subject: [PATCH] baremetal-introspection: allow fetching unprocessed data Depends-On: https://review.opendev.org/743504 Change-Id: I5b42527a10ca93aff98abb62abf3026e107c549e --- openstack/baremetal_introspection/v1/_proxy.py | 6 ++++-- openstack/baremetal_introspection/v1/introspection.py | 10 ++++++++-- .../unit/baremetal_introspection/v1/test_proxy.py | 9 +++++++++ releasenotes/notes/unprocessed-2d75133911945869.yaml | 5 +++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/unprocessed-2d75133911945869.yaml diff --git a/openstack/baremetal_introspection/v1/_proxy.py b/openstack/baremetal_introspection/v1/_proxy.py index f3db88ade..b25eb3378 100644 --- a/openstack/baremetal_introspection/v1/_proxy.py +++ b/openstack/baremetal_introspection/v1/_proxy.py @@ -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. diff --git a/openstack/baremetal_introspection/v1/introspection.py b/openstack/baremetal_introspection/v1/introspection.py index 88819f9f1..1b01c0fd4 100644 --- a/openstack/baremetal_introspection/v1/introspection.py +++ b/openstack/baremetal_introspection/v1/introspection.py @@ -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}" diff --git a/openstack/tests/unit/baremetal_introspection/v1/test_proxy.py b/openstack/tests/unit/baremetal_introspection/v1/test_proxy.py index 6d8ff2116..c71fd3d66 100644 --- a/openstack/tests/unit/baremetal_introspection/v1/test_proxy.py +++ b/openstack/tests/unit/baremetal_introspection/v1/test_proxy.py @@ -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) diff --git a/releasenotes/notes/unprocessed-2d75133911945869.yaml b/releasenotes/notes/unprocessed-2d75133911945869.yaml new file mode 100644 index 000000000..d8738090b --- /dev/null +++ b/releasenotes/notes/unprocessed-2d75133911945869.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Supports fetching raw (unprocessed) introspection data from the bare metal + introspection service.