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

Martin Kletzander mkletzan at redhat.com
Thu Apr 12 11:38:12 UTC 2012


On 04/11/2012 04:04 PM, Guannan Ren wrote:
>     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()

typo:
s/activitie/activity/

plus I'm not sure if we can be sure that all the activities are the same
in this call (if it's just a multiplication of one array)? On other
places (like 'libvirt-test-api.py') we check for all members in the array.

> +
> +    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:

second typo or copy paste error :)
s/activitie/activity/

> +            case_number += 1
> +            if testcase in passed_testcase:
> +                continue
> +
> +            testcase_name = testcase.keys()[0]
> +            actual_params = testcase.values()[0]

I don't quite understand what are you trying to achieve here. The order
of keys and values in python dict cannot be guaranteed if I'm not wrong.
And even if yes, that would mean you are checking just for the first
testcase, I guess. Or maybe I just don't get this right.

> +
> +            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

Martin




More information about the libvir-list mailing list