예제 #1
0
 def setUp(self, mock_connector, mock_root):
     super(SessionOrBasicAuthTestCase, self).setUp()
     self.username = '******'
     self.password = '******'
     self.sess_key = 'TestingKey'
     self.sess_uri = ('https://testing:8000/redfish/v1/'
                      'SessionService/Sessions/testing')
     self.conn = mock_connector.return_value
     self.root = mock_root.return_value
     self.sess_basic_auth = auth.SessionOrBasicAuth(self.username,
                                                    self.password)
예제 #2
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()
예제 #3
0
 def test_context_manager(self, auth_close):
     with auth.SessionOrBasicAuth(self.username,
                                  self.password) as session_or_base_auth:
         self.assertEqual(self.username, session_or_base_auth._username)
         self.assertEqual(self.password, session_or_base_auth._password)
     auth_close.assert_called_once_with(session_or_base_auth)