Change in vdsm[master]: utils: split out execCmd wrapping logic

alitke at redhat.com alitke at redhat.com
Wed Oct 7 20:23:40 UTC 2015


Adam Litke has uploaded a new change for review.

Change subject: utils: split out execCmd wrapping logic
......................................................................

utils: split out execCmd wrapping logic

The execCmd utility contains fairly intricate logic which wraps a given
command with various other utilities (eg. sudo, nice, taskset, etc)
according to the callers preferences.  We should split this logic into
its own function so that other direct consumers of CPopen (eg. qemuimg
in an upcoming patch) can get the same semantics as execCmd.

Change-Id: I98a01c4e8c80202b8e897dacc7628504d3cf7771
Signed-off-by: Adam Litke <alitke at redhat.com>
---
M lib/vdsm/utils.py
1 file changed, 21 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/07/47107/1

diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py
index 383acf1..69a30ea 100644
--- a/lib/vdsm/utils.py
+++ b/lib/vdsm/utils.py
@@ -629,19 +629,8 @@
 _USING_CPU_AFFINITY = config.get('vars', 'cpu_affinity') != ""
 
 
-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,
-            deathSignal=0, childUmask=None, resetCpuAffinity=True):
-    """
-    Executes an external command, optionally via sudo.
-
-    IMPORTANT NOTE: the new process would receive `deathSignal` when the
-    controlling thread dies, which may not be what you intended: if you create
-    a temporary thread, spawn a sync=False sub-process, and have the thread
-    finish, the new subprocess would die immediately.
-    """
-
+def wrap_command(command, ioclass=None, ioclassdata=None, nice=None,
+                 setsid=False, sudo=False, reset_cpu_affinity=True):
     if ioclass is not None:
         command = cmdutils.ionice(command, ioclass=ioclass,
                                   ioclassdata=ioclassdata)
@@ -661,7 +650,7 @@
     # impractical. On the other hand, using 'taskset sudo <command>'
     # is much simpler and delivers the same end result.
 
-    if resetCpuAffinity and _USING_CPU_AFFINITY:
+    if reset_cpu_affinity and _USING_CPU_AFFINITY:
         # only VDSM itself should be bound
         command = cmdutils.taskset(command, _ANY_CPU)
 
@@ -669,6 +658,24 @@
     if not callable(getattr(command, '__getitem__', None)):
         command = tuple(command)
 
+    return command
+
+
+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,
+            deathSignal=0, childUmask=None, resetCpuAffinity=True):
+    """
+    Executes an external command, optionally via sudo.
+
+    IMPORTANT NOTE: the new process would receive `deathSignal` when the
+    controlling thread dies, which may not be what you intended: if you create
+    a temporary thread, spawn a sync=False sub-process, and have the thread
+    finish, the new subprocess would die immediately.
+    """
+
+    command = wrap_command(command, ioclass, ioclassdata, nice, setsid, sudo,
+                           resetCpuAffinity)
     if not printable:
         printable = command
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98a01c4e8c80202b8e897dacc7628504d3cf7771
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <alitke at redhat.com>


More information about the vdsm-patches mailing list