コード例 #1
0
    def test_get_client_should_use_existing_session_if_present(
            self, get_session, _):
        sess = mock.Mock()
        sess.auth = mock.PropertyMock()
        sess.auth.get_auth_ref = mock.Mock()

        config = {'session': sess}
        keystone.get_client(**config)

        get_session.assert_not_called()
コード例 #2
0
    def test_get_client_should_create_session_if_missing(self, get_session, _):
        sess = mock.Mock()
        sess.auth = mock.PropertyMock()
        sess.auth.get_auth_ref = mock.Mock()

        config = {
            'username': __name__,
            'password': str(random.randint(10, 20))
        }
        keystone.get_client(**config)

        get_session.assert_called_once_with(**config)
コード例 #3
0
    def test_get_client_should_use_existing_session_if_present(self,
                                                               get_session,
                                                               _):
        sess = mock.Mock()
        sess.auth = mock.PropertyMock()
        sess.auth.get_auth_ref = mock.Mock()

        config = {
            'session': sess
        }
        keystone.get_client(**config)

        get_session.assert_not_called()
コード例 #4
0
    def test_get_client_should_create_session_if_missing(self,
                                                         get_session,
                                                         _):
        sess = mock.Mock()
        sess.auth = mock.PropertyMock()
        sess.auth.get_auth_ref = mock.Mock()

        config = {
            'username': __name__,
            'password': str(random.randint(10, 20))
        }
        keystone.get_client(**config)

        get_session.assert_called_once_with(**config)
コード例 #5
0
def get_tenant_list(config, log):
    tenants = []
    try:
        log.debug("Retrieving Keystone tenant list")
        client = keystone.get_client(**config)
        if 'v2' in client.__module__:
            tenants = client.tenants.list()
        else:
            tenants = client.projects.list()
    except Exception as e:
        msg = "Unable to get tenant list from keystone: {0}"
        log.error(msg.format(e))

    return tenants
コード例 #6
0
ファイル: utils.py プロジェクト: openstack/monasca-agent
def get_tenant_list(config, log):
    tenants = []
    try:
        log.debug("Retrieving Keystone tenant list")
        client = keystone.get_client(**config)
        if 'v2' in client.__module__:
            tenants = client.tenants.list()
        else:
            tenants = client.projects.list()
    except Exception as e:
        msg = "Unable to get tenant list from keystone: {0}"
        log.error(msg.format(e))

    return tenants