From 04ee0bc031d4396baa24f068ee8f493bd18de979 Mon Sep 17 00:00:00 2001 From: Kaifeng Wang Date: Fri, 14 Sep 2018 17:28:48 +0800 Subject: [PATCH] Support latest as the microversion value Adds support to use latest as the microversion value. When set to latest, the maximum version is assumed by ironic-inspector. Story: 1672400 Task: 11363 Change-Id: I35be1034697a7d69ed30af9542d9711fb2f65bd0 --- ironic_inspector/main.py | 7 +++++-- ironic_inspector/test/unit/test_main.py | 6 ++++++ .../support-microversion-latest-dcf9598c5218e979.yaml | 5 +++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/support-microversion-latest-dcf9598c5218e979.yaml diff --git a/ironic_inspector/main.py b/ironic_inspector/main.py index 4a4cd500e..537dadfc2 100644 --- a/ironic_inspector/main.py +++ b/ironic_inspector/main.py @@ -49,10 +49,13 @@ def _get_version(): ver = flask.request.headers.get(conf_opts.VERSION_HEADER, _DEFAULT_API_VERSION) try: - requested = tuple(int(x) for x in ver.split('.')) + if ver.lower() == 'latest': + requested = CURRENT_API_VERSION + else: + requested = tuple(int(x) for x in ver.split('.')) except (ValueError, TypeError): return error_response(_('Malformed API version: expected string ' - 'in form of X.Y'), code=400) + 'in form of X.Y or latest'), code=400) return requested diff --git a/ironic_inspector/test/unit/test_main.py b/ironic_inspector/test/unit/test_main.py index 1e24f16ef..537856f75 100644 --- a/ironic_inspector/test/unit/test_main.py +++ b/ironic_inspector/test/unit/test_main.py @@ -633,6 +633,12 @@ class TestApiVersions(BaseAPITest): self.assertIn('%d.%d' % main.MINIMUM_API_VERSION, error) self.assertIn('%d.%d' % main.CURRENT_API_VERSION, error) + def test_request_latest_version(self): + headers = {conf_opts.VERSION_HEADER: '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/support-microversion-latest-dcf9598c5218e979.yaml b/releasenotes/notes/support-microversion-latest-dcf9598c5218e979.yaml new file mode 100644 index 000000000..274fc6879 --- /dev/null +++ b/releasenotes/notes/support-microversion-latest-dcf9598c5218e979.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Adds support to use ``latest`` as the microversion value in the request + to the ironic-inspector API. \ No newline at end of file