[node-patches] Change in ovirt-node[ovirt-3.5]: Config.exists: fix exists method

dougsland at redhat.com dougsland at redhat.com
Tue Aug 11 17:23:36 UTC 2015


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: Config.exists: fix exists method
......................................................................

Config.exists: fix exists method

The exists method is used by the persist script
to check if the file that will be persisted
exists. However, in commit 9a1986a8 we moved
from ovirtfunctions.ovirt_store approach and missed
to update the exists method.

Change-Id: If1ba23d67516f1690b223e3dd43985e5d9a502ef
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1251867
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M src/ovirt/node/utils/fs/__init__.py
1 file changed, 27 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/27/44727/1

diff --git a/src/ovirt/node/utils/fs/__init__.py b/src/ovirt/node/utils/fs/__init__.py
index 1204776..de0ff79 100644
--- a/src/ovirt/node/utils/fs/__init__.py
+++ b/src/ovirt/node/utils/fs/__init__.py
@@ -465,27 +465,27 @@
         self._logger.info('Directory "%s" successfully persisted', abspath)
         self._add_path_entry(abspath)
 
+    def cksum(self, filename):
+        try:
+            m = hashlib.md5()
+        except:
+            m = hashlib.sha1()
+
+        with open(filename) as f:
+            data = f.read(4096)
+            while data:
+                m.update(data)
+                data = f.read(4096)
+            return m.hexdigest()
+
     def _persist_file(self, abspath):
         """Persist file and bind mount it back to its current location
         """
 
-        def cksum(filename):
-            try:
-                m = hashlib.md5()
-            except:
-                m = hashlib.sha1()
-
-            with open(filename) as f:
-                data = f.read(4096)
-                while data:
-                    m.update(data)
-                    data = f.read(4096)
-                return m.hexdigest()
-
         persisted_path = self._config_path(abspath)
         if os.path.exists(persisted_path):
-            current_checksum = cksum(abspath)
-            stored_checksum = cksum(persisted_path)
+            current_checksum = self.cksum(abspath)
+            stored_checksum = self.cksum(persisted_path)
             if stored_checksum == current_checksum:
                 self._logger.warn('File "%s" had already been persisted',
                                   abspath)
@@ -680,7 +680,18 @@
     def exists(self, filename):
         """Check if the given file is persisted
         """
-        return filename and File(self._config_path(filename)).exists()
+        persisted_path = self._config_path(filename)
+
+        if not os.path.exists(persisted_path) or \
+                not os.path.exists(filename):
+            return False
+
+        current_checksum = self.cksum(filename)
+        stored_checksum = self.cksum(persisted_path)
+        if stored_checksum == current_checksum:
+            return True
+
+        return False
 
     def is_enabled(self):
         return File("/proc").exists() and is_bind_mount(self.basedir)


-- 
To view, visit https://gerrit.ovirt.org/44727
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If1ba23d67516f1690b223e3dd43985e5d9a502ef
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list