Merge pull request #356 from kishkaru/jenkins_fixes

[PYTHON-322] Retry cluster connection in SSL test
This commit is contained in:
Kishan Karunaratne
2015-06-17 18:54:05 -07:00

View File

@@ -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()