From: Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Date: Thu, 14 Feb 2008 13:15:53 +0000 (+0000)
Subject: fine-grain kill of qemus - new step list_all_qemus
X-Git-Tag: tests-4.2-4~242
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=a7f8a5be133b79e58ddedec46550a118c3894fa0;p=tests.git

fine-grain kill of qemus - new step list_all_qemus
---

diff --git a/system/TestMain.py b/system/TestMain.py
index b06f14a..1458b89 100755
--- a/system/TestMain.py
+++ b/system/TestMain.py
@@ -27,7 +27,8 @@ class TestMain:
                      'check_tcp' ]
     other_steps = [ 'fresh_install', 'stop', 
                     'clean_sites', 'clean_nodes', 'clean_slices', 'clean_keys',
-                    'kill_qemus', 'stop_nodes' ,  'db_dump' , 'db_restore',
+                    'list_all_qemus', 'kill_qemus', 'stop_nodes' ,  
+                    'db_dump' , 'db_restore',
                     'standby_1 through 20',
                     ]
     default_build_url = "http://svn.planet-lab.org/svn/build/trunk"
diff --git a/system/TestPlc.py b/system/TestPlc.py
index cb3a11b..5381444 100644
--- a/system/TestPlc.py
+++ b/system/TestPlc.py
@@ -163,9 +163,20 @@ class TestPlc:
             TestBox(box).kill_all_qemus()
         return True
 
+    # make this a valid step
+    def list_all_qemus(self,options):
+        for (box,nodes) in self.gather_hostBoxes().iteritems():
+	    # push the script
+	    TestBox(box).copy("qemu_kill.sh")	
+            # this is the brute force version, kill all qemus on that host box
+            TestBox(box).run("./qemu_kill.sh -l")
+        return True
+
     # kill only the right qemus
     def kill_qemus(self,options):
         for (box,nodes) in self.gather_hostBoxes().iteritems():
+	    # push the script
+	    TestBox(box).copy("qemu_kill.sh")	
             # the fine-grain version
             for node in nodes:
                 node.kill_qemu()
diff --git a/system/qemu_kill.sh b/system/qemu_kill.sh
index ad1a01f..d2c1fc1 100755
--- a/system/qemu_kill.sh
+++ b/system/qemu_kill.sh
@@ -2,17 +2,36 @@
 COMMAND=$(basename $0)
 
 hostname=$1; shift
-pids="$(ps $(pgrep qemu) | grep $hostname | awk '{print $1;}')"
+
+# -l option 
+if [ "$hostname" = "-l" ] ; then
+    echo $COMMAND - listing qemu processes on $(hostname)
+    pids="$(pgrep -x qemu) $(pgrep -x start-qemu-node)"
+    [ -n "$(echo $pids)" ] && ps $pids
+    exit 0
+fi
+
+# locate only the actual qemu 
+qemu_pids="$(pgrep -x start-qemu-node) $(pgrep -x qemu)"
+
+if [ -z "$(echo $qemu_pids)" ] ; then
+    echo $COMMAND - no qemu found on $(hostname)
+    exit 0
+fi
+
+pids="$(ps $qemu_pids | grep $hostname | awk '{print $1;}')"
 
 if [ -z "$pids" ] ; then
     echo $COMMAND: no qemu instance for $hostname found on $(hostname)
-else
-    echo Killing $pids
-    kill $pids
-    sleep 2
-    if [ -n "$(ps $pids)" ] ; then
-	echo Killing -9 $pids
-	kill -9 $pids
-    fi
-    echo Done
+    exit 0
 fi
+
+echo Killing $pids
+kill $pids
+(sleep 1; 
+ if ps $pids &> /dev/null ; then
+     echo still alive - killing -9 $pids
+     kill -9 $pids
+ fi ) &
+echo Done
+exit 0