From 61faea2eb3a3725e4dc81e15c1a402f2c8dc8fcc Mon Sep 17 00:00:00 2001 From: scottda <scott.dangelo@gmail.com> Date: Tue, 13 Dec 2016 12:14:26 -0700 Subject: [PATCH] Add get_highest_version method Add method to query a server that supports /v3 endpoint and get the highest supported microversion. Change-Id: If179760787526440c852803eafaf9617bcd2d36e --- cinderclient/api_versions.py | 12 ++++++++++++ cinderclient/tests/unit/test_api_versions.py | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/cinderclient/api_versions.py b/cinderclient/api_versions.py index 29a91d464..119ccca13 100644 --- a/cinderclient/api_versions.py +++ b/cinderclient/api_versions.py @@ -244,6 +244,18 @@ def _get_server_version_range(client): return APIVersion(version.min_version), APIVersion(version.version) +def get_highest_version(client): + """Queries the server version info and returns highest supported + microversion + + :param client: client object + :returns: APIVersion + """ + server_start_version, server_end_version = _get_server_version_range( + client) + return server_end_version + + def discover_version(client, requested_version): """Checks ``requested_version`` and returns the most recent version supported by both the API and the client. diff --git a/cinderclient/tests/unit/test_api_versions.py b/cinderclient/tests/unit/test_api_versions.py index c11942b82..ef8f3112c 100644 --- a/cinderclient/tests/unit/test_api_versions.py +++ b/cinderclient/tests/unit/test_api_versions.py @@ -253,3 +253,9 @@ class DiscoverVersionTestCase(utils.TestCase): discovered_version.get_string()) self.assertTrue( self.fake_client.services.server_api_version.called) + + def test_get_highest_version(self): + self._mock_returned_server_version("3.14", "3.0") + highest_version = api_versions.get_highest_version(self.fake_client) + self.assertEqual("3.14", highest_version.get_string()) + self.assertTrue(self.fake_client.services.server_api_version.called)