Skip to content

Commit 9aebba4

Browse files
committed
el9to10: actors: mysql: Deobjectify the actor, tweak messages
Add few more entries to `REMOVED_ARGS` list, as some have multiple ways of being logged in mysqld.
1 parent dbfb54f commit 9aebba4

File tree

2 files changed

+197
-174
lines changed

2 files changed

+197
-174
lines changed

repos/system_upgrade/el9toel10/actors/mysqlcheck/actor.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from leapp.actors import Actor
2-
from leapp.libraries.actor.mysqlcheck import MySQLCheckLib
2+
from leapp.libraries.actor.mysqlcheck import report_installed_packages
33
from leapp.models import DistributionSignedRPM, Report
44
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
55

@@ -17,5 +17,4 @@ class MySQLCheck(Actor):
1717
tags = (ChecksPhaseTag, IPUWorkflowTag)
1818

1919
def process(self):
20-
lib = MySQLCheckLib()
21-
lib.report_installed_packages()
20+
report_installed_packages()

repos/system_upgrade/el9toel10/actors/mysqlcheck/libraries/mysqlcheck.py

Lines changed: 195 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -7,182 +7,206 @@
77

88
FMT_LIST_SEPARATOR = '\n - '
99

10+
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html
11+
# https://dev.mysql.com/doc/refman/8.0/en/server-options.html
12+
# https://dev.mysql.com/doc/refman/8.4/en/mysql-nutshell.html
13+
REMOVED_ARGS = [
14+
'--avoid-temporal-upgrade',
15+
'avoid_temporal_upgrade',
16+
'--show-old-temporals',
17+
'show_old_temporals',
18+
'--old',
19+
'--new',
20+
'--default-authentication-plugin',
21+
'default_authentication_plugin',
22+
'--no-dd-upgrade',
23+
'--language',
24+
'--ssl',
25+
'--admin-ssl',
26+
'--character-set-client-handshake',
27+
'--old-style-user-limits',
28+
]
29+
30+
# Link URL for mysql-server report
31+
report_server_inst_link_url = 'https://access.redhat.com/articles/7099234'
32+
33+
34+
def _generate_mysql_present_report():
35+
"""
36+
Create report on mysql-server package installation detection.
37+
38+
Should remind user about present MySQL server package
39+
installation, warn them about necessary additional steps, and
40+
redirect them to online documentation for the upgrade process.
41+
42+
This report is used in case MySQL package is detected, but no
43+
immediate action is needed.
44+
"""
45+
reporting.create_report([
46+
reporting.Title('Further action to upgrade MySQL might be needed'),
47+
reporting.Summary((
48+
'MySQL server component will be upgraded. '
49+
'Since RHEL-10 includes MySQL server 8.4 by default, '
50+
'it might be necessary to proceed with additional steps after '
51+
'RHEL upgrade is completed. In simple setups MySQL server should '
52+
'automatically upgrade all data on first start, but in more '
53+
'complicated setups manual intervention might be needed.'
54+
)),
55+
reporting.Severity(reporting.Severity.MEDIUM),
56+
reporting.Groups([reporting.Groups.SERVICES]),
57+
reporting.ExternalLink(title='Migrating MySQL databases from RHEL 9 to RHEL 10',
58+
url=report_server_inst_link_url),
59+
reporting.RelatedResource('package', 'mysql-server'),
60+
reporting.Remediation(hint=(
61+
'Dump or backup your data before proceeding with the upgrade '
62+
'and consult attached article '
63+
'\'Migrating MySQL databases from RHEL 9 to RHEL 10\' '
64+
'with up to date recommended steps before and after the upgrade.'
65+
)),
66+
])
67+
68+
69+
def _generate_deprecated_config_report(found_options, found_arguments):
70+
"""
71+
Create report on mysql-server deprecated configuration.
72+
73+
Apart from showing user the article for upgrade process, we inform the
74+
user that there are deprecated configuration options being used and
75+
proceeding with upgrade will result in MySQL server failing to start.
76+
"""
77+
78+
generated_list = ''
79+
if found_options:
80+
generated_list += (
81+
'Following configuration options won\'t work on a new version '
82+
'of MySQL after upgrading and have to be removed from configuration files:'
83+
)
1084

11-
class MySQLCheckLib:
12-
REMOVED_ARGS = [
13-
'--avoid-temporal-upgrade',
14-
'--show-old-temporals',
15-
'--old',
16-
'--new',
17-
'--default-authentication-plugin',
18-
'--no-dd-upgrade',
19-
'--language',
20-
'--ssl',
21-
'--admin-ssl',
22-
'--character-set-client-handshake',
23-
'--old-style-user-limits',
24-
]
25-
26-
# Link URL for mysql-server report
27-
report_server_inst_link_url = 'https://access.redhat.com/articles/7099234'
85+
for arg in found_options:
86+
generated_list += FMT_LIST_SEPARATOR + arg
2887

29-
found_arguments = set()
30-
found_options = set()
88+
generated_list += (
89+
'\nDefault configuration file is present at `/etc/my.cnf`\n'
90+
)
3191

32-
def _generate_mysql_present_report(self):
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-
This report is used in case MySQL package is detected, but no
41-
immediate action is needed.
42-
"""
43-
reporting.create_report([
44-
reporting.Title('Further action to upgrade MySQL might be needed'),
45-
reporting.Summary((
46-
'MySQL server component will be upgraded. '
47-
'Since RHEL-10 includes MySQL server 8.4 by default, '
48-
'it might be necessary to proceed with additional steps after '
49-
'RHEL upgrade is completed. In simple setups MySQL server should '
50-
'automatically upgrade all data on first start, but in more '
51-
'complicated setups further steps might be needed.'
52-
)),
53-
reporting.Severity(self.report_severity),
54-
reporting.Groups([reporting.Severity.LOW]),
55-
reporting.ExternalLink(title='Migrating MySQL databases from RHEL 9 to RHEL 10',
56-
url=self.report_server_inst_link_url),
57-
reporting.RelatedResource('package', 'mysql-server'),
58-
reporting.Remediation(hint=(
59-
'Dump or backup your data before proceeding with the upgrade '
60-
'and consult attached article '
61-
'\'Migrating MySQL databases from RHEL 9 to RHEL 10\' '
62-
'with up to date recommended steps before and after the upgrade - '
63-
'especially different ways of backing up your data or steps you'
64-
'may need to take manually.'
65-
)),
66-
])
67-
68-
def _generate_deprecated_config_report(self):
69-
"""
70-
Create report on mysql-server deprecated configuration.
71-
72-
Apart from showing user the article for upgrade process, we inform the
73-
user that there are deprecated configuration options being used and
74-
proceeding with upgrade will result in MySQL server failing to start.
75-
"""
76-
77-
generated_list = ''
78-
if self.found_options:
79-
generated_list += (
80-
'Following configuration options won\'t work on a new version '
81-
'of MySQL after upgrading and have to be removed from config files:'
82-
)
83-
84-
for arg in self.found_options:
85-
self.report_server_inst_summary += FMT_LIST_SEPARATOR + arg
86-
87-
generated_list += (
88-
'\nDefault configuration file is present in `/etc/my.cnf`\n'
92+
if found_arguments:
93+
generated_list += (
94+
'Following startup arguments won\'t work on a new version '
95+
'of MySQL after upgrading and have to be removed from '
96+
'systemd service files:'
8997
)
9098

91-
if self.found_arguments:
92-
generated_list += (
93-
'Following startup argument won\'t work on a new version '
94-
'of MySQL after upgrading and have to be removed from '
95-
'systemd service files:'
96-
)
99+
for arg in found_arguments:
100+
generated_list += FMT_LIST_SEPARATOR + arg
101+
102+
generated_list += (
103+
'\nDefault service override file is present at '
104+
'`/etc/systemd/system/mysqld.service.d/override.conf`\n'
105+
)
106+
107+
reporting.create_report([
108+
reporting.Title('MySQL is using configuration that will be invalid after upgrade'),
109+
reporting.Summary((
110+
'MySQL server component will be upgraded. '
111+
'Since RHEL-10 includes MySQL server 8.4 by default, '
112+
'it is necessary to proceed with additional steps. '
113+
'Some options that are currently used in MySQL configuration are '
114+
'deprecated and will result in MySQL server failing to start '
115+
'after upgrading. '
116+
'After RHEL upgrade is completed MySQL server should automatically upgrade all '
117+
'data on first start in simple setups. In more '
118+
'complicated setups manual intervention might be needed.'
119+
)),
120+
reporting.Severity(reporting.Severity.MEDIUM),
121+
reporting.Groups([reporting.Groups.SERVICES]),
122+
reporting.ExternalLink(title='Migrating MySQL databases from RHEL 9 to RHEL 10',
123+
url=report_server_inst_link_url),
124+
reporting.RelatedResource('package', 'mysql-server'),
125+
reporting.Remediation(hint=(
126+
'To ensure smooth upgrade process it is strongly recommended to '
127+
'remove deprecated config options \n' +
128+
generated_list +
129+
'Dump or backup your data before proceeding with the upgrade '
130+
'and consult attached article '
131+
'\'Migrating MySQL databases from RHEL 9 to RHEL 10\' '
132+
'with up to date recommended steps before and after the upgrade.'
133+
)),
134+
])
135+
136+
137+
def _generate_report(found_options, found_arguments):
138+
"""
139+
Create report on mysql-server package installation detection.
140+
141+
Should remind user about present MySQL server package
142+
installation, warn them about necessary additional steps, and
143+
redirect them to online documentation for the upgrade process.
144+
"""
145+
146+
if found_arguments or found_options:
147+
_generate_deprecated_config_report(found_options, found_arguments)
148+
else:
149+
_generate_mysql_present_report()
150+
151+
152+
def _check_incompatible_config():
153+
"""
154+
Get incompatible configuration options. Since MySQL can have basically
155+
unlimited number of config files that can link to one another, most
156+
convenient way is running `mysqld` command with `--validate-config
157+
--log-error-verbosity=2` arguments. Validate config only validates the
158+
config, without starting the MySQL server. Verbosity=2 is required to show
159+
deprecated options - which are removed after upgrade.
160+
161+
Example output:
162+
2024-12-18T11:40:04.725073Z 0 [Warning] [MY-011069] [Server]
163+
The syntax '--old' is deprecated and will be removed in a future release.
164+
"""
165+
# mysqld --validate-config --log-error-verbosity=2
166+
# 2024-12-18T11:40:04.725073Z 0 [Warning] [MY-011069] [Server]
167+
# The syntax '--old' is deprecated and will be removed in a future release.
168+
169+
found_options = set()
170+
out = subprocess.run(['mysqld', '--validate-config', '--log-error-verbosity=2'],
171+
capture_output=True,
172+
check=False)
97173

98-
for arg in self.found_arguments:
99-
self.report_server_inst_summary += FMT_LIST_SEPARATOR + arg
174+
stderr = out.stderr.decode("utf-8")
175+
if 'deprecated' in stderr:
176+
found_options = {arg for arg
177+
in REMOVED_ARGS
178+
if arg in stderr}
179+
return found_options
100180

101-
generated_list += (
102-
'\nDefault service override file is present in '
103-
'`/etc/systemd/system/mysqld.service.d/override.conf`'
104-
)
105181

106-
reporting.create_report([
107-
reporting.Title('MySQL is using configuration that will be invalid after upgrade'),
108-
reporting.Summary((
109-
'MySQL server component will be upgraded. '
110-
'Since RHEL-10 includes MySQL server 8.4 by default, '
111-
'it is necessary to proceed with additional steps. '
112-
'Some options that are currently used in MySQL configuration are '
113-
'deprecated and will result in MySQL server failing to start '
114-
'after upgrading.'
115-
'In simple setups MySQL server should automatically upgrade all '
116-
'data on first start, after RHEL upgrade is completed. In more '
117-
'complicated setups further steps might be needed.'
118-
)),
119-
reporting.Severity(self.report_severity),
120-
reporting.Groups([reporting.Severity.MEDIUM]),
121-
reporting.ExternalLink(title='Migrating MySQL databases from RHEL 9 to RHEL 10',
122-
url=self.report_server_inst_link_url),
123-
reporting.RelatedResource('package', 'mysql-server'),
124-
reporting.Remediation(hint=(
125-
'To ensure smooth upgrade process it is strongly recommended to '
126-
'remove deprecated config options \n' +
127-
generated_list +
128-
'Dump or backup your data before proceeding with the upgrade '
129-
'and consult attached article '
130-
'\'Migrating MySQL databases from RHEL 9 to RHEL 10\' '
131-
'with up to date recommended steps before and after the upgrade - '
132-
'especially different ways of backing up your data or steps you'
133-
'may need to take manually.'
134-
)),
135-
])
136-
137-
def _generate_report(self):
138-
"""
139-
Create report on mysql-server package installation detection.
140-
141-
Should remind user about present MySQL server package
142-
installation, warn them about necessary additional steps, and
143-
redirect them to online documentation for the upgrade process.
144-
"""
145-
146-
if self.found_arguments or self.found_options:
147-
self._generate_deprecated_config_report()
148-
else:
149-
self._generate_mysql_present_report()
150-
151-
def _check_incompatible_config(self):
152-
# mysqld --validate-config --log-error-verbosity=2
153-
# 2024-12-18T11:40:04.725073Z 0 [Warning] [MY-011069] [Server]
154-
# The syntax '--old' is deprecated and will be removed in a future release.
155-
out = subprocess.run(['mysqld', '--validate-config', '--log-error-verbosity=2'],
156-
capture_output=True,
157-
check=False)
158-
159-
stderr = out.stderr.decode("utf-8")
160-
if 'deprecated' in stderr:
161-
self.found_options = {arg for arg
162-
in self.REMOVED_ARGS
163-
if arg in stderr}
164-
165-
def _check_incompatible_launch_param(self):
166-
# Check /etc/systemd/system/mysqld.service.d/override.conf
167-
try:
168-
with open('/etc/systemd/system/mysqld.service.d/override.conf') as f:
169-
file_content = f.read()
170-
self.found_arguments = {arg for arg
171-
in self.REMOVED_ARGS
172-
if arg in file_content}
173-
except OSError:
174-
# File probably doesn't exist, ignore it and pass
175-
pass
176-
177-
def report_installed_packages(self, _context=api):
178-
"""
179-
Create reports according to detected MySQL packages.
180-
181-
Create the report if the mysql-server rpm (RH signed) is installed.
182-
"""
183-
184-
self._check_incompatible_config()
185-
self._check_incompatible_launch_param()
186-
187-
if has_package(DistributionSignedRPM, 'mysql-server', context=_context):
188-
self._generate_report()
182+
def _check_incompatible_launch_param():
183+
"""
184+
Get incompatible launch parameters from systemd service override file
185+
located at /etc/systemd/system/mysqld.service.d/override.conf
186+
"""
187+
188+
found_arguments = set()
189+
try:
190+
with open('/etc/systemd/system/mysqld.service.d/override.conf') as f:
191+
file_content = f.read()
192+
found_arguments = {arg for arg
193+
in REMOVED_ARGS
194+
if arg in file_content}
195+
except OSError:
196+
# File probably doesn't exist, ignore it and pass
197+
pass
198+
199+
return found_arguments
200+
201+
202+
def report_installed_packages(_context=api):
203+
"""
204+
Create reports according to detected MySQL packages.
205+
206+
Create the report if the mysql-server rpm (RH signed) is installed.
207+
"""
208+
209+
if has_package(DistributionSignedRPM, 'mysql-server', context=_context):
210+
found_options = _check_incompatible_config()
211+
found_arguments = _check_incompatible_launch_param()
212+
_generate_report(found_options, found_arguments)

0 commit comments

Comments
 (0)