Add DBError to _is_nested_instance
Add support for oslo.db's DBError to is_nested_instance so we can check for IntegrityErrors in DBErrors easily that come back from oslo.db. This will enable the patch that depends on this to detect port creation/network delete races very easily and retry them. Change-Id: I617f2549caced6547d478caba968710ad8f913b3
This commit is contained in:
parent
2eaadd4050
commit
0df9087b37
@ -185,9 +185,13 @@ def reraise_as_retryrequest(f):
|
||||
|
||||
def _is_nested_instance(e, etypes):
|
||||
"""Check if exception or its inner excepts are an instance of etypes."""
|
||||
return (isinstance(e, etypes) or
|
||||
isinstance(e, exceptions.MultipleExceptions) and
|
||||
any(_is_nested_instance(i, etypes) for i in e.inner_exceptions))
|
||||
if isinstance(e, etypes):
|
||||
return True
|
||||
if isinstance(e, exceptions.MultipleExceptions):
|
||||
return any(_is_nested_instance(i, etypes) for i in e.inner_exceptions)
|
||||
if isinstance(e, db_exc.DBError):
|
||||
return _is_nested_instance(e.inner_exception, etypes)
|
||||
return False
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
@ -36,6 +36,11 @@ class TestExceptionToRetryContextManager(base.BaseTestCase):
|
||||
with db_api.exc_to_retry((ValueError, TypeError)):
|
||||
raise TypeError()
|
||||
|
||||
def test_translates_DBerror_inner_exception(self):
|
||||
with testtools.ExpectedException(db_exc.RetryRequest):
|
||||
with db_api.exc_to_retry(ValueError):
|
||||
raise db_exc.DBError(ValueError())
|
||||
|
||||
def test_passes_other_exceptions(self):
|
||||
with testtools.ExpectedException(ValueError):
|
||||
with db_api.exc_to_retry(TypeError):
|
||||
|
Loading…
x
Reference in New Issue
Block a user