本文整理汇总了Python中oslo_db.exception.DBConnectionError方法的典型用法代码示例。如果您正苦于以下问题:Python exception.DBConnectionError方法的具体用法?Python exception.DBConnectionError怎么用?Python exception.DBConnectionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_db.exception
的用法示例。
在下文中一共展示了exception.DBConnectionError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_connection
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _test_connection(engine, max_retries, retry_interval):
if max_retries == -1:
attempts = itertools.count()
else:
attempts = range(max_retries)
# See: http://legacy.python.org/dev/peps/pep-3110/#semantic-changes for
# why we are not using 'de' directly (it can be removed from the local
# scope).
de_ref = None
for attempt in attempts:
try:
return engine.connect()
except exception.DBConnectionError as de:
msg = 'SQL connection failed. %s attempts left.'
LOG.warning(msg, max_retries - attempt)
time.sleep(retry_interval)
de_ref = de
else:
if de_ref is not None:
raise de_ref
示例2: _raise_operational_errors_directly_filter
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _raise_operational_errors_directly_filter(operational_error,
match, engine_name,
is_disconnect):
"""Filter for all remaining OperationalError classes and apply.
Filter for all remaining OperationalError classes and apply
special rules.
"""
if is_disconnect:
# operational errors that represent disconnect
# should be wrapped
raise exception.DBConnectionError(operational_error)
else:
# NOTE(comstud): A lot of code is checking for OperationalError
# so let's not wrap it for now.
raise operational_error
示例3: __init__
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def __init__(self, retry_interval=1, max_retries=20,
inc_retry_interval=True,
max_retry_interval=10, retry_on_disconnect=False,
retry_on_deadlock=False,
exception_checker=lambda exc: False,
jitter=False):
super(wrap_db_retry, self).__init__()
self.jitter = jitter
self.db_error = (exception.RetryRequest, )
# default is that we re-raise anything unexpected
self.exception_checker = exception_checker
if retry_on_disconnect:
self.db_error += (exception.DBConnectionError, )
if retry_on_deadlock:
self.db_error += (exception.DBDeadlock, )
self.retry_interval = retry_interval
self.max_retries = max_retries
self.inc_retry_interval = inc_retry_interval
self.max_retry_interval = max_retry_interval
示例4: test_rollback_doesnt_interfere_with_killed_conn
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_rollback_doesnt_interfere_with_killed_conn(self):
session = self.sessionmaker()
session.begin()
try:
session.execute("select 1")
# close underying DB connection
session.connection().connection.connection.close()
# alternate approach, but same idea:
# conn_id = session.scalar("select connection_id()")
# session.execute("kill connection %s" % conn_id)
# try using it, will raise an error
session.execute("select 1")
except exception.DBConnectionError:
# issue being tested is that this session.rollback()
# does not itself try to re-connect and raise another
# error.
session.rollback()
else:
assert False, "no exception raised"
示例5: test_savepoint_rollback_doesnt_interfere_with_killed_conn
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_savepoint_rollback_doesnt_interfere_with_killed_conn(self):
session = self.sessionmaker()
session.begin()
try:
session.begin_nested()
session.execute("select 1")
# close underying DB connection
session.connection().connection.connection.close()
# alternate approach, but same idea:
# conn_id = session.scalar("select connection_id()")
# session.execute("kill connection %s" % conn_id)
# try using it, will raise an error
session.execute("select 1")
except exception.DBConnectionError:
# issue being tested is that this session.rollback()
# does not itself try to re-connect and raise another
# error.
session.rollback()
else:
assert False, "no exception raised"
示例6: _api_raise
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _api_raise(self, *args, **kwargs):
"""Simulate raising a database-has-gone-away error
This method creates a fake OperationalError with an ID matching
a valid MySQL "database has gone away" situation. It also decrements
the error_counter so that we can artificially keep track of
how many times this function is called by the wrapper. When
error_counter reaches zero, this function returns True, simulating
the database becoming available again and the query succeeding.
"""
if self.error_counter > 0:
self.error_counter -= 1
orig = sqla.exc.DBAPIError(False, False, False)
orig.args = [2006, 'Test raise operational error']
e = exception.DBConnectionError(orig)
raise e
else:
return True
示例7: test_report_state_newly_disconnected
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_report_state_newly_disconnected(self):
service_ref = {'host': self.host,
'binary': self.binary,
'topic': self.topic,
'report_count': 0,
'id': 1}
with mock.patch.object(service, 'db') as mock_db:
mock_db.service_get_by_args.side_effect = exception.NotFound()
mock_db.service_create.return_value = service_ref
mock_db.service_get.side_effect = db_exc.DBConnectionError()
serv = service.Service(
self.host,
self.binary,
self.topic,
'karbor.tests.unit.test_service.FakeManager'
)
serv.start()
serv.report_state()
self.assertTrue(serv.model_disconnected)
self.assertFalse(mock_db.service_update.called)
示例8: test_health_check_stale_amphora
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_health_check_stale_amphora(self, session_mock, get_stale_amp_mock,
failover_mockv2, failover_mock,
db_wait_mock):
conf = oslo_fixture.Config(cfg.CONF)
conf.config(group="health_manager", heartbeat_timeout=5)
amphora_health = mock.MagicMock()
amphora_health.amphora_id = AMPHORA_ID
get_stale_amp_mock.side_effect = [amphora_health, None]
exit_event = threading.Event()
hm = healthmanager.HealthManager(exit_event)
hm.health_check()
# Test DBDeadlock and RetryRequest exceptions
session_mock.reset_mock()
get_stale_amp_mock.reset_mock()
mock_session = mock.MagicMock()
session_mock.return_value = mock_session
get_stale_amp_mock.side_effect = [
db_exc.DBDeadlock,
db_exc.RetryRequest(Exception('retry_test')),
db_exc.DBConnectionError,
TestException('test')]
# Test that a DBDeadlock does not raise an exception
self.assertIsNone(hm.health_check())
# Test that a RetryRequest does not raise an exception
self.assertIsNone(hm.health_check())
# Test that a DBConnectionError does not raise an exception
self.assertIsNone(hm.health_check())
# ... and that it waits for DB reconnection
db_wait_mock.assert_called_once()
# Other exceptions should raise
self.assertRaises(TestException, hm.health_check)
self.assertEqual(4, mock_session.rollback.call_count)
示例9: _connect_ping_listener
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _connect_ping_listener(connection, branch):
"""Ping the server at connection startup.
Ping the server at transaction begin and transparently reconnect
if a disconnect exception occurs.
"""
if branch:
return
# turn off "close with result". This can also be accomplished
# by branching the connection, however just setting the flag is
# more performant and also doesn't get involved with some
# connection-invalidation awkardness that occurs (see
# https://bitbucket.org/zzzeek/sqlalchemy/issue/3215/)
save_should_close_with_result = connection.should_close_with_result
connection.should_close_with_result = False
try:
# run a SELECT 1. use a core select() so that
# any details like that needed by Oracle, DB2 etc. are handled.
connection.scalar(select([1]))
except exception.DBConnectionError:
# catch DBConnectionError, which is raised by the filter
# system.
# disconnect detected. The connection is now
# "invalid", but the pool should be ready to return
# new connections assuming they are good now.
# run the select again to re-validate the Connection.
LOG.exception(
'Database connection was found disconnected; reconnecting')
connection.scalar(select([1]))
finally:
connection.should_close_with_result = save_should_close_with_result
示例10: _is_db_connection_error
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _is_db_connection_error(operational_error, match, engine_name,
is_disconnect):
"""Detect the exception as indicating a recoverable error on connect."""
raise exception.DBConnectionError(operational_error)
示例11: _raise_for_remaining_DBAPIError
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _raise_for_remaining_DBAPIError(error, match, engine_name, is_disconnect):
"""Filter for remaining DBAPIErrors.
Filter for remaining DBAPIErrors and wrap if they represent
a disconnect error.
"""
if is_disconnect:
raise exception.DBConnectionError(error)
else:
LOG.warning('DBAPIError exception wrapped.', exc_info=True)
raise exception.DBError(error)
示例12: test_generic_dbapi_disconnect
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_generic_dbapi_disconnect(self):
matched = self._run_test(
"mysql", "select the_db_disconnected",
self.InterfaceError("connection lost"),
exception.DBConnectionError,
is_disconnect=True
)
self.assertInnerException(
matched,
"InterfaceError", "connection lost",
"select the_db_disconnected", ()),
示例13: test_operational_dbapi_disconnect
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_operational_dbapi_disconnect(self):
matched = self._run_test(
"mysql", "select the_db_disconnected",
self.OperationalError("connection lost"),
exception.DBConnectionError,
is_disconnect=True
)
self.assertInnerException(
matched,
"OperationalError", "connection lost",
"select the_db_disconnected", ()),
示例14: test_connect_retry_stops_infailure
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def test_connect_retry_stops_infailure(self):
self.assertRaises(
exception.DBConnectionError,
self._run_test,
"mysql",
self.OperationalError("Error: (2003) something wrong"),
3, 2
)
示例15: _test_ping_listener_disconnected
# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import DBConnectionError [as 别名]
def _test_ping_listener_disconnected(
self, dialect_name, exc_obj, is_disconnect=True):
with self._fixture(dialect_name, exc_obj, 3, is_disconnect):
conn = self.engine.connect()
self.assertEqual(1, conn.scalar(sqla.select([1])))
conn.close()
with self._fixture(dialect_name, exc_obj, 1, is_disconnect):
self.assertRaises(
exception.DBConnectionError,
self.engine.connect
)
self.assertRaises(
exception.DBConnectionError,
self.engine.connect
)
self.assertRaises(
exception.DBConnectionError,
self.engine.connect
)
with self._fixture(dialect_name, exc_obj, 1, is_disconnect):
self.assertRaises(
exception.DBConnectionError,
self.engine.connect
)
self.assertRaises(
exception.DBConnectionError,
self.engine.connect
)
self.assertRaises(
exception.DBConnectionError,
self.engine.connect
)