[node-patches] Change in ovirt-node[master]: Hide _flush() output on the remote_storage page

hadong0720 at gmail.com hadong0720 at gmail.com
Wed Mar 5 03:47:27 UTC 2014


hadong has uploaded a new change for review.

Change subject: Hide _flush() output on the remote_storage page
......................................................................

Hide _flush() output on the remote_storage page

Redirect stderr and stdout to /dev/null so the screen doesn't get
cluttered.

Change-Id: I1f5fbb5dc30430e3ac79cf14df8a1093dee3eda0
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1072660
Signed-off-by: hadong <hadong0720 at gmail.com>
---
M src/ovirt/node/utils/system.py
1 file changed, 39 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/65/25365/1

diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py
index 18d66c4..4e9071b 100644
--- a/src/ovirt/node/utils/system.py
+++ b/src/ovirt/node/utils/system.py
@@ -560,23 +560,54 @@
 
 class Filesystem(base.Base):
     """A class for finding and handling filesystems"""
+    device = None
+
+    def __init__(self, device):
+        self.device = device
+
+    @staticmethod
+    def _flush():
+        """Let all pending operations finish and flush anything to any disks
+        E.g. iscsi etc
+
+        pipe() is used to capture the output of the calls
+        """
+        # Don't litter the screen with output, so get a handle to /dev/null
+        with open(os.devnull, 'wb') as DEVNULL:
+            process.call(["partprobe"] + [x for x in glob.glob("/dev/mapper/*")
+                                          if not re.match(r'.*\/control$', x)],
+                         stdout=DEVNULL, stderr=DEVNULL)
+            process.call(["udevadm", "settle"], stdout=DEVNULL, stderr=DEVNULL)
+
     @staticmethod
     def by_label(label):
         """Determines whether a filesystem with a given label is present on
         this system
         """
-        process.call(["partprobe"] + [x for x in glob.glob("/dev/mapper/*")
-                                      if not re.match(r'.*\/control$', x)])
-        process.call(["udevadm", "settle"])
+        fs = None
         try:
-            process.check_call(["/sbin/blkid", "-c", "/dev/null", "-l", "-o",
-                                "device", "-t", 'LABEL="%s"' % label])
+            Filesystem._flush()
+            with open(os.devnull, 'wb') as DEVNULL:
+                device = process.check_output(["blkid", "-c", "/dev/null",
+                                               "-L", label], stderr=DEVNULL)
 
-            return True
+            fs = Filesystem(label, device)
 
         except process.CalledProcessError as e:
-            LOGGER.exception("Failed to resolve disks: %s" % e.cmd)
-            return False
+            LOGGER.debug("Failed to resolve disks: %s" % e.cmd, exc_info=True)
+        return fs
+
+    def _tokens(self):
+        tokens = process.check_output(["blkid", "-o", "export", self.device])
+        return parse_varfile(tokens)
+
+    def label(self):
+        return self._tokens().get("LABEL", None)
+
+    def mountpoints(self):
+        targets = process.check_output(["findmnt", "-o", "target", "-n",
+                                        self.device]).split("\n")
+        return [Mount(t.strip()) for t in targets]
 
 
 class Mount(base.Base):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1f5fbb5dc30430e3ac79cf14df8a1093dee3eda0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: hadong <hadong0720 at gmail.com>
Gerrit-Reviewer: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list