diff mbox

[3/4] KVM test: Moving utility functions to kvm_utils.py

Message ID 1253037767-7165-3-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues Sept. 15, 2009, 6:02 p.m. UTC
Moved dump_env and load_env to kvm_utils.py since
it makes the main test class cleaner.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/kvm.py       |   26 +++++---------------------
 client/tests/kvm/kvm_utils.py |   26 ++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 21 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index f6883c8..a5ced7b 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -10,22 +10,6 @@  class test_routine:
         self.routine = None
 
 
-def dump_env(obj, filename):
-    file = open(filename, "w")
-    cPickle.dump(obj, file)
-    file.close()
-
-
-def load_env(filename, default=None):
-    try:
-        file = open(filename, "r")
-    except:
-        return default
-    obj = cPickle.load(file)
-    file.close()
-    return obj
-
-
 class kvm(test.test):
     """
     Suite of KVM virtualization functional tests.
@@ -84,7 +68,7 @@  class kvm(test.test):
 
         # Open the environment file
         env_filename = os.path.join(self.bindir, params.get("env", "env"))
-        env = load_env(env_filename, {})
+        env = kvm_utils.load_env(env_filename, {})
         logging.debug("Contents of environment: %s" % str(env))
 
         try:
@@ -107,20 +91,20 @@  class kvm(test.test):
 
                 # Preprocess
                 kvm_preprocessing.preprocess(self, params, env)
-                dump_env(env, env_filename)
+                kvm_utils.dump_env(env, env_filename)
                 # Run the test function
                 routine_obj.routine(self, params, env)
-                dump_env(env, env_filename)
+                kvm_utils.dump_env(env, env_filename)
 
             except Exception, e:
                 logging.error("Test failed: %s", e)
                 logging.debug("Postprocessing on error...")
                 kvm_preprocessing.postprocess_on_error(self, params, env)
-                dump_env(env, env_filename)
+                kvm_utils.dump_env(env, env_filename)
                 raise
 
         finally:
             # Postprocess
             kvm_preprocessing.postprocess(self, params, env)
             logging.debug("Contents of environment: %s", str(env))
-            dump_env(env, env_filename)
+            kvm_utils.dump_env(env, env_filename)
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index ceae4a4..d0e3ea4 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -11,6 +11,32 @@  from autotest_lib.client.common_lib import error
 import kvm_subprocess
 
 
+def dump_env(obj, filename):
+    """
+    Dump KVM test environment to a file.
+
+    @param filename: Path to a file where the environment will be dumped to.
+    """
+    file = open(filename, "w")
+    cPickle.dump(obj, file)
+    file.close()
+
+
+def load_env(filename, default=None):
+    """
+    Load KVM test environment from an environment file.
+
+    @param filename: Path to a file where the environment was dumped to.
+    """
+    try:
+        file = open(filename, "r")
+    except:
+        return default
+    obj = cPickle.load(file)
+    file.close()
+    return obj
+
+
 def get_sub_dict(dict, name):
     """
     Return a "sub-dict" corresponding to a specific object.