Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cassandra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,14 @@ def _target_type_from_refresh_args(keyspace, table, usertype, function, aggregat
return SchemaTargetType.KEYSPACE
return None

def get_control_connection_host(self):
"""
Returns the control connection host metadata.
"""
connection = self.control_connection._connection
host = connection.host if connection else None
return self.metadata.get_host(host) if host else None

def refresh_schema_metadata(self, max_schema_agreement_wait=None):
"""
Synchronously refresh all schema metadata.
Expand Down Expand Up @@ -2905,7 +2913,7 @@ def _on_timeout(self):
if self.is_schema_agreed:
errors = {self._current_host.address: "Client request timeout. See Session.execute[_async](timeout)"}
else:
connection = getattr(self.session.cluster.control_connection, '_connection')
connection = self.session.cluster.control_connection._connection
host = connection.host if connection else 'unknown'
errors = {host: "Request timed out while waiting for schema agreement. See Session.execute[_async](timeout) and Cluster.max_schema_agreement_wait."}

Expand Down
2 changes: 2 additions & 0 deletions docs/api/cassandra/cluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@

.. automethod:: set_max_connections_per_host

.. automethod:: get_control_connection_host

.. automethod:: refresh_schema_metadata

.. automethod:: refresh_keyspace_metadata
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/standard/test_control_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def setUp(self):
"Native protocol 3,0+ is required for UDTs using %r"
% (PROTOCOL_VERSION,))
self.cluster = Cluster(protocol_version=PROTOCOL_VERSION)
self.session = self.cluster.connect()

def tearDown(self):
try:
Expand All @@ -65,6 +64,7 @@ def test_drop_keyspace(self):
@test_category connection
"""

self.session = self.cluster.connect()
self.session.execute("""
CREATE KEYSPACE keyspacetodrop
WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1' }
Expand All @@ -76,3 +76,18 @@ def test_drop_keyspace(self):
self.session.execute("DROP KEYSPACE keyspacetodrop")
cc_id_post_drop = id(self.cluster.control_connection._connection)
self.assertEqual(cc_id_post_drop, cc_id_pre_drop)

def test_get_control_connection_host(self):
"""
Test to validate Cluster.get_control_connection_host() metadata
"""

host = self.cluster.get_control_connection_host()
self.assertEqual(host, None)

self.session = self.cluster.connect()
cc_host = self.cluster.control_connection._connection.host

host = self.cluster.get_control_connection_host()
self.assertEqual(host.address, cc_host)
self.assertEqual(host.is_up, True)