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

dougsland at redhat.com dougsland at redhat.com
Tue Jun 23 01:44:49 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: Ib13f5e4ecd8b4078bd57a19b21d75609a00e22da
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M src/ovirt/node/utils/fs/__init__.py
1 file changed, 25 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/19/42719/1

diff --git a/src/ovirt/node/utils/fs/__init__.py b/src/ovirt/node/utils/fs/__init__.py
index 39c1785..0bda2cc 100644
--- a/src/ovirt/node/utils/fs/__init__.py
+++ b/src/ovirt/node/utils/fs/__init__.py
@@ -467,27 +467,30 @@
         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()
+
+        if not os.path.exists(filename):
+            return False
+
+        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)
@@ -682,7 +685,13 @@
     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)
+        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/42719
To unsubscribe, visit https://gerrit.ovirt.org/settings

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



More information about the node-patches mailing list