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()
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)
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()
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