Skip to content

Commit

Permalink
Fix TestCqlsh for Cassandra 2.2, except test_client_warnings
Browse files Browse the repository at this point in the history
patch by Aleksandr Sorokoumov; review by Ekaterina Dimitrova and Brandon Williams for CASSANDRA-15985
  • Loading branch information
Gerrrr authored and ekaterinadimitrova2 committed Jul 21, 2021
1 parent af5d69e commit 8fb42c0
Showing 1 changed file with 74 additions and 27 deletions.
101 changes: 74 additions & 27 deletions cqlsh_tests/test_cqlsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ class TestCqlsh(Tester, CqlshMixin):
@pytest.fixture
def fixture_dtest_setup_overrides(self, dtest_config):
dtest_setup_overrides = DTestSetupOverrides()

if dtest_config.cassandra_version_from_build >= '3.0':
dtest_setup_overrides.cluster_options = ImmutableMapping({'enable_user_defined_functions': 'true',
'enable_scripted_user_defined_functions': 'true'})
else:
dtest_setup_overrides.cluster_options = ImmutableMapping({'enable_user_defined_functions': 'true'})

return dtest_setup_overrides

@classmethod
Expand Down Expand Up @@ -151,8 +151,8 @@ def test_pycodestyle_compliance(self):
p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()

assert 0 == len(stdout), str(stdout)
assert 0 == len(stderr), str(stderr)
assert 0 == len(stdout), stdout.decode("utf-8")
assert 0 == len(stderr), stderr.decode("utf-8")

def test_simple_insert(self):

Expand Down Expand Up @@ -555,7 +555,13 @@ def test_unicode_syntax_error(self):

cmds = "ä;"

_, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmds)
if self.cluster.version() >= LooseVersion('3.0'):
_, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmds)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
err = node1.run_cqlsh(cmds=cmds).stderr

assert 'Invalid syntax' in err
assert 'ä' in err

Expand All @@ -572,7 +578,13 @@ def test_unicode_invalid_request_error(self):

cmd = '''create keyspace "ä" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};'''

_, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmd, cqlsh_options=["--debug"])
options = ["--debug"]
if self.cluster.version() >= LooseVersion('3.0'):
_, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmd, cqlsh_options=options)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
err = node1.run_cqlsh(cmds=cmd, cqlsh_options=options).stderr

if self.cluster.version() >= LooseVersion('4.0'):
assert "Keyspace name must not be empty, more than 48 characters long, or contain non-alphanumeric-underscore characters (got 'ä')" in err
Expand Down Expand Up @@ -896,7 +908,6 @@ def test_describe_describes_non_default_compaction_parameters(self):
assert "'min_threshold': '10'" in stdout
assert "'max_threshold': '100'" in stdout

@since('3.0')
def test_describe_functions(self, fixture_dtest_setup_overrides):
"""Test DESCRIBE statements for functions and aggregate functions"""
self.cluster.populate(1)
Expand Down Expand Up @@ -941,15 +952,24 @@ def test_describe_functions(self, fixture_dtest_setup_overrides):
INITCOND (0, 0)
"""

# create keyspace, scalar function, and aggregate function
# create keyspace, scalar function
self.execute(cql=create_ks_statement)
self.execute(cql=create_function_statement)
self.execute(cql=create_aggregate_dependencies_statement)
self.execute(cql=create_aggregate_statement)

# describe scalar functions
self.execute(cql='DESCRIBE FUNCTION test.some_function', expected_output='{};'.format(create_function_statement))
# describe aggregate functions
self.execute(cql='DESCRIBE AGGREGATE test.average', expected_output=self.get_describe_aggregate_output())
if self.cluster.version() >= LooseVersion('3.0'):
expected_output = create_function_statement + ';'
else:
expected_output = create_function_statement
self.execute(cql='DESCRIBE FUNCTION test.some_function', expected_output=expected_output)

if self.cluster.version() >= LooseVersion('3.0'):
# create aggregate function
self.execute(cql=create_aggregate_dependencies_statement)
self.execute(cql=create_aggregate_statement)

# describe aggregate functions
self.execute(cql='DESCRIBE AGGREGATE test.average', expected_output=self.get_describe_aggregate_output())

def get_describe_aggregate_output(self):
if self.cluster.version() >= LooseVersion("4.0"):
Expand Down Expand Up @@ -1003,7 +1023,7 @@ def test_describe_types(self):
)"""
create_address_type_statement = """
CREATE TYPE test.address_type (
name frozen<name_type>,
name frozen<name_type>,
number int,
street text,
phones set<text>
Expand All @@ -1025,8 +1045,15 @@ def test_describe_types(self):
)"""

# DESCRIBE user defined types
self.execute(cql='DESCRIBE TYPE test.name_type', expected_output='{};'.format(create_name_type_statement))
self.execute(cql='DESCRIBE TYPE test.address_type', expected_output='{};'.format(create_address_type_statement))
if self.cluster.version() >= LooseVersion('3.0'):
expected_create_name_type_statement = create_name_type_statement + ';'
expected_create_address_type_statement = create_address_type_statement + ';'
else:
expected_create_name_type_statement = create_name_type_statement
expected_create_address_type_statement = create_address_type_statement

self.execute(cql='DESCRIBE TYPE test.name_type', expected_output=expected_create_name_type_statement)
self.execute(cql='DESCRIBE TYPE test.address_type', expected_output=expected_create_address_type_statement)

def test_describe_on_non_reserved_keywords(self):
"""
Expand Down Expand Up @@ -2502,18 +2529,24 @@ def test_login_rejects_bad_pass(self):
create_cf(self.session, 'ks1table')
self.session.execute("CREATE USER user1 WITH PASSWORD 'changeme';")

cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1,
'''
LOGIN user1 'badpass';
''',
cqlsh_options=['-u', 'cassandra', '-p', 'cassandra'])
cqlsh_options = ['-u', 'cassandra', '-p', 'cassandra']
cmd = "LOGIN user1 'badpass';"
if self.cluster.version() >= LooseVersion('3.0'):
_, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1,
cmds=cmd,
cqlsh_options=cqlsh_options)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
cqlsh_stderr = self.node1.run_cqlsh(cmds=cmd, cqlsh_options=cqlsh_options).stderr

self.assert_login_not_allowed('user1', cqlsh_stderr)

def test_login_authenticates_correct_user(self):
create_ks(self.session, 'ks1', 1)
create_cf(self.session, 'ks1table')
self.session.execute("CREATE USER user1 WITH PASSWORD 'changeme';")
cqlsh_options = ['-u', 'cassandra', '-p', 'cassandra']

if self.cluster.version() >= LooseVersion('2.2'):
query = '''
Expand All @@ -2528,9 +2561,14 @@ def test_login_authenticates_correct_user(self):
'''
expected_error = 'Only superusers are allowed to perform CREATE USER queries'

cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1,
query,
cqlsh_options=['-u', 'cassandra', '-p', 'cassandra'])
if self.cluster.version() >= LooseVersion('3.0'):
cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1,
query,
cqlsh_options=cqlsh_options)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
cqlsh_stderr = self.node1.run_cqlsh(cmds=query, cqlsh_options=cqlsh_options).stderr

err_lines = str(cqlsh_stderr).splitlines()
for err_line in err_lines:
Expand All @@ -2546,13 +2584,22 @@ def test_login_allows_bad_pass_and_continued_use(self):
create_cf(self.session, 'ks1table')
self.session.execute("CREATE USER user1 WITH PASSWORD 'changeme';")

cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1,
'''
cmds = '''
LOGIN user1 'badpass';
USE ks1;
DESCRIBE TABLES;
''',
cqlsh_options=['-u', 'cassandra', '-p', 'cassandra'])
'''
cqlsh_options=['-u', 'cassandra', '-p', 'cassandra']
if self.cluster.version() >= LooseVersion('3.0'):
cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1,
cmds=cmds,
cqlsh_options=cqlsh_options)
else:
# Versions prior to 3.0 print the error message to stderr, but do not throw.
# See CASSANDRA-15985 for more details
ret = self.node1.run_cqlsh(cmds=cmds, cqlsh_options=cqlsh_options)
cqlsh_stdout, cqlsh_stderr = ret.stdout, ret.stderr

assert [x for x in cqlsh_stdout.split() if x] == ['ks1table']
self.assert_login_not_allowed('user1', cqlsh_stderr)

Expand Down

0 comments on commit 8fb42c0

Please sign in to comment.