[node-patches] Change in ovirt-node[master]: fs: Don't use ovirtfunctions for persistence

fabiand at redhat.com fabiand at redhat.com
Fri Nov 7 16:38:16 UTC 2014


Fabian Deutsch has uploaded a new change for review.

Change subject: fs: Don't use ovirtfunctions for persistence
......................................................................

fs: Don't use ovirtfunctions for persistence

Previously the legacy ovirtfunctions module was used for the peristence
of files, on el7 this lead to problems.
Now the legacy module is not used anymore to prevent failing
persistence.

Change-Id: I19931fb98a113dba609ce484ec2f5031fd1f6936
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1152873
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M src/ovirt/node/utils/fs/__init__.py
1 file changed, 19 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/46/34946/1

diff --git a/src/ovirt/node/utils/fs/__init__.py b/src/ovirt/node/utils/fs/__init__.py
index fcfa40b..d03a1b3 100644
--- a/src/ovirt/node/utils/fs/__init__.py
+++ b/src/ovirt/node/utils/fs/__init__.py
@@ -29,6 +29,7 @@
 import os
 import StringIO
 import re
+import hashlib
 
 
 from . import mount
@@ -422,7 +423,8 @@
                 elif os.path.isfile(abspath):
                     self._persist_file(abspath)
             except Exception:
-                self._logger.error('Failed to persist "%s"', path)
+                self._logger.error('Failed to persist "%s"', path,
+                                   exc_info=True)
                 return -1
 
             restorecon(abspath)
@@ -444,11 +446,24 @@
     def _persist_file(self, abspath):
         """Persist file and bind mount it back to its current location
         """
-        from ovirtnode import ovirtfunctions
+
+        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 = ovirtfunctions.cksum(abspath)
-            stored_checksum = ovirtfunctions.cksum(persisted_path)
+            current_checksum = cksum(abspath)
+            stored_checksum = cksum(persisted_path)
             if stored_checksum == current_checksum:
                 self._logger.warn('File "%s" had already been persisted',
                                   abspath)


-- 
To view, visit http://gerrit.ovirt.org/34946
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I19931fb98a113dba609ce484ec2f5031fd1f6936
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at redhat.com>



More information about the node-patches mailing list