diff --git a/cinderclient/client.py b/cinderclient/client.py index 298ec945f..f6513b62a 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -97,6 +97,13 @@ def get_server_version(url): return api_versions.APIVersion("2.0"), api_versions.APIVersion("2.0") +def get_highest_client_server_version(url): + min_server, max_server = get_server_version(url) + max_server_version = api_versions.APIVersion.get_string(max_server) + + return min(float(max_server_version), float(api_versions.MAX_VERSION)) + + def get_volume_api_from_url(url): scheme, netloc, path, query, frag = urlparse.urlsplit(url) components = path.split("/") diff --git a/cinderclient/tests/unit/test_client.py b/cinderclient/tests/unit/test_client.py index 7a6588cd9..0ca0f1973 100644 --- a/cinderclient/tests/unit/test_client.py +++ b/cinderclient/tests/unit/test_client.py @@ -332,3 +332,22 @@ class GetAPIVersionTestCase(utils.TestCase): min_version, max_version = cinderclient.client.get_server_version(url) self.assertEqual(min_version, api_versions.APIVersion('3.0')) self.assertEqual(max_version, api_versions.APIVersion('3.16')) + + @mock.patch('cinderclient.client.requests.get') + def test_get_highest_client_server_version(self, mock_request): + + mock_response = utils.TestResponse({ + "status_code": 200, + "text": json.dumps(fakes.fake_request_get()) + }) + + mock_request.return_value = mock_response + + url = "http://192.168.122.127:8776/v3/e5526285ebd741b1819393f772f11fc3" + + highest = cinderclient.client.get_highest_client_server_version(url) + current_client_MAX_VERSION = float(api_versions.MAX_VERSION) + if current_client_MAX_VERSION > 3.16: + self.assertEqual(3.16, highest) + else: + self.assertEqual(current_client_MAX_VERSION, highest)