[FT] Capture and dismiss the `DBReferenceError` exceptions

The base testing class now captures the ``DBReferenceError`` exceptions
and retries the test execution. If the test raises the same exception
again, the test is skipped. However, it will be necessary to manually
check the cause of the error.

Related-Bug: #2121935
Signed-off-by: Rodolfo Alonso Hernandez <ralonsoh@redhat.com>
Change-Id: I904919fdfd604d1692b8d760978b38eeda26d931
This commit is contained in:
Rodolfo Alonso Hernandez
2025-09-03 11:27:08 +00:00
committed by Rodolfo Alonso
parent 82f71409bb
commit 7a1a8038f9

View File

@@ -171,17 +171,25 @@ class AttributeDict(dict):
raise AttributeError(_("Unknown attribute '%s'.") % name)
def _catch_timeout(f):
def _catch_errors(f):
@functools.wraps(f)
def func(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except eventlet.Timeout as e:
self.fail('Execution of this test timed out: %s' % e)
except db_exceptions.DBReferenceError:
# TODO(ralonsoh): fix the ``DBReferenceError`` issues in the functional
# tests. This is retrying the test execution once more. If it fails
# again, the test is skipped. See LP#2121935
self.skipTest(
'The test raised a ``DBReferenceError`` exception; please '
'check if this issue is a random occurrence or is '
'explicitly caused by the test')
return func
class _CatchTimeoutMetaclass(abc.ABCMeta):
class _CatchErrorsMetaclass(abc.ABCMeta):
def __init__(cls, name, bases, dct):
super().__init__(name, bases, dct)
for name, method in inspect.getmembers(
@@ -189,14 +197,14 @@ class _CatchTimeoutMetaclass(abc.ABCMeta):
# both unbound methods (python2) and functions (python3)
cls, predicate=inspect.isroutine):
if name.startswith('test_'):
setattr(cls, name, _catch_timeout(method))
setattr(cls, name, _catch_errors(method))
# Test worker cannot survive eventlet's Timeout exception, which effectively
# kills the whole worker, with all test cases scheduled to it. This metaclass
# makes all test cases convert Timeout exceptions into unittest friendly
# failure mode (self.fail).
class DietTestCase(base.BaseTestCase, metaclass=_CatchTimeoutMetaclass):
class DietTestCase(base.BaseTestCase, metaclass=_CatchErrorsMetaclass):
"""Same great taste, less filling.
BaseTestCase is responsible for doing lots of plugin-centric setup