From 7b6f37f73a83bf92a458489ba2052e499abfa340 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 18 Jan 2018 18:10:26 +0100 Subject: [PATCH] Restore interface of Connector It was changed in a backwards incompatible way. This change corrects it and issues a deprecation warning on using old arguments. Change-Id: I991ddb50818fd84a4e707204c86d50d3a2b553c8 --- sushy/connector.py | 8 +++++++- sushy/tests/unit/test_connector.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sushy/connector.py b/sushy/connector.py index 84474d48..d507f682 100644 --- a/sushy/connector.py +++ b/sushy/connector.py @@ -26,11 +26,17 @@ LOG = logging.getLogger(__name__) class Connector(object): - def __init__(self, url, verify=True): + def __init__(self, url, username=None, password=None, verify=True): self._url = url self._verify = verify self._session = requests.Session() self._session.verify = self._verify + if username or password: + LOG.warning('Passing username and password to Connector is ' + 'deprecated. Authentication is passed through ' + 'set_auth now, support for these arguments will ' + 'be removed in the future') + self.set_http_basic_auth(username, password) def set_auth(self, auth): """Sets the authentication mechanism for our connector.""" diff --git a/sushy/tests/unit/test_connector.py b/sushy/tests/unit/test_connector.py index ebbf8eb8..a46ecfa6 100644 --- a/sushy/tests/unit/test_connector.py +++ b/sushy/tests/unit/test_connector.py @@ -37,6 +37,12 @@ class ConnectorMethodsTestCase(base.TestCase): self.data = {'fake': 'data'} self.headers = {'X-Fake': 'header'} + def test_init_with_credentials(self): + conn = connector.Connector('http://foo.bar:1234', + username='admin', + password='password') + self.assertEqual(conn._session.auth, ('admin', 'password')) + @mock.patch.object(connector.Connector, '_op', autospec=True) def test_get(self, mock__op): self.conn.get(path='fake/path', data=self.data.copy(),