From fe595d7b87211828e5a250a1943ed39f9569bd6c Mon Sep 17 00:00:00 2001 From: Jan Kolarik Date: Wed, 18 Dec 2024 12:12:16 +0000 Subject: [PATCH 1/2] automatic: Test errors reporting and emitting This is a follow-up to commit 12eba2f1d1e0b54914f609a69955889a9df4c244 and 6965c62a391380b1e5a3fd696e500538343d76aa adjusted for the dnf5 behavior. --- .../dnf/dnf-automatic/error-report.feature | 45 +++++++++++++++++++ .../dnf-ci-automatic-update/test-1.0-1.spec | 16 +++++++ .../dnf-ci-automatic-update/test-1.1-1.spec | 19 ++++++++ 3 files changed, 80 insertions(+) create mode 100644 dnf-behave-tests/dnf/dnf-automatic/error-report.feature create mode 100644 dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.0-1.spec create mode 100644 dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.1-1.spec diff --git a/dnf-behave-tests/dnf/dnf-automatic/error-report.feature b/dnf-behave-tests/dnf/dnf-automatic/error-report.feature new file mode 100644 index 000000000..2f038b963 --- /dev/null +++ b/dnf-behave-tests/dnf/dnf-automatic/error-report.feature @@ -0,0 +1,45 @@ +@dnf5 +Feature: dnf-automatic reports an error when transaction failed + + +Background: +Given I use repository "dnf-ci-automatic-update" + + +# First, install the "test-1.0" package, which should proceed successfully. +# Then, attempt to update to "test-1.1", which contains a broken scriptlet. +# An error should be reported during the installation of the update. +@bz2170093 +Scenario: dnf-automatic reports an error when package installation failed + Given I successfully execute dnf with args "install test-1.0" + When I execute dnf with args "automatic --installupdates" + Then the exit code is 1 + And RPMDB Transaction is empty + And stdout contains "Failed to install upgrades." + And stdout contains "Error in pre-install scriptlet" + And stdout contains "Transaction failed: Rpm transaction failed." + +# https://github.com/rpm-software-management/dnf/issues/1918 +# https://issues.redhat.com/browse/RHEL-61882 +Scenario: emitters report errors by default + Given I create and substitute file "/etc/dnf/automatic.conf" with + """ + [commands] + download_updates = yes + apply_updates = yes + + [emitters] + emit_via = command_email + + [command_email] + command_format = "echo {{body}} > {context.dnf.tempdir}/dnf_error" + """ + And I successfully execute dnf with args "install test-1.0" + And file "/{context.dnf.tempdir}/dnf_error" does not exist + When I execute dnf with args "automatic --installupdates" + Then the exit code is 1 + And RPMDB Transaction is empty + And file "/{context.dnf.tempdir}/dnf_error" contains lines + """ + Transaction failed: Rpm transaction failed. + """ diff --git a/dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.0-1.spec b/dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.0-1.spec new file mode 100644 index 000000000..2d9090b8e --- /dev/null +++ b/dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.0-1.spec @@ -0,0 +1,16 @@ +Name: test +Epoch: 0 +Version: 1.0 +Release: 1 + +License: Public Domain +URL: None + +Summary: The made up package for dnf-automatic updates testing. + +%description +Installs correctly. + +%files + +%changelog diff --git a/dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.1-1.spec b/dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.1-1.spec new file mode 100644 index 000000000..23f1d8b25 --- /dev/null +++ b/dnf-behave-tests/fixtures/specs/dnf-ci-automatic-update/test-1.1-1.spec @@ -0,0 +1,19 @@ +Name: test +Epoch: 0 +Version: 1.1 +Release: 1 + +License: Public Domain +URL: None + +Summary: The made up package for dnf-automatic updates testing. + +%description +Fails on pre scriptlet. + +%pre -p +error("failing on pre scriptlet", 1) + +%files + +%changelog From 0a7e8a60a80a4a681de8d5e6fb10e165b4bc6f32 Mon Sep 17 00:00:00 2001 From: Jan Kolarik Date: Wed, 18 Dec 2024 14:11:31 +0000 Subject: [PATCH 2/2] automatic: Tests for no updates functionality --- .../dnf/dnf-automatic/emit-no-updates.feature | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 dnf-behave-tests/dnf/dnf-automatic/emit-no-updates.feature diff --git a/dnf-behave-tests/dnf/dnf-automatic/emit-no-updates.feature b/dnf-behave-tests/dnf/dnf-automatic/emit-no-updates.feature new file mode 100644 index 000000000..9a8b270ea --- /dev/null +++ b/dnf-behave-tests/dnf/dnf-automatic/emit-no-updates.feature @@ -0,0 +1,21 @@ +@dnf5 +Feature: dnf-automatic does not emit when no updates are available + + +Scenario: dnf-automatic does not emit when no updates are available + When I execute dnf with args "automatic --installupdates" + Then the exit code is 0 + And Transaction is empty + And stdout is empty + + +Scenario: dnf-automatic emits message when no updates are available when emit_no_updates is on + Given I create file "/etc/dnf/automatic.conf" with + """ + [emitters] + emit_no_updates = yes + """ + When I execute dnf with args "automatic --installupdates" + Then the exit code is 0 + And Transaction is empty + And stdout contains "No new upgrades available."