[libvirt] [test-API PATCH 1/3] cleanup:make clean function optional

Guannan Ren gren at redhat.com
Mon Apr 16 06:11:21 UTC 2012


    The patch make the writing of clean function optional
    If a testcase makes testing environment dirty after running, it
    must write a CASENAME_clean function to restore back the
    testing environment, otherwise, the clean function could be omitted
---
 env_clear.py |    9 ++++-----
 proxy.py     |    7 ++++---
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/env_clear.py b/env_clear.py
index 3efc9be..2e5bcf5 100644
--- a/env_clear.py
+++ b/env_clear.py
@@ -30,7 +30,7 @@ class EnvClear(object):
         self.loglevel = loglevel
 
         mapper_obj = mapper.Mapper(activity)
-        clean_pkg_casename_func = mapper_obj.clean_package_casename_func_map()
+        clean_pkg_casename_func = mapper_obj.module_casename_cleanfunc_map()
 
         self.cases_ref_names = []
         for case in clean_pkg_casename_func:
@@ -47,7 +47,7 @@ class EnvClear(object):
         return retflag
 
     def env_clear(self):
-        """ Run each clearing function with the corresponding arguments """
+        """ Run each clean function with the corresponding arguments """
 
         envlog = log.EnvLog(self.logfile, self.loglevel)
         logger = envlog.env_log()
@@ -60,8 +60,7 @@ class EnvClear(object):
             case_params = self.cases_params_list[i]
 
             case_params['logger'] = logger
-            self.cases_clearfunc_ref_dict[case_ref_name](case_params)
-
-        del envlog
+            if self.cases_clearfunc_ref_dict.has_key(case_ref_name):
+                self.cases_clearfunc_ref_dict[case_ref_name](case_params)
 
         return 0
diff --git a/proxy.py b/proxy.py
index 3c4cd63..fdbffd9 100644
--- a/proxy.py
+++ b/proxy.py
@@ -85,12 +85,13 @@ class Proxy(object):
             var_func_names = dir(casemod_ref)
 
             key = module + ':' + casename + ':' + func
+
+            # the clean function is optional, we get its reference
+            # only if it exists in testcases
             if func in var_func_names:
                 func_ref = getattr(casemod_ref, func)
                 func_dict[key] = func_ref
-            else:
-                raise exception.TestCaseError("clean function not found in %s" % \
-                                              (func, testcase_name))
+
         return func_dict
 
     def get_params_variables(self):
-- 
1.7.7.5




More information about the libvir-list mailing list