summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorj-griffith <john.griffith8@gmail.com>2017-05-31 08:44:07 -0600
committerJohn Griffith <john.griffith8@gmail.com>2017-07-26 11:49:03 -0600
commit7547e55bbebfeb4232968780cfed4d9a448594ae (patch)
treed9e96681e2b68748a6c1d47e51a2a5248b82c514
parent18381fb872e7280539e2b41ea2673bd230c89518 (diff)
downloadpython-cinderclient-7547e55bbebfeb4232968780cfed4d9a448594ae.tar.gz
cinderclient might not return version for V2 API
The get_server_version call in cidnerclient/client.py relies on either finding v 3.x or encountering an exception to revert back to v 2.0. It's not clear that this call will always raise if a non V3 capable Cinder is called, so just to be safe make sure we return a 2.0 response if there's no V3 reported back. Change-Id: I3b5fb895cad4b85d5f4ea286fb33f7dd0929e691 Closes-Bug: #1694729
-rw-r--r--cinderclient/client.py10
-rw-r--r--cinderclient/tests/unit/test_client.py16
-rw-r--r--cinderclient/tests/unit/v3/fakes.py28
3 files changed, 51 insertions, 3 deletions
diff --git a/cinderclient/client.py b/cinderclient/client.py
index 16152fb..dabfcd3 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 194eb55..bd3b3f6 100644
--- a/cinderclient/tests/unit/test_client.py
+++ b/cinderclient/tests/unit/test_client.py
@@ -316,6 +316,22 @@ class ClientTestSensitiveInfo(utils.TestCase):
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):
mock_response = utils.TestResponse({
diff --git a/cinderclient/tests/unit/v3/fakes.py b/cinderclient/tests/unit/v3/fakes.py
index 76c0718..04c5aa0 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