Skip to content

Commit 5a80c19

Browse files
committed
Add libdb actor to inform users about libdb removal from RHEL-10
Resolves: RHEL-35618
1 parent f89c069 commit 5a80c19

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from leapp.actors import Actor
2+
from leapp.libraries.actor.libdbcheck import report_installed_packages
3+
from leapp.models import DistributionSignedRPM, Report
4+
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
5+
6+
7+
class PostgresqlCheck(Actor):
8+
"""
9+
Actor checking for presence of libdb(Berkeley DB) installation.
10+
11+
Provides user with information related to upgrading systems
12+
with libdb installed.
13+
"""
14+
name = 'libdb_check'
15+
consumes = (DistributionSignedRPM,)
16+
produces = (Report,)
17+
tags = (ChecksPhaseTag, IPUWorkflowTag)
18+
19+
def process(self):
20+
report_installed_packages()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from leapp import reporting
2+
from leapp.libraries.common.rpms import has_package
3+
from leapp.libraries.stdlib import api
4+
from leapp.models import DistributionSignedRPM
5+
6+
# Summary for libdb report
7+
report_libdb_inst_summary = (
8+
'Libdb was marked as deprecated in RHEL-9 and in RHEL-10 is not included anymore.'
9+
' There are a couple of alternatives in RHEL-10; the applications that'
10+
' depend on libdb will not work. Such applications must implement another'
11+
' type of backend storage. And migrate existing data to the new database'
12+
' format; for the conversion, the tool db_converter from the libdb-utils'
13+
' rpm could be used.'
14+
)
15+
16+
report_libdb_inst_hint = (
17+
'Back up your data before proceeding with the data upgrade/migration.'
18+
)
19+
20+
# Link URL for libdb report
21+
report_libdb_inst_link_url = 'https://access.redhat.com/articles/7099256'
22+
23+
24+
def _report_libdb_installed():
25+
"""
26+
Create report on libdb package installation detection.
27+
28+
Should remind user about present libdb package
29+
installation, warn them about the lack of libdb support in RHEL 10, and
30+
redirect them to online documentation for the migration process.
31+
"""
32+
reporting.create_report([
33+
reporting.Title('Berkeley DB (libdb) has been detected on your system'),
34+
reporting.Summary(report_libdb_inst_summary),
35+
reporting.Severity(reporting.Severity.MEDIUM),
36+
reporting.Groups([reporting.Groups.SERVICES]),
37+
reporting.ExternalLink(title='Migrating to a RHEL 10 without libdb',
38+
url=report_libdb_inst_link_url),
39+
reporting.RelatedResource('package', 'libdb'),
40+
reporting.Remediation(hint=report_libdb_inst_hint),
41+
])
42+
43+
44+
def report_installed_packages(_context=api):
45+
"""
46+
Create reports according to detected libdb packages.
47+
48+
Create the report if the libdb rpm (RH signed) is installed.
49+
"""
50+
has_libdb = has_package(DistributionSignedRPM, 'libdb', context=_context)
51+
52+
if has_libdb:
53+
_report_libdb_installed()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
3+
from leapp import reporting
4+
from leapp.libraries.actor.libdbcheck import report_installed_packages
5+
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked
6+
from leapp.libraries.stdlib import api
7+
from leapp.models import DistributionSignedRPM, RPM
8+
9+
10+
def _generate_rpm_with_name(name):
11+
"""
12+
Generate new RPM model item with given name.
13+
14+
Parameters:
15+
name (str): rpm name
16+
17+
Returns:
18+
rpm (RPM): new RPM object with name parameter set
19+
"""
20+
return RPM(name=name,
21+
version='0.1',
22+
release='1.sm01',
23+
epoch='1',
24+
pgpsig='RSA/SHA256, Mon 01 Jan 1970 00:00:00 AM -03, Key ID 199e2f91fd431d51',
25+
packager='Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>',
26+
arch='noarch')
27+
28+
29+
@pytest.mark.parametrize('has_libdb', [
30+
(True), # with libdb
31+
(False), # without libdb
32+
])
33+
def test_actor_execution(monkeypatch, has_libdb):
34+
"""
35+
Parametrized helper function for test_actor_* functions.
36+
37+
First generate list of RPM models based on set arguments. Then, run
38+
the actor fed with our RPM list. Finally, assert Reports
39+
according to set arguments.
40+
41+
Parameters:
42+
has_libdb (bool): libdb installed
43+
"""
44+
45+
# Couple of random packages
46+
rpms = [_generate_rpm_with_name('sed'),
47+
_generate_rpm_with_name('htop')]
48+
49+
if has_server:
50+
# Add postgresql-server
51+
rpms += [_generate_rpm_with_name('libdb')]
52+
53+
curr_actor_mocked = CurrentActorMocked(msgs=[DistributionSignedRPM(items=rpms)])
54+
monkeypatch.setattr(api, 'current_actor', curr_actor_mocked)
55+
monkeypatch.setattr(reporting, "create_report", create_report_mocked())
56+
57+
# Executed actor fed with out fake RPMs
58+
report_installed_packages(_context=api)
59+
60+
if has_server:
61+
# Assert for postgresql-server package installed
62+
assert reporting.create_report.called == 1
63+
else:
64+
# Assert for no postgresql packages installed
65+
assert not reporting.create_report.called

0 commit comments

Comments
 (0)