----- Original Message ----- From: "Alex Jia" <[email protected]> To: "Feng Yang" <[email protected]> Cc: [email protected] Sent: Thursday, August 16, 2012 4:16:10 PM Subject: Re: [Autotest] [PATCH V2] virt: Support multi type in kvm test
On 08/10/2012 11:17 AM, Feng Yang wrote: > This patch is useful if we want use existing script to combinate new test > case. > We have migrate test script and s4 test script. After this patch it is > easy for us to get s4 after migration or migration after s4 by updating > configure. > > Changes from v1: > Fix bug introduced in code merge. Test patch in local. > > Signed-off-by: Feng Yang<[email protected]> > --- > client/virt/virt_test.py | 48 > ++++++++++++++++++++++++--------------------- > 1 files changed, 26 insertions(+), 22 deletions(-) > > diff --git a/client/virt/virt_test.py b/client/virt/virt_test.py > index d9e052e..7ccdcb1 100644 > --- a/client/virt/virt_test.py > +++ b/client/virt/virt_test.py > @@ -53,10 +53,6 @@ class virt_test(test.test): > try: > try: > try: > - # Get the test routine corresponding to the specified > - # test type > - t_type = params.get("type") > - > subtest_dirs = [] > tests_dir = self.job.testdir > > @@ -72,31 +68,39 @@ class virt_test(test.test): > subtest_dirs.append(os.path.join(virt_dir, "tests")) > subtest_dirs.append(os.path.join(self.bindir, "tests")) > subtest_dir = None > - for d in subtest_dirs: > - module_path = os.path.join(d, "%s.py" % t_type) > - if os.path.isfile(module_path): > - subtest_dir = d > - break > - if subtest_dir is None: > - raise error.TestError("Could not find test file > %s.py " > - "on tests dirs %s" % > - (t_type, subtest_dirs)) > - # Load the test module > - f, p, d = imp.find_module(t_type, [subtest_dir]) > - test_module = imp.load_module(t_type, f, p, d) > - f.close() > > + # Get the test routine corresponding to the specified > + # test type > + t_types = params.get("type").split() > + test_modules = {} Note that is the python dictionary is unordered. > + for t_type in t_types: > + for d in subtest_dirs: > + module_path = os.path.join(d, "%s.py" % t_type) > + if os.path.isfile(module_path): > + subtest_dir = d > + break > + if subtest_dir is None: > + msg = "Could not find test file %s.py on tests"\ > + "dirs %s" % (t_type, subtest_dirs) > + raise error.TestError(msg) > + # Load the test module > + f, p, d = imp.find_module(t_type, [subtest_dir]) > + test_modules[t_type] = imp.load_module(t_type, f, p, > d) For example, the 'test_modules' may be {'a': 1, 'c': 3, 'b': 2, ...} or {'c': 3, 'a': 1, 'b': 2, ...} or ... > + f.close() > # Preprocess > try: > virt_env_process.preprocess(self, params, env) > finally: > env.save() > # Run the test function > - run_func = getattr(test_module, "run_%s" % t_type) > - try: > - run_func(self, params, env) > - finally: > - env.save() > + for t_type, test_module in test_modules.items(): And then the 'type' has been sequentially executed by codes, for s/has/hasn't/. example, type = "s4 migration" then the result is 'migration' case is run firstly, it's not our expected, so we should use a list with 2-tupes instead of dictionary to complete similar function, please check patch in the attachment. Alex > + msg = "Running function: %s.run_%s()" % (t_type, > t_type) > + logging.info(msg) > + run_func = getattr(test_module, "run_%s" % t_type) > + try: > + run_func(self, params, env) > + finally: > + env.save() > test_passed = True > > except Exception, e: _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
