fix command_in_slice - was working in lxc but not vs
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 10 Jul 2013 09:10:41 +0000 (11:10 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Wed, 10 Jul 2013 09:10:41 +0000 (11:10 +0200)
plugins/omf_resctl.py
tools.py

index a0f14ab..1f17453 100644 (file)
@@ -106,7 +106,7 @@ def GetSlivers(data, conf = None, plc = None):
             try:
                 fetch_trigger_script_if_missing (slicename)
                 # the trigger script actually needs to be run in the slice context of course
-                slice_command = ["sudo -i %s"%omf_rc_trigger_script]
+                slice_command = [ "sudo", "-i",  omf_rc_trigger_script ]
                 to_run = tools.command_in_slice (slicename, slice_command)
                 logger.log("command_in_slice: %s"%to_run)
                 sp=subprocess.Popen(to_run, stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
index a53c158..dbfa55f 100644 (file)
--- a/tools.py
+++ b/tools.py
@@ -309,15 +309,22 @@ def get_node_virt ():
         f.write(virt)
     return virt
 
+# how to run a command in a slice
+# now this is a painful matter
+# the problem is with capsh that forces a bash command to be injected in its exec'ed command
+# so because lxcsu uses capsh, you cannot exec anything else than bash
+# bottom line is, what actually needs to be called is
+# vs:  vserver exec slicename command and its arguments
+# lxc: lxcsu slicename "command and its arguments"
+# which, OK, is no big deal as long as the command is simple enough, 
+# but do not stretch it with arguments that have spaces or need quoting as that will become a nightmare
 def command_in_slice (slicename, argv):
-    # with vserver this can be done using vserver .. exec <trigger-script>
-    # with lxc this is less clear as we are still discussing how lxcsu should behave
-    # ideally we'd need to run lxcsu .. <trigger-script>
     virt=get_node_virt()
     if virt=='vs':
         return [ 'vserver', slicename, 'exec', ] + argv
     elif virt=='lxc':
-        return [ 'lxcsu', slicename, ] + argv
+        # wrap up argv in a single string for -c
+        return [ 'lxcsu', slicename, ] + [ " ".join(argv) ]
     logger.log("command_in_slice: WARNING: could not find a valid virt")
     return argv