From 08c89b7dbc6c5663b182bfd0dc932f01483d9da8 Mon Sep 17 00:00:00 2001 From: Filip Date: Wed, 4 Dec 2024 02:58:00 +0100 Subject: [PATCH] Add libdb actor to inform users about libdb removal from RHEL-10 Resolves: RHEL-35618 --- .../el9toel10/actors/libdbcheck/actor.py | 20 ++++++ .../actors/libdbcheck/libraries/libdbcheck.py | 53 +++++++++++++++ .../libdbcheck/tests/test_libdbcheck.py | 65 +++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 repos/system_upgrade/el9toel10/actors/libdbcheck/actor.py create mode 100644 repos/system_upgrade/el9toel10/actors/libdbcheck/libraries/libdbcheck.py create mode 100644 repos/system_upgrade/el9toel10/actors/libdbcheck/tests/test_libdbcheck.py diff --git a/repos/system_upgrade/el9toel10/actors/libdbcheck/actor.py b/repos/system_upgrade/el9toel10/actors/libdbcheck/actor.py new file mode 100644 index 0000000000..646707f3e3 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/libdbcheck/actor.py @@ -0,0 +1,20 @@ +from leapp.actors import Actor +from leapp.libraries.actor.libdbcheck import report_installed_packages +from leapp.models import DistributionSignedRPM, Report +from leapp.tags import ChecksPhaseTag, IPUWorkflowTag + + +class PostgresqlCheck(Actor): + """ + Actor checking for presence of libdb(Berkeley DB) installation. + + Provides user with information related to upgrading systems + with libdb installed. + """ + name = 'libdb_check' + consumes = (DistributionSignedRPM,) + produces = (Report,) + tags = (ChecksPhaseTag, IPUWorkflowTag) + + def process(self): + report_installed_packages() diff --git a/repos/system_upgrade/el9toel10/actors/libdbcheck/libraries/libdbcheck.py b/repos/system_upgrade/el9toel10/actors/libdbcheck/libraries/libdbcheck.py new file mode 100644 index 0000000000..598e4fd11b --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/libdbcheck/libraries/libdbcheck.py @@ -0,0 +1,53 @@ +from leapp import reporting +from leapp.libraries.common.rpms import has_package +from leapp.libraries.stdlib import api +from leapp.models import DistributionSignedRPM + +# Summary for libdb report +report_libdb_inst_summary = ( + 'Libdb was marked as deprecated in RHEL-9 and in RHEL-10 is not included anymore.' + ' There are a couple of alternatives in RHEL-10; the applications that' + ' depend on libdb will not work. Such applications must implement another' + ' type of backend storage. And migrate existing data to the new database' + ' format; for the conversion, the tool db_converter from the libdb-utils' + ' rpm could be used.' +) + +report_libdb_inst_hint = ( + 'Back up your data before proceeding with the data upgrade/migration.' +) + +# Link URL for libdb report +report_libdb_inst_link_url = 'https://access.redhat.com/articles/7099256' + + +def _report_libdb_installed(): + """ + Create report on libdb package installation detection. + + Should remind user about present libdb package + installation, warn them about the lack of libdb support in RHEL 10, and + redirect them to online documentation for the migration process. + """ + reporting.create_report([ + reporting.Title('Berkeley DB (libdb) has been detected on your system'), + reporting.Summary(report_libdb_inst_summary), + reporting.Severity(reporting.Severity.MEDIUM), + reporting.Groups([reporting.Groups.SERVICES]), + reporting.ExternalLink(title='Migrating to a RHEL 10 without libdb', + url=report_libdb_inst_link_url), + reporting.RelatedResource('package', 'libdb'), + reporting.Remediation(hint=report_libdb_inst_hint), + ]) + + +def report_installed_packages(_context=api): + """ + Create reports according to detected libdb packages. + + Create the report if the libdb rpm (RH signed) is installed. + """ + has_libdb = has_package(DistributionSignedRPM, 'libdb', context=_context) + + if has_libdb: + _report_libdb_installed() diff --git a/repos/system_upgrade/el9toel10/actors/libdbcheck/tests/test_libdbcheck.py b/repos/system_upgrade/el9toel10/actors/libdbcheck/tests/test_libdbcheck.py new file mode 100644 index 0000000000..3e7cfcc6f0 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/libdbcheck/tests/test_libdbcheck.py @@ -0,0 +1,65 @@ +import pytest + +from leapp import reporting +from leapp.libraries.actor.libdbcheck import report_installed_packages +from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked +from leapp.libraries.stdlib import api +from leapp.models import DistributionSignedRPM, RPM + + +def _generate_rpm_with_name(name): + """ + Generate new RPM model item with given name. + + Parameters: + name (str): rpm name + + Returns: + rpm (RPM): new RPM object with name parameter set + """ + return RPM(name=name, + version='0.1', + release='1.sm01', + epoch='1', + pgpsig='RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51', + packager='Red Hat, Inc. ', + arch='noarch') + + +@pytest.mark.parametrize('has_libdb', [ + (True), # with libdb + (False), # without libdb +]) +def test_actor_execution(monkeypatch, has_libdb): + """ + Parametrized helper function for test_actor_* functions. + + First generate list of RPM models based on set arguments. Then, run + the actor fed with our RPM list. Finally, assert Reports + according to set arguments. + + Parameters: + has_libdb (bool): libdb installed + """ + + # Couple of random packages + rpms = [_generate_rpm_with_name('sed'), + _generate_rpm_with_name('htop')] + + if has_libdb: + # Add libdb + rpms += [_generate_rpm_with_name('libdb')] + + curr_actor_mocked = CurrentActorMocked(msgs=[DistributionSignedRPM(items=rpms)]) + monkeypatch.setattr(api, 'current_actor', curr_actor_mocked) + monkeypatch.setattr(reporting, "create_report", create_report_mocked()) + + # Executed actor fed with out fake RPMs + report_installed_packages(_context=api) + + if has_libdb: + # Assert for libdb package installed + assert reporting.create_report.called == 1 + else: + # Assert for no libdb packages installed + assert not reporting.create_report.called