From a7d19c4cef416358d9c7710e79b263d61c2c820d Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Fri, 17 Feb 2023 20:05:44 +0200 Subject: [PATCH] improvement(versions): Use ComparableScyllaVersion in more places Use 'ComparableScyllaVersion' instead of the 'parse_scylla_version'. Delete 'parse_scylla_version' as unneeded. It is follow-up for the following PR: https://github.com/scylladb/scylla-cluster-tests/pull/5817 --- sdcm/fill_db_data.py | 12 ++++----- sdcm/utils/version_utils.py | 9 ------- unit_tests/test_version_utils.py | 30 --------------------- utils/get_supported_scylla_base_versions.py | 16 +++++------ 4 files changed, 13 insertions(+), 54 deletions(-) diff --git a/sdcm/fill_db_data.py b/sdcm/fill_db_data.py index 61e2428c62..b06498bd9d 100644 --- a/sdcm/fill_db_data.py +++ b/sdcm/fill_db_data.py @@ -33,7 +33,7 @@ from sdcm.tester import ClusterTester from sdcm.utils.decorators import retrying from sdcm.utils.cdc.options import CDC_LOGTABLE_SUFFIX -from sdcm.utils.version_utils import parse_scylla_version +from sdcm.utils.version_utils import ComparableScyllaVersion LOGGER = logging.getLogger(__name__) @@ -3143,7 +3143,7 @@ def cql_create_tables(self, session): @property def parsed_scylla_version(self): - return parse_scylla_version(self.db_cluster.nodes[0].scylla_version) + return ComparableScyllaVersion(self.db_cluster.nodes[0].scylla_version) @property def is_enterprise(self) -> bool: @@ -3154,14 +3154,14 @@ def version_null_values_support(self): version_with_support = self.NULL_VALUES_SUPPORT_ENTERPRISE_MIN_VERSION else: version_with_support = self.NULL_VALUES_SUPPORT_OS_MIN_VERSION - return self.parsed_scylla_version >= parse_scylla_version(version_with_support) + return self.parsed_scylla_version >= version_with_support def version_new_sorting_order_with_secondary_indexes(self): if self.is_enterprise: version_with_support = self.NEW_SORTING_ORDER_WITH_SECONDARY_INDEXES_ENTERPRISE_MIN_VERSION else: version_with_support = self.NEW_SORTING_ORDER_WITH_SECONDARY_INDEXES_OS_MIN_VERSION - return self.parsed_scylla_version >= parse_scylla_version(version_with_support) + return self.parsed_scylla_version >= version_with_support def version_non_frozen_udt_support(self): """ @@ -3172,14 +3172,14 @@ def version_non_frozen_udt_support(self): version_with_support = self.NON_FROZEN_SUPPORT_ENTERPRISE_MIN_VERSION else: version_with_support = self.NON_FROZEN_SUPPORT_OS_MIN_VERSION - return self.parsed_scylla_version >= parse_scylla_version(version_with_support) + return self.parsed_scylla_version >= version_with_support def version_cdc_support(self): if self.is_enterprise: version_with_support = self.CDC_SUPPORT_MIN_ENTERPRISE_VERSION else: version_with_support = self.CDC_SUPPORT_MIN_VERSION - return self.parsed_scylla_version >= parse_scylla_version(version_with_support) + return self.parsed_scylla_version >= version_with_support @retrying(n=3, sleep_time=20, allowed_exceptions=ProtocolException) def truncate_table(self, session, truncate): # pylint: disable=no-self-use diff --git a/sdcm/utils/version_utils.py b/sdcm/utils/version_utils.py index 767164dad0..13e7d67e7b 100644 --- a/sdcm/utils/version_utils.py +++ b/sdcm/utils/version_utils.py @@ -21,7 +21,6 @@ from urllib.parse import urlparse from functools import lru_cache, wraps from itertools import count -from pkg_resources import parse_version import yaml import boto3 @@ -30,7 +29,6 @@ from mypy_boto3_s3 import S3Client from botocore import UNSIGNED from botocore.client import Config -from packaging import version from repodataParser.RepoParser import Parser from sdcm.remote import LOCALRUNNER @@ -118,13 +116,6 @@ class ScyllaFileType(Enum): RepositoryDetails = namedtuple("RepositoryDetails", ["type", "urls"]) -def parse_scylla_version(version_to_parse: str) -> version.Version: - version_format = re.compile(r'(\d+\.\d)|(\.\d+)') - major_version = version_format.search(version_to_parse) - assert major_version, f"version_to_parse: '{version_to_parse}' isn't supported scylla version string" - return parse_version(major_version[0]) - - class ComparableScyllaVersion: """Accepts and compares known 'non-semver' and 'semver'-like Scylla versions.""" diff --git a/unit_tests/test_version_utils.py b/unit_tests/test_version_utils.py index f2b0b6c4d8..10c5468fd0 100644 --- a/unit_tests/test_version_utils.py +++ b/unit_tests/test_version_utils.py @@ -6,7 +6,6 @@ import pytest import requests -import pkg_resources import sdcm from sdcm.utils.version_utils import ( @@ -19,7 +18,6 @@ get_scylla_urls_from_repository, get_specific_tag_of_docker_image, is_enterprise, - parse_scylla_version, scylla_versions, ComparableScyllaOperatorVersion, ComparableScyllaVersion, @@ -446,34 +444,6 @@ def raise_request_error(**kwargs): assert get_docker_image_by_version(scylla_version=non_existing_version) == expected_fallback -@pytest.mark.parametrize("version_string, expected", ( - ("5.1", "5.1"), - ("5.1.0~rc1", "5.1"), - ("5.1.rc1", "5.1"), - ("2023.1", "2023.1"), - ("2023.1~rc0", "2023.1"), - ("2021.1.dev", "2021.1"), -)) -def test_parse_scylla_version(version_string, expected): - version_object = parse_scylla_version(version_string) - assert isinstance(version_object, pkg_resources.parse_version) - assert str(version_object) == expected - - -@pytest.mark.parametrize("version_string, expected", ( - pytest.param("2021", - "version_to_parse: '2021' isn't supported scylla version string", - id="2021"), - pytest.param("this_is_not_a_version", - "version_to_parse: 'this_is_not_a_version' isn't supported scylla version string", - id="this_is_not_a_version"), -)) -def test_parse_scylla_version_unsupported(version_string, expected): - with pytest.raises(AssertionError) as exp: - parse_scylla_version(version_string) - assert str(exp.value) == expected - - @pytest.mark.parametrize("version_string, expected", ( ("5.1", (5, 1, 0, '', '')), ("5.1.0", (5, 1, 0, '', '')), diff --git a/utils/get_supported_scylla_base_versions.py b/utils/get_supported_scylla_base_versions.py index 4a16b37754..583163ae6a 100755 --- a/utils/get_supported_scylla_base_versions.py +++ b/utils/get_supported_scylla_base_versions.py @@ -6,7 +6,7 @@ from sdcm.utils.version_utils import is_enterprise, get_all_versions from sdcm.utils.common import get_s3_scylla_repos_mapping -from sdcm.utils.version_utils import parse_scylla_version +from sdcm.utils.version_utils import ComparableScyllaVersion sys.path.append(os.path.join(os.path.dirname(__file__), "..")) @@ -97,10 +97,9 @@ def get_supported_scylla_base_versions(self, supported_versions) -> list: # pyl else: # Choose the last two releases as upgrade base ent_base_version += ent_release_list[idx-1:][:2] - elif version == 'enterprise' or parse_scylla_version(version) > parse_scylla_version(ent_release_list[0]): + elif version == 'enterprise' or ComparableScyllaVersion(version) > ent_release_list[0]: ent_base_version.append(ent_release_list[-1]) - elif re.match(r'\d+.\d+', version) and parse_scylla_version(version) \ - >= parse_scylla_version(ent_release_list[0]): + elif re.match(r'\d+.\d+', version) and ComparableScyllaVersion(version) >= ent_release_list[0]: oss_base_version.append(oss_release_list[-1]) ent_base_version += ent_release_list[-2:] elif product == 'scylla': @@ -113,10 +112,9 @@ def get_supported_scylla_base_versions(self, supported_versions) -> list: # pyl else: # Choose the last two releases as upgrade base oss_base_version += oss_release_list[idx-1:][:2] - elif version == 'master' or parse_scylla_version(version) > parse_scylla_version(oss_release_list[0]): + elif version == 'master' or ComparableScyllaVersion(version) > oss_release_list[0]: oss_base_version.append(oss_release_list[-1]) - elif re.match(r'\d+.\d+', version) and parse_scylla_version(version) \ - < parse_scylla_version(oss_release_list[0]): + elif re.match(r'\d+.\d+', version) and ComparableScyllaVersion(version) < oss_release_list[0]: # If dest version is smaller than the first supported opensource release, # it might be an invalid dest version oss_base_version.append(oss_release_list[-1]) @@ -156,11 +154,11 @@ def get_version_list(self) -> tuple[list, list]: continue # OSS: the major version is smaller than the start support version if self.oss_start_support_version and not is_enterprise(version_prefix) and \ - parse_scylla_version(version_prefix) < parse_scylla_version(self.oss_start_support_version): + ComparableScyllaVersion(version_prefix) < self.oss_start_support_version: continue # Enterprise: the major version is smaller than the start support version if self.ent_start_support_version and is_enterprise(version_prefix) and \ - parse_scylla_version(version_prefix) < parse_scylla_version(self.ent_start_support_version): + ComparableScyllaVersion(version_prefix) < self.ent_start_support_version: continue supported_versions.append(version_prefix) version_list = self.get_supported_scylla_base_versions(supported_versions)