From: Ian Jackson Subject: [OSSTEST PATCH 12/12] RFC: sg-report-job-history Date: Mon, 15 Jun 2015 18:13:13 +0100 Message-ID: <1434388394-26099-13-git-send-email-ian.jackson@eu.citrix.com> References: <1434388394-26099-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.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z4YPK-0000S7-Nh for xen-devel@lists.xenproject.org; Mon, 15 Jun 2015 17:42:50 +0000 In-Reply-To: <1434388394-26099-1-git-send-email-ian.jackson@eu.citrix.com> 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 Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org This script is still a work in progress. Things which I know are still needed: * --flight= option to make it automatically report host usage for a flight * handle db deadlock report (by putting whole script in a db retry) * hook this into the automatic reporting in cr-* Signed-off-by: Ian Jackson --- sg-report-host-history | 243 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100755 sg-report-host-history diff --git a/sg-report-host-history b/sg-report-host-history new file mode 100755 index 0000000..7aacb42 --- /dev/null +++ b/sg-report-host-history @@ -0,0 +1,243 @@ +#!/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 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 $!; + +$dbh_tests->begin_work; + +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; + +our $flightcond = "(flight > $minflight)"; + +$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. + +my $runvarq = db_prepare(<execute($jr->{flight}, $jr->{job}); + return $q->fetchrow_hashref(); +} + +sub reporthost ($) { + my ($hostname) = @_; + + die if $hostname =~ m/[^-_.+0-9a-z]/; + + my $html_file= "$htmlout/host.$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"; + + my @rows; + $runvarq->execute($hostname); + + print DEBUG "FIRST PASS\n"; + while (my $jr= $runvarq->fetchrow_hashref()) { + print DEBUG "JOB $jr->{flight}.$jr->{job} "; + + my $endedrow = jobquery($endedq, $jr); + if (!$endedrow) { + print "no-finished\n"; + next; + } + print DEBUG join " ", map { $endedrow->{$_} } sort keys %$endedrow; + print DEBUG ".\n"; + + push @rows, { %$jr, %$endedrow }; + } + + print DEBUG "FOUND ", (scalar @rows), " ROWS\n"; + + @rows = sort { $b->{finished} <=> $a->{finished} } @rows; + $#rows = $limit-1 if @rows > $limit; + + my $alternate = 0; + foreach my $jr (@rows) { + print DEBUG "JOB $jr->{flight}.$jr->{job}\n"; + + 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}$ar->{status}$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"; +} + +reporthost $_ foreach @ARGV; -- 1.7.10.4