From: Ian Jackson Subject: [OSSTEST PATCH 00/25] Reporting improvements Date: Wed, 17 Jun 2015 17:44:56 +0100 Message-ID: <1434559521-8751-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z5GT1-0004G5-G6 for xen-devel@lists.xenproject.org; Wed, 17 Jun 2015 16:45:35 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Campbell List-Id: xen-devel@lists.xenproject.org Most of the early part of this series is straightforward (and acked) and could go in whenever. Patches 15-24 introduce sg-report-host-history. It's probably easiest to simply review the final version of the script, which can be found below. The history is preserved mostly for archeological purposes. Ian. #!/usr/bin/perl -w # This is part of "osstest", an automated testing framework for Xen. # Copyright (C) 2009-2013 Citrix Inc. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . use strict qw(vars); use DBI; use Osstest; use IO::Handle; use HTML::Entities; use POSIX; use Osstest::Executive qw(:DEFAULT :colours); our $limit= 200; our $flightlimit; our $htmlout = "."; our @blessings; open DEBUG, ">/dev/null"; my $namecond= "(name = 'host' or name like '%_host')"; csreadconfig(); while (@ARGV && $ARGV[0] =~ m/^-/) { $_= shift @ARGV; last if m/^--?$/; if (m/^--(limit)\=([1-9]\d*)$/) { $$1= $2; } elsif (m/^--flight-limit\=([1-9]\d*)$/) { $flightlimit= $1; } elsif (m/^--blessings?=(.*)$/) { push @blessings, split ',', $1; } elsif (m/^--html-dir=(.*)$/) { $htmlout= $1; } elsif (m/^--debug/) { open DEBUG, ">&2" or die $!; DEBUG->autoflush(1); } else { die "$_ ?"; } } @blessings= qw(real) if !@blessings; @ARGV or die $!; our $flightcond; sub computeflightsrange () { if (!$flightlimit) { my $flagscond = '('.join(' OR ', map { "f.hostflag = 'blessed-$_'" } @blessings).')'; my $nhostsq = db_prepare(<execute(); my ($nhosts) = $nhostsq->fetchrow_array(); print DEBUG "COUNTED $nhosts hosts\n"; $flightlimit = $nhosts * $limit * 2; } my $minflightsq = db_prepare(<execute(); my ($minflight) = $minflightsq->fetchrow_array(); $minflight //= 0; $flightcond = "(flight > $minflight)"; } sub jobquery ($$) { my ($q, $jr) = @_; $q->execute($jr->{flight}, $jr->{job}); return $q->fetchrow_hashref(); } our %hosts; sub mainquery () { our $valcond = join " OR ", map { "val = ?" } keys %hosts; our @params = keys %hosts; our $runvarq //= db_prepare(<execute(@params); print DEBUG "FIRST PASS\n"; while (my $jr= $runvarq->fetchrow_hashref()) { print DEBUG "JOB $jr->{flight}.$jr->{job} "; push @{ $hosts{$jr->{val}} }, $jr; } } sub reporthost ($) { my ($hostname) = @_; die if $hostname =~ m/[^-_.+0-9a-z]/; my $html_file= "$htmlout/$hostname.html"; open H, "> $html_file.new" or die "$html_file $!"; my $title= "host history $hostname\n"; $title= encode_entities($title); print H "$title\n"; print H "

$title

\n"; print H "\n"; print H "\n"; print H "\n"; print H "\n"; print H "\n"; print H "\n"; print H "\n"; print H "\n"; our $endedq //= db_prepare(<{flight}.$jr->{job}\n"; my $endedrow = jobquery($endedq, $jr); if (!$endedrow) { print DEBUG "no-finished\n"; next; } print DEBUG join " ", map { $endedrow->{$_} } sort keys %$endedrow; print DEBUG ".\n"; push @rows, { %$jr, %$endedrow }; } @rows = sort { $b->{finished} <=> $a->{finished} } @rows; $#rows = $limit-1 if @rows > $limit; my $alternate = 0; foreach my $jr (@rows) { my $ir = jobquery($infoq, $jr); my $ar = jobquery($allocdq, $jr); my $altcolour = report_altcolour($alternate); print H ""; if (!defined $ar->{testid}) { print H ""; print H ""; } else { if ($ar->{status} eq 'pass') { print H ""; print H ""; } elsif ($ar->{status} eq 'running') { print H ""; print H ""; } else { print H ""; print H ""; } } print H "\n"; print H "\n"; print H "\n"; my $url= "$c{ReportHtmlPubBaseUrl}/$jr->{flight}"; print H "\n"; $url= "$c{ReportHtmlPubBaseUrl}/$jr->{flight}/". encode_entities($jr->{job})."/"; print H ""; print H ""; print H ""; print H "\n"; my $ri = report_run_getinfo({ %$jr, %$ir }); print H "\n"; print H "\n\n"; $alternate ^= 1; } print H "
alloc testidalloc completedjob finishedroleflightbranchintendedblessingjobfailure
?$ar->{testid}", (show_abs_time $ar->{finished}), "$ar->{testid}(incomplete)$ar->{testid}$ar->{status}", (show_abs_time $jr->{finished}), "", $jr->{name}, "$jr->{flight}$ir->{branch}$ir->{intended}"; print H $ir->{blessing} unless $ir->{blessing} eq 'running'; print H "$jr->{job}{Colour}\">$ri->{Summary}
\n"; close H or die $!; rename "$html_file.new", "$html_file" or die "$html_file $!"; } db_retry($dbh_tests, [qw(flights resources)], sub { computeflightsrange(); }); $dbh_tests->do("SET LOCAL enable_seqscan=false"); # Otherwise the PostgreSQL query planner likes to do a complete scan # of the runvars table, rather than walking backwards through the # flights until it has what we've told it is enough. foreach my $host (@ARGV) { if ($host =~ m/^flight:/) { my $flight=$'; #'; db_retry($dbh_tests, [qw(flights)], sub { our $hostsinflightq //= db_prepare(<execute($flight); while (my $row = $hostsinflightq->fetchrow_hashref()) { $hosts{$row->{val}} = [ ]; } }); } elsif ($host !~ m/:/) { $hosts{$host} = [ ]; } else { die "$host ?"; } } exit 0 unless %hosts; db_retry($dbh_tests, [qw(flights)], sub { mainquery(); }); foreach my $host (sort keys %hosts) { db_retry($dbh_tests, [qw(flights)], sub { reporthost $host; }); }