Skip to content

Commit 50bf851

Browse files
tlasicajacek-lewandowski
authored andcommitted
STAR-765: Add tests for cloud connection. (#23)
* STAR-765: Add tests for cloud connection. It is not possible without some infrastructre or tooling effort to trully test cloud connection. Instead added tests focus on proper cqlsh behavior when secure connect bundle is specified: - proper default consistency level - debug information - reading from cqlshrc and parameters - skipping host / port information Testing validation is based on error msgs and debug info. (cherry picked from commit 9f8cba3)
1 parent fd2b1c3 commit 50bf851

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

cqlsh_tests/cqlshrc.sample.cloud

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; Copyright DataStax, Inc.
2+
;
3+
; Licensed under the Apache License, Version 2.0 (the "License");
4+
; you may not use this file except in compliance with the License.
5+
; You may obtain a copy of the License at
6+
;
7+
; http://www.apache.org/licenses/LICENSE-2.0
8+
;
9+
; Unless required by applicable law or agreed to in writing, software
10+
; distributed under the License is distributed on an "AS IS" BASIS,
11+
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
; See the License for the specific language governing permissions and
13+
; limitations under the License.
14+
;
15+
; Sample ~/.cqlshrc file with cloud configuration.
16+
[connection]
17+
secure_connect_bundle = /path/to/creds.zip

cqlsh_tests/secure-connect-test.zip

12.1 KB
Binary file not shown.

cqlsh_tests/test_cqlsh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def run_cqlsh(self, node, cmds, cqlsh_options=None, env_vars=None):
9393
logger.debug("Cqlsh command stderr:\n" + stderr)
9494
return stdout, stderr
9595

96+
9697
class TestCqlsh(Tester, CqlshMixin):
9798

9899
# override cluster options to enable user defined functions

cqlsh_tests/test_cqlsh_cloud.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# coding=utf-8
2+
3+
# Copyright DataStax, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import logging
18+
import pytest
19+
from ccmlib.node import ToolError
20+
21+
from dtest import Tester
22+
23+
logger = logging.getLogger(__name__)
24+
since = pytest.mark.since
25+
26+
27+
@since("4.0")
28+
class TestSecureBundleConnection(Tester):
29+
"""
30+
Tests related to cqlsh behavior for cloud e.g. secure bundle connection.
31+
We only test cqlshrc behavior.
32+
Testing if the connection using secure bundle is really working
33+
requires a true cluster with generated secure bundle to run.
34+
And this is not possible without testing infrastructure/tooling changes.
35+
36+
We can assume that it is correctly tested by the python driver or
37+
will be tested in the next stage of testing (cloud native).
38+
39+
Validation is done using --debug information or error msgs.
40+
41+
Inspired by STAR-765.
42+
"""
43+
44+
CQLSHRC_PATH = 'cqlsh_tests/cqlshrc.sample.cloud'
45+
BUNDLE_PATH = 'cqlsh_tests/secure-connect-test.zip'
46+
47+
def prepare(self, start=False):
48+
if not self.cluster.nodelist():
49+
self.cluster.populate(1)
50+
if start:
51+
self.cluster.start()
52+
return self.cluster.nodelist()[0]
53+
54+
def _expect_tool_error(self, cmds, options, msg):
55+
node = self.cluster.nodelist()[0]
56+
with pytest.raises(ToolError, match=msg):
57+
out, err, _ = node.run_cqlsh(cmds=cmds, cqlsh_options=options)
58+
return out, err
59+
60+
def test_start_fails_on_non_existing_file(self):
61+
self.prepare()
62+
self._expect_tool_error(cmds='HELP',
63+
options=['--secure-connect-bundle', 'not-existing-file.zip'],
64+
msg='No such file or directory')
65+
66+
def test_start_fails_when_file_not_a_bundle(self):
67+
self.prepare()
68+
self._expect_tool_error(cmds='HELP',
69+
options=['--secure-connect-bundle', self.CQLSHRC_PATH],
70+
msg='Unable to open the zip file for the cloud config')
71+
72+
def test_read_bundle_path_from_cqlshrc(self):
73+
self.prepare()
74+
self._expect_tool_error(cmds='HELP',
75+
options=['--cqlshrc', self.CQLSHRC_PATH],
76+
msg="No such file or directory: '/path/to/creds.zip'")
77+
78+
def test_host_and_port_are_ignored_with_secure_bundle(self):
79+
# it should connect with provided host and port to the started ccm node
80+
node = self.prepare(start=True)
81+
node.run_cqlsh("HELP", [])
82+
# but fail with secure bundle even if port and host are set
83+
expected_msg = "https://1263dd11-0aa5-41ef-8e56-17fa5fc7036e-europe-west1.db.astra.datastax.com:31669"
84+
self._expect_tool_error(cmds='HELP',
85+
options=['--secure-connect-bundle', self.BUNDLE_PATH, node.ip_addr, '9042'],
86+
msg=expected_msg)
87+
88+
def test_default_consistency_level_for_secure_connect_bundle_param(self):
89+
self.prepare()
90+
self._expect_tool_error(cmds='HELP',
91+
options=['--secure-connect-bundle', 'not-existing-file.zip', '--debug'],
92+
msg='Using consistency level:.*LOCAL_QUORUM')
93+
94+
def test_default_consistency_level_for_secure_connect_bundle_in_clqshrc(self):
95+
self.prepare()
96+
self._expect_tool_error(cmds='HELP',
97+
options=['--cqlshrc', self.CQLSHRC_PATH, '--debug'],
98+
msg='Using consistency level:.*LOCAL_QUORUM')
99+
100+
def test_set_consistency_level_for_secure_connect_bundle_in_clqshrc(self):
101+
self.prepare()
102+
self._expect_tool_error(cmds='HELP',
103+
options=['--cqlshrc', self.CQLSHRC_PATH, '--debug', '--consistency-level', 'TWO'],
104+
msg='Using consistency level:.*TWO')
105+
106+
def test_debug_should_include_cloud_details(self):
107+
self.prepare()
108+
self._expect_tool_error(cmds='HELP',
109+
options=['--secure-connect-bundle', 'not-existing-file.zip', '--debug'],
110+
msg='Using secure connect bundle.*not-existing-file.zip')
111+
112+
@pytest.mark.skip("we cannot test it without ccm secure conn bundle support in ccm")
113+
def test_endpoint_load_balancing_policy_is_used(self):
114+
# to test this we would need a 3 nodes cloud cluster
115+
assert False, "TODO: implement"
116+
117+
@pytest.mark.skip("we cannot test it without ccm secure conn bundle support in ccm")
118+
def test_connects_correctly(self):
119+
assert False, "TODO: implement"
120+
121+
@pytest.mark.skip("we cannot test it without ccm secure conn bundle support in ccm")
122+
def test_login_command_keeps_cloud_connection_using_bundle(self):
123+
# cqlsh.py -b some-bundle.zip -u user -p password
124+
# LOGIN user(password)
125+
assert False

0 commit comments

Comments
 (0)