From 430a1e7a4d440b56c53b20d7f8676a0ca37743dc Mon Sep 17 00:00:00 2001 From: Dmitry Kropachev Date: Sat, 4 Jan 2025 18:55:05 -0400 Subject: [PATCH] Log cqlsh output in get_cluster_info ScyllaCloudConfigTests are failing due to the get_cluster_info returned empty list. To investigate it furthere we need to dump cqlsh output to debug log. --- .../integration/standard/test_scylla_cloud.py | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/integration/standard/test_scylla_cloud.py b/tests/integration/standard/test_scylla_cloud.py index d1a22f882..3e72b25c3 100644 --- a/tests/integration/standard/test_scylla_cloud.py +++ b/tests/integration/standard/test_scylla_cloud.py @@ -1,8 +1,9 @@ +import json import logging import os.path from unittest import TestCase from ccmlib.utils.ssl_utils import generate_ssl_stores -from ccmlib.utils.sni_proxy import refresh_certs, get_cluster_info, start_sni_proxy, create_cloud_config +from ccmlib.utils.sni_proxy import refresh_certs, start_sni_proxy, create_cloud_config, NodeInfo from tests.integration import use_cluster from cassandra.cluster import Cluster, TwistedConnection @@ -22,6 +23,49 @@ # need to run them with specific configuration like `gevent.monkey.patch_all()` or under async functions # unsupported_connection_classes = [GeventConnection, AsyncioConnection, EventletConnection] +LOGGER = logging.getLogger(__name__) + +def get_cluster_info(cluster, port=9142): + + node1 = cluster.nodelist()[0] + stdout, stderr = node1.run_cqlsh(cmds='select JSON host_id,broadcast_address,data_center from system.local ;', + return_output=True, show_output=True) + + if stdout: + LOGGER.debug("cqlsh 'select JSON host_id,broadcast_address,data_center from system.local' returned stdout: %s", stdout) + if stderr: + LOGGER.debug("cqlsh 'select JSON host_id,broadcast_address,data_center from system.local' returned stderr: %s", stderr) + + nodes_info = [] + for line in stdout.splitlines(): + try: + host = json.loads(line) + except json.decoder.JSONDecodeError: + continue + if 'broadcast_address' in host and 'host_id' in host: + nodes_info.append(NodeInfo(address=host['broadcast_address'], + port=port, + host_id=host['host_id'], + data_center=host['data_center'])) + + stdout, stderr = node1.run_cqlsh(cmds='select JSON peer,host_id,data_center from system.peers ;', + return_output=True, show_output=True) + if stdout: + LOGGER.debug("cqlsh 'select JSON peer,host_id,data_center from system.peers' returned stdout: %s", stdout) + if stderr: + LOGGER.debug("cqlsh 'select JSON peer,host_id,data_center from system.peers' returned stderr: %s", stderr) + for line in stdout.splitlines(): + try: + host = json.loads(line) + except json.decoder.JSONDecodeError: + continue + if 'peer' in host and 'host_id' in host: + nodes_info.append(NodeInfo(address=host['peer'], + port=port, + host_id=host['host_id'], + data_center=host['data_center'])) + + return nodes_info class ScyllaCloudConfigTests(TestCase):