diff --git a/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/libraries/clmysqlrepositorysetup.py b/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/libraries/clmysqlrepositorysetup.py index 6dbca7bd61..231b85127a 100644 --- a/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/libraries/clmysqlrepositorysetup.py +++ b/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/libraries/clmysqlrepositorysetup.py @@ -31,6 +31,7 @@ OLD_CLMYSQL_VERSIONS = ["5.0", "5.1"] OLD_MYSQL_UPSTREAM_VERSIONS_CL7 = ["5.7", "5.6", "5.5"] OLD_MYSQL_UPSTREAM_VERSIONS_CL8 = ["5.7", "5.6"] # adjust as needed for CL8 +OLD_MARIADB_UPSTREAM_VERSIONS_CL8 = ["10.3", "10.4"] # MariaDB versions to block for CL8 source def build_install_list(prefix): @@ -180,6 +181,32 @@ def clmysql_process(self, repofile_name, repofile_data): else: api.current_logger().debug("No repos from CloudLinux repofile {} enabled, ignoring".format(repofile_name)) + def _make_upgrade_mariadb_url(self, mariadb_url, source_major, target_major): + """ + Maria URLs look like this: + baseurl = https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64 + baseurl = https://archive.mariadb.org/mariadb-10.7/yum/centos7-ppc64/ + baseurl = https://distrohub.kyiv.ua/mariadb/yum/11.8/rhel/$releasever/$basearch + baseurl = https://mariadb.gb.ssimn.org/yum/12.0/centos/$releasever/$basearch + baseurl = https://mariadb.gb.ssimn.org/yum/12.0/almalinux8-amd64/$releasever/$basearch + We want to replace the parts of the url to make them work with target os version. + """ + + # Replace the first occurrence of source_major with target_major after 'yum' + url_parts = mariadb_url.split("yum", 1) + if len(url_parts) == 2: + # Replace major version in "/centos/7/" and /12.0/almalinux9-amd64/, + # but do not replace it in /mariadb-10.7/yum/ + url_parts[1] = url_parts[1].replace("/{}/".format(source_major), "/{}/".format(target_major)) + url_parts[1] = url_parts[1].replace("{}-".format(source_major), "{}-".format(target_major)) + # Replace $releasever because upstream repos expect major version + # and cloudlinux provides major.minor as $releasever + url_parts[1] = url_parts[1].replace('$releasever', str(target_major)) + return "yum".join(url_parts) + else: + api.current_logger().warning("Unsupported repository URL={}, skipping".format(mariadb_url)) + return + def mariadb_process(self, repofile_name, repofile_data): """ Process upstream MariaDB options. @@ -191,24 +218,36 @@ def mariadb_process(self, repofile_name, repofile_data): source_major = get_source_major_version() for source_repo in repofile_data.data: - # Maria URLs look like this: - # baseurl = https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64 - # baseurl = https://archive.mariadb.org/mariadb-10.7/yum/centos7-ppc64/ - # We want to replace the source_major in OS name after /yum/ with target_major target_repo = copy.deepcopy(source_repo) target_repo.repoid = "{}-{}".format(target_repo.repoid, target_major) - # Replace the first occurrence of source_major with target_major after 'yum' - url_parts = target_repo.baseurl.split("yum", 1) - if len(url_parts) == 2: - # Replace only the first digit (source_major) after 'yum' - url_parts[1] = url_parts[1].replace(str(source_major), str(target_major), 1) - target_repo.baseurl = "yum".join(url_parts) - else: - # TODO: fix in https://cloudlinux.atlassian.net/browse/CLOS-3490 - api.current_logger().warning("Unsupported repository URL={}, skipping".format(target_repo.baseurl)) - return + target_repo.baseurl = self._make_upgrade_mariadb_url(source_repo.baseurl, source_major, target_major) if target_repo.enabled: + # MariaDB 10.4 is not compatible with Leapp upgrade + if str(source_major) == "8" and any(ver in target_repo.baseurl for ver in OLD_MARIADB_UPSTREAM_VERSIONS_CL8): + reporting.create_report( + [ + reporting.Title("MariaDB version is not compatible with Leapp upgrade"), + reporting.Summary( + "MariaDB is installed on this system but its version is not compatible with Leapp upgrade process. " + "The upgrade is blocked to prevent system instability. " + "This situation cannot be automatically resolved by Leapp. " + "Problematic repository: {0}".format(target_repo.repoid) + ), + reporting.Severity(reporting.Severity.MEDIUM), + reporting.Groups([reporting.Groups.REPOSITORY]), + reporting.Groups([reporting.Groups.INHIBITOR]), + reporting.Remediation( + hint=( + "Upgrade to a more recent MariaDB version, or " + "uninstall the MariaDB packages and disable the repository. " + "Note that you will also need to update any bindings (e.g., PHP or Python) " + "that are dependent on this MariaDB version." + ) + ), + ] + ) + api.current_logger().debug("Generating custom MariaDB repo: {}".format(target_repo.repoid)) self.custom_repo_msgs.append( CustomTargetRepository( diff --git a/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/tests/test_upgrade_mariadb_community.py b/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/tests/test_upgrade_mariadb_community.py new file mode 100644 index 0000000000..a7db4950cf --- /dev/null +++ b/repos/system_upgrade/cloudlinux/actors/clmysqlrepositorysetup/tests/test_upgrade_mariadb_community.py @@ -0,0 +1,91 @@ +import pytest + +from leapp.libraries.actor import clmysqlrepositorysetup + + +@pytest.mark.parametrize( + "source_url,source_major,target_major,expected_url", + [ + # Test cases from docstring + ( + "https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64", + 7, 8, + "https://archive.mariadb.org/mariadb-10.3/yum/centos/8/x86_64", + ), + ( + "https://archive.mariadb.org/mariadb-10.7/yum/centos7-ppc64/", + 7, 8, + "https://archive.mariadb.org/mariadb-10.7/yum/centos8-ppc64/", + ), + ( + "https://distrohub.kyiv.ua/mariadb/yum/11.8/rhel/7/x86_64", + 7, 8, + "https://distrohub.kyiv.ua/mariadb/yum/11.8/rhel/8/x86_64", + ), + ( + "https://mariadb.gb.ssimn.org/yum/12.0/centos/7/x86_64", + 7, 8, + "https://mariadb.gb.ssimn.org/yum/12.0/centos/8/x86_64", + ), + ( + "https://mariadb.gb.ssimn.org/yum/12.0/almalinux8-amd64/", + 8, 9, + "https://mariadb.gb.ssimn.org/yum/12.0/almalinux9-amd64/", + ), + + # Test with trailing slash + ( + "https://archive.mariadb.org/mariadb-10.3/yum/centos/7/x86_64/", + 7, 8, + "https://archive.mariadb.org/mariadb-10.3/yum/centos/8/x86_64/", + ), + + # Test cases based on SSIMN.org mirror patterns + # RHEL patterns + ( + "https://mariadb.gb.ssimn.org/yum/12.0/rhel8-amd64/", + 8, 9, + "https://mariadb.gb.ssimn.org/yum/12.0/rhel9-amd64/", + ), + + # Rocky Linux patterns + ( + "https://mariadb.gb.ssimn.org/yum/12.0/rocky8-amd64/", + 8, 9, + "https://mariadb.gb.ssimn.org/yum/12.0/rocky9-amd64/", + ), + ( + "https://mariadb.gb.ssimn.org/yum/12.0/rockylinux8-amd64/", + 8, 9, + "https://mariadb.gb.ssimn.org/yum/12.0/rockylinux9-amd64/", + ), + + # Test cases that should return None and log warning + ( + "https://example.com/mariadb/repo/centos/7/x86_64", + 7, 8, + None, + ), + ( + "https://example.com/mariadb/yum", + 7, 8, + None, + ), + ( + "", + 7, 8, + None, + ), + ( + None, + 7, 8, + None, + ), + ] +) +def test_make_upgrade_mariadb_url(source_url, source_major, target_major, expected_url): + """Test URL transformation for various MariaDB repository URLs.""" + library = clmysqlrepositorysetup.MySqlRepositorySetupLibrary() + result = library._make_upgrade_mariadb_url(source_url, source_major, target_major) + + assert result == expected_url