[test-API PATCH 2/4] cfgcheck: new class implement testcase config file checking

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

 



    casecfgcheck.py
---
 casecfgcheck.py |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 casecfgcheck.py

diff --git a/casecfgcheck.py b/casecfgcheck.py
new file mode 100644
index 0000000..3c4696d
--- /dev/null
+++ b/casecfgcheck.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+#
+# libvirt-test-API is copyright 2010, 2012 Red Hat, Inc.
+#
+# libvirt-test-API is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version. This program is distributed in
+# the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+# even the implied warranties of TITLE, NON-INFRINGEMENT,
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# The GPL text is available in the file COPYING that accompanies this
+# distribution and at <http://www.gnu.org/licenses>.
+#
+
+import proxy
+
+class CaseCfgCheck(object):
+    """validate the options in testcase config file"""
+    def __init__(self, unique_testcases, activities_list):
+        self.unique_testcases = unique_testcases
+
+        # XXX to check the first testcase list in activities_list
+        self.activitie = activities_list[0]
+
+        proxy_obj = proxy.Proxy(self.unique_testcases)
+        self.case_params = proxy_obj.get_params_variables()
+
+    def check(self):
+        """check options to each testcase in case config file"""
+        case_number = 0
+        error_flag = 0
+        passed_testcase = []
+        for testcase in self.activitie:
+            case_number += 1
+            if testcase in passed_testcase:
+                continue
+
+            testcase_name = testcase.keys()[0]
+            actual_params = testcase.values()[0]
+
+            required_params, optional_params = self.case_params[testcase_name]
+            ret = self._check_params(required_params, optional_params, actual_params)
+            if ret:
+                error_flag = 1
+                print "the No.%s : %s\n" % (case_number, testcase_name)
+
+            passed_testcase.append(testcase)
+
+        if error_flag:
+            return 1
+        return 0
+
+    def _check_params(self, required_params, optional_params, actual_params):
+        for p in required_params:
+            if p not in actual_params.keys():
+                print "Parameter %s is required" % p
+                return 1
+
+        for p in actual_params.keys():
+            if p not in required_params and p not in optional_params:
+                print "Unknown parameter '%s'" % p
+                return 1
+
+        return 0
-- 
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]