Adding kvm test

The KVM team has been working on a set of tests for our virtualization
stack based on autotest. The project is known as kvm-autotest:

http://www.linux-kvm.org/page/KVM-Autotest

git://git.kernel.org/pub/scm/virt/kvm/kvm-autotest.git

In order to accomodate the needs of KVM Quality Engineering, quite a
substantial amount of code was written. A very brief overview of how the
tests are structured follows:

* kvm_runtest_2: Entry point, that defines hooks to all the KVM tests,
documented under:

http://www.linux-kvm.org/page/KVM-Autotest/Tests

* kvm_config: Module that handles the KVM configuration file format

http://www.linux-kvm.org/page/KVM-Autotest/Test_Config_File

It parses the configuration file and generates a list of dictionaries
that will be used by the other tests.

* step editor and stepmaker: A method to automate installation of guests
was devised, the idea is to send input to qemu through *step files*.
StepEditor and StepMaker are pygtk applications that allow to create and
edit step files.

From:
uril@redhat.com (Uri Lublin)
mgoldish@redhat.com (Michael Goldish)
dhuff@redhat.com (David Huff)
aeromenk@redhat.com (Alexey Eromenko)
mburns@redhat.com (Mike Burns)

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3187 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/fix_cdkeys.py b/client/tests/kvm/fix_cdkeys.py
new file mode 100755
index 0000000..4f7a824
--- /dev/null
+++ b/client/tests/kvm/fix_cdkeys.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+import shutil, os, sys
+
+"""
+Program that replaces the CD keys present on a KVM autotest configuration file.
+
+@copyright: Red Hat 2008-2009
+@author: uril@redhat.com (Uri Lublin)
+"""
+
+
+def file_to_lines(filename):
+    f = open(filename, 'r')
+    lines = f.readlines()
+    f.close
+    return lines
+
+def lines_to_file(filename, lines):
+    f = open(filename, 'w')
+    f.writelines(lines)
+    f.close()
+
+def replace_var_with_val(lines, variables):
+    new = []
+    for line in lines:
+        for (var,val) in variables:
+            if var in line:
+                print 'replacing %s with %s in "%s"' % (var, val, line[:-1])
+                line = line.replace(var, val)
+                print ' ... new line is "%s"' % (line[:-1])
+        new.append(line)
+    return new
+
+def filter_comments(line):
+    return not line.strip().startswith('#')
+
+def filter_empty(line):
+    return len(line.strip()) != 0
+
+def line_to_pair(line):
+    x,y = line.split('=', 1)
+    return (x.strip(), y.strip())
+
+def read_vars(varfile):
+    varlines = file_to_lines(varfile)
+    varlines = filter(filter_comments, varlines)
+    varlines = filter(filter_empty,    varlines)
+    vars = map(line_to_pair, varlines)
+    return vars
+
+def main(cfgfile, varfile):
+    # first save a copy of the original file (if does not exist)
+    backupfile = '%s.backup' % cfgfile
+    if not os.path.exists(backupfile):
+        shutil.copy(cfgfile, backupfile)
+
+    vars = read_vars(varfile)
+    datalines = file_to_lines(cfgfile)
+    newlines = replace_var_with_val(datalines, vars)
+    lines_to_file(cfgfile, newlines)
+
+
+if __name__ == '__main__':
+    def die(msg, val):
+        print msg
+        sys.exit(val)
+    if len(sys.argv) != 3:
+        die('usage: %s <kvm_tests-config-file> <varfile>', 1)
+    cfgfile = sys.argv[1]
+    varfile = sys.argv[2]
+    if not os.path.exists(cfgfile):
+        die('bad cfgfile "%s"' % cfgfile, 2)
+    if not os.path.exists(varfile):
+        die('bad varfile "%s"' % varfile, 2)
+    main(cfgfile, varfile)