diff --git a/repos/system_upgrade/el9toel10/actors/mysqlcheck/actor.py b/repos/system_upgrade/el9toel10/actors/mysqlcheck/actor.py new file mode 100644 index 0000000000..3920f2e107 --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/mysqlcheck/actor.py @@ -0,0 +1,20 @@ +from leapp.actors import Actor +from leapp.libraries.actor.mysqlcheck import report_installed_packages +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): + report_installed_packages() diff --git a/repos/system_upgrade/el9toel10/actors/mysqlcheck/libraries/mysqlcheck.py b/repos/system_upgrade/el9toel10/actors/mysqlcheck/libraries/mysqlcheck.py new file mode 100644 index 0000000000..f02771a5ac --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/mysqlcheck/libraries/mysqlcheck.py @@ -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 mysql-server report +report_server_inst_summary = ( + 'MySQL server component will be upgraded. Since RHEL-10 includes' + ' MySQL server 8.4 by default, which is incompatible with 8.0' + ' included in RHEL-9, it is necessary to proceed with additional steps' + ' for the complete upgrade of the MySQL data.' +) + +report_server_inst_hint = ( + 'Back up your data before proceeding with the upgrade' + ' and follow steps in the documentation section "Migrating to a RHEL 10 version of MySQL"' + ' after the upgrade.' +) + +# Link URL for mysql-server report +report_server_inst_link_url = 'https://access.redhat.com/articles/7099234' + + +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('MySQL (mysql-server) has been detected on your system'), + reporting.Summary(report_server_inst_summary), + reporting.Severity(reporting.Severity.MEDIUM), + reporting.Groups([reporting.Groups.SERVICES]), + reporting.ExternalLink(title='Migrating to a RHEL 10 version of MySQL', + url=report_server_inst_link_url), + reporting.RelatedResource('package', 'mysql-server'), + reporting.Remediation(hint=report_server_inst_hint), + ]) + + +def report_installed_packages(_context=api): + """ + 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', context=_context) + + if has_server: + _report_server_installed() diff --git a/repos/system_upgrade/el9toel10/actors/mysqlcheck/tests/test_mysqlcheck.py b/repos/system_upgrade/el9toel10/actors/mysqlcheck/tests/test_mysqlcheck.py new file mode 100644 index 0000000000..e1727067ea --- /dev/null +++ b/repos/system_upgrade/el9toel10/actors/mysqlcheck/tests/test_mysqlcheck.py @@ -0,0 +1,65 @@ +import pytest + +from leapp import reporting +from leapp.libraries.actor.mysqlcheck 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. ', + 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 + report_installed_packages(_context=api) + + 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