[node-patches] Change in ovirt-node[master]: scripts: mimic output of previous un/persist cmds

dougsland at redhat.com dougsland at redhat.com
Wed Mar 4 23:56:57 UTC 2015


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: scripts: mimic output of previous un/persist cmds
......................................................................

scripts: mimic output of previous un/persist cmds

Previously persist and unpersit commands showed output
messages to users for success or unsuccess operations.
This patch returns the output to users.

Change-Id: I8f52960d7da50c35ada14474c2a46a38b5e153de
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1187034
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M scripts/persist
M scripts/unpersist
M src/ovirt/node/utils/fs/__init__.py
3 files changed, 26 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/94/38394/1

diff --git a/scripts/persist b/scripts/persist
index fb486b8..88d2d6a 100755
--- a/scripts/persist
+++ b/scripts/persist
@@ -21,6 +21,7 @@
 # Convenience wrapper to give access to ovirt/node/utils/fs persistence
 # facilities
 import argparse
+import os
 import sys
 
 from ovirt.node.utils import fs
@@ -36,7 +37,17 @@
 
     conf = fs.Config()
     for path in arguments.FILE:
-        conf.persist(path)
+        if os.path.exists("/config" + path) and os.path.exists(path):
+            print "File already persisted: %s" % path
+            continue
+
+        if not conf.persist(path):
+            print "Cannot persist: %s" % path
+            return -1
+
+        print "File persisted\n\nSuccessfully persisted: %s" % path
+
+    return 0
 
 if __name__ == '__main__':
     sys.exit(persist())
diff --git a/scripts/unpersist b/scripts/unpersist
index 047000a..f196d63 100755
--- a/scripts/unpersist
+++ b/scripts/unpersist
@@ -21,6 +21,7 @@
 # Convenience wrapper to give access to ovirt/node/utils/fs persistence
 # facilities
 import argparse
+import os
 import sys
 
 from ovirt.node.utils import fs
@@ -35,7 +36,15 @@
 
     conf = fs.Config()
     for path in arguments.PATH:
-        conf.unpersist(path)
+        if not os.path.exists("/config" + path):
+            print "File not explicitly persisted: %s" % path
+            continue
+
+        if not os.path.exists(path) or not conf.unpersist(path):
+            print "Cannot unpersist"
+            return -1
+
+        print "%s successully unpersisted" % path
 
 if __name__ == '__main__':
     sys.exit(unpersist())
diff --git a/src/ovirt/node/utils/fs/__init__.py b/src/ovirt/node/utils/fs/__init__.py
index 965aac2..7ca8098 100644
--- a/src/ovirt/node/utils/fs/__init__.py
+++ b/src/ovirt/node/utils/fs/__init__.py
@@ -429,9 +429,10 @@
             except Exception:
                 self._logger.error('Failed to persist "%s"', path,
                                    exc_info=True)
-                return -1
+                return False
 
             restorecon(abspath)
+            return True
 
     def _persist_dir(self, abspath):
         """Persist directory and bind mount it back to its current location
@@ -579,7 +580,8 @@
             except Exception:
                 self._logger.error('Failed to unpersist "%s"', path,
                                    exc_info=True)
-                return -1
+                return False
+        return True
 
     def _cleanup_tree(self, dirpath):
         """Removes empty directories in the structure. abspath must be a dir"""


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f52960d7da50c35ada14474c2a46a38b5e153de
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