This is an automated email from the ASF dual-hosted git repository. djoshi pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cassandra-dtest.git
The following commit(s) were added to refs/heads/master by this push: new 35cee51 Fix CQLSH UTF-8 encoding issue for Python 2/3 compatibility 35cee51 is described below commit 35cee51a058c1970fe15bcb06c22ef4f2b9af5ba Author: Dinesh A. Joshi <dinesh.jo...@apple.com> AuthorDate: Sun Apr 19 13:13:04 2020 -0700 Fix CQLSH UTF-8 encoding issue for Python 2/3 compatibility This fix also addresses test failures due to cqlsh return code behavior change Patch by Dinesh Joshi; Reviewed by Jordan West and Mick Semb Wever for CASSANDRA-15739 --- cqlsh_tests/test_cqlsh.py | 26 ++++++++++++++------------ cqlsh_tests/test_cqlsh_copy.py | 21 +++++++-------------- cqlsh_tests/util.py | 19 +++++++++++++++++++ sstable_generation_loading_test.py | 6 +++++- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/cqlsh_tests/test_cqlsh.py b/cqlsh_tests/test_cqlsh.py index 1de4fcb..262df8a 100644 --- a/cqlsh_tests/test_cqlsh.py +++ b/cqlsh_tests/test_cqlsh.py @@ -8,7 +8,6 @@ import datetime import locale import os import re -import six import subprocess import sys import logging @@ -30,6 +29,7 @@ from dtest_setup_overrides import DTestSetupOverrides from tools.assertions import assert_all, assert_none from tools.data import create_c1c2_table, insert_c1c2, rows_to_list from tools.misc import ImmutableMapping +from . import util since = pytest.mark.since logger = logging.getLogger(__name__) @@ -468,8 +468,8 @@ UPDATE varcharmaptable SET varcharvarintmap['Vitrum edere possum, mihi non nocet node1, = self.cluster.nodelist() cmds = "ä;" - _, err, _ = node1.run_cqlsh(cmds=cmds) + _, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmds) assert 'Invalid syntax' in err assert 'ä' in err @@ -485,7 +485,8 @@ UPDATE varcharmaptable SET varcharvarintmap['Vitrum edere possum, mihi non nocet node1, = self.cluster.nodelist() cmd = '''create keyspace "ä" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};''' - _, err, _ = node1.run_cqlsh(cmds=cmd, cqlsh_options=["--debug"]) + + _, err, _ = util.run_cqlsh_safe(node=node1, cmds=cmd, cqlsh_options=["--debug"]) 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 @@ -2097,13 +2098,14 @@ class TestCqlshSmoke(Tester): create_cf(self.session, 'test') self.node1.run_cqlsh( - """ + cmds=""" -- commented line // Another comment /* multiline * * comment */ - """) + """, + terminator="") out, err, _ = self.node1.run_cqlsh("DESCRIBE KEYSPACE ks; // post-line comment") assert err == "" assert out.strip().startswith("CREATE KEYSPACE ks") @@ -2398,11 +2400,11 @@ class TestCqlLogin(Tester): create_cf(self.session, 'ks1table') self.session.execute("CREATE USER user1 WITH PASSWORD 'changeme';") - cqlsh_stdout, cqlsh_stderr, _ = self.node1.run_cqlsh( + 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']) self.assert_login_not_allowed('user1', cqlsh_stderr) @@ -2424,9 +2426,9 @@ class TestCqlLogin(Tester): ''' expected_error = 'Only superusers are allowed to perform CREATE USER queries' - cqlsh_stdout, cqlsh_stderr, _ = self.node1.run_cqlsh( - query, - cqlsh_options=['-u', 'cassandra', '-p', 'cassandra']) + cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1, + query, + cqlsh_options=['-u', 'cassandra', '-p', 'cassandra']) err_lines = str(cqlsh_stderr).splitlines() for err_line in err_lines: @@ -2442,13 +2444,13 @@ class TestCqlLogin(Tester): create_cf(self.session, 'ks1table') self.session.execute("CREATE USER user1 WITH PASSWORD 'changeme';") - cqlsh_stdout, cqlsh_stderr, _ = self.node1.run_cqlsh( + cqlsh_stdout, cqlsh_stderr, _ = util.run_cqlsh_safe(self.node1, ''' LOGIN user1 'badpass'; USE ks1; DESCRIBE TABLES; ''', - cqlsh_options=['-u', 'cassandra', '-p', 'cassandra']) + cqlsh_options=['-u', 'cassandra', '-p', 'cassandra']) assert [x for x in cqlsh_stdout.split() if x] == ['ks1table'] self.assert_login_not_allowed('user1', cqlsh_stderr) diff --git a/cqlsh_tests/test_cqlsh_copy.py b/cqlsh_tests/test_cqlsh_copy.py index 286b488..e4155fc 100644 --- a/cqlsh_tests/test_cqlsh_copy.py +++ b/cqlsh_tests/test_cqlsh_copy.py @@ -8,36 +8,29 @@ import json import locale import logging import os -import pytest import re -import sys import time - from collections import namedtuple -from contextlib import contextmanager from decimal import Decimal from distutils.version import LooseVersion -from functools import partial from tempfile import NamedTemporaryFile, gettempdir, template from uuid import uuid1, uuid4 +import pytest from cassandra.cluster import ConsistencyLevel, SimpleStatement from cassandra.concurrent import execute_concurrent_with_args -from cassandra.cqltypes import EMPTY from cassandra.murmur3 import murmur3 from cassandra.util import SortedSet from ccmlib.common import is_win +from dtest import (FlakyRetryPolicy, Tester, create_ks) +from tools.data import rows_to_list +from . import util from .cqlsh_test_types import (Address, Datetime, ImmutableDict, ImmutableSet, Name, UTC, drop_microseconds) -from .cqlsh_tools import (DummyColorMap, assert_csvs_items_equal, +from .cqlsh_tools import (assert_csvs_items_equal, csv_rows, monkeypatch_driver, random_list, unmonkeypatch_driver, write_rows_to_csv) -from dtest import (Tester, create_ks) -from dtest import (FlakyRetryPolicy, Tester, create_ks) -from tools.data import rows_to_list -from tools.metadata_wrapper import (UpdatingClusterMetadataWrapper, - UpdatingTableMetadataWrapper) since = pytest.mark.since logger = logging.getLogger(__name__) @@ -171,14 +164,14 @@ class TestCqlshCopy(Tester): if retry_on_request_timeout: num_attempts = 0 while num_attempts < 5: - ret = self.node1.run_cqlsh(cmds=cmds, cqlsh_options=cqlsh_options) + ret = util.run_cqlsh_safe(self.node1, cmds=cmds, cqlsh_options=cqlsh_options, expect_error=False) if not re.search(r"Client request timeout", ret[0]): break num_attempts += 1 else: - ret = self.node1.run_cqlsh(cmds=cmds, cqlsh_options=cqlsh_options) + ret = util.run_cqlsh_safe(self.node1, cmds=cmds, cqlsh_options=cqlsh_options, expect_error=False) if show_output: logger.debug('Output:\n{}'.format(ret[0])) # show stdout of copy cmd diff --git a/cqlsh_tests/util.py b/cqlsh_tests/util.py new file mode 100644 index 0000000..34212cb --- /dev/null +++ b/cqlsh_tests/util.py @@ -0,0 +1,19 @@ +from collections import namedtuple + +import pytest +from ccmlib.node import ToolError + + +def run_cqlsh_safe(node, cmds, cqlsh_options=None, expect_error=True): + """ + cqlsh behavior has changed to set an error code on exit. This wrapper + makes it easier to run cqlsh commands while expecting exceptions. + """ + try: + ret = node.run_cqlsh(cmds=cmds, cqlsh_options=cqlsh_options) + if expect_error: + pytest.fail("Expected ToolError but didn't get one") + return ret + except ToolError as e: + ret = namedtuple('Subprocess_Return', 'stdout stderr rc') + return ret(stdout=e.stdout, stderr=e.stderr, rc=e.exit_status) diff --git a/sstable_generation_loading_test.py b/sstable_generation_loading_test.py index 906ad5c..7b0a41d 100644 --- a/sstable_generation_loading_test.py +++ b/sstable_generation_loading_test.py @@ -8,6 +8,7 @@ import pytest import logging from ccmlib import common as ccmcommon +from ccmlib.node import ToolError from dtest import Tester, create_ks, create_cf, MAJOR_VERSION_4 from tools.assertions import assert_all, assert_none, assert_one @@ -230,7 +231,10 @@ class TestBaseSStableLoader(Tester): # do some operations and try reading the data again. node1.nodetool('scrub') node1.nodetool('compact') - node1.nodetool('repair') + try: + node1.nodetool('repair') + except ToolError as e: + print("Caught ToolError") logger.debug("Reading data back one more time") read_and_validate_data(session) --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org