]> xenbits.xensource.com Git - osstest.git/commitdiff
history reporting (nfc): Refactor to generalise, cache_read_existing
authorIan Jackson <ian.jackson@eu.citrix.com>
Wed, 5 Aug 2020 12:23:41 +0000 (13:23 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Wed, 19 Aug 2020 10:41:18 +0000 (11:41 +0100)
* Introduce @cache_row_key_cols and cache_row_key
* Handle $html_file pathname construction and $read_existing
  at the call site.
* Rename cache_read_existing.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
sg-report-host-history

index 4c0022e82e4f7576496cb873a6036c7c3d06f273..83344a40a436fee619461371059b337e1d020302 100755 (executable)
@@ -77,11 +77,15 @@ our $flightcond;
 our $minflight;
 
 our %cache;
+our @cache_row_key_cols = qw(flight job status name);
 
-sub read_existing_logs ($) {
-    my ($hostname) = @_;
-    return unless $read_existing;
-    my $html_file = "$htmlout/$hostname.html";
+sub cache_row_key ($) {
+    my ($jr) = @_;
+    return join $; , map { $jr->{$_} } @cache_row_key_cols;
+}
+
+sub cache_read_existing ($) {
+    my ($html_file) = @_;
     if (!open H, $html_file) {
         return if $!==ENOENT;
         die "failed to open $html_file: $!";
@@ -103,7 +107,7 @@ sub read_existing_logs ($) {
            s{\%([0-9a-f]{2})}{ chr hex $1 }ge;
            $ch->{$k} = $_;
        }
-       $cache{$jr->{flight},$jr->{job},$jr->{status},$jr->{name}} = $jr;
+       $cache{cache_row_key($jr)} = $jr;
     }
     close H;
 }
@@ -261,8 +265,7 @@ END
     foreach my $jr (@$inrows) {
        #print DEBUG "JOB $jr->{flight}.$jr->{job} ";
 
-       my $cacherow =
-           $cache{$jr->{flight},$jr->{job},$jr->{status},$jr->{name}};
+       my $cacherow = $cache{cache_row_key($jr)};
        if ($cacherow) {
            $jr = $cacherow;
            $cachehits++;
@@ -492,7 +495,7 @@ foreach my $host (sort keys %hosts) {
     my $pid = fork // die $!;
     if (!$pid) {
        opendb_tests();
-       read_existing_logs($host);
+       cache_read_existing("$htmlout/$host.html") if $read_existing;
        db_retry($dbh_tests, [], sub {
             mainquery($host);
            reporthost $host;