[test-API PATCH 3/4] proxy: improve it to support testcase options checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 proxy.py |   78 ++++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 48 insertions(+), 30 deletions(-)

diff --git a/proxy.py b/proxy.py
index 3cd31bd..990e1f0 100644
--- a/proxy.py
+++ b/proxy.py
@@ -20,7 +20,6 @@
 
 import exception
 
-
 class Proxy(object):
     """ The Proxy class is used for getting real function call reference """
 
@@ -30,59 +29,75 @@ class Proxy(object):
 
     def get_func_call_dict(self):
         """Return running function reference dictionary """
-        self.func_dict = dict()
+        func_dict = dict()
         for testcase_name in self.testcases_names:
-            # Get programming package, casename
+            # Get module, casename
             elements = testcase_name.split(":")
-            package = elements[0]
+            module = elements[0]
             casename = elements[1]
             func = casename
 
             if len(elements) == 3:
-                keyword = elements[2]
-                func = casename + keyword
+                # flag is like ":_clean" in testcases_names
+                # this func is for _clean function in testcase
+                flag = elements[2]
+                func = casename + flag
 
-            # Dispatch functions
-            funcs = getattr(self, "get_call_dict")
-            func_ref = None
-            func_ref = funcs(package, casename, func)
+            func_ref = self.get_call_dict(module, casename, func)
 
             # Construct function call dictionary
-            key = package + ":" + casename + ":" + func
-            self.func_dict[key] = func_ref
-        return self.func_dict
+            key = module + ":" + casename + ":" + func
+            func_dict[key] = func_ref
+
+        return func_dict
 
     def get_clearfunc_call_dict(self):
         """ Return a clearing function reference dictionary. """
-        self.func_dict = dict()
+        func_dict = dict()
         for testcase_name in self.testcases_names:
-            # Get programming package, casename
+            # Get module, casename
             elements = testcase_name.split(":")
 
             if len(elements) == 3:
                 continue
 
-            package = testcase_name.split(":")[0]
+            module = testcase_name.split(":")[0]
             casename = testcase_name.split(":")[1]
-
-            # According to language kind to dispatch function
-            funcs = getattr(self, "get_call_dict")
-            func_ref = None
             func = casename + "_clean"
 
-            func_ref = funcs(package, casename, func)
+            func_ref = self.get_call_dict(module, casename, func)
 
             # Construct function call dictionary
-            key = package + ":" + casename + ":" + func
-            self.func_dict[key] = func_ref
-        return self.func_dict
+            key = module + ":" + casename + ":" + func
+            func_dict[key] = func_ref
+
+        return func_dict
 
-    def get_call_dict(self, *args):
+    def get_params_variables(self):
+        """ Return the reference to global variable 'required_params'
+            in testcase
+        """
+        case_params = {}
+        for testcase_name in self.testcases_names:
+            elements = testcase_name.split(":")
+
+            if len(elements) == 3:
+                continue
+
+            module = testcase_name.split(":")[0]
+            casename = testcase_name.split(":")[1]
+
+            mod_ref = self.get_call_dict(module, casename)
+            case_params[testcase_name] = \
+                [mod_ref.required_params, mod_ref.optional_params]
+
+        return case_params
+
+    def get_call_dict(self, module, casename, func = None):
         """ Return testing function reference dictionary """
-        (package, casename, func) = args
-        case_abs_path = '%s.%s.%s' % ('repos', package, casename)
+        case_abs_path = '%s.%s.%s' % ('repos', module, casename)
 
-        # Main function name is the same as casename here
+        # import tescase file
         case_mod = __import__(case_abs_path)
         components = case_abs_path.split('.')
 
@@ -91,6 +106,9 @@ class Proxy(object):
             if component == "":
                 raise exception.CaseConfigfileError("Missing module name after \":\"")
             case_mod = getattr(case_mod, component)
-        main_function_ref = getattr(case_mod, func)
-        return main_function_ref
 
+        if func:
+            main_function_ref = getattr(case_mod, func)
+            return main_function_ref
+
+        return case_mod
-- 
1.7.7.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]