Skip to contentSkip to conversation

KVM test: refactor kvm_config.py

PATCH New Michael Goldish 1 participant 1 message Feb 11, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM test: refactor kvm_config.py

This is a reimplementation of the dict generator. It is much faster than the current implementation and uses a very small amount of memory. Running time and memory usage scale polynomially with the number of defined variants, compared to exponentially in the current implementation.

Instead of regular expressions in the filters, the following syntax is used:

, means OR
.. means AND
. means IMMEDIATELY-FOLLOWED-BY

Example:

only qcow2..Fedora.14, RHEL.6..raw..boot, smp2..qcow2..migrate..ide

means select all dicts whose names have:

(qcow2 AND (Fedora IMMEDIATELY-FOLLOWED-BY 14)) OR ((RHEL IMMEDIATELY-FOLLOWED-BY 6) AND raw AND boot) OR (smp2 AND qcow2 AND migrate AND ide)

'qcow2..Fedora.14' is equivalent to 'Fedora.14..qcow2'. 'qcow2..Fedora.14' is not equivalent to 'qcow2..14.Fedora'. 'ide, scsi' is equivalent to 'scsi, ide'.

Filters can be used in 3 ways:
only <filter>
no <filter>
<filter>:

The last one starts a conditional block, e.g.

Fedora.14..qcow2:
no migrate, reboot
foo = bar

Interface changes:
- The main class is now called 'Parser' instead of 'config'.
- fork_and_parse() has been removed. parse_file() and parse_string() should be used instead.
- When run as a standalone program, kvm_config.py just prints the shortnames of the generated dicts by default, and can optionally print the full names and contents of the dicts.
- By default, debug messages are not printed, but they can be enabled by passing debug=True to Parser's constructor, or by running kvm_config.py -v.
- The 'depend' key has been renamed to 'dep'.

Changes from v1:
- Check the syntax of filters and variant definitions and raise an exception if an error is found.
- Support the 'del' operator ('del key' removes key).
- Store simple statements as Op objects instead of storing them as strings.

---
 client/tests/kvm/control               |   28 +-
 client/tests/kvm/control.parallel      |   12 +-
 client/tests/kvm/kvm_config.py         | 1124 +++++++++++++++-----------------
 client/tests/kvm/kvm_scheduler.py      |    9 +-
 client/tests/kvm/kvm_utils.py          |    2 +-
 client/tests/kvm/tests.cfg.sample      |   13 +-
 client/tests/kvm/tests_base.cfg.sample |   46 +-
 7 files changed, 581 insertions(+), 653 deletions(-)
client/tests/kvm/control +14 -14
index d226adf..be37678 100644
@@ -35,13 +35,11 @@ str = """
 # build configuration here.  For example:
 #release_tag = 84
 """
-build_cfg = kvm_config.config()
-# As the base test config is quite large, in order to save memory, we use the
-# fork_and_parse() method, that creates another parser process and destroys it
-# at the end of the parsing, so the memory spent can be given back to the OS.
-build_cfg_path = os.path.join(kvm_test_dir, "build.cfg")
-build_cfg.fork_and_parse(build_cfg_path, str)
-if not kvm_utils.run_tests(build_cfg.get_generator(), job):
+
+parser = kvm_config.Parser()
+parser.parse_file(os.path.join(kvm_test_dir, "build.cfg"))
+parser.parse_string(str)
+if not kvm_utils.run_tests(parser.get_dicts(), job):
     logging.error("KVM build step failed, exiting.")
     sys.exit(1)
 
@@ -49,10 +47,11 @@ str = """
 # This string will be parsed after tests.cfg.  Make any desired changes to the
 # test configuration here.  For example:
 #display = sdl
-#install|setup: timeout_multiplier = 3
+#install, setup: timeout_multiplier = 3
 """
-tests_cfg = kvm_config.config()
-tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg")
+
+parser = kvm_config.Parser()
+parser.parse_file(os.path.join(kvm_test_dir, "tests.cfg"))
 
 if args:
     # We get test parameters from command line
@@ -67,11 +66,12 @@ if args:
                 str += "%s = %s\n" % (key, value)
         except IndexError:
             pass
-tests_cfg.fork_and_parse(tests_cfg_path, str)
+parser.parse_string(str)
 
-# Run the tests
-kvm_utils.run_tests(tests_cfg.get_generator(), job)
+logging.info("Selected tests:")
+for i, d in enumerate(parser.get_dicts()):
+    logging.info("Test %4d:  %s" % (i + 1, d["shortname"]))
+kvm_utils.run_tests(parser.get_dicts(), job)
 
 # Generate a nice HTML report inside the job's results dir
 kvm_utils.create_report(kvm_test_dir, job.resultdir)
-
client/tests/kvm/control.parallel +5 -7
index ac84638..640ccf5 100644
@@ -163,16 +163,15 @@ import kvm_config
 str = """
 # This string will be parsed after tests.cfg.  Make any desired changes to the
 # test configuration here.  For example:
-#install|setup: timeout_multiplier = 3
-#only fc8_quick
+#install, setup: timeout_multiplier = 3
 #display = sdl
 """
-cfg = kvm_config.config()
-filename = os.path.join(pwd, "tests.cfg")
-cfg.fork_and_parse(filename, str)
 
-tests = cfg.get_list()
+parser = kvm_config.Parser()
+parser.parse_file(os.path.join(pwd, "tests.cfg"))
+parser.parse_string(str)
 
+tests = list(parser.get_dicts())
 
 # -------------
 # Run the tests
@@ -192,7 +191,6 @@ s = kvm_scheduler.scheduler(tests, num_workers, total_cpus, total_mem, pwd)
 job.parallel([s.scheduler],
              *[(s.worker, i, job.run_test) for i in range(num_workers)])
 
-
 # create the html report in result dir
 reporter = os.path.join(pwd, 'make_html_report.py')
 html_file = os.path.join(job.resultdir,'results.html')
client/tests/kvm/kvm_config.py +531 -593

1,255 lines not on this page · raw message

client/tests/kvm/kvm_scheduler.py +4 -5
index 95282e4..b96bb32 100644
@@ -63,7 +63,6 @@ class scheduler:
                 test_index = int(cmd[1])
                 test = self.tests[test_index].copy()
                 test.update(self_dict)
-                test = kvm_utils.get_sub_pool(test, index, self.num_workers)
                 test_iterations = int(test.get("iterations", 1))
                 status = run_test_func("kvm", params=test,
                                        tag=test.get("shortname"),
@@ -129,7 +128,7 @@ class scheduler:
                     # If the test failed, mark all dependent tests as "failed" too
                     if not status:
                         for i, other_test in enumerate(self.tests):
-                            for dep in other_test.get("depend", []):
+                            for dep in other_test.get("dep", []):
                                 if dep in test["name"]:
                                     test_status[i] = "fail"
 
@@ -154,7 +153,7 @@ class scheduler:
                         continue
                     # Make sure the test's dependencies are satisfied
                     dependencies_satisfied = True
-                    for dep in test["depend"]:
+                    for dep in test["dep"]:
                         dependencies = [j for j, t in enumerate(self.tests)
                                         if dep in t["name"]]
                         bad_status_deps = [j for j in dependencies
@@ -200,14 +199,14 @@ class scheduler:
                     used_mem[worker] = test_used_mem
                     # Assign all related tests to this worker
                     for j, other_test in enumerate(self.tests):
-                        for other_dep in other_test["depend"]:
+                        for other_dep in other_test["dep"]:
                             # All tests that depend on this test
                             if other_dep in test["name"]:
                                 test_worker[j] = worker
                                 break
                             # ... and all tests that share a dependency
                             # with this test
-                            for dep in test["depend"]:
+                            for dep in test["dep"]:
                                 if dep in other_dep or other_dep in dep:
                                     test_worker[j] = worker
                                     break
client/tests/kvm/kvm_utils.py +1 -1
index 44ebb88..9e25a0a 100644
@@ -1101,7 +1101,7 @@ def run_tests(test_list, job):
         if dict.get("skip") == "yes":
             continue
         dependencies_satisfied = True
-        for dep in dict.get("depend"):
+        for dep in dict.get("dep"):
             for test_name in status_dict.keys():
                 if not dep in test_name:
                     continue
client/tests/kvm/tests.cfg.sample +6 -7
index bde7aba..4b3b965 100644
@@ -18,10 +18,9 @@ include cdkeys.cfg
 image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/
 cdrom(_.*)? ?<= /tmp/kvm_autotest_root/
 floppy ?<= /tmp/kvm_autotest_root/
-Linux:
-    unattended_install:
-        kernel ?<= /tmp/kvm_autotest_root/
-        initrd ?<= /tmp/kvm_autotest_root/
+Linux..unattended_install:
+    kernel ?<= /tmp/kvm_autotest_root/
+    initrd ?<= /tmp/kvm_autotest_root/
 
 # Here are the test sets variants. The variant 'qemu_kvm_windows_quick' is
 # fully commented, the following ones have comments only on noteworthy points
@@ -49,7 +48,7 @@ variants:
         # Operating system choice
         only Win7.64
         # Subtest choice. You can modify that line to add more subtests
-        only unattended_install.cdrom boot shutdown
+        only unattended_install.cdrom, boot, shutdown
 
     # Runs qemu, f14 64 bit guest OS, install, boot, shutdown
     - @qemu_f14_quick:
@@ -65,7 +64,7 @@ variants:
         only no_pci_assignable
         only smallpages
         only Fedora.14.64
-        only unattended_install.cdrom boot shutdown
+        only unattended_install.cdrom, boot, shutdown
         # qemu needs -enable-kvm on the cmdline
         extra_params += ' -enable-kvm'
 
@@ -81,7 +80,7 @@ variants:
         only no_pci_assignable
         only smallpages
         only Fedora.14.64
-        only unattended_install.cdrom boot shutdown
+        only unattended_install.cdrom, boot, shutdown
 
 # You may provide information about the DTM server for WHQL tests here:
 #whql:
client/tests/kvm/tests_base.cfg.sample +20 -26

169 lines not on this page · raw message

Signature · 1 line
1.7.3.4