-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
el9to10: actors: mysql: Split into scanner and checker actors
- Loading branch information
1 parent
9aebba4
commit 83e4219
Showing
11 changed files
with
264 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from leapp.actors import Actor | ||
from leapp.libraries.actor import scanmysql | ||
from leapp.models import DistributionSignedRPM, MySQLConfiguration | ||
from leapp.tags import FactsPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class ScanMySQL(Actor): | ||
""" | ||
Actor checking for presence of MySQL installation. | ||
Provides user with information related to upgrading systems | ||
with MySQL installed. | ||
""" | ||
name = 'scan_mysql' | ||
consumes = (DistributionSignedRPM,) | ||
produces = (MySQLConfiguration,) | ||
tags = (FactsPhaseTag, IPUWorkflowTag) | ||
|
||
def process(self) -> None: | ||
self.produce(scanmysql.check_status()) |
100 changes: 100 additions & 0 deletions
100
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/libraries/scanmysql.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from leapp.models import DistributionSignedRPM, MySQLConfiguration | ||
from leapp.libraries.common.rpms import has_package | ||
from leapp.libraries.stdlib import api | ||
|
||
import subprocess | ||
|
||
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html | ||
# https://dev.mysql.com/doc/refman/8.0/en/server-options.html | ||
# https://dev.mysql.com/doc/refman/8.4/en/mysql-nutshell.html | ||
REMOVED_ARGS = [ | ||
'--avoid-temporal-upgrade', | ||
'avoid_temporal_upgrade', | ||
'--show-old-temporals', | ||
'show_old_temporals', | ||
'--old', | ||
'--new', | ||
'--default-authentication-plugin', | ||
'default_authentication_plugin', | ||
'--no-dd-upgrade', | ||
'--language', | ||
'--ssl', | ||
'--admin-ssl', | ||
'--character-set-client-handshake', | ||
'--old-style-user-limits', | ||
] | ||
|
||
|
||
def _check_incompatible_config() -> set[str]: | ||
""" | ||
Get incompatible configuration options. Since MySQL can have basically | ||
unlimited number of config files that can link to one another, most | ||
convenient way is running `mysqld` command with `--validate-config | ||
--log-error-verbosity=2` arguments. Validate config only validates the | ||
config, without starting the MySQL server. Verbosity=2 is required to show | ||
deprecated options - which are removed after upgrade. | ||
Example output: | ||
2024-12-18T11:40:04.725073Z 0 [Warning] [MY-011069] [Server] | ||
The syntax '--old' is deprecated and will be removed in a future release. | ||
Returns: | ||
set[str]: Config options found that will be removed | ||
""" | ||
|
||
found_options = set() | ||
out = subprocess.run(['mysqld', '--validate-config', '--log-error-verbosity=2'], | ||
capture_output=True, | ||
check=False) | ||
|
||
stderr = out.stderr.decode("utf-8") | ||
if 'deprecated' in stderr: | ||
found_options = {arg for arg | ||
in REMOVED_ARGS | ||
if arg in stderr} | ||
return found_options | ||
|
||
|
||
def _check_incompatible_launch_param() -> set[str]: | ||
""" | ||
Get incompatible launch parameters from systemd service override file | ||
located at /etc/systemd/system/mysqld.service.d/override.conf | ||
Returns: | ||
set[str]: Launch parameters found that will be removed | ||
""" | ||
|
||
found_arguments = set() | ||
try: | ||
with open('/etc/systemd/system/mysqld.service.d/override.conf') as f: | ||
file_content = f.read() | ||
found_arguments = {arg for arg | ||
in REMOVED_ARGS | ||
if arg in file_content} | ||
except OSError: | ||
# File probably doesn't exist, ignore it and pass | ||
pass | ||
|
||
return found_arguments | ||
|
||
|
||
def check_status(_context=api) -> MySQLConfiguration: | ||
""" | ||
Check whether MySQL is installed and if so whether config is compatible with | ||
newer version. | ||
Returns: | ||
MySQLConfiguration: Current status of MySQL on the system | ||
""" | ||
|
||
mysql_present = has_package(DistributionSignedRPM, 'mysql-server', context=_context) | ||
|
||
found_options = None | ||
found_arguments = None | ||
if mysql_present: | ||
found_options = list(_check_incompatible_config()) | ||
found_arguments = list(_check_incompatible_launch_param()) | ||
|
||
return MySQLConfiguration(mysql_present=mysql_present, | ||
removed_options=found_options, | ||
removed_arguments=found_arguments) |
19 changes: 19 additions & 0 deletions
19
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/tests/config_invalid.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# This group are read by MySQL server. | ||
# Use it for options that only the server (but not clients) should see | ||
# | ||
# For advice on how to change settings please see | ||
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html | ||
|
||
# Settings user and group are ignored when systemd is used. | ||
# If you need to run mysqld under a different user or group, | ||
# customize your systemd unit file for mysqld according to the | ||
# instructions in http://fedoraproject.org/wiki/Systemd | ||
|
||
[mysqld] | ||
datadir=/var/lib/mysql | ||
socket=/var/lib/mysql/mysql.sock | ||
log-error=/var/log/mysql/mysqld.log | ||
pid-file=/run/mysqld/mysqld.pid | ||
old=true | ||
avoid_temporal_upgrade=true |
17 changes: 17 additions & 0 deletions
17
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/tests/config_valid.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# This group are read by MySQL server. | ||
# Use it for options that only the server (but not clients) should see | ||
# | ||
# For advice on how to change settings please see | ||
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html | ||
|
||
# Settings user and group are ignored when systemd is used. | ||
# If you need to run mysqld under a different user or group, | ||
# customize your systemd unit file for mysqld according to the | ||
# instructions in http://fedoraproject.org/wiki/Systemd | ||
|
||
[mysqld] | ||
datadir=/var/lib/mysql | ||
socket=/var/lib/mysql/mysql.sock | ||
log-error=/var/log/mysql/mysqld.log | ||
pid-file=/run/mysqld/mysqld.pid |
3 changes: 3 additions & 0 deletions
3
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/tests/service_invalid.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[Service] | ||
ExecStart= | ||
ExecStart=/usr/libexec/mysqld --language=/usr/local/mysql/share/mysql/english/ --basedir=/usr |
2 changes: 2 additions & 0 deletions
2
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/tests/sterr_invalid.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
2025-01-23T15:28:05.352420Z 0 [Warning] [MY-011069] [Server] The syntax '--old' is deprecated and will be removed in a future release. | ||
2025-01-23T15:28:05.352425Z 0 [Warning] [MY-011069] [Server] The syntax 'avoid_temporal_upgrade' is deprecated and will be removed in a future release. |
65 changes: 65 additions & 0 deletions
65
repos/system_upgrade/el9toel10/actors/mysql/scanmysql/tests/test_mysqlcheck.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. <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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from leapp.models import fields, Model | ||
from leapp.topics import SystemInfoTopic | ||
|
||
|
||
class MySQLConfiguration(Model): | ||
""" | ||
Model describing current state of MySQL server including configuration compatibility | ||
""" | ||
|
||
topic = SystemInfoTopic | ||
|
||
mysql_present = fields.Boolean(default=False) | ||
|
||
""" | ||
Configured options which are removed in RHEL 10 MySQL | ||
""" | ||
removed_options = fields.List(fields.String(), default=[]) | ||
removed_arguments = fields.List(fields.String(), default=[]) |