Example #1
0
    def __init__(self,
                 base_url,
                 username=None,
                 password=None,
                 root_prefix='/redfish/v1/',
                 verify=True):
        """A class representing a RootService

        :param base_url: The base URL to the Redfish controller. It
            should include scheme and authority portion of the URL. For
            example: https://mgmt.vendor.com
        :param username: User account with admin/server-profile access
            privilege
        :param password: User account password
        :param root_prefix: The default URL prefix. This part includes
            the root service and version. Defaults to /redfish/v1
        :param verify: Either a boolean value, a path to a CA_BUNDLE
            file or directory with certificates of trusted CAs. If set to
            True the driver will verify the host certificates; if False
            the driver will ignore verifying the SSL certificate; if it's
            a path the driver will use the specified certificate or one of
            the certificates in the directory. Defaults to True.
        """
        self._root_prefix = root_prefix
        super(Sushy,
              self).__init__(connector.Connector(base_url, username, password,
                                                 verify),
                             path=self._root_prefix)
Example #2
0
 def setUp(self, mock_auth):
     mock_auth.get_session_key.return_value = None
     super(ConnectorMethodsTestCase, self).setUp()
     self.conn = connector.Connector('http://foo.bar:1234', verify=True)
     self.conn._auth = mock_auth
     self.data = {'fake': 'data'}
     self.headers = {'X-Fake': 'header'}
Example #3
0
 def setUp(self):
     super(ConnectorMethodsTestCase, self).setUp()
     self.conn = connector.Connector('http://foo.bar:1234',
                                     username='******',
                                     password='******',
                                     verify=True)
     self.data = {'fake': 'data'}
     self.headers = {'X-Fake': 'header'}
Example #4
0
    def test_init_with_callback(self):
        def response_callback(response):
            return

        conn = connector.Connector('http://foo.bar:1234',
                                   username='******',
                                   password='******',
                                   response_callback=response_callback)
        self.assertIs(conn._response_callback, response_callback)
Example #5
0
 def setUp(self):
     super(ConnectorOpTestCase, self).setUp()
     self.conn = connector.Connector('http://foo.bar:1234',
                                     username='******',
                                     password='******',
                                     verify=True)
     self.data = {'fake': 'data'}
     self.headers = {'X-Fake': 'header'}
     self.session = mock.Mock(spec=requests.Session)
     self.conn._session = self.session
     self.request = self.session.request
     self.request.return_value.status_code = 200
Example #6
0
    def __init__(self,
                 base_url,
                 username=None,
                 password=None,
                 root_prefix='/redfish/v1/',
                 verify=True,
                 auth=None,
                 connector=None,
                 public_connector=None,
                 language='en'):
        """A class representing a RootService

        :param base_url: The base URL to the Redfish controller. It
            should include scheme and authority portion of the URL. For
            example: https://mgmt.vendor.com
        :param username: User account with admin/server-profile access
            privilege
        :param password: User account password
        :param root_prefix: The default URL prefix. This part includes
            the root service and version. Defaults to /redfish/v1
        :param verify: Either a boolean value, a path to a CA_BUNDLE
            file or directory with certificates of trusted CAs. If set to
            True the driver will verify the host certificates; if False
            the driver will ignore verifying the SSL certificate; if it's
            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.
        :param public_connector: A user-defined connector to use for requests
            on the Internet, e.g., for Message Registries. Defaults to None.
        :param language: RFC 5646 language code for Message Registries.
            Defaults to 'en'.
        """
        self._root_prefix = root_prefix
        if (auth is not None
                and (password is not None or username is not None)):
            msg = ('Username or Password were provided to Sushy '
                   'when an authentication mechanism was specified.')
            raise ValueError(msg)
        if auth is None:
            auth = sushy_auth.SessionOrBasicAuth(username=username,
                                                 password=password)
        self._auth = auth

        super(Sushy, self).__init__(
            connector or sushy_connector.Connector(base_url, verify=verify),
            path=self._root_prefix)
        self._public_connector = public_connector or requests
        self._language = language
        self._base_url = base_url
        self._auth.set_context(self, self._conn)
        self._auth.authenticate()
Example #7
0
 def setUp(self, mock_auth):
     mock_auth.get_session_key.return_value = None
     mock_auth._session_key = None
     self.auth = mock_auth
     super(ConnectorOpTestCase, self).setUp()
     self.conn = connector.Connector('http://foo.bar:1234', verify=True)
     self.conn._auth = mock_auth
     self.data = {'fake': 'data'}
     self.headers = {'X-Fake': 'header'}
     self.session = mock.Mock(spec=requests.Session)
     self.conn._session = self.session
     self.request = self.session.request
     self.request.return_value.status_code = http_client.OK
Example #8
0
 def test_init_with_credentials(self):
     conn = connector.Connector('http://foo.bar:1234',
                                username='******',
                                password='******')
     self.assertEqual(conn._session.auth, ('admin', 'password'))