security/nss/tests/clean_tbx

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/nss/tests/clean_tbx	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,172 @@
     1.4 +#! /bin/perl
     1.5 +
     1.6 +#######################################################################
     1.7 +#
     1.8 +# /u/sonmi/bin/clean_tbx.pl
     1.9 +#
    1.10 +# this script is supposed to remove tinderbox  QA if:
    1.11 +# QA has passed, there are 2+ newer QA dirs of the same machine and 
    1.12 +#     platform (32/64) and it is older than 2 hours
    1.13 +# QA has failed, there are 2+ newer QA dirsof the same machine and 
    1.14 +#     platform (32/64) with _identical failures and it is older than 
    1.15 +#     2 hours
    1.16 +# directory is older than 48 hours
    1.17 +#
    1.18 +#######################################################################
    1.19 +
    1.20 +use Time::Local;
    1.21 +
    1.22 +$ANY_TBX_KEEP_HOURS=48;
    1.23 +$NOT_FAILED_TBX_KEEP_HOURS=24;
    1.24 +$PASSED_TBX_KEEP_HOURS=2;
    1.25 +$IF_TBX_KEEP_HOURS=2;
    1.26 +$PASSED_NEWER_DIRS=2;
    1.27 +$IF_NEWER_DIRS=2;
    1.28 +$verbose = 1;
    1.29 +
    1.30 +$TBX_TESTDIR="/share/builds/mccrel3/nss/nsstip/tinderbox/tests_results/security";
    1.31 +$FTP_STAGE="/u/sonmi/tmp/ftp_stage/tinderbox";
    1.32 +
    1.33 +@tbx_dirs = ();  
    1.34 +
    1.35 +$eANY_TBX_KEEP=$ANY_TBX_KEEP_HOURS*60*60;
    1.36 +$ePASSED_TBX_KEEP=$PASSED_TBX_KEEP_HOURS*60*60;
    1.37 +$eIF_TBX_KEEP=$IF_TBX_KEEP_HOURS*60*60;
    1.38 +$eNOT_FAILED_TBX_KEEP=$NOT_FAILED_TBX_KEEP_HOURS*60*60;
    1.39 +
    1.40 +$year, $month, $days, $hours, $minutes, $seconds;
    1.41 +$efulldate=0;
    1.42 +
    1.43 +$fulldate=0;
    1.44 +
    1.45 +$no_bits="";
    1.46 +$last_no_bits="";
    1.47 +
    1.48 +$host="";
    1.49 +$last_host="";
    1.50 +
    1.51 +@tbx_dirs = `ls -r $TBX_TESTDIR`; #sort first by host, 
    1.52 +                               #then 64, 
    1.53 +                               #then newest - oldest
    1.54 +debug ("found $#tbx_dirs directories ");
    1.55 +
    1.56 +($seconds, $minutes, $hours, $days, $month, $year) = localtime; 
    1.57 +
    1.58 +debug ("$seconds, $minutes, $hours, $days, $month, $year");
    1.59 +
    1.60 +$enow = timelocal(localtime);
    1.61 +
    1.62 +sub debug;
    1.63 +sub warning;
    1.64 +sub error;
    1.65 +sub msg;
    1.66 +sub init;
    1.67 +sub check_tbx_dirs;
    1.68 +
    1.69 +sub check_tbx_dirs
    1.70 +{
    1.71 +    my $platform_idx=0; # counts directories per platform, newest 
    1.72 +                        # to oldest (ignores incomplete)
    1.73 +    my $passed_idx=0;   # counts passed  directories newest to oldest
    1.74 +    my $QAstatus="unknown";
    1.75 +    foreach $tbx_dir  (@tbx_dirs) {
    1.76 +        $tbx_dir =~ s/\n//g;
    1.77 +        $fulldate = $tbx_dir;
    1.78 +        $fulldate =~ s/^.*-(20.*-..\...$)/$1/;
    1.79 +        $day = $month = $year = $hour = $min = $fulldate;
    1.80 +        $host = $tbx_dir;
    1.81 +        $host =~ s/-20.*//;
    1.82 +        $no_bits = $host;
    1.83 +        $host =~ s/64$//;
    1.84 +        $no_bits =~ s/.*64$/64/;
    1.85 +        $no_bits =~ s/^[^6].*/other/;
    1.86 +        $year =~ s/(....).*/$1/;
    1.87 +        $month =~ s/....(..).*/$1/;
    1.88 +        $day =~ s/......(..).*/$1/;
    1.89 +        $hour =~ s/........-(..).*/$1/;
    1.90 +        $min =~ s/.*\.(..)$/$1/;
    1.91 +        
    1.92 +
    1.93 +        if ( -f "$TBX_TESTDIR/$tbx_dir/QAstatus" ) {
    1.94 +            $QAstatus=`cat $TBX_TESTDIR/$tbx_dir/QAstatus 2>/dev/null`;
    1.95 +            $QAstatus =~ s/\n$//g;
    1.96 +        } else {
    1.97 +            $QAstatus="unknown";
    1.98 +        }
    1.99 +
   1.100 +        $efulldate = timelocal( 0, $min, $hour, $day, $month-1, $year-1900);
   1.101 +        if ( "$host" !~ "$last_host" || "$no_bits" !~ "$last_no_bits" ) {
   1.102 +            if ( $QAstatus !~ "QA running" ) {
   1.103 +                $platform_idx = 0;
   1.104 +            } else {
   1.105 +                $platform_idx = -1;
   1.106 +            }
   1.107 +            $passed_idx = 0;
   1.108 +
   1.109 +            $last_host = $host;
   1.110 +            $last_no_bits = $no_bits;
   1.111 +        } else {
   1.112 +            $platform_idx ++;
   1.113 +            $passed_idx++ if ( $QAstatus =~ "QA passed" ) ;
   1.114 +        }
   1.115 +
   1.116 +        debug ("$tbx_dir host $host date $fulldate bits $no_bits $year/$month/$day  $hour:$min QAstatus $QAstatus pli $platform_idx pai $passed_idx");
   1.117 +
   1.118 +        if ( $passed_idx > $PASSED_NEWER_DIRS && $QAstatus =~ "QA passed" ) {
   1.119 +            $ekeeptime=$efulldate + $ePASSED_TBX_KEEP;
   1.120 +            #($s, $m, $h, $d, $mo, $y) = localtime($ekeeptime);
   1.121 +            #debug ("$passed_idx > $PASSED_NEWER_DIRS ekeeptime ($s, $m, $h, $d, $mo, $y) == $ekeeptime");
   1.122 +             rm_tbx ("Passed $PASSED_TBX_KEEP_HOURS +  hours old") if ( $ekeeptime <= $enow );
   1.123 +        } elsif ( $QAstatus !~ "QA failed" ) {
   1.124 +            $ekeeptime=$efulldate + $eNOT_FAILED_TBX_KEEP;
   1.125 +            rm_tbx ("Not failed $NOT_FAILED_TBX_KEEP_HOURS + hours old") if ( $ekeeptime <= $enow );
   1.126 +	} else {
   1.127 +            $ekeeptime=$efulldate + $eANY_TBX_KEEP;
   1.128 +             rm_tbx ("Passed 2+ hours old") if ( $ekeeptime <= $enow );
   1.129 +        }
   1.130 +        if  ( $QAstatus =~ "QA failed" ) {
   1.131 +            $ekeeptime=$efulldate + $eIF_TBX_KEEP;
   1.132 +            #FIXME - compare to the previous failure by filtering and 
   1.133 +            #FIXME diffing the results.html files (first grep failed)
   1.134 +        }
   1.135 +    }
   1.136 +
   1.137 +}
   1.138 +
   1.139 +sub rm_tbx()
   1.140 +{
   1.141 +
   1.142 +debug ("DELETING $tbx_dir... (@_[0]) ");
   1.143 +system("rm -rf $TBX_TESTDIR/$tbx_dir");
   1.144 +#debug ("rm -rf $TBX_TESTDIR/$tbx_dir");
   1.145 +
   1.146 +}
   1.147 +
   1.148 +sub msg
   1.149 +{
   1.150 +    my $i;
   1.151 +    for ($i = 0; $i <= $#_ ; $i++ ) {
   1.152 +        print "@_[$i] ";
   1.153 +    }
   1.154 +    print "\n";
   1.155 +
   1.156 +}
   1.157 +sub error
   1.158 +{
   1.159 +    msg ("ERROR:  " ,@_ );
   1.160 +}
   1.161 +
   1.162 +sub warning
   1.163 +{
   1.164 +    msg ("WARNING:" ,@_ );
   1.165 +}
   1.166 +sub debug
   1.167 +{
   1.168 +    if ( $verbose == 1 ) {
   1.169 +        msg ("DEBUG:  " ,@_ );
   1.170 +    } elsif ( $verbose == 2 ) {
   1.171 +        msg (@_ );
   1.172 +    }
   1.173 +}
   1.174 +
   1.175 +check_tbx_dirs;

mercurial