|
| 1 | +import os.path |
| 2 | +from unittest import TestCase |
| 3 | +from ccmlib.utils.ssl_utils import generate_ssl_stores |
| 4 | +from ccmlib.utils.sni_proxy import refresh_certs, get_cluster_info, start_sni_proxy, create_cloud_config |
| 5 | + |
| 6 | +from tests.integration import use_cluster |
| 7 | +from cassandra.cluster import Cluster, TwistedConnection |
| 8 | +from cassandra.connection import SniEndPointFactory |
| 9 | +from cassandra.io.asyncorereactor import AsyncoreConnection |
| 10 | +from cassandra.io.libevreactor import LibevConnection |
| 11 | +from cassandra.io.geventreactor import GeventConnection |
| 12 | +from cassandra.io.eventletreactor import EventletConnection |
| 13 | +from cassandra.io.asyncioreactor import AsyncioConnection |
| 14 | + |
| 15 | +supported_connection_classes = [AsyncoreConnection, LibevConnection, TwistedConnection] |
| 16 | +# need to run them with specific configuration like `gevent.monkey.patch_all()` or under async functions |
| 17 | +unsupported_connection_classes = [GeventConnection, AsyncioConnection, EventletConnection] |
| 18 | + |
| 19 | + |
| 20 | +class ScyllaCloudConfigTests(TestCase): |
| 21 | + def start_cluster_with_proxy(self): |
| 22 | + ccm_cluster = self.ccm_cluster |
| 23 | + generate_ssl_stores(ccm_cluster.get_path()) |
| 24 | + ssl_port = 9142 |
| 25 | + sni_port = 443 |
| 26 | + ccm_cluster.set_configuration_options(dict( |
| 27 | + client_encryption_options= |
| 28 | + dict(require_client_auth=True, |
| 29 | + truststore=os.path.join(ccm_cluster.get_path(), 'ccm_node.cer'), |
| 30 | + certificate=os.path.join(ccm_cluster.get_path(), 'ccm_node.pem'), |
| 31 | + keyfile=os.path.join(ccm_cluster.get_path(), 'ccm_node.key'), |
| 32 | + enabled=True), |
| 33 | + native_transport_port_ssl=ssl_port)) |
| 34 | + |
| 35 | + ccm_cluster._update_config() |
| 36 | + |
| 37 | + ccm_cluster.start(wait_for_binary_proto=True) |
| 38 | + |
| 39 | + nodes_info = get_cluster_info(ccm_cluster, port=ssl_port) |
| 40 | + refresh_certs(ccm_cluster, nodes_info) |
| 41 | + |
| 42 | + docker_id, listen_address, listen_port = \ |
| 43 | + start_sni_proxy(ccm_cluster.get_path(), nodes_info=nodes_info, listen_port=sni_port) |
| 44 | + ccm_cluster.sni_proxy_docker_id = docker_id |
| 45 | + ccm_cluster.sni_proxy_listen_port = listen_port |
| 46 | + ccm_cluster._update_config() |
| 47 | + |
| 48 | + config_data_yaml, config_path_yaml = create_cloud_config(ccm_cluster.get_path(), listen_port) |
| 49 | + |
| 50 | + endpoint_factory = SniEndPointFactory(listen_address, port=int(listen_port), |
| 51 | + node_domain="cluster-id.scylla.com") |
| 52 | + |
| 53 | + return config_data_yaml, config_path_yaml, endpoint_factory |
| 54 | + |
| 55 | + def test_1_node_cluster(self): |
| 56 | + self.ccm_cluster = use_cluster("sni_proxy", [1], start=False) |
| 57 | + config_data_yaml, config_path_yaml, endpoint_factory = self.start_cluster_with_proxy() |
| 58 | + |
| 59 | + for config in [config_path_yaml, config_data_yaml]: |
| 60 | + for connection_class in supported_connection_classes: |
| 61 | + cluster = Cluster(scylla_cloud=config, connection_class=connection_class, |
| 62 | + endpoint_factory=endpoint_factory) |
| 63 | + with cluster.connect() as session: |
| 64 | + res = session.execute("SELECT * FROM system.local") |
| 65 | + assert res.all() |
| 66 | + |
| 67 | + assert len(cluster.metadata._hosts) == 1 |
| 68 | + assert len(cluster.metadata._host_id_by_endpoint) == 1 |
| 69 | + |
| 70 | + def test_3_node_cluster(self): |
| 71 | + self.ccm_cluster = use_cluster("sni_proxy", [3], start=False) |
| 72 | + config_data_yaml, config_path_yaml, endpoint_factory = self.start_cluster_with_proxy() |
| 73 | + |
| 74 | + for config in [config_path_yaml, config_data_yaml]: |
| 75 | + for connection_class in supported_connection_classes: |
| 76 | + cluster = Cluster(scylla_cloud=config, connection_class=connection_class, |
| 77 | + endpoint_factory=endpoint_factory) |
| 78 | + with cluster.connect() as session: |
| 79 | + res = session.execute("SELECT * FROM system.local") |
| 80 | + assert res.all() |
| 81 | + assert len(cluster.metadata._hosts) == 3 |
| 82 | + assert len(cluster.metadata._host_id_by_endpoint) == 3 |
0 commit comments