diff --git a/cinderclient/client.py b/cinderclient/client.py index 16152fbf7..dabfcd38e 100644 --- a/cinderclient/client.py +++ b/cinderclient/client.py @@ -78,6 +78,8 @@ def get_server_version(url): :returns: APIVersion object for min and max version supported by the server """ + min_version = "2.0" + current_version = "2.0" logger = logging.getLogger(__name__) try: @@ -87,12 +89,14 @@ def get_server_version(url): versions = data['versions'] for version in versions: if '3.' in version['version']: - return (api_versions.APIVersion(version['min_version']), - api_versions.APIVersion(version['version'])) + min_version = version['min_version'] + current_version = version['version'] + break except exceptions.ClientException as e: logger.warning("Error in server version query:%s\n" "Returning APIVersion 2.0", six.text_type(e.message)) - return api_versions.APIVersion("2.0"), api_versions.APIVersion("2.0") + return (api_versions.APIVersion(min_version), + api_versions.APIVersion(current_version)) def get_highest_client_server_version(url): diff --git a/cinderclient/tests/unit/test_client.py b/cinderclient/tests/unit/test_client.py index 194eb55fb..bd3b3f63e 100644 --- a/cinderclient/tests/unit/test_client.py +++ b/cinderclient/tests/unit/test_client.py @@ -315,6 +315,22 @@ class ClientTestSensitiveInfo(utils.TestCase): @ddt.ddt class GetAPIVersionTestCase(utils.TestCase): + @mock.patch('cinderclient.client.requests.get') + def test_get_server_version_v2(self, mock_request): + + mock_response = utils.TestResponse({ + "status_code": 200, + "text": json.dumps(fakes.fake_request_get_no_v3()) + }) + + mock_request.return_value = mock_response + + url = "http://192.168.122.127:8776/v2/e5526285ebd741b1819393f772f11fc3" + + min_version, max_version = cinderclient.client.get_server_version(url) + self.assertEqual(api_versions.APIVersion('2.0'), min_version) + self.assertEqual(api_versions.APIVersion('2.0'), max_version) + @mock.patch('cinderclient.client.requests.get') def test_get_server_version(self, mock_request): diff --git a/cinderclient/tests/unit/v3/fakes.py b/cinderclient/tests/unit/v3/fakes.py index 76c071892..04c5aa077 100644 --- a/cinderclient/tests/unit/v3/fakes.py +++ b/cinderclient/tests/unit/v3/fakes.py @@ -612,3 +612,31 @@ def fake_request_get(): 'updated': '2016-02-08T12:20:21Z', 'version': '3.16'}]} return versions + + +def fake_request_get_no_v3(): + versions = {'versions': [{'id': 'v1.0', + 'links': [{'href': 'http://docs.openstack.org/', + 'rel': 'describedby', + 'type': 'text/html'}, + {'href': 'http://192.168.122.197/v1/', + 'rel': 'self'}], + 'media-types': [{'base': 'application/json', + 'type': 'application/'}], + 'min_version': '', + 'status': 'DEPRECATED', + 'updated': '2016-05-02T20:25:19Z', + 'version': ''}, + {'id': 'v2.0', + 'links': [{'href': 'http://docs.openstack.org/', + 'rel': 'describedby', + 'type': 'text/html'}, + {'href': 'http://192.168.122.197/v2/', + 'rel': 'self'}], + 'media-types': [{'base': 'application/json', + 'type': 'application/'}], + 'min_version': '', + 'status': 'SUPPORTED', + 'updated': '2014-06-28T12:20:21Z', + 'version': ''}]} + return versions