Pause resource cleanup

When pause_teardown flag in tempest.conf is set to True a pdb breakpoint
is added to tearDown and tearDownClass methods in test.py.
This allows to pause cleaning resources process, so that, used resources
can be examined. Closer examination of used resources may lead to faster
debugging.

Change-Id: I09b7721e64cda161289f915d30888ec54bbed821
This commit is contained in:
Martin Kopec 2017-06-26 09:41:21 +00:00
parent 7226611b00
commit ae155b7095
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,9 @@
---
features:
- |
Pause teardown
When pause_teardown flag in tempest.conf is set to True a pdb breakpoint
is added to tearDown and tearDownClass methods in test.py.
This allows to pause cleaning resources process, so that used resources
can be examined. Closer examination of used resources may lead to faster
debugging.

View File

@ -1070,6 +1070,15 @@ DefaultGroup = [
"prefix to ideintify resources which are "
"created by Tempest and no projects set "
"this option on OpenStack dev community."),
cfg.BoolOpt('pause_teardown',
default=False,
help="""Whether to pause a test in global teardown.
The best use case is investigating used resources of one test.
A test can be run as follows:
$ ostestr --pdb TEST_ID
or
$ python -m testtools.run TEST_ID"""),
]
_opts = [

View File

@ -247,6 +247,9 @@ class BaseTestCase(testtools.testcase.WithAttributes,
@classmethod
def tearDownClass(cls):
# insert pdb breakpoint when pause_teardown is enabled
if CONF.pause_teardown:
cls.insert_pdb_breakpoint()
at_exit_set.discard(cls)
# It should never be overridden by descendants
if hasattr(super(BaseTestCase, cls), 'tearDownClass'):
@ -283,6 +286,22 @@ class BaseTestCase(testtools.testcase.WithAttributes,
finally:
del trace # to avoid circular refs
def tearDown(self):
super(BaseTestCase, self).tearDown()
# insert pdb breakpoint when pause_teardown is enabled
if CONF.pause_teardown:
BaseTestCase.insert_pdb_breakpoint()
@classmethod
def insert_pdb_breakpoint(cls):
"""Add pdb breakpoint.
This can help in debugging process, cleaning of resources is
paused, so they can be examined.
"""
import pdb
pdb.set_trace()
@classmethod
def skip_checks(cls):
"""Class level skip checks.