leapp-repository/SOURCES/0057-el8to9-actors-mysql-Add-MySQL-actor-with-recommendat.patch
2025-07-21 11:47:55 +00:00

177 lines
6.7 KiB
Diff

From 7c5d7f711d92fffac5567fd4b31bd6df4d24f1f9 Mon Sep 17 00:00:00 2001
From: Ales Nezbeda <anezbeda@redhat.com>
Date: Wed, 16 Jul 2025 11:58:47 +0200
Subject: [PATCH 57/66] el8to9: actors: mysql: Add MySQL actor with
recommendations (#1335)
Introduce a new mysql_check actor which checks for presence of the
mysql_server package and reports related recommendations for upgrade.
Jira: RHEL-5459
---
.../el8toel9/actors/mysqlcheck/actor.py | 20 ++++++
.../actors/mysqlcheck/libraries/mysqlcheck.py | 51 +++++++++++++++
.../mysqlcheck/tests/test_mysqlcheck.py | 65 +++++++++++++++++++
3 files changed, 136 insertions(+)
create mode 100644 repos/system_upgrade/el8toel9/actors/mysqlcheck/actor.py
create mode 100644 repos/system_upgrade/el8toel9/actors/mysqlcheck/libraries/mysqlcheck.py
create mode 100644 repos/system_upgrade/el8toel9/actors/mysqlcheck/tests/test_mysqlcheck.py
diff --git a/repos/system_upgrade/el8toel9/actors/mysqlcheck/actor.py b/repos/system_upgrade/el8toel9/actors/mysqlcheck/actor.py
new file mode 100644
index 00000000..d675d75c
--- /dev/null
+++ b/repos/system_upgrade/el8toel9/actors/mysqlcheck/actor.py
@@ -0,0 +1,20 @@
+from leapp.actors import Actor
+from leapp.libraries.actor.mysqlcheck import process
+from leapp.models import DistributionSignedRPM, Report
+from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
+
+
+class MySQLCheck(Actor):
+ """
+ Actor checking for presence of MySQL installation.
+
+ Provides user with information related to upgrading systems
+ with MySQL installed.
+ """
+ name = 'mysql_check'
+ consumes = (DistributionSignedRPM,)
+ produces = (Report,)
+ tags = (ChecksPhaseTag, IPUWorkflowTag)
+
+ def process(self):
+ process()
diff --git a/repos/system_upgrade/el8toel9/actors/mysqlcheck/libraries/mysqlcheck.py b/repos/system_upgrade/el8toel9/actors/mysqlcheck/libraries/mysqlcheck.py
new file mode 100644
index 00000000..b446d9c4
--- /dev/null
+++ b/repos/system_upgrade/el8toel9/actors/mysqlcheck/libraries/mysqlcheck.py
@@ -0,0 +1,51 @@
+from leapp import reporting
+from leapp.libraries.common.rpms import has_package
+from leapp.models import DistributionSignedRPM
+
+
+def _report_server_installed():
+ """
+ Create report on mysql-server package installation detection.
+
+ Should remind user about present MySQL server package
+ installation, warn them about necessary additional steps, and
+ redirect them to online documentation for the upgrade process.
+ """
+ reporting.create_report([
+ reporting.Title('Further action to upgrade MySQL might be needed'),
+ reporting.Summary(
+ 'The MySQL server component will be reinstalled during the upgrade with a RHEL 9'
+ ' version. Since RHEL 9 includes the same MySQL version 8.0 by default, no action'
+ ' should be required and there should not be any compatibility issues. However,'
+ ' it is still advisable to follow the documentation on this topic for up to date'
+ ' recommendations.'
+ ' Keep in mind that MySQL 8.0, which is the default in RHEL 9, will reach the end'
+ ' of \'Extended Support\' in April 2026. As such it is advisable to upgrade to'
+ ' MySQL version 8.4, which is provided via a module. MySQL 8.4 is also the'
+ ' default version for RHEL 10, therefore having MySQL 8.4 on the RHEL 9 system'
+ ' will make a future upgrade process to RHEL 10 smoother.'
+ ),
+ reporting.Severity(reporting.Severity.MEDIUM),
+ reporting.Groups([reporting.Groups.SERVICES]),
+ reporting.ExternalLink(title='Migrating MySQL databases from RHEL 8 to RHEL 9',
+ url='https://access.redhat.com/articles/7099753'),
+ reporting.RelatedResource('package', 'mysql-server'),
+ reporting.Remediation(hint=(
+ 'Dump or backup your data before proceeding with the upgrade '
+ 'and consult attached article '
+ '\'Migrating MySQL databases from RHEL 8 to RHEL 9\' '
+ 'with up to date recommended steps before and after the upgrade.'
+ )),
+ ])
+
+
+def process():
+ """
+ Create reports according to detected MySQL packages.
+
+ Create the report if the mysql-server rpm (RH signed) is installed.
+ """
+ has_server = has_package(DistributionSignedRPM, 'mysql-server')
+
+ if has_server:
+ _report_server_installed()
diff --git a/repos/system_upgrade/el8toel9/actors/mysqlcheck/tests/test_mysqlcheck.py b/repos/system_upgrade/el8toel9/actors/mysqlcheck/tests/test_mysqlcheck.py
new file mode 100644
index 00000000..385f4dfd
--- /dev/null
+++ b/repos/system_upgrade/el8toel9/actors/mysqlcheck/tests/test_mysqlcheck.py
@@ -0,0 +1,65 @@
+import pytest
+
+from leapp import reporting
+from leapp.libraries.actor.mysqlcheck import process
+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_server', [
+ (True), # with server
+ (False), # without server
+])
+def test_actor_execution(monkeypatch, has_server):
+ """
+ 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_server (bool): mysql-server installed
+ """
+
+ # Couple of random packages
+ rpms = [_generate_rpm_with_name('sed'),
+ _generate_rpm_with_name('htop')]
+
+ if has_server:
+ # Add mysql-server
+ rpms += [_generate_rpm_with_name('mysql-server')]
+
+ 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 fake RPMs
+ process()
+
+ if has_server:
+ # Assert for mysql-server package installed
+ assert reporting.create_report.called == 1
+ else:
+ # Assert for no mysql packages installed
+ assert not reporting.create_report.called
--
2.50.1