KVM test: deal with incompatible env files gracefully (using version numbers)
Keep a version number in kvm.py (env_version) and record it in new env objects.
When loading an env file, compare its version against env_version. If it's too
old, don't use it.
When changes are made to the KVM test that break compatibility with existing
env files, env_version should be increased.
This will prevent exceptions being raised due to newly added VM attributes that
are missing from old env files.
Signed-off-by: Michael Goldish <mgoldish@redhat.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@4713 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index 4183f1c..fb2d1c2 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -21,17 +21,23 @@
file.close()
-def load_env(filename, default={}):
+def load_env(filename, version):
"""
- Load KVM test environment from an environment file.
+ Load KVM test environment from an env file.
+ If the version recorded in the file is lower than version, return an empty
+ env. If some other error occurs during unpickling, return an empty env.
- @param filename: Path to a file where the environment was dumped to.
+ @param filename: Path to an env file.
"""
+ default = {"version": version}
try:
file = open(filename, "r")
- obj = cPickle.load(file)
+ env = cPickle.load(file)
file.close()
- return obj
+ if env.get("version", 0) < version:
+ logging.warn("Incompatible env file found. Not using it.")
+ return default
+ return env
# Almost any exception can be raised during unpickling, so let's catch
# them all
except Exception, e: