From 3b0d15f110c8bd25c767643daf0638043fee7af1 Mon Sep 17 00:00:00 2001
From: Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Date: Mon, 7 Apr 2008 21:10:54 +0000
Subject: [PATCH] quick fix for qemu start/stop on remote testboxes

---
 system/TestBox.py                    |  5 +++--
 system/TestPlc.py                    |  8 +++++---
 system/template-qemu/qemu-kill-node  | 15 ++++++++++++---
 system/template-qemu/qemu-start-node |  1 +
 4 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/system/TestBox.py b/system/TestBox.py
index 978344c..773a914 100644
--- a/system/TestBox.py
+++ b/system/TestBox.py
@@ -34,8 +34,9 @@ class TestBox:
     def mkdir (self,dirname):
         return self.test_ssh.mkdir(dirname)
 
-    def kill_all_qemus(self):
-        self.run_in_buildname("template-qemu/qemu-kill-node")
+    # we need at least one nodename, as template-qemu is not synced on remote testboxes
+    def kill_all_qemus(self,nodename):
+        self.run_in_buildname("qemu-%s/qemu-kill-node"%nodename)
         return True
 
     def list_all_qemus(self):
diff --git a/system/TestPlc.py b/system/TestPlc.py
index 112b993..df4d431 100644
--- a/system/TestPlc.py
+++ b/system/TestPlc.py
@@ -181,7 +181,7 @@ class TestPlc:
                 test_node = TestNode (self, test_site, node_spec)
                 if not test_node.is_real():
                     tuples.append( (test_node.host_box(),test_node) )
-        # transform into a dict { 'host_box' -> [ hostnames .. ] }
+        # transform into a dict { 'host_box' -> [ test_node .. ] }
         result = {}
         for (box,node) in tuples:
             if not result.has_key(box):
@@ -198,9 +198,11 @@ class TestPlc:
 
     # make this a valid step
     def kill_all_qemus(self):
+        # this is the brute force version, kill all qemus on that host box
         for (box,nodes) in self.gather_hostBoxes().iteritems():
-            # this is the brute force version, kill all qemus on that host box
-            TestBox(box,self.options.buildname).kill_all_qemus()
+            # pass the first nodename, as we don't push template-qemu on testboxes
+            nodename=nodes[0].name()
+            TestBox(box,self.options.buildname).kill_all_qemus(nodename)
         return True
 
     # make this a valid step
diff --git a/system/template-qemu/qemu-kill-node b/system/template-qemu/qemu-kill-node
index 830d33d..a4a00d0 100755
--- a/system/template-qemu/qemu-kill-node
+++ b/system/template-qemu/qemu-kill-node
@@ -4,11 +4,16 @@ COMMAND=$(basename $0)
 cd $(dirname $0)
 cd ..
 
+# somehow qemu-system-x86_64 show up in pgrep as qemu-system-x86
+COMMANDS_TO_KILL="qemu qemu-system-x86_64 qemu-system-x86"
+
 function usage () {
     echo "Usage: $COMMAND -l"
     echo "  lists current qemu processes"
     echo "usage: $COMMAND hostname"
     echo "  kill qemu instance for that node"
+    echo "usage: $COMMAND"
+    echo "  kill all instances of [$COMMANDS_TO_KILL]"
     exit 1
 }
 
@@ -20,7 +25,9 @@ function list_pids () {
 	    cat $nodedir/qemu.pid 2> /dev/null
 	done
     else
-	pgrep qemu
+	for command in $COMMANDS_TO_KILL; do
+	    pgrep -x $command
+	done
     fi
 }
 
@@ -44,8 +51,10 @@ function kill_pids () {
 	    kill_from_file $nodedir/qemu.pid
 	done
     else
-	echo Killing all processes mathing qemu
-	pkill qemu
+	echo "Killing all processes mathing $COMMANDS_TO_KILL"
+	for command in $COMMANDS_TO_KILL ; do
+	    pkill -x $command
+	done
     fi
 }
 
diff --git a/system/template-qemu/qemu-start-node b/system/template-qemu/qemu-start-node
index c0606f0..29f465c 100755
--- a/system/template-qemu/qemu-start-node
+++ b/system/template-qemu/qemu-start-node
@@ -22,6 +22,7 @@ fi
 . $CONFIG
 
 # the launcher, depending on local/target archs
+# make sure to check qemu-kill-node for consistency
 archs="$(uname -i)+$TARGET_ARCH"
 case $archs in
     i386+i386)		QEMU=qemu;;
-- 
2.47.0