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:
parent
f5787a4b83
commit
71081e91de
@ -89,6 +89,13 @@ def Client(version='1', username=None, auth_url=None, **kwargs):
|
|||||||
osprofiler_profiler.init(profile)
|
osprofiler_profiler.init(profile)
|
||||||
|
|
||||||
api_version, client_class = _get_client_class_and_version(version)
|
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,
|
return client_class(api_version=api_version,
|
||||||
auth_url=auth_url,
|
auth_url=auth_url,
|
||||||
username=username,
|
username=username,
|
||||||
|
@ -22,24 +22,28 @@ from zunclient import exceptions
|
|||||||
|
|
||||||
class ClientTest(testtools.TestCase):
|
class ClientTest(testtools.TestCase):
|
||||||
|
|
||||||
|
@mock.patch('zunclient.api_versions.discover_version',
|
||||||
|
return_value=api_versions.APIVersion('1.1'))
|
||||||
@mock.patch('zunclient.v1.client.Client')
|
@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',
|
client.Client(auth_url='http://example/identity',
|
||||||
username='admin')
|
username='admin')
|
||||||
api_version = api_versions.get_api_version('1')
|
|
||||||
mock_zun_client_v1.assert_called_with(
|
mock_zun_client_v1.assert_called_with(
|
||||||
api_version=api_version,
|
api_version=api_versions.APIVersion('1.1'),
|
||||||
auth_url='http://example/identity',
|
auth_url='http://example/identity',
|
||||||
username='admin')
|
username='admin')
|
||||||
|
|
||||||
|
@mock.patch('zunclient.api_versions.discover_version',
|
||||||
|
return_value=api_versions.APIVersion('1.1'))
|
||||||
@mock.patch('zunclient.v1.client.Client')
|
@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',
|
client.Client(version='1',
|
||||||
auth_url='http://example/identity',
|
auth_url='http://example/identity',
|
||||||
username='admin')
|
username='admin')
|
||||||
api_version = api_versions.get_api_version('1')
|
|
||||||
mock_zun_client_v1.assert_called_with(
|
mock_zun_client_v1.assert_called_with(
|
||||||
api_version=api_version,
|
api_version=api_versions.APIVersion('1.1'),
|
||||||
auth_url='http://example/identity',
|
auth_url='http://example/identity',
|
||||||
username='admin')
|
username='admin')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user