summaryrefslogtreecommitdiff
path: root/cinderclient/tests/unit
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 /cinderclient/tests/unit
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
Diffstat (limited to 'cinderclient/tests/unit')
-rw-r--r--cinderclient/tests/unit/test_client.py16
-rw-r--r--cinderclient/tests/unit/v3/fakes.py28
2 files changed, 44 insertions, 0 deletions
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