diff mbox

[KVM-AUTOTEST,3/5] KVM test: kvm_utils.load_env(): do not fail if env file is corrupted

Message ID 1269225797-11827-3-git-send-email-mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish March 22, 2010, 2:43 a.m. UTC
None
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index d386456..cc39b5d 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -22,7 +22,7 @@  def dump_env(obj, filename):
     file.close()
 
 
-def load_env(filename, default=None):
+def load_env(filename, default={}):
     """
     Load KVM test environment from an environment file.
 
@@ -30,11 +30,13 @@  def load_env(filename, default=None):
     """
     try:
         file = open(filename, "r")
+        obj = cPickle.load(file)
+        file.close()
+        return obj
+    # Almost any exception can be raised during unpickling, so let's catch
+    # them all
     except:
         return default
-    obj = cPickle.load(file)
-    file.close()
-    return obj
 
 
 def get_sub_dict(dict, name):