From df41a349f5a0883683be5ce1f543c5243caeb4b8 Mon Sep 17 00:00:00 2001 From: Kishan Karunaratne Date: Wed, 17 Jun 2015 18:51:15 -0700 Subject: [PATCH] retry cluster connection in SSL test --- tests/integration/long/test_ssl.py | 56 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/tests/integration/long/test_ssl.py b/tests/integration/long/test_ssl.py index 69e60db7..d7cfc5a8 100644 --- a/tests/integration/long/test_ssl.py +++ b/tests/integration/long/test_ssl.py @@ -12,29 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. - try: import unittest2 as unittest except ImportError: import unittest -import os -import ssl +import os, sys, traceback, logging, ssl from cassandra.cluster import Cluster from cassandra import ConsistencyLevel from cassandra.query import SimpleStatement -from tests.integration import use_singledc, PROTOCOL_VERSION, get_cluster +from tests.integration import use_singledc, PROTOCOL_VERSION, get_cluster, remove_cluster +log = logging.getLogger(__name__) DEFAULT_PASSWORD = "cassandra" - DEFAULT_SERVER_KEYSTORE_PATH = "tests/integration/long/ssl/keystore.jks" - DEFAULT_CLIENT_CA_CERTS = 'tests/integration/long/ssl/driver_ca_cert.pem' def setup_module(): - """ We need some custom setup for this module. This will start the ccm cluster with basic ssl connectivity. No client authentication is performed at this time. @@ -56,31 +52,27 @@ def setup_module(): def teardown_module(): - """ - The rest of the tests don't need ssl enabled - reset the config options so as to not interfere with other tests. + The rest of the tests don't need ssl enabled, remove the cluster so as to not interfere with other tests. """ - ccm_cluster = get_cluster() - config_options = {} - ccm_cluster.set_configuration_options(config_options) - if ccm_cluster is not None: - ccm_cluster.stop() + remove_cluster() class SSLConnectionTests(unittest.TestCase): - def test_ssl_connection(self): + def test_can_connect_with_ssl_ca(self): """ - Test to validate that we are able to connect to a cluster using ssl. - - test_ssl_connection Performs a simple sanity check to ensure that we can connect to a cluster with ssl. + Test to validate that we are able to connect to a cluster using ssl. + test_can_connect_with_ssl_ca performs a simple sanity check to ensure that we can connect to a cluster with ssl + authentication via simple server-side shared certificate authority. The client is able to validate the identity + of the server, however by using this method the server can't trust the client unless additional authentication + has been provided. @since 2.6.0 @jira_ticket PYTHON-332 - @expected_result we can connect and preform some basic operations + @expected_result The client can connect via SSL and preform some basic operations @test_category connection:ssl """ @@ -88,9 +80,20 @@ class SSLConnectionTests(unittest.TestCase): # Setup temporary keyspace. abs_path_ca_cert_path = os.path.abspath(DEFAULT_CLIENT_CA_CERTS) - self.cluster = Cluster(protocol_version=PROTOCOL_VERSION, ssl_options={'ca_certs': abs_path_ca_cert_path, + cluster = Cluster(protocol_version=PROTOCOL_VERSION, ssl_options={'ca_certs': abs_path_ca_cert_path, 'ssl_version': ssl.PROTOCOL_TLSv1}) - self.session = self.cluster.connect() + tries = 0 + while True: + if tries > 5: + raise RuntimeError("Failed to connect to SSL cluster after 5 attempts") + try: + session = cluster.connect() + break + except Exception: + ex_type, ex, tb = sys.exc_info() + log.warn("{0}: {1} Backtrace: {2}".format(ex_type.__name__, ex, traceback.extract_tb(tb))) + del tb + tries += 1 # attempt a few simple commands. insert_keyspace = """CREATE KEYSPACE ssltest @@ -98,14 +101,11 @@ class SSLConnectionTests(unittest.TestCase): """ statement = SimpleStatement(insert_keyspace) statement.consistency_level = 3 - self.session.execute(statement) + session.execute(statement) drop_keyspace = "DROP KEYSPACE ssltest" - statement = SimpleStatement(drop_keyspace) statement.consistency_level = ConsistencyLevel.ANY - self.session.execute(statement) - - - + session.execute(statement) + cluster.shutdown() \ No newline at end of file