Skip to content

Commit

Permalink
Merge pull request #20544 from pdostal/img_proof_logs
Browse files Browse the repository at this point in the history
PC: Parse img_proof logs into external results
  • Loading branch information
asmorodskyi authored Nov 4, 2024
2 parents 0907f05 + af76a3c commit b532ec0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/publiccloud/provider.pm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ sub parse_img_proof_output {
$ret->{fail} = $4;
$ret->{error} = $5;
}
$ret->{output} .= $line . "\n";
}

for my $k (qw(ip logfile results tests pass skip fail error)) {
Expand Down
52 changes: 50 additions & 2 deletions tests/publiccloud/img_proof.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Mojo::Base 'publiccloud::basetest';
use testapi;
use Mojo::File 'path';
use Path::Tiny;
use Mojo::JSON;
use publiccloud::utils qw(is_ondemand is_hardened);
use publiccloud::ssh_interactive 'select_host_console';
Expand All @@ -33,6 +33,49 @@ sub patch_json {
}
}

sub analyze_results {
my ($log, $output, $extra_test_results) = @_;
my @runs;

# parse the img-proof log by each test
my $runs_count = 0;
for my $line (split(/\n/, $log)) {
last if ($line =~ /systemd\-analyze/);
$runs_count = $runs_count + 1 if ($line =~ /session starts/);
$line =~ s/={5,}/=====/g;
$line =~ s/-{5,}/-----/g;
$runs[$runs_count]{log} .= $line . "\n";
if ($line =~ /([a-z_]+)\.py::([a-z_]+)\[paramiko:\/[0-9.]*-*([a-zA-Z-_]*)\] [a-zA-Z]+/) {
$runs[$runs_count]->{name} = $1;
$runs[$runs_count]->{test} .= $2 . "\n";
$runs[$runs_count]->{param} .= $3 . "\n";
}
}

# parse the output from img-proof by each test
$runs_count = 0;
for my $line (split(/\n/, $output)) {
last if ($line =~ /Collecting basic info about VM/);
next if ($line =~ /Testing soft reboot|Testing hard reboot|Testing refresh/);
$runs_count = $runs_count + 1 if ($line =~ /Running test/);
$runs[$runs_count]{output} .= $line . "\n";
}

# Alter the extra_test_results log files with output and log from img-proof
for my $t (@{$extra_test_results}) {
my $filename = 'result-' . $t->{name} . '.json';
my $file = path(bmwqemu::result_dir(), $filename);
my $json = Mojo::JSON::decode_json($file->slurp);
my $logfile = path(bmwqemu::result_dir(), $json->{details}[0]->{text});
for my $run (@runs) {
if ($run->{name} ne '' && index($t->{name}, $run->{name}) != -1) {
$logfile->append("\n\nimg-proof output:\n" . $run->{output});
$logfile->append("\n\nimg-proof log:\n" . $run->{log});
}
}
}
}

sub run {
my ($self, $args) = @_;

Expand Down Expand Up @@ -89,12 +132,17 @@ sub run {
}

upload_logs($img_proof->{logfile}, log_name => basename($img_proof->{logfile}) . ".txt");

parse_extra_log(IPA => $img_proof->{results});
assert_script_run('rm -rf img_proof_results');

$instance->ssh_script_run(cmd => 'sudo chmod a+r /var/tmp/report.html || true', no_quote => 1);
$instance->upload_log('/var/tmp/report.html', failok => 1);

my $log = script_output('cat ' . $img_proof->{logfile});
eval { analyze_results($log, $img_proof->{output}, $self->{extra_test_results}) };

assert_script_run('rm -rf img_proof_results');

# fail, if at least one test failed
if ($img_proof->{fail} > 0) {

Expand Down

0 comments on commit b532ec0

Please sign in to comment.