Skip to content

Commit

Permalink
Log cqlsh output in get_cluster_info
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dkropachev committed Jan 4, 2025
1 parent d62eb38 commit 430a1e7
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/integration/standard/test_scylla_cloud.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 430a1e7

Please sign in to comment.