|
| 1 | +import json |
1 | 2 | import logging |
2 | 3 | import os.path |
3 | 4 | from unittest import TestCase |
4 | 5 | from ccmlib.utils.ssl_utils import generate_ssl_stores |
5 | | -from ccmlib.utils.sni_proxy import refresh_certs, get_cluster_info, start_sni_proxy, create_cloud_config |
| 6 | +from ccmlib.utils.sni_proxy import refresh_certs, start_sni_proxy, create_cloud_config, NodeInfo |
6 | 7 |
|
7 | 8 | from tests.integration import use_cluster |
8 | 9 | from cassandra.cluster import Cluster, TwistedConnection |
|
22 | 23 |
|
23 | 24 | # need to run them with specific configuration like `gevent.monkey.patch_all()` or under async functions |
24 | 25 | # unsupported_connection_classes = [GeventConnection, AsyncioConnection, EventletConnection] |
| 26 | +LOGGER = logging.getLogger(__name__) |
| 27 | + |
| 28 | +def get_cluster_info(cluster, port=9142): |
| 29 | + |
| 30 | + node1 = cluster.nodelist()[0] |
| 31 | + stdout, stderr = node1.run_cqlsh(cmds='select JSON host_id,broadcast_address,data_center from system.local ;', |
| 32 | + return_output=True, show_output=True) |
| 33 | + |
| 34 | + if stdout: |
| 35 | + LOGGER.debug("cqlsh 'select JSON host_id,broadcast_address,data_center from system.local' returned stdout: %s", stdout) |
| 36 | + if stderr: |
| 37 | + LOGGER.debug("cqlsh 'select JSON host_id,broadcast_address,data_center from system.local' returned stderr: %s", stderr) |
| 38 | + |
| 39 | + nodes_info = [] |
| 40 | + for line in stdout.splitlines(): |
| 41 | + try: |
| 42 | + host = json.loads(line) |
| 43 | + except json.decoder.JSONDecodeError: |
| 44 | + continue |
| 45 | + if 'broadcast_address' in host and 'host_id' in host: |
| 46 | + nodes_info.append(NodeInfo(address=host['broadcast_address'], |
| 47 | + port=port, |
| 48 | + host_id=host['host_id'], |
| 49 | + data_center=host['data_center'])) |
| 50 | + |
| 51 | + stdout, stderr = node1.run_cqlsh(cmds='select JSON peer,host_id,data_center from system.peers ;', |
| 52 | + return_output=True, show_output=True) |
| 53 | + if stdout: |
| 54 | + LOGGER.debug("cqlsh 'select JSON peer,host_id,data_center from system.peers' returned stdout: %s", stdout) |
| 55 | + if stderr: |
| 56 | + LOGGER.debug("cqlsh 'select JSON peer,host_id,data_center from system.peers' returned stderr: %s", stderr) |
| 57 | + for line in stdout.splitlines(): |
| 58 | + try: |
| 59 | + host = json.loads(line) |
| 60 | + except json.decoder.JSONDecodeError: |
| 61 | + continue |
| 62 | + if 'peer' in host and 'host_id' in host: |
| 63 | + nodes_info.append(NodeInfo(address=host['peer'], |
| 64 | + port=port, |
| 65 | + host_id=host['host_id'], |
| 66 | + data_center=host['data_center'])) |
| 67 | + |
| 68 | + return nodes_info |
25 | 69 |
|
26 | 70 |
|
27 | 71 | class ScyllaCloudConfigTests(TestCase): |
|
0 commit comments