On Wed, 2012-08-01 at 11:13 -0300, Lucas Meneghel Rodrigues wrote:
> From: Feng Yang <[email protected]>
> 
> 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.
> 
> Signed-off-by: Feng Yang <[email protected]>
> ---
>  client/virt/virt_test.py | 49 
> ++++++++++++++++++++++++++----------------------
>  1 file changed, 27 insertions(+), 22 deletions(-)
> 
> diff --git a/client/virt/virt_test.py b/client/virt/virt_test.py
> index d9e052e..deade2e 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,19 +68,25 @@ 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 = {}

Here, you have defined a dict that will be used later to run the tests,
good.

> +                    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_module = imp.load_module(t_type, f, p, d)
> +                        f.close()

But here on this loop you don't update the dict whatsoever. it'll end up
empty and not doing what you want.

The obvious fix is to actually update the dict:

diff --git a/client/virt/virt_test.py b/client/virt/virt_test.py
index deade2e..5912fd4 100644
--- a/client/virt/virt_test.py
+++ b/client/virt/virt_test.py
@@ -86,6 +86,7 @@ class virt_test(test.test):
                         # Load the test module
                         f, p, d = imp.find_module(t_type, [subtest_dir])
                         test_module = imp.load_module(t_type, f, p, d)
+                        test_modules[t_type] = test_module
                         f.close()
 
                     # Preprocess

Then it starts doing what you want. Now, with the fix, the patch looks
OK, but messing around with this core code might bring problems, and I'd
only accept it if we have things very well tested, to reduce the chance
of breakages. I've had enough trouble on Mon and Tue fixing bugs that
could have been caught by more careful testing (ok, the bugs are my
fault, but anyway, we need to be more careful).

>  
>                      # Preprocess
>                      try:
> @@ -92,11 +94,14 @@ class virt_test(test.test):
>                      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():
> +                        logging.info("Running function: %s.run_%s" % (t_type,
> +                                                                      
> t_type))
> +                        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

Reply via email to