cleanup resources in setUpClass if exception raised
Resources created would not be cleanup if exception raised
in setUpClass.
This patch adds a new decorator to wrap setUpClass for
catching the exception in setUpClass and cleanup resources
using tearDownClass().
Use the decorator in the following test classes:
FloatingIPsTestJSON
ImagesMetadataTestJSON
ListServerFiltersTestJSON
Change-Id: Ia20ebd2a5d1b5ecbd5e8b21e51e7c2ee4c99fbd5
Closes-Bug: #1285509
diff --git a/tempest/test.py b/tempest/test.py
index c6e3d6e..9332f93 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -63,6 +63,25 @@
return decorator
+def safe_setup(f):
+ """A decorator used to wrap the setUpClass for cleaning up resources
+ when setUpClass failed.
+ """
+
+ def decorator(cls):
+ try:
+ f(cls)
+ except Exception as se:
+ LOG.exception("setUpClass failed: %s" % se)
+ try:
+ cls.tearDownClass()
+ except Exception as te:
+ LOG.exception("tearDownClass failed: %s" % te)
+ raise se
+
+ return decorator
+
+
def services(*args, **kwargs):
"""A decorator used to set an attr for each service used in a test case