Skip to content

Commit 1d1c73f

Browse files
committed
el8to9: actors: mysql: Add MySQL actor with recommendations
Checks if `mysql-server` package is installed and if so provide recommendations for upgrade.
1 parent bfcf59e commit 1d1c73f

File tree

3 files changed

+146
-0
lines changed

3 files changed

+146
-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.mysqlcheck import report_installed_packages
3+
from leapp.models import DistributionSignedRPM, Report
4+
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
5+
6+
7+
class MySQLCheck(Actor):
8+
"""
9+
Actor checking for presence of MySQL installation.
10+
11+
Provides user with information related to upgrading systems
12+
with MySQL installed.
13+
"""
14+
name = 'mysql_check'
15+
consumes = (DistributionSignedRPM,)
16+
produces = (Report,)
17+
tags = (ChecksPhaseTag, IPUWorkflowTag)
18+
19+
def process(self):
20+
report_installed_packages()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 mysql-server report
7+
# TODO: Fix versions
8+
report_server_inst_summary = (
9+
'MySQL server component will be reinstalled during upgrade with RHEL 9 version. '
10+
'Since RHEL 9 includes the same version by default, no action should be '
11+
'needed and there shouldn\'t be any compatibility issues. It is still advisable '
12+
'to follow documentation/article on this topic for up to date recommendations. '
13+
'Keep in mind that MySQL version 8.0, which is present as a default in RHEL 9, '
14+
'will go out of the \'Extended Support\' in April 2026. MySQL 8.4 will be '
15+
'provided in RHEL 9 via module, and it is advisable to upgrade to that version. '
16+
'MySQL 8.4 is also the default version for RHEL 10, so having the MySQL 8.4 '
17+
'on RHEL 9 system will make the process of upgrading to RHEL 10 even smoother.'
18+
)
19+
20+
report_server_inst_hint = (
21+
'Dump or backup your data before proceeding with the upgrade '
22+
'and consult attached article '
23+
'\'Migrating MySQL databases from RHEL 8 to RHEL 9\' '
24+
'with up to date recommended steps before and after the upgrade.'
25+
)
26+
27+
# TODO: Replace with mysql-report
28+
# Link URL for mysql-server report
29+
report_server_inst_link_url = 'https://access.redhat.com/articles/7099753'
30+
31+
32+
def _report_server_installed():
33+
"""
34+
Create report on mysql-server package installation detection.
35+
36+
Should remind user about present MySQL server package
37+
installation, warn them about necessary additional steps, and
38+
redirect them to online documentation for the upgrade process.
39+
"""
40+
reporting.create_report([
41+
reporting.Title('Further action to upgrade MySQL might be needed'),
42+
reporting.Summary(report_server_inst_summary),
43+
reporting.Severity(reporting.Severity.MEDIUM),
44+
reporting.Groups([reporting.Groups.SERVICES]),
45+
reporting.ExternalLink(title='Migrating MySQL databases from RHEL 8 to RHEL 9',
46+
url=report_server_inst_link_url),
47+
reporting.RelatedResource('package', 'mysql-server'),
48+
reporting.Remediation(hint=report_server_inst_hint),
49+
])
50+
51+
52+
def report_installed_packages(_context=api):
53+
"""
54+
Create reports according to detected MySQL packages.
55+
56+
Create the report if the mysql-server rpm (RH signed) is installed.
57+
"""
58+
has_server = has_package(DistributionSignedRPM, 'mysql-server', context=_context)
59+
60+
if has_server:
61+
_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.mysqlcheck 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): mysql-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 mysql-server
51+
rpms += [_generate_rpm_with_name('mysql-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 mysql-server package installed
62+
assert reporting.create_report.called == 1
63+
else:
64+
# Assert for no mysql packages installed
65+
assert not reporting.create_report.called

0 commit comments

Comments
 (0)