static method to get_highest_client_server_version

This method takes a url for the cinder server endpoint and queries
the server for version info. It then returns the min of the server's
highest supported version and the cinderclients MAX_VERSION.

Change-Id: Ifb3478f1dba660a5d75d243dc2aaf6b421940752
This commit is contained in:
scottda 2017-01-26 09:48:22 -07:00
parent 4395dbdda6
commit d10b467af4
2 changed files with 26 additions and 0 deletions

View File

@ -97,6 +97,13 @@ def get_server_version(url):
return api_versions.APIVersion("2.0"), api_versions.APIVersion("2.0")
def get_highest_client_server_version(url):
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))
def get_volume_api_from_url(url):
scheme, netloc, path, query, frag = urlparse.urlsplit(url)
components = path.split("/")

View File

@ -332,3 +332,22 @@ class GetAPIVersionTestCase(utils.TestCase):
min_version, max_version = cinderclient.client.get_server_version(url)
self.assertEqual(min_version, api_versions.APIVersion('3.0'))
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):
mock_response = utils.TestResponse({
"status_code": 200,
"text": json.dumps(fakes.fake_request_get())
})
mock_request.return_value = mock_response
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)