Skip to content

Commit

Permalink
Merge pull request #5643 from marmarek/sut-packages
Browse files Browse the repository at this point in the history
Compare SUT package versions in investigation, if available
  • Loading branch information
mergify[bot] authored May 19, 2024
2 parents 049c328 + 4d80c34 commit fcb740d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
31 changes: 31 additions & 0 deletions docs/WritingTests.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,37 @@ sub run () {
}
--------------------------------------------------------------

=== Logging package versions used for test

There are two sets of packages that can be included in test logs:
1. Packages installed on the worker itself - stored as `worker_packages.txt`.
2. Packages installed on SUT - stored as `sut_packages.txt`.

For both sets, if present, openQA will include the difference to the last good
job in the "Investigation" tab of a failed job.

To enable logging of worker package versions, set `PACKAGES_CMD` in
`workers.ini`. The command should print installed packages with their version
to stdout. For RPM-based systems it can be for example `rpm -qa`.

To enable logging of SUT package versions, make the test create the file
`sut_packages.txt` in the current worker directory. If `upload_logs()` is used,
the resulting file needs to be copied/moved.

[caption="Example: "]
.Logging SUT package versions
[source,perl]
--------------------------------------------------------------
use Mojo::File qw(path);
sub run {
...
assert_script_run("rpm -qa > sut_packages.txt");
my $fname = upload_logs("sut_packages.txt");
path("ulogs/$fname")->move_to("sut_packages.txt");
...
}
--------------------------------------------------------------

=== Assigning jobs to workers

By default, any worker can get any job with the matching architecture.
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenQA/Jobs/Constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ use constant {
use constant MODULE_RESULTS => (CANCELLED, FAILED, NONE, PASSED, RUNNING, SKIPPED, SOFTFAILED);

# common result files to be expected in all jobs
use constant COMMON_RESULT_LOG_FILES => qw(autoinst-log.txt worker-log.txt worker_packages.txt);
use constant COMMON_RESULT_LOG_FILES => qw(autoinst-log.txt worker-log.txt worker_packages.txt sut_packages.txt);
use constant COMMON_RESULT_FILES => COMMON_RESULT_LOG_FILES, qw(vars.json);

# result files handled by the cleanup of logs
Expand Down
13 changes: 7 additions & 6 deletions lib/OpenQA/Schema/Result/Jobs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,8 @@ sub investigate ($self, %args) {
eval { Mojo::File->new($_->result_dir(), 'vars.json')->slurp }
// undef
} ($prev, $self);
$inv{diff_packages_to_last_good} = $self->packages_diff($prev, $ignore) // 'Diff of packages not available';
$inv{diff_packages_to_last_good} = $self->packages_diff($prev, $ignore, 'worker_packages.txt');
$inv{diff_sut_packages_to_last_good} = $self->packages_diff($prev, $ignore, 'sut_packages.txt');
last unless $self_file && $prev_file;
# just ignore any problems on generating the diff with eval, e.g.
# files missing. This is a best-effort approach.
Expand Down Expand Up @@ -1927,11 +1928,11 @@ sub investigate ($self, %args) {
return \%inv;
}

sub packages_diff ($self, $prev, $ignore) {
my $current_file = path($self->result_dir, 'worker_packages.txt');
return unless -e $current_file;
my $prev_file = path($prev->result_dir, 'worker_packages.txt');
return unless -e $prev_file;
sub packages_diff ($self, $prev, $ignore, $filename, $fallback = 'Diff of packages not available') {
my $current_file = path($self->result_dir, $filename);
return $fallback unless -e $current_file;
my $prev_file = path($prev->result_dir, $filename);
return $fallback unless -e $prev_file;
my @files_packages = map { $_->slurp } ($prev_file, $current_file);
my $diff_packages = eval { diff(\$files_packages[0], \$files_packages[1], {CONTEXT => 0}) };
return join("\n", grep { !/(^@@|$ignore)/ } split(/\n/, $diff_packages));
Expand Down

0 comments on commit fcb740d

Please sign in to comment.