Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cassandra 18321 #265

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions bootstrap_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import time
import logging
import signal
from distutils.version import LooseVersion
from packaging.version import parse


from cassandra import ConsistencyLevel
from cassandra.concurrent import execute_concurrent_with_args
Expand Down Expand Up @@ -136,7 +137,7 @@ def bootstrap_on_write_survey_and_join(cluster, token):
assert len(node2.grep_log('Startup complete, but write survey mode is active, not becoming an active ring member.'))
# bootstrapping is considered complete if streaming is successful. Post CEP-21 this is distinct from
# fully joining the ring or leaving write survey mode
bootstrap_state = 'COMPLETED' if self.cluster.version() >= LooseVersion('5.1') else 'IN_PROGRESS'
bootstrap_state = 'COMPLETED' if self.cluster.version() >= parse('5.1') else 'IN_PROGRESS'
assert_bootstrap_state(self, node2, bootstrap_state)

node2.nodetool("join")
Expand Down Expand Up @@ -329,7 +330,7 @@ def test_rf_gt_nodes_multidc_should_succeed(self):
# TCM, node2 also logs the warning as it applies the transform when it gets replicated to it by the CMS.
if cluster.version() >= '4.0':
warning = 'Your replication factor 3 for keyspace k is higher than the number of nodes 1 for datacenter dc1'
if cluster.version() >= LooseVersion('5.1'): # we now log this on all nodes
if cluster.version() >= parse('5.1'): # we now log this on all nodes
assert len(node1.grep_log(warning)) == 2
assert len(node2.grep_log(warning)) == 1
else:
Expand All @@ -342,7 +343,7 @@ def test_rf_gt_nodes_multidc_should_succeed(self):

if cluster.version() >= '4.0':
warning = 'Your replication factor 2 for keyspace k is higher than the number of nodes 1 for datacenter dc1'
if cluster.version() >= LooseVersion('5.1'):
if cluster.version() >= parse('5.1'):
assert len(node1.grep_log(warning)) == 2 # we now log this on all nodes
assert len(node2.grep_log(warning)) == 1
else:
Expand Down Expand Up @@ -411,7 +412,7 @@ def _bootstrap_test_with_replica_down(self, consistent_range_movement, rf=2):
node3 = new_node(cluster, token=node3_token)

jvmargs = ["-Dcassandra.consistent.rangemovement={}".format(consistent_range_movement)]
if cluster.version() >= LooseVersion('5.1'):
if cluster.version() >= parse('5.1'):
node3.set_configuration_options(values={'progress_barrier_min_consistency_level': 'NODE_LOCAL', 'progress_barrier_default_consistency_level': 'NODE_LOCAL', 'progress_barrier_timeout': '2000ms'})
node3.start(wait_for_binary_proto=successful_bootstrap_expected,
wait_other_notice=successful_bootstrap_expected,
Expand Down Expand Up @@ -782,7 +783,7 @@ def test_failed_bootstrap_wiped_node_can_join(self):

# wipe any data for node2
self._cleanup(node2)
if cluster.version() >= LooseVersion('5.1'):
if cluster.version() >= parse('5.1'):
node1.watch_log_for("127.0.0.2:7000 is now DOWN", from_mark=mark)
res = node1.nodetool('abortbootstrap --ip 127.0.0.2')
# Now start it again, it should be allowed to join
Expand Down
9 changes: 3 additions & 6 deletions client_network_stop_start_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import logging
import os
import os.path

import pytest
import shutil
import string
import time
from packaging.version import parse

from ccmlib.node import TimeoutError
from distutils.version import LooseVersion
from dtest import Tester
from tools import sslkeygen

Expand Down Expand Up @@ -50,7 +47,7 @@ def _assert_binary_actually_found(self, node_or_cluster):
def _assert_client_enable(self, node, native_enabled=True, thrift_enabled=False):
out = node.nodetool("info")
self._assert_client_active_msg("Native Transport", native_enabled, out.stdout)
if node.get_cassandra_version() >= LooseVersion('4.0'):
if node.get_cassandra_version() >= parse('4.0'):
assert "Thrift" not in out.stdout, "Thrift found in output: {}".format(out.stdout)
else:
self._assert_client_active_msg("Thrift", thrift_enabled, out.stdout)
Expand Down
11 changes: 6 additions & 5 deletions compaction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import string
import tempfile
import time
from distutils.version import LooseVersion
from packaging.version import parse

import pytest
import parse
import logging
Expand Down Expand Up @@ -150,7 +151,7 @@ def test_bloomfilter_size(self, strategy):
dir_count = len(node1.data_directories())
logger.debug("sstable_count is: {}".format(sstable_count))
logger.debug("dir_count is: {}".format(dir_count))
if node1.get_cassandra_version() < LooseVersion('3.2'):
if node1.get_cassandra_version() < parse('3.2'):
size_factor = sstable_count
else:
size_factor = sstable_count / float(dir_count)
Expand Down Expand Up @@ -226,7 +227,7 @@ def test_dtcs_deletion(self, strategy):
time.sleep(40)
expired_sstables = node1.get_sstables('ks', 'cf')
expected_sstable_count = 1
if self.cluster.version() > LooseVersion('3.1'):
if self.cluster.version() > parse('3.1'):
expected_sstable_count = cluster.data_dir_count
assert len(expired_sstables) == expected_sstable_count
# write a new sstable to make DTCS check for expired sstables:
Expand Down Expand Up @@ -290,7 +291,7 @@ def test_compaction_throughput(self):
"B": 1. / (1024 * 1024),
}

units = ['MB'] if cluster.version() < LooseVersion('3.6') else ['B', 'KiB', 'MiB', 'GiB']
units = ['MB'] if cluster.version() < parse('3.6') else ['B', 'KiB', 'MiB', 'GiB']
assert found_units in units

logger.debug(avgthroughput)
Expand Down Expand Up @@ -376,7 +377,7 @@ def test_large_compaction_warning(self):

node.nodetool('compact ks large')
verb = 'Writing' if self.cluster.version() > '2.2' else 'Compacting'
sizematcher = '\d+ bytes' if self.cluster.version() < LooseVersion('3.6') else '\d+\.\d{3}(K|M|G)iB'
sizematcher = '\d+ bytes' if self.cluster.version() < parse('3.6') else '\d+\.\d{3}(K|M|G)iB'
node.watch_log_for('{} large partition ks/large:user \({}'.format(verb, sizematcher), from_mark=mark, timeout=180)

ret = list(session.execute("SELECT properties from ks.large where userid = 'user'"))
Expand Down
5 changes: 3 additions & 2 deletions compression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import logging

from dtest import create_ks
from distutils.version import LooseVersion
from packaging.version import parse

from scrub_test import TestHelper
from tools.assertions import assert_crc_check_chance_equal

Expand Down Expand Up @@ -81,7 +82,7 @@ def test_compression_cql_options(self):
assert '256' == meta.options['compression']['chunk_length_in_kb']
assert_crc_check_chance_equal(session, "compression_opts_table", 0.25)

if self.cluster.version() < LooseVersion('5.0'):
if self.cluster.version() < parse('5.0'):
warn = node.grep_log("The option crc_check_chance was deprecated as a compression option.")
assert len(warn) == 0
session.execute("""
Expand Down
5 changes: 3 additions & 2 deletions configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from dtest import Tester, create_ks
from tools.jmxutils import (JolokiaAgent, make_mbean)
from distutils.version import LooseVersion
from packaging.version import parse


logger = logging.getLogger(__name__)

Expand All @@ -27,7 +28,7 @@ def test_compression_chunk_length(self):
create_table_query = "CREATE TABLE test_table (row varchar, name varchar, value int, PRIMARY KEY (row, name));"


if self.cluster.version() >= LooseVersion('5.0'):
if self.cluster.version() >= parse('5.0'):
alter_chunk_len_query = "ALTER TABLE test_table WITH " \
"compression = {{'class' : 'SnappyCompressor', " \
"'chunk_length_in_kb' : {chunk_length}}};"
Expand Down
25 changes: 14 additions & 11 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
from datetime import datetime
from distutils.version import LooseVersion
from packaging.version import parse
# Python 3 imports
from itertools import zip_longest

Expand Down Expand Up @@ -377,7 +378,7 @@ def fixture_dtest_setup(request,

# Based on https://bugs.python.org/file25808/14894.patch
def loose_version_compare(a, b):
for i, j in zip_longest(a.version, b.version, fillvalue=''):
for i, j in zip_longest(str(a), str(b), fillvalue=''):
if type(i) != type(j):
i = str(i)
j = str(j)
Expand All @@ -389,8 +390,8 @@ def loose_version_compare(a, b):
return 1

# Longer version strings with equal prefixes are equal, but if one version string is longer than it is greater
aLen = len(a.version)
bLen = len(b.version)
aLen = len(str(a))
bLen = len(str(b))
if aLen == bLen:
return 0
elif aLen < bLen:
Expand All @@ -415,7 +416,9 @@ def _skip_msg(current_running_version, since_version, max_version):
if loose_version_compare(current_running_version, previous) < 0:
return None

previous = LooseVersion('.'.join([str(s) for s in sv.version[:-1]]))
#changed
version_string = '.'.join([str(s) for s in sv.version[:-1]])
previous = parse(version_string)

# no matches found, so fail
return "%s < %s" % (current_running_version, since_version)
Expand All @@ -432,19 +435,19 @@ def fixture_since(request, fixture_dtest_setup):
max_version_str = request.node.get_closest_marker('since').kwargs.get('max_version', None)
max_version = None
if max_version_str:
max_version = LooseVersion(max_version_str)
max_version = parse(max_version_str)

since_str_or_list = request.node.get_closest_marker('since').args[0]
if not isinstance(since_str_or_list, str) and isinstance(since_str_or_list, collections.Sequence):
since = [LooseVersion(since_str) for since_str in since_str_or_list]
since = [parse(since_str) for since_str in since_str_or_list]
else:
since = LooseVersion(since_str_or_list)
since = parse(since_str_or_list)
# For upgrade tests don't run the test if any of the involved versions
# are excluded by the annotation
if hasattr(request.cls, "UPGRADE_PATH"):
upgrade_path = request.cls.UPGRADE_PATH
if hasattr(upgrade_path, 'upgrade_meta'):
skip_msg = _skip_msg(LooseVersion(upgrade_path.upgrade_meta.family), since, max_version)
skip_msg = _skip_msg(parse(upgrade_path.upgrade_meta.family), since, max_version)
if skip_msg:
pytest.skip(skip_msg)
ccm_repo_cache_dir, _ = ccmlib.repository.setup(upgrade_path.starting_meta.version)
Expand Down Expand Up @@ -485,7 +488,7 @@ def fixture_ported_to_in_jvm(request, fixture_dtest_setup):
if marker:

from_str = marker.args[0] if marker.args else "2.2.13" # JVM dtests were introduced on 2.2.13
ported_from_version = LooseVersion(from_str)
ported_from_version = parse(from_str)
use_vnodes = request.config.getoption("--use-vnodes")

# For upgrade tests don't run the test if any of the involved versions are excluded by the annotation
Expand Down Expand Up @@ -518,7 +521,7 @@ def fixture_ported_to_in_jvm(request, fixture_dtest_setup):
current_running_version = fixture_dtest_setup.dtest_config.cassandra_version_from_build

# vnodes weren't supported nor tested before 4.1, so we can't skip them if the version is older than that
if use_vnodes and loose_version_compare(current_running_version, LooseVersion('4.1')) < 0:
if use_vnodes and loose_version_compare(current_running_version, ('4.1')) < 0:
return

skip_msg = _skip_ported_msg(current_running_version, ported_from_version)
Expand All @@ -530,7 +533,7 @@ def fixture_ported_to_in_jvm(request, fixture_dtest_setup):
def fixture_skip_version(request, fixture_dtest_setup):
marker = request.node.get_closest_marker('skip_version')
if marker is not None:
version_to_skip = LooseVersion(marker.args[0])
version_to_skip = parse(marker.args[0])
if version_to_skip == fixture_dtest_setup.dtest_config.cassandra_version_from_build:
pytest.skip("Test marked not to run on version %s" % version_to_skip)

Expand Down
5 changes: 3 additions & 2 deletions counter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from tools.assertions import assert_invalid, assert_length_equal, assert_one
from dtest import Tester, create_ks, create_cf, mk_bman_path
from tools.data import rows_to_list
from distutils.version import LooseVersion
from packaging.version import parse


since = pytest.mark.since
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -178,7 +179,7 @@ def test_upgrade(self):
c counter
)
"""
if self.cluster.version() >= LooseVersion('5.0'):
if self.cluster.version() >= parse('5.0'):
query = query + "WITH compression = { 'class' : 'SnappyCompressor' }"
else:
query = query + "WITH compression = { 'sstable_compression' : 'SnappyCompressor' }"
Expand Down
7 changes: 4 additions & 3 deletions cql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from cassandra.query import SimpleStatement

from dtest import Tester, create_ks, mk_bman_path
from distutils.version import LooseVersion
from packaging.version import parse

from thrift_bindings.thrift010.ttypes import \
ConsistencyLevel as ThriftConsistencyLevel
from thrift_bindings.thrift010.ttypes import (CfDef, Column, ColumnOrSuperColumn,
Expand Down Expand Up @@ -651,7 +652,7 @@ def test_prepared_statement_invalidation(self):
result = session.execute(wildcard_prepared.bind(None))
assert result, [(0, 0, 0 == None)]

if self.cluster.version() < LooseVersion('3.0'):
if self.cluster.version() < parse('3.0'):
explicit_prepared = session.prepare("SELECT k, a, b, d FROM test")

# when the type is altered, both statements will need to be re-prepared
Expand Down Expand Up @@ -1596,7 +1597,7 @@ def _validate_non_existing_or_null_values(self, table_name, session):
assert_one(session, "SELECT a, s, d FROM {} WHERE a = 4".format(table_name), [4, 4, None])

def _is_new_lwt_format_version(self, version):
return version > LooseVersion('3.9') or (version > LooseVersion('3.0.9') and version < LooseVersion('3.1'))
return version > parse('3.9') or (version > parse('3.0.9') and version < parse('3.1'))

@flaky
def test_conditional_updates_on_static_columns_with_null_values(self):
Expand Down
13 changes: 7 additions & 6 deletions cql_tracing_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import logging

from distutils.version import LooseVersion
from packaging.version import parse


from dtest import Tester, create_ks

Expand All @@ -27,7 +28,7 @@ def prepare(self, create_keyspace=True, nodes=3, rf=3, protocol_version=3, jvm_a

cluster = self.cluster
opts = {'write_request_timeout_in_ms': 30000, 'read_request_timeout_in_ms': 30000}
if self.cluster.version() >= LooseVersion('4.1'):
if self.cluster.version() >= parse('4.1'):
opts['native_transport_timeout'] = '30s'
cluster.set_configuration_options(values=opts);

Expand Down Expand Up @@ -70,7 +71,7 @@ def trace(self, session):
""")

out, err, _ = node1.run_cqlsh('TRACING ON')
if self.cluster.version() >= LooseVersion('5.0'):
if self.cluster.version() >= parse('5.0'):
# See CASSANDRA-18547
assert 'TRACING set to ON' in out
else:
Expand Down Expand Up @@ -144,7 +145,7 @@ def test_tracing_unknown_impl(self):
errs = self.cluster.nodelist()[0].grep_log_for_errors()
logger.debug('Errors after attempted trace with unknown tracing class: {errs}'.format(errs=errs))
assert len(errs) == 1
if self.cluster.version() >= LooseVersion('3.10'):
if self.cluster.version() >= parse('3.10'):
# See CASSANDRA-11706 and PR #1281
assert len(errs[0]) > 0
else:
Expand Down Expand Up @@ -177,7 +178,7 @@ def test_tracing_default_impl(self):
errs = self.cluster.nodelist()[0].grep_log_for_errors()
logger.debug('Errors after attempted trace with default tracing class: {errs}'.format(errs=errs))
assert len(errs) == 1
if self.cluster.version() >= LooseVersion('3.10'):
if self.cluster.version() >= parse('3.10'):
# See CASSANDRA-11706 and PR #1281
assert len(errs[0]) > 0
else:
Expand All @@ -188,7 +189,7 @@ def test_tracing_default_impl(self):
# part of the expected error to avoid having to escape parens and
# periods for regexes.

if self.cluster.version() >= LooseVersion('3.10'):
if self.cluster.version() >= parse('3.10'):
# See CASSANDRA-11706 and PR #1281
check_for_errs_in = errs[0][1]
else:
Expand Down
Loading