Make SessionClient interface similar to HTTPClient
HttpClient will be deprecated soon and SessionClient will be used by default. To not break integration novaclient with other project at the step of moving from HTTPClient, SessionClient should have similar interface. Change-Id: I855ccc5160dc7628f4550e93bf133adf8263aace
This commit is contained in:
parent
b4bd07e5a7
commit
e4dc84e0f6
@ -121,6 +121,21 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
|||||||
def reset_timings(self):
|
def reset_timings(self):
|
||||||
self.times = []
|
self.times = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def management_url(self):
|
||||||
|
self.logger.warning(
|
||||||
|
_LW("Property `management_url` is deprecated for SessionClient. "
|
||||||
|
"Use `endpoint_override` instead."))
|
||||||
|
return self.endpoint_override
|
||||||
|
|
||||||
|
@management_url.setter
|
||||||
|
def management_url(self, value):
|
||||||
|
self.logger.warning(
|
||||||
|
_LW("Property `management_url` is deprecated for SessionClient. "
|
||||||
|
"It should be set via `endpoint_override` variable while class"
|
||||||
|
" initialization."))
|
||||||
|
self.endpoint_override = value
|
||||||
|
|
||||||
|
|
||||||
def _original_only(f):
|
def _original_only(f):
|
||||||
"""Decorator to indicate and enforce original HTTPClient object.
|
"""Decorator to indicate and enforce original HTTPClient object.
|
||||||
|
@ -201,16 +201,6 @@ class ClientTest(utils.TestCase):
|
|||||||
cs.reset_timings()
|
cs.reset_timings()
|
||||||
self.assertEqual(0, len(cs.get_timings()))
|
self.assertEqual(0, len(cs.get_timings()))
|
||||||
|
|
||||||
@mock.patch('novaclient.client.HTTPClient')
|
|
||||||
def test_contextmanager_v1_1(self, mock_http_client):
|
|
||||||
fake_client = mock.Mock()
|
|
||||||
mock_http_client.return_value = fake_client
|
|
||||||
with novaclient.client.Client("2", "user", "password", "project_id",
|
|
||||||
auth_url="foo/v2"):
|
|
||||||
pass
|
|
||||||
self.assertTrue(fake_client.open_session.called)
|
|
||||||
self.assertTrue(fake_client.close_session.called)
|
|
||||||
|
|
||||||
def test_get_password_simple(self):
|
def test_get_password_simple(self):
|
||||||
cs = novaclient.client.HTTPClient("user", "password", "", "")
|
cs = novaclient.client.HTTPClient("user", "password", "", "")
|
||||||
cs.password_func = mock.Mock()
|
cs.password_func = mock.Mock()
|
||||||
|
@ -379,14 +379,3 @@ class AuthenticationTests(utils.TestCase):
|
|||||||
self.assertTrue(mock_request.called)
|
self.assertTrue(mock_request.called)
|
||||||
|
|
||||||
test_auth_call()
|
test_auth_call()
|
||||||
|
|
||||||
def test_auth_manual(self):
|
|
||||||
cs = Client("username", "password", project_name="project_id",
|
|
||||||
auth_url=utils.AUTH_URL)
|
|
||||||
|
|
||||||
@mock.patch.object(cs.client, 'authenticate')
|
|
||||||
def test_auth_call(m):
|
|
||||||
cs.authenticate()
|
|
||||||
self.assertTrue(m.called)
|
|
||||||
|
|
||||||
test_auth_call()
|
|
||||||
|
@ -279,17 +279,22 @@ class Client(object):
|
|||||||
"Ocata. Use 'project_id' instead."))
|
"Ocata. Use 'project_id' instead."))
|
||||||
return self.project_id
|
return self.project_id
|
||||||
|
|
||||||
@client._original_only
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.client.open_session()
|
self.logger.warning(_LW("NovaClient instance can't be used as a "
|
||||||
|
"context manager since Ocata (deprecated "
|
||||||
|
"behaviour) since it is redundant in case of "
|
||||||
|
"SessionClient."))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@client._original_only
|
|
||||||
def __exit__(self, t, v, tb):
|
def __exit__(self, t, v, tb):
|
||||||
self.client.close_session()
|
# do not do anything
|
||||||
|
pass
|
||||||
|
|
||||||
@client._original_only
|
|
||||||
def set_management_url(self, url):
|
def set_management_url(self, url):
|
||||||
|
self.logger.warning(
|
||||||
|
_LW("Method `set_management_url` is deprecated since Ocata. "
|
||||||
|
"Use `endpoint_override` argument instead while initializing "
|
||||||
|
"novaclient's instance."))
|
||||||
self.client.set_management_url(url)
|
self.client.set_management_url(url)
|
||||||
|
|
||||||
def get_timings(self):
|
def get_timings(self):
|
||||||
@ -315,7 +320,6 @@ class Client(object):
|
|||||||
except key_ex.EndpointNotFound:
|
except key_ex.EndpointNotFound:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@client._original_only
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
"""Authenticate against the server.
|
"""Authenticate against the server.
|
||||||
|
|
||||||
@ -325,4 +329,5 @@ class Client(object):
|
|||||||
Returns on success; raises :exc:`exceptions.Unauthorized` if the
|
Returns on success; raises :exc:`exceptions.Unauthorized` if the
|
||||||
credentials are wrong.
|
credentials are wrong.
|
||||||
"""
|
"""
|
||||||
self.client.authenticate()
|
self.logger.warning(_LW(
|
||||||
|
"Method 'authenticate' is deprecated since Ocata."))
|
||||||
|
Loading…
Reference in New Issue
Block a user