-m lists running tests on testmaster
[infrastructure.git] / scripts / manage-infrastructure.py
index bdd434e..5da94cf 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import os.path
+import os.path, sys
 import re
 import subprocess
 from optparse import OptionParser
@@ -8,14 +8,15 @@ from optparse import OptionParser
 class BuildBoxes:
 
     # everything in the onelab.eu domain
-    domain = 'onelab.eu'
+    domain = 'pl.sophia.inria.fr'
     testmaster = 'testmaster'
     build_boxes = [ "mirror", "liquid", "reed", "velvet", ]
     plc_boxes = [ "testplc" ]
     qemu_boxes = \
-        [ "testqemu%d"%i for i in range (1,4) ] + \
-        [ "testqemu32-%d"%i for i in range (1,6) ]
+        [ "qemu64-%d"%i for i in range (1,4) ] + \
+        [ "qemu32-%d"%i for i in range (1,6) ]
     test_boxes = plc_boxes + qemu_boxes
+    testmaster_boxes = [ testmaster ]
 
     def __init__ (self):
         # dummy defaults
@@ -36,6 +37,7 @@ class BuildBoxes:
 
     def header (self,message):
         print "===============",message
+        sys.stdout.flush()
 
     def run (self,argv,message, trash_err=False):
         if self.options.dry_run:
@@ -62,7 +64,6 @@ class BuildBoxes:
             return subprocess.Popen(argv,stdout=subprocess.PIPE,stderr=file('/dev/null','w')).communicate()[0]
 
     def backquote_ssh (self, box, argv, trash_err=False):
-#        print 'BACKQUOTE_SSH [%s] %s'%(box,' '.join(argv))
         # first probe the ssh link
         hostname=self.backquote ( self.ssh(box) + [ "hostname"], trash_err=True )
         if not hostname:
@@ -185,7 +186,6 @@ class BuildBoxes:
         if match: return match.groups(0)
         else: return ""
 
-
     def handle_qemu_box (self,box):
         if not self.options.probe:
             self.reboot(box)
@@ -212,17 +212,47 @@ class BuildBoxes:
                         if not ps_line or ps_line.find('PID') >=0 : continue
                         print self.margin_outline(self.vnodename(ps_line)), ps_line
 
+    # the ouput of ps -o pid,command gives us <pid> bash <buildname>/run_log
+    def testmaster_buildname (self, ps_line):
+        chunks=ps_line.split()
+        path=chunks[2]
+        [buildname,command]=path.split('/')
+        return buildname
+
+    def handle_testmaster_box (self, box):
+            command=['pgrep','run_log']
+            if self.options.dry_run:
+                self.run_ssh(box,command,None)
+            else:
+                pids=self.backquote_ssh(box,command)
+                if not pids:
+                    self.header ('No run_log process on %s'%box)
+                else:
+                    self.header ("Active run_log processes on %s"%(box))
+                    command=['ps','-o','pid,command'] + [ pid for pid in pids.split("\n") if pid]
+                    ps_lines = self.backquote_ssh (box,command).split("\n")
+                    for ps_line in ps_lines:
+                        if not ps_line or ps_line.find('PID') >=0 : continue
+                        print self.margin_outline(self.testmaster_buildname(ps_line)), ps_line
+        
+
     def handle_box(self,box,type):
         if box in self.qemu_boxes:
             if type=="qemu": self.handle_qemu_box(self.fqdn(box))
         elif box in self.plc_boxes:
             if type=="plc":  self.handle_plc_box(self.fqdn(box))
+        elif box in self.testmaster_boxes:
+            if type=='testmaster': self.handle_testmaster_box(self.fqdn(box))
         elif type=="build":
             self.handle_build_box(self.fqdn(box))
 
+    def handle_disk (self,box):
+        box=self.fqdn(box)
+        return self.run_ssh(box,["df","-h",],"Disk space on %s"%box)
+
     def main (self):
         usage="""%prog [options] [hostname..(s)]
-Default is to act on test boxes only (with trackers clean)"""
+Default is to act on test boxes only"""
         parser = OptionParser (usage=usage)
         parser.add_option ("-n","--dry-run",action="store_true",dest="dry_run",default=False,
                            help="Dry run")
@@ -240,6 +270,10 @@ Default is to act on test boxes only (with trackers clean)"""
                            help="Only acts on the qemu boxes")
         parser.add_option ("-t","--trackers",action="store_true",dest="trackers_only",default=False,
                            help="Only wipes trackers")
+        parser.add_option ("-m","--master",action="store_true",dest="testmaster_only",default=False,
+                           help="Display the testmaster status")
+        parser.add_option ("-d","--disk",action="store_true",dest="show_disk",default=False,
+                           help="Only inspects disk status")
 
         (self.options,args) = parser.parse_args()
 
@@ -265,6 +299,10 @@ Default is to act on test boxes only (with trackers clean)"""
             self.boxes=self.plc_boxes
             self.do_tracker_plcs = True
             self.do_tracker_qemus = False
+        elif self.options.testmaster_only:
+            self.boxes=self.testmaster_boxes
+            self.do_tracker_plcs = False
+            self.do_tracker_qemus = False
         elif self.options.trackers_only:
             self.boxes = []
             self.do_tracker_plcs = True
@@ -275,8 +313,14 @@ Default is to act on test boxes only (with trackers clean)"""
             self.do_tracker_plcs = True
             self.do_tracker_qemus = True
 
+        if self.options.show_disk:
+            for box in self.boxes: self.handle_disk(box)
+            return
+
         # ALL OTHERS
         for box in self.boxes:  self.handle_box (box,"build")
+        # TESTMASTER
+        for box in self.boxes:  self.handle_box (box,"testmaster")
         # PLCS
         if self.do_tracker_plcs:self.handle_tracker_plcs ()
         for box in self.boxes:  self.handle_box (box,"plc")