use base "installedtest"; use strict; use testapi; use utils; use dnf; # This script will make sure that DNF5 is able to # record the history of transactions and that it # can perform various activities based on that. # https://fedoraproject.org/wiki/QA:Testcase_DNF_history sub run { my $self = shift; # Install one package assert_script_run("dnf5 install -y mc"); # Check that the transaction appears in DNF history. my $output = script_output("dnf5 history list"); my $history = parse_list_output($output); my $last = latest_item($history); # Read the last transaction my $transaction = $history->{$last}; # Read transaction information my $command = $transaction->[1]; my $package = $transaction->[2]; # Check for errors. my $errors = []; if ($command ne "install") { push(@$errors, "command should be install but is $command."); } if ($package ne "mc") { push(@$errors, "package should be mc but is $package."); } # Check if errors were recorded. my $ecount = scalar @$errors; if ($ecount > 0) { diag("DNF5 history list errors:"); foreach (@$errors) { diag($_); } die("The last transaction in the history differs from what we expected."); } # Check that info can be listed about the last transaction. $errors = []; $output = script_output("dnf5 history info $last"); my $info = parse_history_info($output); if ($info->{User} != 0) { push(@$errors, "user"); } if ($info->{Status} ne "Ok") { push(@$errors, "status"); } if ($info->{Description} ne "dnf5 install -y mc") { push(@$errors, "description"); } if ($info->{"Transaction ID"} ne $last) { push(@$errors, "id"); } $ecount = scalar @$errors; if ($ecount > 0) { diag("DNF5 history info errors:"); foreach (@$errors) { diag($_); } die("The last transaction info differs from what we expected"); } # Check that the transaction can be undone and redone. $errors = []; # FIXME WARNING: # The subcommands redo, undo, rollback, etc. are not implemented # yet, so we cannot use them. However, we will try to use them # anyway and let the test softfail if they cannot be used. # Once it stops softfailing, we'll know that they have been # implemented and we'll start checking more strictly. # # See, if subcommands work. my @subcommands = qw(undo redo rollback); foreach (@subcommands) { my $result = script_run("dnf5 history $_ -y $last"); # Error code 2 means that the command is not supported # yet and that usage info was returned instead. if ($result == 2) { diag("DNF5 history: $_ is probably not implemented yet."); push(@$errors, $_); } } # See, if we have errors and softfail if we do. $ecount = scalar @$errors; if ($ecount > 0) { record_soft_failure("The DNF5 subcommands could not be run properly. Check the logs for more info."); } } sub test_flags { return {always_rollback => 1}; } 1; # vim: set sw=4 et: