Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
34 changes: 17 additions & 17 deletions auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
from collections import namedtuple
from datetime import datetime, timedelta
from distutils.version import LooseVersion
from packaging.version import parse
import re
import pytest
import logging
Expand Down Expand Up @@ -35,7 +35,7 @@ def role_creator_permissions(self, creator, role):
return [(creator, role, perm) for perm in permissions]

def cluster_version_has_masking_permissions(self):
return self.cluster.version() >= LooseVersion('5.0')
return self.cluster.version() >= parse('5.0')

def data_resource_creator_permissions(self, creator, resource):
"""
Expand Down Expand Up @@ -1371,7 +1371,7 @@ def test_creator_of_db_resource_granted_all_permissions(self):
as_mike.execute("CREATE KEYSPACE ks WITH replication = {'class':'SimpleStrategy', 'replication_factor':1}")
as_mike.execute("CREATE TABLE ks.cf (id int primary key, val int)")
as_mike.execute("CREATE ROLE role1 WITH PASSWORD = '11111' AND SUPERUSER = false AND LOGIN = true")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
as_mike.execute("""CREATE FUNCTION ks.state_function_1(a int, b int)
CALLED ON NULL INPUT
RETURNS int
Expand Down Expand Up @@ -1668,7 +1668,7 @@ def test_filter_granted_permissions_by_resource_type(self):
self.superuser.execute("CREATE TABLE ks.cf (id int primary key, val int)")
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND SUPERUSER = false AND LOGIN = true")
self.superuser.execute("CREATE ROLE role1 WITH SUPERUSER = false AND LOGIN = false")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.state_func(a int, b int) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'a+b'")
else:
self.superuser.execute("CREATE FUNCTION ks.state_func(a int, b int) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS ' return a+b;'")
Expand Down Expand Up @@ -2150,7 +2150,7 @@ def test_grant_revoke_udf_permissions(self):
"""
self.setup_table()
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
self.superuser.execute("CREATE FUNCTION ks.\"plusOne\" ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
Expand Down Expand Up @@ -2199,7 +2199,7 @@ def test_grant_revoke_are_idempotent(self):
"""
self.setup_table()
self.superuser.execute("CREATE ROLE mike")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
Expand Down Expand Up @@ -2230,7 +2230,7 @@ def test_function_resource_hierarchy_permissions(self):
self.superuser.execute("INSERT INTO ks.t1 (k,v) values (1,1)")
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
self.superuser.execute("GRANT SELECT ON ks.t1 TO mike")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.func_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
self.superuser.execute("CREATE FUNCTION ks.func_two ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
Expand Down Expand Up @@ -2289,15 +2289,15 @@ def test_udf_permissions_validation(self):
* Verify mike can create a new UDF iff he has the CREATE permission
"""
self.setup_table()
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
as_mike = self.get_session(user='mike', password='12345')

# can't replace an existing function without ALTER permission on the parent ks
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
cql = "CREATE OR REPLACE FUNCTION ks.plus_one( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript as '1 + input'"
else:
cql = "CREATE OR REPLACE FUNCTION ks.plus_one( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java as 'return 1 + input;'"
Expand Down Expand Up @@ -2340,7 +2340,7 @@ def test_udf_permissions_validation(self):
InvalidRequest)

# can't create a new function without CREATE on the parent keyspace's collection of functions
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
cql = "CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'"
else:
cql = "CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'"
Expand All @@ -2360,7 +2360,7 @@ def test_drop_role_cleans_up_udf_permissions(self):
"""
self.setup_table()
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
Expand Down Expand Up @@ -2391,7 +2391,7 @@ def test_drop_function_and_keyspace_cleans_up_udf_permissions(self):
"""
self.setup_table()
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
Expand Down Expand Up @@ -2422,7 +2422,7 @@ def test_udf_with_overloads_permissions(self):
"""
self.setup_table()
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input double ) CALLED ON NULL INPUT RETURNS double LANGUAGE javascript AS 'input + 1'")
else:
Expand Down Expand Up @@ -2469,7 +2469,7 @@ def test_drop_keyspace_cleans_up_function_level_permissions(self):
"""
self.setup_table()
self.superuser.execute("CREATE ROLE mike WITH PASSWORD = '12345' AND LOGIN = true")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.state_func (a int, b int) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'a + b'")
else:
self.superuser.execute("CREATE FUNCTION ks.state_func (a int, b int) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return a + b;'")
Expand Down Expand Up @@ -2525,7 +2525,7 @@ def verify_udf_permissions(self, cql):
@param cql The statement to verify. Should contain the UDF ks.plus_one
"""
self.setup_table()
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
Expand All @@ -2549,7 +2549,7 @@ def test_inheritence_of_udf_permissions(self):
self.setup_table()
self.superuser.execute("CREATE ROLE function_user")
self.superuser.execute("GRANT EXECUTE ON ALL FUNCTIONS IN KEYSPACE ks TO function_user")
if self.cluster.version() < LooseVersion('4.2'):
if self.cluster.version() < parse('4.2'):
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE javascript AS 'input + 1'")
else:
self.superuser.execute("CREATE FUNCTION ks.plus_one ( input int ) CALLED ON NULL INPUT RETURNS int LANGUAGE java AS 'return input + 1;'")
Expand Down Expand Up @@ -2721,7 +2721,7 @@ def assert_unauthenticated(self, user, password):
host, error = response._excinfo[1].errors.popitem()

message = "Provided username {user} and/or password are incorrect".format(user=user)\
if node.cluster.version() >= LooseVersion('3.10') \
if node.cluster.version() >= parse('3.10') \
else "Username and/or password are incorrect"
pattern = 'Failed to authenticate to {host}: Error from server: code=0100 ' \
'[Bad credentials] message="{message}"'.format(host=host, message=message)
Expand Down
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
5 changes: 2 additions & 3 deletions commitlog_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import stat
import struct
import time
from distutils.version import LooseVersion
from packaging.version import parse
import pytest
import logging

Expand Down Expand Up @@ -172,7 +172,7 @@ def test_mv_lock_contention_during_replay(self):
@jira_ticket CASSANDRA-11891
"""
cluster_ver = self.cluster.version()
if LooseVersion('3.1') <= cluster_ver < LooseVersion('3.7'):
if parse('3.1') <= cluster_ver < parse('3.7'):
pytest.skip("Fixed in 3.0.7 and 3.7")

node1 = self.node1
Expand Down Expand Up @@ -320,7 +320,6 @@ def test_stop_failure_policy(self):
self.prepare()

self._provoke_commitlog_failure()
time.sleep(2)
failure = self.node1.grep_log("Failed .+ commit log segments. Commit disk failure policy is stop; terminating thread")
logger.debug(failure)
assert failure, "Cannot find the commitlog failure message in logs"
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
Loading