KVM test: kvm_utils.load_env(): do not fail if env file is corrupted
- Include the unpickling code in the 'try' block, so that an exception raised
during unpickling will not fail the test.
- Change the default env (returned by load_env() when the file is missing or
corrupt) to {}.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4320 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 78da9f1..0d92d79 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -22,7 +22,7 @@
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 @@
"""
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):