summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGorka Eguileor <geguileo@redhat.com>2017-07-19 14:45:13 +0200
committerGorka Eguileor <geguileo@redhat.com>2017-07-19 14:45:13 +0200
commit52cc5c6cb3856dcddd455122742a5bf8de0fe834 (patch)
treee60be3273ca36882ec784e1e951534c1feb6bbcb
parent83230498eb75ce080de4fe6806b8079b0b87b144 (diff)
downloadpython-cinderclient-52cc5c6cb3856dcddd455122742a5bf8de0fe834.tar.gz
Fix highest version supported by client and server
Current code mistakenly thinks that 3.40 is older than 3.27, because it's treating 3.40 as 3.4, thus returning the wrong maximum supported version by both server and client. It is also returning a 3.40 version as 3.4 because it's returning it as a float. This patch fixes both issues by not using float conversion but using the APIVersion object to do the comparison and by changing returned type to a string so it can be used to instantiate a client. Change-Id: Ica4d718b3de31c31da047f07c5154b242e122596 Closes-Bug: #1705093
-rw-r--r--cinderclient/client.py6
-rw-r--r--cinderclient/tests/unit/test_client.py16
2 files changed, 12 insertions, 10 deletions
diff --git a/cinderclient/client.py b/cinderclient/client.py
index 485be9f..57ebd17 100644
--- a/cinderclient/client.py
+++ b/cinderclient/client.py
@@ -96,10 +96,10 @@ def get_server_version(url):
def get_highest_client_server_version(url):
+ """Returns highest supported version by client and server as a string."""
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))
+ max_client = api_versions.APIVersion(api_versions.MAX_VERSION)
+ return min(max_server, max_client).get_string()
def get_volume_api_from_url(url):
diff --git a/cinderclient/tests/unit/test_client.py b/cinderclient/tests/unit/test_client.py
index 8048180..f1121de 100644
--- a/cinderclient/tests/unit/test_client.py
+++ b/cinderclient/tests/unit/test_client.py
@@ -14,6 +14,7 @@
import json
import logging
+import ddt
import fixtures
from keystoneauth1 import adapter
from keystoneauth1 import exceptions as keystone_exception
@@ -309,6 +310,7 @@ class ClientTestSensitiveInfo(utils.TestCase):
self.assertNotIn(auth_password, output[1], output)
+@ddt.ddt
class GetAPIVersionTestCase(utils.TestCase):
@mock.patch('cinderclient.client.requests.get')
@@ -334,7 +336,8 @@ class GetAPIVersionTestCase(utils.TestCase):
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):
+ @ddt.data('3.12', '3.40')
+ def test_get_highest_client_server_version(self, version, mock_request):
mock_response = utils.TestResponse({
"status_code": 200,
@@ -345,9 +348,8 @@ class GetAPIVersionTestCase(utils.TestCase):
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)
+ with mock.patch.object(api_versions, 'MAX_VERSION', version):
+ highest = (
+ cinderclient.client.get_highest_client_server_version(url))
+ expected = version if version == '3.12' else '3.16'
+ self.assertEqual(expected, highest)