Skip to content

Commit

Permalink
improvement(versions): Use ComparableScyllaVersion in more places
Browse files Browse the repository at this point in the history
Use 'ComparableScyllaVersion' instead of the 'parse_scylla_version'.
Delete 'parse_scylla_version' as unneeded.

It is follow-up for the following PR:

    scylladb#5817
  • Loading branch information
vponomaryov committed Feb 20, 2023
1 parent 3c58029 commit a7d19c4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 54 deletions.
12 changes: 6 additions & 6 deletions sdcm/fill_db_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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:
Expand All @@ -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):
"""
Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions sdcm/utils/version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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."""

Expand Down
30 changes: 0 additions & 30 deletions unit_tests/test_version_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pytest
import requests
import pkg_resources

import sdcm
from sdcm.utils.version_utils import (
Expand All @@ -19,7 +18,6 @@
get_scylla_urls_from_repository,
get_specific_tag_of_docker_image,
is_enterprise,
parse_scylla_version,
scylla_versions,
ComparableScyllaOperatorVersion,
ComparableScyllaVersion,
Expand Down Expand Up @@ -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, '', '')),
Expand Down
16 changes: 7 additions & 9 deletions utils/get_supported_scylla_base_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__), ".."))

Expand Down Expand Up @@ -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':
Expand All @@ -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])
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a7d19c4

Please sign in to comment.