Skip to contentSkip to conversation

KVM test: Move top level docstrings, other cleanups

PATCH New Lucas Meneghel Rodrigues 1 participant 3 messages Sep 10, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 KVM test: Move top level docstrings, other cleanups

In order to prepare for the subsequent changes, made some cleanups on the kvm source files: I've noticed that the top level docstrings were going before the imports block, and that does not follow the pattern found on other files (my fault). This patch fixes that problem and fixed some places on scan_results.py where 80 char line width was not being obeyed. Also, cleaned up the last places where we were using the shebang #/usr/bin/env python, which is not the preferred usage of the shebang across the project.

---
 client/tests/kvm/calc_md5sum_1m.py   |    8 ++++----
 client/tests/kvm/fix_cdkeys.py       |    6 +++---
 client/tests/kvm/kvm_config.py       |   10 +++++-----
 client/tests/kvm/kvm_guest_wizard.py |   12 ++++++------
 client/tests/kvm/kvm_subprocess.py   |    8 ++++----
 client/tests/kvm/kvm_test_utils.py   |    8 ++++----
 client/tests/kvm/kvm_tests.py        |    8 ++++----
 client/tests/kvm/kvm_utils.py        |   12 ++++++------
 client/tests/kvm/kvm_vm.py           |    6 +++---
 client/tests/kvm/make_html_report.py |   14 +++-----------
 client/tests/kvm/ppm_utils.py        |    5 +++--
 client/tests/kvm/scan_results.py     |   20 ++++++++++++++------
 client/tests/kvm/stepeditor.py       |    8 ++++----
 client/tests/kvm/stepmaker.py        |   13 +++++++------
 14 files changed, 70 insertions(+), 68 deletions(-)
client/tests/kvm/calc_md5sum_1m.py +4 -4
index 6660d0e..2325673 100755
@@ -1,7 +1,4 @@
-#!/usr/bin/env python
-import os, sys
-import kvm_utils
-
+#!/usr/bin/python
 """
 Program that calculates the md5sum for the first megabyte of a file.
 It's faster than calculating the md5sum for the whole ISO image.
@@ -10,6 +7,9 @@ It's faster than calculating the md5sum for the whole ISO image.
 @author: Uri Lublin ([email protected])
 """
 
+import os, sys
+import kvm_utils
+
 
 if len(sys.argv) < 2:
     print 'usage: %s <iso-filename>' % sys.argv[0]
client/tests/kvm/fix_cdkeys.py +3 -3
index 7a821fa..aa9fc3e 100755
@@ -1,7 +1,4 @@
 #!/usr/bin/python
-import shutil, os, sys
-import common
-
 """
 Program that replaces the CD keys present on a KVM autotest configuration file.
 
@@ -9,6 +6,9 @@ Program that replaces the CD keys present on a KVM autotest configuration file.
 @author: [email protected] (Uri Lublin)
 """
 
+import shutil, os, sys
+import common
+
 
 def file_to_lines(filename):
     f = open(filename, 'r')
client/tests/kvm/kvm_config.py +5 -5
index 405de4b..3114c07 100755
@@ -1,15 +1,15 @@
 #!/usr/bin/python
-import logging, re, os, sys, StringIO, optparse
-import common
-from autotest_lib.client.common_lib import error
-from autotest_lib.client.common_lib import logging_config, logging_manager
-
 """
 KVM configuration file utility functions.
 
 @copyright: Red Hat 2008-2009
 """
 
+import logging, re, os, sys, StringIO, optparse
+import common
+from autotest_lib.client.common_lib import error
+from autotest_lib.client.common_lib import logging_config, logging_manager
+
 
 class KvmLoggingConfig(logging_config.LoggingConfig):
     def configure_logging(self, results_dir=None, verbose=False):
client/tests/kvm/kvm_guest_wizard.py +6 -6
index 3d3f3b2..8bc85f2 100644
@@ -1,3 +1,9 @@
+"""
+Utilities to perform automatic guest installation using step files.
+
+@copyright: Red Hat 2008-2009
+"""
+
 import os, time, md5, re, shutil, logging
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, ppm_utils, kvm_subprocess
@@ -9,12 +15,6 @@ except ImportError:
                     'please install python-imaging or the equivalent for your '
                     'distro.')
 
-"""
-Utilities to perform automatic guest installation using step files.
-
-@copyright: Red Hat 2008-2009
-"""
-
 
 def handle_var(vm, params, varname):
     var = params.get(varname)
client/tests/kvm/kvm_subprocess.py +4 -4
index c3c48cd..f748586 100755
@@ -1,14 +1,14 @@
 #!/usr/bin/python
-import sys, subprocess, pty, select, os, time, signal, re, termios, fcntl
-import threading, logging, commands
-import common, kvm_utils
-
 """
 A class and functions used for running and controlling child processes.
 
 @copyright: 2008-2009 Red Hat Inc.
 """
 
+import sys, subprocess, pty, select, os, time, signal, re, termios, fcntl
+import threading, logging, commands
+import common, kvm_utils
+
 
 def run_bg(command, termination_func=None, output_func=None, output_prefix="",
            timeout=1.0):
client/tests/kvm/kvm_test_utils.py +4 -4
index 39e92b9..00a46ed 100644
@@ -1,7 +1,3 @@
-import time, os, logging, re, commands
-from autotest_lib.client.common_lib import utils, error
-import kvm_utils, kvm_vm, kvm_subprocess
-
 """
 High-level KVM test utility functions.
 
@@ -25,6 +21,10 @@ More specifically:
 @copyright: 2008-2009 Red Hat Inc.
 """
 
+import time, os, logging, re, commands
+from autotest_lib.client.common_lib import utils, error
+import kvm_utils, kvm_vm, kvm_subprocess
+
 
 def get_living_vm(env, vm_name):
     """
client/tests/kvm/kvm_tests.py +4 -4
index b61d98c..70d8641 100644
@@ -1,13 +1,13 @@
-import time, os, logging, re, commands
-from autotest_lib.client.common_lib import utils, error
-import kvm_utils, kvm_subprocess, ppm_utils, scan_results, kvm_test_utils
-
 """
 KVM test definitions.
 
 @copyright: 2008-2009 Red Hat Inc.
 """
 
+import time, os, logging, re, commands
+from autotest_lib.client.common_lib import utils, error
+import kvm_utils, kvm_subprocess, ppm_utils, scan_results, kvm_test_utils
+
 
 def run_boot(test, params, env):
     """
client/tests/kvm/kvm_utils.py +6 -6
index ac9ede7..e73346e 100644
@@ -1,15 +1,15 @@
-import md5, thread, subprocess, time, string, random, socket, os, signal, pty
-import select, re, logging, commands
-from autotest_lib.client.bin import utils
-from autotest_lib.client.common_lib import error
-import kvm_subprocess
-
 """
 KVM test utility functions.
 
 @copyright: 2008-2009 Red Hat Inc.
 """
 
+import md5, thread, subprocess, time, string, random, socket, os, signal, pty
+import select, re, logging, commands
+from autotest_lib.client.bin import utils
+from autotest_lib.client.common_lib import error
+import kvm_subprocess
+
 
 def get_sub_dict(dict, name):
     """
client/tests/kvm/kvm_vm.py +3 -3
index f728104..8b795b7 100755
@@ -1,13 +1,13 @@
 #!/usr/bin/python
-import time, socket, os, logging, fcntl, re, commands
-import kvm_utils, kvm_subprocess
-
 """
 Utility classes and functions to handle Virtual Machine creation using qemu.
 
 @copyright: 2008-2009 Red Hat Inc.
 """
 
+import time, socket, os, logging, fcntl, re, commands
+import kvm_utils, kvm_subprocess
+
 
 def get_image_filename(params, root_dir):
     """
client/tests/kvm/make_html_report.py +3 -11
index e63fcfa..ebc9c12 100755
@@ -1,7 +1,4 @@
 #!/usr/bin/python
-import os, sys, re, getopt, time, datetime, commands
-import common
-
 """
 Script used to parse the test results and generate an HTML report.
 
@@ -10,6 +7,9 @@ Script used to parse the test results and generate an HTML report.
 @author: Dror Russo ([email protected])
 """
 
+import os, sys, re, getopt, time, datetime, commands
+import common
+
 
 format_css="""
 html,body {
@@ -180,7 +180,6 @@ font-size: 13px;}
 """
 
 
-
 table_js="""
 /**
  * Copyright (c)2005-2007 Matt Kruse (javascripttoolbox.com)
@@ -1376,13 +1375,6 @@ function processList(ul) {
 """
 
 
-
-
-
-
-
-
-
 #################################################################
 ##  This script gets kvm autotest results directory path as an ##
 ##  input and create a single html formatted result page.      ##
client/tests/kvm/ppm_utils.py +3 -2
index f0435ce..8ff31da 100644
@@ -1,11 +1,12 @@
-import md5, os, struct, time, re
-
 """
 Utility functions to deal with ppm (qemu screendump format) files.
 
 @copyright: Red Hat 2008-2009
 """
 
+import md5, os, struct, time, re
+
+
 # Some directory/filename utils, for consistency
 
 def find_id_for_screendump(md5sum, dir):
client/tests/kvm/scan_results.py +14 -6
index a22634e..f7bafa9 100755
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python
 """
 Program that parses the autotest results and return a nicely printed final test
 result.
@@ -7,7 +7,11 @@ result.
 """
 
 def parse_results(text):
-    """Parse text containing Autotest results and return a list of result 4-tuples."""
+    """
+    Parse text containing Autotest results.
+
+    @return: A list of result 4-tuples.
+    """
     result_list = []
     start_time_list = []
     info_list = []
@@ -18,13 +22,15 @@ def parse_results(text):
         parts = line.split("\t")
 
         # Found a START line -- get start time
-        if line.startswith("START") and len(parts) >= 5 and parts[3].startswith("timestamp"):
+        if (line.startswith("START") and len(parts) >= 5 and
+            parts[3].startswith("timestamp")):
             start_time = float(parts[3].split('=')[1])
             start_time_list.append(start_time)
             info_list.append("")
 
         # Found an END line -- get end time, name and status
-        elif line.startswith("END") and len(parts) >= 5 and parts[3].startswith("timestamp"):
+        elif (line.startswith("END") and len(parts) >= 5 and
+              parts[3].startswith("timestamp")):
             end_time = float(parts[3].split('=')[1])
             start_time = start_time_list.pop()
             info = info_list.pop()
@@ -33,10 +39,12 @@ def parse_results(text):
             # Remove 'kvm.' prefix
             if test_name.startswith("kvm."):
                 test_name = test_name.split("kvm.")[1]
-            result_list.append((test_name, test_status, int(end_time - start_time), info))
+            result_list.append((test_name, test_status,
+                                int(end_time - start_time), info))
 
         # Found a FAIL/ERROR/GOOD line -- get failure/success info
-        elif len(parts) >= 6 and parts[3].startswith("timestamp") and parts[4].startswith("localtime"):
+        elif (len(parts) >= 6 and parts[3].startswith("timestamp") and
+              parts[4].startswith("localtime")):
             info_list[-1] = parts[5]
 
     return result_list
client/tests/kvm/stepeditor.py +4 -4
index e7794ac..43e189f 100755
@@ -1,8 +1,4 @@
 #!/usr/bin/python
-import pygtk, gtk, os, glob, shutil, sys, logging
-import common, ppm_utils
-pygtk.require('2.0')
-
 """
 Step file creator/editor.
 
@@ -11,6 +7,10 @@ Step file creator/editor.
 @version: "20090401"
 """
 
+import pygtk, gtk, os, glob, shutil, sys, logging
+import common, ppm_utils
+pygtk.require('2.0')
+
 
 # General utilities
 
client/tests/kvm/stepmaker.py +7 -6
index e478350..24060db 100755
@@ -1,10 +1,4 @@
 #!/usr/bin/python
-import pygtk, gtk, gobject, time, os, commands
-import common
-from autotest_lib.client.common_lib import error
-import kvm_utils, logging, ppm_utils, stepeditor
-pygtk.require('2.0')
-
 """
 Step file creator/editor.
 
@@ -13,6 +7,13 @@ Step file creator/editor.
 @version: "20090401"
 """
 
+import pygtk, gtk, gobject, time, os, commands
+import common
+from autotest_lib.client.common_lib import error
+import kvm_utils, logging, ppm_utils, stepeditor
+pygtk.require('2.0')
+
+
 class StepMaker(stepeditor.StepMakerWindow):
     """
     Application used to create a step file. It will grab your input to the
Signature · 1 line
1.6.2.5
#1 lore raw

PATCH 2/3 KVM test: Removing the fix_cdkeys.py program

That is no longer necessary since we handle cd keys on a separate configuration file.

---
 client/tests/kvm/fix_cdkeys.py |   76 ----------------------------------------
 1 files changed, 0 insertions(+), 76 deletions(-)
 delete mode 100755 client/tests/kvm/fix_cdkeys.py
client/tests/kvm/fix_cdkeys.py deleted +0 -76
deleted file mode 100755
index aa9fc3e..0000000
@@ -1,76 +0,0 @@
-#!/usr/bin/python
-"""
-Program that replaces the CD keys present on a KVM autotest configuration file.
-
-@copyright: Red Hat 2008-2009
-@author: [email protected] (Uri Lublin)
-"""
-
-import shutil, os, sys
-import common
-
-
-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)
Signature · 1 line
1.6.2.5
#2 lore raw

PATCH 3/3 KVM test: Points user to online documentation

* Renamed BEFORE_YOU_START to README, and point
to the online documentation in there (it's
pointless to duplicate procedures).
* The control file docstring points to the
top level KVM testing documentation.
* The kvm class docstring points to the getting
started guide.

---
 client/tests/kvm/BEFORE_YOU_START |   19 -------------------
 client/tests/kvm/README           |    3 +++
 client/tests/kvm/control          |    2 ++
 client/tests/kvm/kvm.py           |    3 +++
 4 files changed, 8 insertions(+), 19 deletions(-)
 delete mode 100644 client/tests/kvm/BEFORE_YOU_START
 create mode 100644 client/tests/kvm/README
client/tests/kvm/BEFORE_YOU_START deleted +0 -19
deleted file mode 100644
index 7478d9d..0000000
@@ -1,19 +0,0 @@
-Install kvm and load modules.
-Remove 'env' file if exists.
-Remove control.state file if exists.
-
-Copy kvm_tests.cfg.sample into kvm_tests.cfg
-Modify kvm_tests.cfg to your liking.
-Modify control if you prefer to "use your own kvm" (comment out kvm_install).
-
-Create those symbolic links under kvm or under <rootdir>
-qemu                   -> qemu-kvm binary (unless using kvm_install)
-qemu-img               -> qemu-img binary (unless using kvm_install)
-isos/                  -> isos (mount or symlink)
-images/                -> images (mount or symlink)
-autotest/              -> ../../ (an autotest client directroy)
-steps_data/            -> steps_data dir (when available)
-
-Please make sure qemu points to an "installed" kvm-qemu executable, and
-not one just compiled in the source directory. An installed executable "knows"
-where to find its associated data-dir (e.g. for bios).
client/tests/kvm/README new file +3 -0
new file mode 100644
index 0000000..88d2c15
@@ -0,0 +1,3 @@
+In order to get started, please refer to the online documentation:
+
+http://www.linux-kvm.org/page/KVM-Autotest/Client_Install
client/tests/kvm/control +2 -0
index 2ad8d81..f8390d6 100644
@@ -16,6 +16,8 @@ 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
 """
 
 
client/tests/kvm/kvm.py +3 -0
index 4930e80..8e66fc0 100644
@@ -38,6 +38,9 @@ class kvm(test.test):
     @author: David Huff ([email protected])
     @author: Alexey Eromenko ([email protected])
     @author: Mike Burns ([email protected])
+
+    @see: http://www.linux-kvm.org/page/KVM-Autotest/Client_Install
+            (Online doc - Getting started with KVM testing)
     """
     version = 1
     def initialize(self):
Signature · 1 line
1.6.2.5