From 887b6c4f04fa21945cf371cac62a09f5787863e6 Mon Sep 17 00:00:00 2001 From: cid Date: Thu, 18 Apr 2024 01:48:35 +0100 Subject: [PATCH] Follow-up: Use ``microversion-parse`` to parse version headers in API requests Adds a release note, unit test, and documentation update as a follow-up to the `microversion-parse change `_ Change-Id: I2fc3ff32a96035e40d70c39ea34d494466060fb6 --- api-ref/source/introspection-api-versions.inc | 12 ++++++++---- ironic_inspector/test/unit/test_main.py | 11 +++++++++++ ...-microversion-parse-library-1b655eb52998f1df.yaml | 7 +++++++ 3 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/parse-headers-with-the-microversion-parse-library-1b655eb52998f1df.yaml diff --git a/api-ref/source/introspection-api-versions.inc b/api-ref/source/introspection-api-versions.inc index 86b9ea4de..f24ea9f12 100644 --- a/api-ref/source/introspection-api-versions.inc +++ b/api-ref/source/introspection-api-versions.inc @@ -12,14 +12,18 @@ Inspector API supports versioning. There are two kinds of versions: - ``major versions``, which have dedicated urls. - ``microversions``, which can be requested through the use of the - ``X-OpenStack-Ironic-Inspector-API-Version`` header. + ``X-OpenStack-Ironic-Inspector-API-Version`` header or the new standard singular header + ``OpenStack-API-Version: baremetal-introspection ``. The Version APIs work differently from other APIs as they *do not* require authentication. -All API requests support the ``X-OpenStack-Ironic-Inspector-API-Version`` -header. This header SHOULD be supplied with every request; in the absence of -this header, server will default to current supported version in all responses. +All API requests support the new standard singular header +``OpenStack-API-Version: baremetal-introspection `` and the legacy +``X-OpenStack-Ironic-Inspector-API-Version`` header. + +Either of these headers SHOULD be supplied with every request; in the absence of +both headers, server will default to current supported version in all responses. List API versions ================= diff --git a/ironic_inspector/test/unit/test_main.py b/ironic_inspector/test/unit/test_main.py index da8fe56d9..b5ae21397 100644 --- a/ironic_inspector/test/unit/test_main.py +++ b/ironic_inspector/test/unit/test_main.py @@ -763,6 +763,11 @@ class TestApiVersions(BaseAPITest): main._format_version(main.CURRENT_API_VERSION)} self._check_version_present(self.app.get('/', headers=headers)) + def test_request_correct_version_with_standard_singular_header(self): + headers = {'OpenStack-API-Version': 'baremetal-introspection %s' % + main._format_version(main.CURRENT_API_VERSION)} + self._check_version_present(self.app.get('/', headers=headers)) + def test_request_unsupported_version(self): bad_version = (main.CURRENT_API_VERSION[0], main.CURRENT_API_VERSION[1] + 1) @@ -782,6 +787,12 @@ class TestApiVersions(BaseAPITest): self.assertEqual(200, res.status_code) self._check_version_present(res) + def test_request_latest_version_with_standard_singular_header(self): + headers = {'OpenStack-API-Version': 'baremetal-introspection latest'} + res = self.app.get('/', headers=headers) + self.assertEqual(200, res.status_code) + self._check_version_present(res) + class TestPlugins(unittest.TestCase): @mock.patch.object(example_plugin.ExampleProcessingHook, diff --git a/releasenotes/notes/parse-headers-with-the-microversion-parse-library-1b655eb52998f1df.yaml b/releasenotes/notes/parse-headers-with-the-microversion-parse-library-1b655eb52998f1df.yaml new file mode 100644 index 000000000..b46e0c800 --- /dev/null +++ b/releasenotes/notes/parse-headers-with-the-microversion-parse-library-1b655eb52998f1df.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Delegate parsing of version headers in API requests to the + ``microversion-parse`` library which also adds support for the new + standard singular header: + 'OpenStack-API-Version: baremetal-introspection '.