Change in vdsm[master]: utils: add logged CPopen command execution

Federico Simoncelli fsimonce at redhat.com
Tue Mar 17 17:40:23 UTC 2015


Federico Simoncelli has uploaded a new change for review.

Change subject: utils: add logged CPopen command execution
......................................................................

utils: add logged CPopen command execution

Now that we're moving to a more wide use of CPopen in the code we
still need consistent logging of command line executions.

Change-Id: I5e04bde10be24457fe12362456e42528f9fd7196
Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
---
M lib/vdsm/utils.py
1 file changed, 15 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/38831/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index d467af6..0b64d4a 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -641,6 +641,18 @@
     return ' '.join(parts)
 
 
+def loggedCPopen(args, close_fds=False, cwd=None, env=None, deathSignal=0,
+                 childUmask=None, printable=None, logger=logging.root,
+                 level=logging.DEBUG):
+    if not printable:
+        printable = args
+
+    logger.log(level, "%s (cwd %s)", _list2cmdline(printable), cwd)
+
+    return CPopen(args, close_fds=close_fds, cwd=cwd, env=env,
+                  deathSignal=deathSignal, childUmask=childUmask)
+
+
 def execCmd(command, sudo=False, cwd=None, data=None, raw=False,
             printable=None, env=None, sync=True, nice=None, ioclass=None,
             ioclassdata=None, setsid=False, execCmdLogger=logging.root,
@@ -671,13 +683,9 @@
     if not callable(getattr(command, '__getitem__', None)):
         command = tuple(command)
 
-    if not printable:
-        printable = command
-
-    execCmdLogger.debug("%s (cwd %s)", _list2cmdline(printable), cwd)
-
-    p = CPopen(command, close_fds=True, cwd=cwd, env=env,
-               deathSignal=deathSignal, childUmask=childUmask)
+    p = loggedCPopen(command, close_fds=True, cwd=cwd, env=env,
+                     deathSignal=deathSignal, childUmask=childUmask,
+                     printable=printable)
     if not sync:
         p = AsyncProc(p)
         if data is not None:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e04bde10be24457fe12362456e42528f9fd7196
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce at redhat.com>


More information about the vdsm-patches mailing list