Add support to accept custom connector object
There are libraries which use Sushy to connect to Redfish based systems. At times there arises some need for those extension libraries to pass on their custom made Connector objects which can extend the functionality of Sushy connector. For instance, refer [0]. Hence, adding the support to accept custom connector object in Sushy's constructor. [0] https://github.com/openstack/proliantutils/blob/master/proliantutils/redfish/connector.py Change-Id: I220b44b2c5a65b0ee410097594a5a87dd87e4753
This commit is contained in:
parent
fc9a7f8ea4
commit
15f00a0347
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
features:
|
||||
- |
|
||||
Adds the ability to specify user-defined connector object on creation
|
||||
of a root Sushy instance.
|
|
@ -15,7 +15,7 @@
|
|||
import logging
|
||||
|
||||
from sushy import auth as sushy_auth
|
||||
from sushy import connector
|
||||
from sushy import connector as sushy_connector
|
||||
from sushy.resources import base
|
||||
from sushy.resources.manager import manager
|
||||
from sushy.resources.sessionservice import session
|
||||
|
@ -48,7 +48,7 @@ class Sushy(base.ResourceBase):
|
|||
|
||||
def __init__(self, base_url, username=None, password=None,
|
||||
root_prefix='/redfish/v1/', verify=True,
|
||||
auth=None):
|
||||
auth=None, connector=None):
|
||||
"""A class representing a RootService
|
||||
|
||||
:param base_url: The base URL to the Redfish controller. It
|
||||
|
@ -66,6 +66,7 @@ class Sushy(base.ResourceBase):
|
|||
a path the driver will use the specified certificate or one of
|
||||
the certificates in the directory. Defaults to True.
|
||||
:param auth: An authentication mechanism to utilize.
|
||||
:param connector: A user-defined connector object. Defaults to None.
|
||||
"""
|
||||
self._root_prefix = root_prefix
|
||||
if (auth is not None and (password is not None or
|
||||
|
@ -78,7 +79,7 @@ class Sushy(base.ResourceBase):
|
|||
password=password)
|
||||
|
||||
super(Sushy, self).__init__(
|
||||
connector.Connector(base_url, verify),
|
||||
connector or sushy_connector.Connector(base_url, verify),
|
||||
path=self._root_prefix)
|
||||
self._auth = auth
|
||||
self._auth.set_context(self, self._conn)
|
||||
|
|
|
@ -64,6 +64,18 @@ class MainTestCase(base.TestCase):
|
|||
ValueError, main.Sushy, 'http://foo.bar:1234',
|
||||
'foo', 'bar', auth=mock.MagicMock())
|
||||
|
||||
@mock.patch.object(connector, 'Connector', autospec=True)
|
||||
def test_custom_connector(self, mock_Sushy_Connector):
|
||||
connector_mock = mock.MagicMock()
|
||||
with open('sushy/tests/unit/json_samples/root.json', 'r') as f:
|
||||
connector_mock.get.return_value.json.return_value = (
|
||||
json.loads(f.read()))
|
||||
main.Sushy('http://foo.bar:1234', 'foo', 'bar',
|
||||
connector=connector_mock)
|
||||
self.assertTrue(connector_mock.post.called)
|
||||
self.assertTrue(connector_mock.get.called)
|
||||
self.assertFalse(mock_Sushy_Connector.called)
|
||||
|
||||
@mock.patch.object(system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
self.root.get_system_collection()
|
||||
|
|
Loading…
Reference in New Issue