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
This commit is contained in:

committed by
John Griffith

parent
18381fb872
commit
7547e55bbe
@@ -78,6 +78,8 @@ def get_server_version(url):
|
|||||||
:returns: APIVersion object for min and max version supported by
|
:returns: APIVersion object for min and max version supported by
|
||||||
the server
|
the server
|
||||||
"""
|
"""
|
||||||
|
min_version = "2.0"
|
||||||
|
current_version = "2.0"
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
try:
|
try:
|
||||||
@@ -87,12 +89,14 @@ def get_server_version(url):
|
|||||||
versions = data['versions']
|
versions = data['versions']
|
||||||
for version in versions:
|
for version in versions:
|
||||||
if '3.' in version['version']:
|
if '3.' in version['version']:
|
||||||
return (api_versions.APIVersion(version['min_version']),
|
min_version = version['min_version']
|
||||||
api_versions.APIVersion(version['version']))
|
current_version = version['version']
|
||||||
|
break
|
||||||
except exceptions.ClientException as e:
|
except exceptions.ClientException as e:
|
||||||
logger.warning("Error in server version query:%s\n"
|
logger.warning("Error in server version query:%s\n"
|
||||||
"Returning APIVersion 2.0", six.text_type(e.message))
|
"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):
|
def get_highest_client_server_version(url):
|
||||||
|
@@ -315,6 +315,22 @@ class ClientTestSensitiveInfo(utils.TestCase):
|
|||||||
@ddt.ddt
|
@ddt.ddt
|
||||||
class GetAPIVersionTestCase(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')
|
@mock.patch('cinderclient.client.requests.get')
|
||||||
def test_get_server_version(self, mock_request):
|
def test_get_server_version(self, mock_request):
|
||||||
|
|
||||||
|
@@ -612,3 +612,31 @@ def fake_request_get():
|
|||||||
'updated': '2016-02-08T12:20:21Z',
|
'updated': '2016-02-08T12:20:21Z',
|
||||||
'version': '3.16'}]}
|
'version': '3.16'}]}
|
||||||
return versions
|
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
|
||||||
|
Reference in New Issue
Block a user