From e4dc84e0f6ebaefeed114d4ac1663d35730629a4 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Tue, 2 Aug 2016 18:50:34 +0300 Subject: [PATCH] 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 --- novaclient/client.py | 15 +++++++++++++++ novaclient/tests/unit/test_client.py | 10 ---------- novaclient/tests/unit/v2/test_auth.py | 11 ----------- novaclient/v2/client.py | 19 ++++++++++++------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/novaclient/client.py b/novaclient/client.py index 7951c7e18..8a840afcf 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -121,6 +121,21 @@ class SessionClient(adapter.LegacyJsonAdapter): def reset_timings(self): 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): """Decorator to indicate and enforce original HTTPClient object. diff --git a/novaclient/tests/unit/test_client.py b/novaclient/tests/unit/test_client.py index ab25fe0b4..5ff6133ee 100644 --- a/novaclient/tests/unit/test_client.py +++ b/novaclient/tests/unit/test_client.py @@ -201,16 +201,6 @@ class ClientTest(utils.TestCase): cs.reset_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): cs = novaclient.client.HTTPClient("user", "password", "", "") cs.password_func = mock.Mock() diff --git a/novaclient/tests/unit/v2/test_auth.py b/novaclient/tests/unit/v2/test_auth.py index ec9ba3e91..512e6743d 100644 --- a/novaclient/tests/unit/v2/test_auth.py +++ b/novaclient/tests/unit/v2/test_auth.py @@ -379,14 +379,3 @@ class AuthenticationTests(utils.TestCase): self.assertTrue(mock_request.called) 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() diff --git a/novaclient/v2/client.py b/novaclient/v2/client.py index d2a7c5d3d..35158fc9a 100644 --- a/novaclient/v2/client.py +++ b/novaclient/v2/client.py @@ -279,17 +279,22 @@ class Client(object): "Ocata. Use 'project_id' instead.")) return self.project_id - @client._original_only 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 - @client._original_only def __exit__(self, t, v, tb): - self.client.close_session() + # do not do anything + pass - @client._original_only 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) def get_timings(self): @@ -315,7 +320,6 @@ class Client(object): except key_ex.EndpointNotFound: return False - @client._original_only def authenticate(self): """Authenticate against the server. @@ -325,4 +329,5 @@ class Client(object): Returns on success; raises :exc:`exceptions.Unauthorized` if the credentials are wrong. """ - self.client.authenticate() + self.logger.warning(_LW( + "Method 'authenticate' is deprecated since Ocata."))