[PATCH] client.virt.virt_utils: Only try to load the env file if it exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We are trying to load a previous env file even when there's no
such file available, leading to the unnecessary warning message

15:44:52 WARNI| [Errno 2] No such file or directory: '/home/lmr/Code/autotest-git/client/tests/kvm/env'

So let's try to load the env file only if the file exists, otherwise
just skip the cPickle.load(file) step.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx>
---
 client/virt/virt_utils.py |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/client/virt/virt_utils.py b/client/virt/virt_utils.py
index d443a84..7026492 100644
--- a/client/virt/virt_utils.py
+++ b/client/virt/virt_utils.py
@@ -150,13 +150,17 @@ class Env(UserDict.IterableUserDict):
         if filename:
             self._filename = filename
             try:
-                f = open(filename, "r")
-                env = cPickle.load(f)
-                f.close()
-                if env.get("version", 0) >= version:
-                    self.data = env
+                if os.path.isfile(filename):
+                    f = open(filename, "r")
+                    env = cPickle.load(f)
+                    f.close()
+                    if env.get("version", 0) >= version:
+                        self.data = env
+                    else:
+                        logging.warn("Incompatible env file found. Not using it.")
+                        self.data = empty
                 else:
-                    logging.warn("Incompatible env file found. Not using it.")
+                    # No previous env file found, proceed...
                     self.data = empty
             # Almost any exception can be raised during unpickling, so let's
             # catch them all
-- 
1.7.6

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux