convenience to inspect and manage pools
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 18 May 2009 09:06:08 +0000 (09:06 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 18 May 2009 09:06:08 +0000 (09:06 +0000)
system/TestPool.py
system/TestResources.py
system/helpers.aliases [new file with mode: 0644]

index b516ade..85a7397 100644 (file)
@@ -73,8 +73,7 @@ class TestPoolIP (TestPool):
 # OS-dependent ping option (support for macos, for convenience)
     ping_timeout_option = None
 # checks whether a given hostname/ip responds to ping
-    @staticmethod
-    def check_ping (hostname):
+    def check_ping (self,hostname):
         if not TestPoolIP.ping_timeout_option:
             (status,osname) = commands.getstatusoutput("uname -s")
             if status != 0:
@@ -84,6 +83,8 @@ class TestPoolIP (TestPool):
             elif osname == "Darwin":
                 TestPoolIP.ping_timeout_option="-t"
 
+        if self.options.verbose:
+            utils.header ("TestPoolIP: pinging %s"%hostname)
         command="ping -c 1 %s 1 %s"%(TestPoolIP.ping_timeout_option,hostname)
         (status,output) = commands.getstatusoutput(command)
         return status == 0
@@ -97,8 +98,9 @@ class TestPoolQemu (TestPool):
         return not TestPoolQemu.busy_qemu(hostname)
 
     # is there a qemu runing on that box already ?
-    @staticmethod
-    def busy_qemu (hostname):
+    def busy_qemu (self, hostname):
+        if self.options.verbose:
+            utils.header("TestPoolQemu: checking for running qemu instances on %s"%hostname)
         command="ssh -o ConnectTimeout=5 root@%s ps -e -o cmd"%hostname
         (status,output) = commands.getstatusoutput(command)
         # if we fail to run that, let's assume we don't have ssh access, so
index f69c12d..93dd9f0 100644 (file)
@@ -17,18 +17,18 @@ class TestResources:
     def localize (self,plcs,options):
         try:
             plcs = self.localize_qemus(plcs,options)
-        except:
-            print 'Could not localize qemus - exiting'
+        except Exception, e:
+            print 'Could not localize qemus','--',e,'--','exiting'
             sys.exit(1)
         try:
             plcs = self.localize_nodes(plcs,options)
-        except:
-            print 'Could not localize nodes - exiting'
+        except Exception,e:
+            print 'Could not localize nodes','--',e,'--','exiting'
             sys.exit(1)
         try:
             plcs = self.localize_plcs(plcs,options)
-        except:
-            print 'Could not localize plcs - exiting'
+        except Exception,e:
+            print 'Could not localize plcs','--',e,'--','exiting'
             sys.exit(1)
         return plcs
 
diff --git a/system/helpers.aliases b/system/helpers.aliases
new file mode 100644 (file)
index 0000000..4743d11
--- /dev/null
@@ -0,0 +1,53 @@
+## -*-sh-*-
+
+########## locad local defs
+local_defs=~/LocalTestResources.helpers
+if [ -f $local_defs ] ; then 
+    source $local_defs
+else
+    echo "you should define qemuboxes and plcboxes in $local_defs"
+    exit
+fi
+
+if [ -z "$qemuboxes" -o -z "$plcboxes" ] ; then
+    echo "you should define qemuboxes and plcboxes in $local_defs"
+    exit
+fi
+
+########## list: from trackers, what should be
+alias list_qemus="head -v ~/tracker-qemus"
+alias list_plcs="head -v ~/tracker-plcs"
+alias list_all="list_qemus ; list_plcs"
+
+########## probe: from real data
+alias probe_qemus='for box in $qemuboxes ; do echo qemu instances in $box ; ssh root@$box pgrep qemu ; done'
+alias probe_plcs='for box in $plcboxes ; do echo plc instances in $box; ssh $box vserver-stat; done'
+alias probe_all="probe_qemus ; probe_plcs"
+
+########## cleanup: stop plc or kill qemus
+function cleanup_qemus () {
+    for box in $qemuboxes ; do 
+       echo killing qemu instances in $box
+       ssh root@$box pkill qemu
+    done
+    if [ -f ~/tracker-qemus ] ; then 
+       echo ~/cleaning tracker-qemus ; rm ~/tracker-qemus 
+    fi
+}
+function cleanup_plcs () { 
+    for box in $plcboxes ; do 
+       echo stopping vserver instances in $box 
+       ssh root@$box 'cd /vservers ; for vsname in *; do echo -n "stop $vsname y/[n] ? "; read answer ; case $answer in nN) echo skipping $vsname ;; *) vserver $vsname stop ;; esac; done'
+    done
+    if [ -f ~/tracker-plcs ] ; then 
+       echo ~/cleaning tracker-plcs
+       rm ~/tracker-plcs
+    fi
+}
+alias cleanup_all="cleanup_qemus ; cleanup_plcs"
+
+########## reboot: reboot the root contexts 
+alias reboot_qemus='for box in $qemuboxes; do echo rebooting $box ; ssh root@$box shutdown -r now ; done'
+alias reboot_plcs='for box in $plcboxes; do echo rebooting $box ; ssh root@$box shutdown -r now ; done'
+alias reboot_all="reboot_qemus ; reboot_plcs"
+