Handle the case that a generic api version

For example, if users provide an api version '1' (instead of 1.X),
we treat that as a request to negotiate api version with server.

Change-Id: I96cc8fae3a493d9ddc4165af47d2d376ec8f2cd8
This commit is contained in:
Hongbin Lu 2018-11-07 04:17:22 +00:00
parent f5787a4b83
commit 71081e91de
2 changed files with 17 additions and 6 deletions

View File

@ -89,6 +89,13 @@ def Client(version='1', username=None, auth_url=None, **kwargs):
osprofiler_profiler.init(profile)
api_version, client_class = _get_client_class_and_version(version)
if api_version.is_latest():
c = client_class(api_version=api_versions.APIVersion("1.1"),
auth_url=auth_url,
username=username,
**kwargs)
api_version = api_versions.discover_version(c, api_version)
return client_class(api_version=api_version,
auth_url=auth_url,
username=username,

View File

@ -22,24 +22,28 @@ from zunclient import exceptions
class ClientTest(testtools.TestCase):
@mock.patch('zunclient.api_versions.discover_version',
return_value=api_versions.APIVersion('1.1'))
@mock.patch('zunclient.v1.client.Client')
def test_no_version_argument(self, mock_zun_client_v1):
def test_no_version_argument(self, mock_zun_client_v1,
mock_discover_version):
client.Client(auth_url='http://example/identity',
username='admin')
api_version = api_versions.get_api_version('1')
mock_zun_client_v1.assert_called_with(
api_version=api_version,
api_version=api_versions.APIVersion('1.1'),
auth_url='http://example/identity',
username='admin')
@mock.patch('zunclient.api_versions.discover_version',
return_value=api_versions.APIVersion('1.1'))
@mock.patch('zunclient.v1.client.Client')
def test_valid_version_argument(self, mock_zun_client_v1):
def test_valid_version_argument(self, mock_zun_client_v1,
mock_discover_version):
client.Client(version='1',
auth_url='http://example/identity',
username='admin')
api_version = api_versions.get_api_version('1')
mock_zun_client_v1.assert_called_with(
api_version=api_version,
api_version=api_versions.APIVersion('1.1'),
auth_url='http://example/identity',
username='admin')