The patch tries to make using kvm-autotest much more easier by
enabling the ability of passing the test parameters from command line
directly.

In order to achieve this, a control.cli was introduced and it uses the
autotest's ability to passing additional args to client tests ( so all
args must be passed through  --args="..." ) and generate the
additional string in the control file which is passed to the
kvm_config to get the final test matrix.

The params are categorized into two kinds:
- Variants used to limit the test matrix, its default configuration
was stored with "key->value" in test_cli.cfg and can be changed by
user. The cli just add 'only xxx' at the end of configuration file.

  The following options are used to limit the variants:
  diskformat= qcow2/raw
  nicmodel= virtio_net/rtl8139/e1000
  driveformat= virtio_blk/ide/scsi
  vcpu= up/smp2
  pciassign= no_pci_assignable/pf_assignable/vf_assianable
  pagesize= smallpages/hugepages
  guest= Guest supports by autotest can be read from tests_base.cfg
  testcase= Test cases you want to be run, can be read form
  test_base.cfg

- Test attributs is used to specify the customized test attributes for
a dedicated test such as "image_mode", when cli get "key=value" from
cmdline, it just add it to the end of file.

Example of usage:

1: ../../bin/autotest control.cli
This would use default test configuration (stored in test_cli.cfg).
As you can see there's no need to specifiy all params through cmd line
and you can only specify the options you are interested. This would
use default tests configuration just as the above.

2: ../../bin/autotest control.cli --args="diskformat=qcow2 nicmodel=virtio_net
driveformat=virtio_blk vcpu=smp2 pciassign=no_pci_assignable
pagesize=smallpages guest=Fedora.14.64
testcase=unattended_install.cdrom"

This would test installation for Fedora 14 64 bit guests with
qcow2 as its image format, virtio-net as its nic model, virtio_blk as
its drive format, 2 vcpus and with small pages and no assigned devices.

3: Run an nfs based installation with 4 vcpu and 2G memory
../../bin/autotest control.cli --args="guest=RHEL.5.5.x86_64
testcase=unattend_install.nfs nfs_server=$server nfs_dir=$directory
smp=4 mem=2048"

4: Use test specific params - run pxe using tap mode network
../../bin/autotest control.cli --args="nic_mode=tap testcase=pxe"

Change from V1:
Drop the wrapper method and use the control file directly.

Signed-off-by: Jason Wang <[email protected]>
---
 client/tests/kvm/control.cli          |   86 +++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_cli.cfg.sample |   24 +++++++++
 2 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/control.cli
 create mode 100644 client/tests/kvm/tests_cli.cfg.sample

diff --git a/client/tests/kvm/control.cli b/client/tests/kvm/control.cli
new file mode 100644
index 0000000..46a4777
--- /dev/null
+++ b/client/tests/kvm/control.cli
@@ -0,0 +1,86 @@
+AUTHOR = """
[email protected] (Uri Lublin)
[email protected] (Dror Russo)
[email protected] (Michael Goldish)
[email protected] (David Huff)
[email protected] (Alexey Eromenko)
[email protected] (Mike Burns)
+"""
+TIME = 'MEDIUM'
+NAME = 'KVM test'
+TEST_TYPE = 'client'
+TEST_CLASS = 'Virtualization'
+TEST_CATEGORY = 'Functional'
+
+DOC = """
+Executes the KVM test framework on a given host. This module is separated in
+minor functions, that execute different tests for doing Quality Assurance on
+KVM (both kernelspace and userspace) code.
+
+For online docs, please refer to http://www.linux-kvm.org/page/KVM-Autotest
+"""
+
+import sys, os, logging
+# Add the KVM tests dir to the python path
+kvm_test_dir = os.path.join(os.environ['AUTODIR'],'tests/kvm')
+sys.path.append(kvm_test_dir)
+# Now we can import modules inside the KVM tests dir
+import kvm_utils, kvm_config
+
+# set English environment (command output might be localized, need to be safe)
+os.environ['LANG'] = 'en_US.UTF-8'
+
+str = """
+# This string will be parsed after build.cfg.  Make any desired changes to the
+# 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):
+    logging.error("KVM build step failed, exiting.")
+    sys.exit(1)
+
+# Analyze the args passed from autotest and make it readable by
+# kvm-autotest, the args were divided into two groups: variants and
+# attributes, varaints were used to limit the test matrix and its
+# default value were stored in test.cli.cfg; attributes were used to
+# specify customized test parameters.
+
+variants = {}
+attributes = {}
+str = ""
+
+for (key, value) in re.findall("#\s+(.*)->(.*)",
+                               file("tests_cli.cfg").read()):
+    variants[key] = value
+
+for argv in job.args:
+    try:
+        (key, value) = re.findall("(.*)=(.*)", argv)[0]
+        if key in variants.keys():
+            variants[key] = value
+        else:
+            attributes[key] = value
+    except IndexError:
+        pass
+
+for key in variants.keys():
+    str += "only %s\n" % variants[key]
+for (key, value) in attributes.items():
+    str += "%s = %s\n" % (key, value)
+
+tests_cfg = kvm_config.config()
+tests_cfg_path = os.path.join(kvm_test_dir, "tests_cli.cfg")
+tests_cfg.fork_and_parse(tests_cfg_path, str)
+
+# Run the tests
+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)
+
diff --git a/client/tests/kvm/tests_cli.cfg.sample 
b/client/tests/kvm/tests_cli.cfg.sample
new file mode 100644
index 0000000..f5074bd
--- /dev/null
+++ b/client/tests/kvm/tests_cli.cfg.sample
@@ -0,0 +1,24 @@
+# Do not edit this file directly, it is used by run-test.py
+#
+include tests_base.cfg
+include cdkeys.cfg
+
+# As for the defaults:
+# * qemu and qemu-img are expected to be found under /usr/bin/qemu-kvm and
+#   /usr/bin/qemu-img respectively.
+# * All image files are expected under /tmp/kvm_autotest_root/images/
+# * All iso files are expected under /tmp/kvm_autotest_root/isos/
+qemu_img_binary = /usr/bin/qemu-img
+qemu_binary = /usr/bin/qemu-kvm
+image_name(_.*)? ?<= /tmp/kvm_autotest_root/images/
+cdrom(_.*)? ?<= /tmp/kvm_autotest_root/isos/
+
+# you can change default configuration here:
+# diskformat->qcow2
+# nicmodel->virtio_net
+# driveformat->virtio_blk
+# vcpu->smp2
+# pciassign->no_pci_assignable
+# pagesize->smallpages
+# guest->Fedora.14.64
+# testcase->unattended_install.cdrom

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to