Skip to content

Commit ebe3f4e

Browse files
authored
Merge pull request #39 from cloudlinux/clos-3490-fix-upstream-mariadb-upgrade
Fix upstream MariaDB upgrade
2 parents ccc776d + 4e91b1f commit ebe3f4e

File tree

2 files changed

+144
-14
lines changed

2 files changed

+144
-14
lines changed

repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/libraries/clmysqlrepositorysetup.py

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
OLD_CLMYSQL_VERSIONS = ["5.0", "5.1"]
3232
OLD_MYSQL_UPSTREAM_VERSIONS_CL7 = ["5.7", "5.6", "5.5"]
3333
OLD_MYSQL_UPSTREAM_VERSIONS_CL8 = ["5.7", "5.6"] # adjust as needed for CL8
34+
OLD_MARIADB_UPSTREAM_VERSIONS_CL8 = ["10.3", "10.4"] # MariaDB versions to block for CL8 source
3435

3536

3637
def build_install_list(prefix):
@@ -180,6 +181,32 @@ def clmysql_process(self, repofile_name, repofile_data):
180181
else:
181182
api.current_logger().debug("No repos from CloudLinux repofile {} enabled, ignoring".format(repofile_name))
182183

184+
def _make_upgrade_mariadb_url(self, mariadb_url, source_major, target_major):
185+
"""
186+
Maria URLs look like this:
187+
baseurl = https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64
188+
baseurl = https://archive.mariadb.org/mariadb-10.7/yum/centos7-ppc64/
189+
baseurl = https://distrohub.kyiv.ua/mariadb/yum/11.8/rhel/$releasever/$basearch
190+
baseurl = https://mariadb.gb.ssimn.org/yum/12.0/centos/$releasever/$basearch
191+
baseurl = https://mariadb.gb.ssimn.org/yum/12.0/almalinux8-amd64/$releasever/$basearch
192+
We want to replace the parts of the url to make them work with target os version.
193+
"""
194+
195+
# Replace the first occurrence of source_major with target_major after 'yum'
196+
url_parts = mariadb_url.split("yum", 1)
197+
if len(url_parts) == 2:
198+
# Replace major version in "/centos/7/" and /12.0/almalinux9-amd64/,
199+
# but do not replace it in /mariadb-10.7/yum/
200+
url_parts[1] = url_parts[1].replace("/{}/".format(source_major), "/{}/".format(target_major))
201+
url_parts[1] = url_parts[1].replace("{}-".format(source_major), "{}-".format(target_major))
202+
# Replace $releasever because upstream repos expect major version
203+
# and cloudlinux provides major.minor as $releasever
204+
url_parts[1] = url_parts[1].replace('$releasever', str(target_major))
205+
return "yum".join(url_parts)
206+
else:
207+
api.current_logger().warning("Unsupported repository URL={}, skipping".format(mariadb_url))
208+
return
209+
183210
def mariadb_process(self, repofile_name, repofile_data):
184211
"""
185212
Process upstream MariaDB options.
@@ -191,24 +218,36 @@ def mariadb_process(self, repofile_name, repofile_data):
191218
source_major = get_source_major_version()
192219

193220
for source_repo in repofile_data.data:
194-
# Maria URLs look like this:
195-
# baseurl = https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64
196-
# baseurl = https://archive.mariadb.org/mariadb-10.7/yum/centos7-ppc64/
197-
# We want to replace the source_major in OS name after /yum/ with target_major
198221
target_repo = copy.deepcopy(source_repo)
199222
target_repo.repoid = "{}-{}".format(target_repo.repoid, target_major)
200-
# Replace the first occurrence of source_major with target_major after 'yum'
201-
url_parts = target_repo.baseurl.split("yum", 1)
202-
if len(url_parts) == 2:
203-
# Replace only the first digit (source_major) after 'yum'
204-
url_parts[1] = url_parts[1].replace(str(source_major), str(target_major), 1)
205-
target_repo.baseurl = "yum".join(url_parts)
206-
else:
207-
# TODO: fix in https://cloudlinux.atlassian.net/browse/CLOS-3490
208-
api.current_logger().warning("Unsupported repository URL={}, skipping".format(target_repo.baseurl))
209-
return
223+
target_repo.baseurl = self._make_upgrade_mariadb_url(source_repo.baseurl, source_major, target_major)
210224

211225
if target_repo.enabled:
226+
# MariaDB 10.4 is not compatible with Leapp upgrade
227+
if str(source_major) == "8" and any(ver in target_repo.baseurl for ver in OLD_MARIADB_UPSTREAM_VERSIONS_CL8):
228+
reporting.create_report(
229+
[
230+
reporting.Title("MariaDB version is not compatible with Leapp upgrade"),
231+
reporting.Summary(
232+
"MariaDB is installed on this system but its version is not compatible with Leapp upgrade process. "
233+
"The upgrade is blocked to prevent system instability. "
234+
"This situation cannot be automatically resolved by Leapp. "
235+
"Problematic repository: {0}".format(target_repo.repoid)
236+
),
237+
reporting.Severity(reporting.Severity.MEDIUM),
238+
reporting.Groups([reporting.Groups.REPOSITORY]),
239+
reporting.Groups([reporting.Groups.INHIBITOR]),
240+
reporting.Remediation(
241+
hint=(
242+
"Upgrade to a more recent MariaDB version, or "
243+
"uninstall the MariaDB packages and disable the repository. "
244+
"Note that you will also need to update any bindings (e.g., PHP or Python) "
245+
"that are dependent on this MariaDB version."
246+
)
247+
),
248+
]
249+
)
250+
212251
api.current_logger().debug("Generating custom MariaDB repo: {}".format(target_repo.repoid))
213252
self.custom_repo_msgs.append(
214253
CustomTargetRepository(
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import pytest
2+
3+
from leapp.libraries.actor import clmysqlrepositorysetup
4+
5+
6+
@pytest.mark.parametrize(
7+
"source_url,source_major,target_major,expected_url",
8+
[
9+
# Test cases from docstring
10+
(
11+
"https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64",
12+
7, 8,
13+
"https://archive.mariadb.org/mariadb-10.3/yum/centos/8/x86_64",
14+
),
15+
(
16+
"https://archive.mariadb.org/mariadb-10.7/yum/centos7-ppc64/",
17+
7, 8,
18+
"https://archive.mariadb.org/mariadb-10.7/yum/centos8-ppc64/",
19+
),
20+
(
21+
"https://distrohub.kyiv.ua/mariadb/yum/11.8/rhel/7/x86_64",
22+
7, 8,
23+
"https://distrohub.kyiv.ua/mariadb/yum/11.8/rhel/8/x86_64",
24+
),
25+
(
26+
"https://mariadb.gb.ssimn.org/yum/12.0/centos/7/x86_64",
27+
7, 8,
28+
"https://mariadb.gb.ssimn.org/yum/12.0/centos/8/x86_64",
29+
),
30+
(
31+
"https://mariadb.gb.ssimn.org/yum/12.0/almalinux8-amd64/",
32+
8, 9,
33+
"https://mariadb.gb.ssimn.org/yum/12.0/almalinux9-amd64/",
34+
),
35+
36+
# Test with trailing slash
37+
(
38+
"https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64/",
39+
7, 8,
40+
"https://archive.mariadb.org/mariadb-10.3/yum/centos/8/x86_64/",
41+
),
42+
43+
# Test cases based on SSIMN.org mirror patterns
44+
# RHEL patterns
45+
(
46+
"https://mariadb.gb.ssimn.org/yum/12.0/rhel8-amd64/",
47+
8, 9,
48+
"https://mariadb.gb.ssimn.org/yum/12.0/rhel9-amd64/",
49+
),
50+
51+
# Rocky Linux patterns
52+
(
53+
"https://mariadb.gb.ssimn.org/yum/12.0/rocky8-amd64/",
54+
8, 9,
55+
"https://mariadb.gb.ssimn.org/yum/12.0/rocky9-amd64/",
56+
),
57+
(
58+
"https://mariadb.gb.ssimn.org/yum/12.0/rockylinux8-amd64/",
59+
8, 9,
60+
"https://mariadb.gb.ssimn.org/yum/12.0/rockylinux9-amd64/",
61+
),
62+
63+
# Test cases that should return None and log warning
64+
(
65+
"https://example.com/mariadb/repo/centos/7/x86_64",
66+
7, 8,
67+
None,
68+
),
69+
(
70+
"https://example.com/mariadb/yum",
71+
7, 8,
72+
None,
73+
),
74+
(
75+
"",
76+
7, 8,
77+
None,
78+
),
79+
(
80+
None,
81+
7, 8,
82+
None,
83+
),
84+
]
85+
)
86+
def test_make_upgrade_mariadb_url(source_url, source_major, target_major, expected_url):
87+
"""Test URL transformation for various MariaDB repository URLs."""
88+
library = clmysqlrepositorysetup.MySqlRepositorySetupLibrary()
89+
result = library._make_upgrade_mariadb_url(source_url, source_major, target_major)
90+
91+
assert result == expected_url

0 commit comments

Comments
 (0)