KVM test: A memory efficient kvm_config implementation
RFC PATCH v2 1/1 KVM test: A memory efficient kvm_config implementation
This patch:
- Makes kvm_config use less memory during parsing, by storing config data compactly in arrays during parsing, and generating the final dicts only when requested.
On my machine this results in 5-10 times less memory being used (depending on the size of the final generated list).
This allows the test configuration to keep expanding without having the parser run out of memory.
- Adds config.fork_and_parse(), a function that parses a config file/string in a forked process and then terminates the process. This works around Python's policy of keeping allocated memory to itself even after the objects occupying the memory have been destroyed. If the process that does the parsing is the same one that runs the tests, less memory will be available to the VMs during testing.
- Makes parsing 4-5 times faster as a result of the new internal representation.
Differences from previous version:
- Added config.get_generator() which is similar to get_list() but returns a dict generator instead of a list. This should save some more memory and will make tests start sooner.
- Use get_generator() in control.
- Call waitpid() at the end of fork_and_parse().
--- client/tests/kvm/control | 30 +- client/tests/kvm/control.parallel | 21 +- client/tests/kvm/kvm_config.py | 669 +++++++++++++++++++++++-------------- 3 files changed, 440 insertions(+), 280 deletions(-)
client/tests/kvm/control +17 -13
@@ -30,34 +30,38 @@ import kvm_utils, kvm_config # set English environment (command output might be localized, need to be safe) os.environ['LANG'] = 'en_US.UTF-8' -build_cfg_path = os.path.join(kvm_test_dir, "build.cfg") -build_cfg = kvm_config.config(build_cfg_path) -# Make any desired changes to the build configuration here. For example: -#build_cfg.parse_string(""" +str = """ +# This string will be parsed after build.cfg. Make any desired changes to the +# build configuration here. For example: #release_tag = 84 -#""") -if not kvm_utils.run_tests(build_cfg.get_list(), job): +""" +build_cfg = kvm_config.config() +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): logging.error("KVM build step failed, exiting.") sys.exit(1) -tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg") -tests_cfg = kvm_config.config(tests_cfg_path) -# Make any desired changes to the test configuration here. For example: -#tests_cfg.parse_string(""" +str = """ +# This string will be parsed after tests.cfg. Make any desired configuration +# changes here. For example: #display = sdl #install|setup: timeout_multiplier = 3 -#""") +""" +tests_cfg = kvm_config.config() +tests_cfg_path = os.path.join(kvm_test_dir, "tests.cfg") +tests_cfg.fork_and_parse(tests_cfg_path, str) pools_cfg_path = os.path.join(kvm_test_dir, "address_pools.cfg") tests_cfg.parse_file(pools_cfg_path) hostname = os.uname()[1].split(".")[0] -if tests_cfg.filter("^" + hostname): +if tests_cfg.count("^" + hostname): tests_cfg.parse_string("only ^%s" % hostname) else: tests_cfg.parse_string("only ^default_host") # Run the tests -kvm_utils.run_tests(tests_cfg.get_list(), job) +kvm_utils.run_tests(tests_cfg.get_generator(), 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 +12 -9
@@ -160,19 +160,22 @@ if not params.get("mode") == "noinstall": # ---------------------------------------------------------- import kvm_config -filename = os.path.join(pwd, "kvm_tests.cfg") -cfg = kvm_config.config(filename) - -# If desirable, make changes to the test configuration here. For example: -# cfg.parse_string("install|setup: timeout_multiplier = 2") -# cfg.parse_string("only fc8_quick") -# cfg.parse_string("display = sdl") +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 +#display = sdl +""" +cfg = kvm_config.config() +filename = os.path.join(pwd, "tests.cfg") +cfg.fork_and_parse(filename, str) -filename = os.path.join(pwd, "kvm_address_pools.cfg") +filename = os.path.join(pwd, "address_pools.cfg") if os.path.exists(filename): cfg.parse_file(filename) hostname = os.uname()[1].split(".")[0] - if cfg.filter("^" + hostname): + if cfg.count("^" + hostname): cfg.parse_string("only ^%s" % hostname) else: cfg.parse_string("only ^default_host")
client/tests/kvm/kvm_config.py +411 -258
890 lines not on this page · raw message
Signature · 1 line
1.5.4.1