Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Libdb actor #1319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions repos/system_upgrade/el9toel10/actors/libdbcheck/actor.py
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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. <http://bugzilla.redhat.com/bugzilla>',
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
Loading