[Collab-qa-commits] r1245 - buildstat/trunk/buildstat-agent

goneri at alioth.debian.org goneri at alioth.debian.org
Mon Sep 8 18:50:22 UTC 2008


Author: goneri
Date: 2008-09-08 18:50:21 +0000 (Mon, 08 Sep 2008)
New Revision: 1245

Modified:
   buildstat/trunk/buildstat-agent/buildstat-buildagent
Log:
improve the output message


Modified: buildstat/trunk/buildstat-agent/buildstat-buildagent
===================================================================
--- buildstat/trunk/buildstat-agent/buildstat-buildagent	2008-09-08 10:42:57 UTC (rev 1244)
+++ buildstat/trunk/buildstat-agent/buildstat-buildagent	2008-09-08 18:50:21 UTC (rev 1245)
@@ -36,8 +36,11 @@
 my $adminname = $cfg->val('admin', 'name');
 my $adminemail = $cfg->val('admin', 'email');
 my $adminteam = $cfg->val('admin', 'team');
+my $maxjob = $cfg->val('settings', 'maxjob');
 
-
+if (!$adminname || !$adminemail) {
+    die "Please set your name and your email in $inifile";
+}
 if (!$debmirror) {
     die "Can't find the debmirror in $inifile";
 }
@@ -48,7 +51,6 @@
     die "Can't find the vardir directory in $inifile";
 }
 
-my $maxjob = 1;
 my $workplace = $vardir."/workplace";
 my $pbuilderplace = $vardir."/pbuilder";
 my $buildarea = $vardir."/report";
@@ -57,7 +59,7 @@
 my $pbuildertgz = "$pbuilderplace/$distro.tar.gz";
 my $sigTermCatched = 0;
 my $exit = 0;
-sub sigterm {print "SIGTERM!\n";$sigTermCatched=1};
+sub sigterm {print "SIGTERM catched, please wait!\n";$sigTermCatched=1};
 $SIG{INT}= 'sigterm';
 
 my $keeptmpdir;
@@ -66,8 +68,13 @@
 $ENV{LC_ALL} = 'C';
 $ENV{LANG} = 'C';
 
+sub logger {
+    chomp (my $msg = shift);
 
+    print $msg."\n";
+}
 
+
 sub killThemAll {
     my ($mainpid, $signal) = @_;
 
@@ -76,7 +83,7 @@
         my $pid = $1;
         killThemAll($pid, $signal);
         kill ($pid, $signal);
-        print "kill ($pid, $signal)\n";
+#        print "kill ($pid, $signal)\n";
     }
 
 }
@@ -85,26 +92,27 @@
   die "please create: `".$vardir unless -d $vardir;
 # TODO check for running script in background
 # Purge
-  `rm -rf $workplace/*`;
-  `rm -rf $buildarea/*`;
-  `rm -rf $tmpdir/*`;
+  `/bin/rm -r $workplace/*`;
+  `/bin/rm -r $buildarea/*`;
+  `/bin/rm -r $tmpdir/*`;
+  `apt-get clean`;
 
   foreach (`mount`) {
     if (/^\/\S+\son\s(\S+)/) {
       my $mountPoint = $1;
       if ($mountPoint =~ /^$pbuilderplace/) {
-        print "umounting $mountPoint\n";
+#        print "umounting $mountPoint\n";
         system("umount $mountPoint");
       }
     }
   }
-  # !!! Maybe danger if $pbuilderplace is unset
+  # !!! danger if $pbuilderplace is unset
   # so I do another check here!
   die "DANGER: pbuilderplace not correct!" unless $pbuilderplace =~ /\/./;
 
   foreach (bsd_glob($pbuilderplace.'/*')) {
     next if /tar.gz$/; # pbuilder tarball
-    system ("rm -r $_");
+    system ("/bin/rm -r $_");
   }
 
 # (Re)Create the directorys
@@ -130,7 +138,7 @@
   $exit = 1 if $sigTermCatched;
   if ($exit||isMemFull()||isDiskFull($workplace)||isDiskFull($buildarea)||isDiskFull('/tmp')) {
     if (%job&&($exit||isDiskFull($workplace)||isDiskFull($buildarea))) {
-      print "Emergency clean up\n";
+      logger("Emergency clean up");
       killThemAll($$, 9);
    
       foreach (keys %job) {
@@ -147,14 +155,16 @@
   my $file = shift;
 
   my $ua = new LWP::UserAgent;
+  $ua->env_proxy;
 
+  return if $sigTermCatched;
 
   my $response = $ua->request(POST $server.'/controls/buildInput',
     Content_Type => 'form-data',
     Content => ['file' => [ $file, basename($file) ]]) or die "Upload failed\n";
 
   if ($response->is_error) {
-    print "Failed to post file: ".$response->as_string()."\n";
+    logger("Failed to post file: ".$response->as_string());
   }
 
 }
@@ -192,7 +202,9 @@
   my $p;
   my $report = {};
 
+  logger("Getting a build to do");
   my $ua  = LWP::UserAgent->new();
+  $ua->env_proxy;
   my $req = POST $server."/controls/getBuildJob", Content_Type => 'form-data',
   Content      => [
   submit => 1,
@@ -219,7 +231,7 @@
     if (!(time % 300)) {
         system ("gzip -t $pbuildertgz");
         if (($? >> 8)!=0) {
-            print "pbuildertgz is corrupted, removing it\n";
+            logger("pbuildertgz is corrupted, removing it");
             unlink $pbuildertgz 
         }
     }
@@ -234,10 +246,11 @@
   }
 
   if (! -s $pbuildertgz) {
+    logger("Upgrading the chroot");
     # TODO redirect the log on another place
     `/usr/sbin/pbuilder create $pdebuildparam >/tmp/pbuilder-create.log 1>&2`;
     if (($? >> 8)!=0) {
-      print "Failed to create pbuilder image\n";
+      logger("Failed to create pbuilder image");
       if (-f "$pbuildertgz.save") {
         # I restore the previous chroot
         `cp $pbuildertgz.save $pbuildertgz`;
@@ -252,7 +265,7 @@
   if (! -s $pbuildertgz) {
     my $timer = 10*$retry;
     $timer = 180 if $timer > 180;
-    print "Failed to create a pbuilder tarball, will sleep for $timer minutes and retry ...\n";
+    logger("Failed to create a pbuilder tarball, will sleep for $timer minutes and retry ...");
     my $secondremaining=$timer*60;
     while ($timer) {
     	exit 0 if $sigTermCatched;
@@ -268,7 +281,7 @@
 
   my ($report, $threadbuildarea) = @_;
 
-  print "sending result that are in $threadbuildarea\n";
+  #print "sending result that are in $threadbuildarea\n";
 
   $report->{'arch'} = $arch;
   $report->{hostname} = $hostname;
@@ -286,9 +299,9 @@
   my $logfile = $prefix.'.log';
   my $infofile = $prefix.'.info';
 
-  open (BUILDLOGTMP, "<","$threadbuildarea/build.log.tmp") or die;
+  open (BUILDLOGTMP, "<","$threadbuildarea/build.log.tmp") or return;
   seek(BUILDLOGTMP, -1000000, 2); # I just keep the end of the logfile
-  open (BUILDLOG, ">", "$threadbuildarea/".$logfile) or die;
+  open (BUILDLOG, ">", "$threadbuildarea/".$logfile) or return;
   # If I'm not at the end of BUILDLOGTMP it means that seek moved me
   print BUILDLOG "(log file truncated) ... " if tell(BUILDLOGTMP);
 
@@ -305,16 +318,19 @@
   postFile($threadbuildarea."/".$logfile);
   $report->{logfile} = $logfile;
   if (bsd_glob($threadbuildarea.'/*.changes')) {
-    print "build is ok\n";
+    logger ("build is ok");
     $report->{build} = "ok";
     $report->{files} = '';
-    foreach (bsd_glob($threadbuildarea.'/*')) {
-      next if /orig\.tar\.gz$/; # deb & udeb
-      $report->{files} = $report->{files}.basename($_).' ';
-      postFile($_);
+
+    if ($report->{sendbackdebs} ne 'no') {
+      foreach (bsd_glob($threadbuildarea.'/*')) {
+        next if /orig\.tar\.gz$/; # deb & udeb
+        $report->{files} = $report->{files}.basename($_).' ';
+        postFile($_);
+        }
     }
   } else {
-    print "build is nok\n";
+    logger ("build is ko");
     $report->{build} = "nok";
   }
 
@@ -349,31 +365,40 @@
 ###########################################################################
 ###########################################################################
 
-  print "dsc: ".$report->{dsc}."\n";
+  #print "dsc: ".$report->{dsc}."\n";
 
   my $tarballdir;
+  my $packagesrc;
   # The archive are not signed for the moment
-  my $cmd = "cd $threadworkplace; dget -qxu ".$report->{dsc};
+  logger("Getting the source package");
+  my $dscuri = $report->{dsc};
+  $dscuri =~ s/\@DEB_MIRROR\@/$debmirror/;
+  my $cmd = "cd $threadworkplace; dget -qxu ".$dscuri." 2> /dev/null";
   foreach (`$cmd`) {
-    $tarballdir = $1 if /dpkg-source:\sextracting\s\S+\sin\s(\S+)/;
+    if (/dpkg-source:\sextracting\s(\S+)\sin\s(\S+)/) {
+        $packagesrc = $1;
+        $tarballdir = $2;
+    }
   }
   if (!$tarballdir) {
-    system("rm -r $threadworkplace $threadbuildarea") unless $keeptmpdir;
+    logger ("Failed to fetch the sources from $dscuri");
+    system("/bin/rm -r $threadworkplace $threadbuildarea 2> /dev/null") unless $keeptmpdir;
     return;
   }
 
+  logger("Building $packagesrc");
   $report->{'stamp_build-start'} = time;
   my $dsc_localpath = $threadworkplace.'/'.basename($report->{dsc});
 
   `cd $threadworkplace/$tarballdir; pbuilder --build --buildresult $threadbuildarea --buildplace $pbuilderplace --aptcache $aptcachedir --distribution $distro --basetgz $pbuilderplace/$distro.tar.gz --timeout 10h $dsc_localpath >$threadbuildarea/build.log.tmp 2>&1`;
   if (($? >> 8)!=0) {
-      print "DEBUG: PBUILDER RETURNED AN ERROR CODE\n";
+#      print "DEBUG: PBUILDER RETURNED AN ERROR CODE\n";
   }
   $report->{'stamp_build-end'} = time;
 
   sendReport($report, $threadbuildarea);
 
-  `rm -rf $threadworkplace $threadbuildarea` unless $keeptmpdir;
+  `/bin/rm -r $threadworkplace $threadbuildarea 2> /dev/null` unless $keeptmpdir;
 
   1;
 }
@@ -384,8 +409,7 @@
 ###### Main
 purge();
 
-while (sleep 10) {
-
+while (sleep 5) {
   checkSanity();
   exit(1) if $exit;
   upgradeChroot();
@@ -394,8 +418,8 @@
   foreach my $pid (keys %job) {
     waitpid($pid, WNOHANG);
     if (! -d "/proc/".$pid) {
-      print "$pid is finish\n";
-      `rm -rf $workplace/$pid $buildarea/$pid` unless $keeptmpdir;
+        #print "$pid is finish\n";
+      `rm -rf $workplace/$pid $buildarea/$pid 2> /dev/null` unless $keeptmpdir;
       delete ($job{$pid});
     }
   }
@@ -406,12 +430,11 @@
       $job{$newpid} = time;
     } else { # Son
       my $report = getBuildJob ();
-      print $report->{dsc}."\n";
       if (!exists($report->{dsc})) {
-        print "Can't get a package to build from $server\n";
+        logger ("Can't get a package to build from $server");
       } else {
         build($report);
-        print "done\n";
+        #print "done\n";
       }
       exit;
     }




More information about the Collab-qa-commits mailing list