Skip to content

Commit f89c069

Browse files
committed
Add actor for mariadb migration RHEL9->RHEL10
Resolves: https://issues.redhat.com/browse/RHEL-62690
1 parent 4ad2739 commit f89c069

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from leapp.actors import Actor
2+
from leapp.libraries.actor.mariadbcheck import report_installed_packages
3+
from leapp.models import DistributionSignedRPM, Report
4+
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
5+
6+
7+
class MariadbCheck(Actor):
8+
"""
9+
Actor checking for presence of MariaDB installation.
10+
11+
Provides user with information related to upgrading systems
12+
with MariaDB installed.
13+
"""
14+
name = 'mariadb_check'
15+
consumes = (DistributionSignedRPM,)
16+
produces = (Report,)
17+
tags = (ChecksPhaseTag, IPUWorkflowTag)
18+
19+
def process(self):
20+
report_installed_packages()
Lines changed: 53 additions & 0 deletions
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 mariadb-server report
7+
report_server_inst_summary = (
8+
'MariaDB server component will be upgraded. Since RHEL-10 includes'
9+
' MariaDB server 10.11 by default, which is incompatible with 10.5'
10+
' included in RHEL-9, it is necessary to proceed with additional steps'
11+
' for the complete upgrade of the MariaDB data.'
12+
)
13+
14+
report_server_inst_hint = (
15+
'Back up your data before proceeding with the upgrade'
16+
' and follow steps in the documentation section "Migrating to a RHEL 10 version of MariaDB"'
17+
' after the upgrade.'
18+
)
19+
20+
# Link URL for mariadb-server report
21+
report_server_inst_link_url = 'https://access.redhat.com/articles/7097551'
22+
23+
24+
def _report_server_installed():
25+
"""
26+
Create report on mariadb-server package installation detection.
27+
28+
Should remind user about present MariaDB server package
29+
installation, warn them about necessary additional steps, and
30+
redirect them to online documentation for the upgrade process.
31+
"""
32+
reporting.create_report([
33+
reporting.Title('MariaDB (mariadb-server) has been detected on your system'),
34+
reporting.Summary(report_server_inst_summary),
35+
reporting.Severity(reporting.Severity.MEDIUM),
36+
reporting.Groups([reporting.Groups.SERVICES]),
37+
reporting.ExternalLink(title='Migrating to a RHEL 10 version of MariaDB',
38+
url=report_server_inst_link_url),
39+
reporting.RelatedResource('package', 'mariadb-server'),
40+
reporting.Remediation(hint=report_server_inst_hint),
41+
])
42+
43+
44+
def report_installed_packages(_context=api):
45+
"""
46+
Create reports according to detected MariaDB packages.
47+
48+
Create the report if the mariadb-server rpm (RH signed) is installed.
49+
"""
50+
has_server = has_package(DistributionSignedRPM, 'mariadb-server', context=_context)
51+
52+
if has_server:
53+
_report_server_installed()
Lines changed: 65 additions & 0 deletions
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.mariadbcheck 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_server', [
30+
(True), # with server
31+
(False), # without server
32+
])
33+
def test_actor_execution(monkeypatch, has_server):
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_server (bool): mariadb-server 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 mariadb-server
51+
rpms += [_generate_rpm_with_name('mariadb-server')]
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 fake RPMs
58+
report_installed_packages(_context=api)
59+
60+
if has_server:
61+
# Assert for mariadb-server package installed
62+
assert reporting.create_report.called == 1
63+
else:
64+
# Assert for no mariadb packages installed
65+
assert not reporting.create_report.called

0 commit comments

Comments
 (0)