Skip to content
Draft
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
18 changes: 9 additions & 9 deletions tarantool/connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
)
from tarantool.error import (
ClusterConnectWarning,
PoolTolopogyError,
PoolTolopogyWarning,
PoolTopologyError,
PoolTopologyWarning,
ConfigurationError,
NetworkError,
warn
Expand Down Expand Up @@ -294,14 +294,14 @@ def _getnext_by_mode(self, *iters, err_msg="Can't find healthy instance in pool"

:rtype: :class:`~tarantool.connection_pool.PoolUnit`

:raise: :exc:`~tarantool.error.PoolTolopogyError`
:raise: :exc:`~tarantool.error.PoolTopologyError`

:meta private:
"""
for itr in iters:
if itr is not None:
return next(itr)
raise PoolTolopogyError(err_msg)
raise PoolTopologyError(err_msg)

def getnext(self, mode):
"""
Expand All @@ -312,7 +312,7 @@ def getnext(self, mode):

:rtype: :class:`~tarantool.connection_pool.PoolUnit`

:raise: :exc:`~tarantool.error.PoolTolopogyError`
:raise: :exc:`~tarantool.error.PoolTopologyError`
"""

if self.rebuild_needed:
Expand Down Expand Up @@ -578,28 +578,28 @@ def _get_new_state(self, unit):
except NetworkError as exc:
msg = (f"Failed to get box.info for {unit.get_address()}, "
f"reason: {repr(exc)}")
warn(msg, PoolTolopogyWarning)
warn(msg, PoolTopologyWarning)
return InstanceState(Status.UNHEALTHY)

try:
read_only = resp.data[0]['ro']
except (IndexError, KeyError) as exc:
msg = (f"Incorrect box.info response from {unit.get_address()}"
f"reason: {repr(exc)}")
warn(msg, PoolTolopogyWarning)
warn(msg, PoolTopologyWarning)
return InstanceState(Status.UNHEALTHY)

try:
status = resp.data[0]['status']

if status != 'running':
msg = f"{unit.get_address()} instance status is not 'running'"
warn(msg, PoolTolopogyWarning)
warn(msg, PoolTopologyWarning)
return InstanceState(Status.UNHEALTHY)
except (IndexError, KeyError) as exc:
msg = (f"Incorrect box.info response from {unit.get_address()}"
f"reason: {repr(exc)}")
warn(msg, PoolTolopogyWarning)
warn(msg, PoolTopologyWarning)
return InstanceState(Status.UNHEALTHY)

return InstanceState(Status.HEALTHY, read_only)
Expand Down
9 changes: 7 additions & 2 deletions tarantool/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,14 @@ class ClusterConnectWarning(UserWarning):
"""


class PoolTolopogyWarning(UserWarning):
class PoolTopologyWarning(UserWarning):
"""
Warning related to unsatisfying `box.info.ro`_ state of
pool instances.
"""


class PoolTolopogyError(DatabaseError):
class PoolTopologyError(DatabaseError):
"""
Exception raised due to unsatisfying `box.info.ro`_ state of
pool instances.
Expand All @@ -325,6 +325,11 @@ class PoolTolopogyError(DatabaseError):
"""


# Backward-compatible aliases for the previously exposed misspelled names.
PoolTolopogyWarning = PoolTopologyWarning
PoolTolopogyError = PoolTopologyError


class CrudModuleError(DatabaseError):
"""
Exception raised for errors that are related to
Expand Down
14 changes: 11 additions & 3 deletions test/suites/test_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
ClusterConnectWarning,
DatabaseError,
NetworkWarning,
PoolTopologyError,
PoolTopologyWarning,
PoolTolopogyError,
PoolTolopogyWarning,
)
Expand All @@ -23,6 +25,12 @@
from .utils import assert_admin_success


class TestSuitePoolErrorAliases(unittest.TestCase): # pylint: disable=too-few-public-methods
def test_pool_topology_error_aliases(self):
self.assertIs(PoolTolopogyError, PoolTopologyError)
self.assertIs(PoolTolopogyWarning, PoolTopologyWarning)


def create_server(_id):
srv = TarantoolServer()
srv.script = 'test/suites/box.lua'
Expand Down Expand Up @@ -188,7 +196,7 @@ def get_port(self, mode):

# Expect RW to fail if there are no RW.
def expect_rw_to_fail_if_there_are_no_rw():
with self.assertRaises(PoolTolopogyError):
with self.assertRaises(PoolTopologyError):
self.pool.eval('return box.cfg.listen', mode=tarantool.Mode.RW)

self.retry(func=expect_rw_to_fail_if_there_are_no_rw)
Expand All @@ -208,7 +216,7 @@ def expect_prefer_rw_iterate_through_all_instances_if_there_are_no_rw():

# Expect RO to fail if there are no RO.
def expect_ro_to_fail_if_there_are_no_ro():
with self.assertRaises(PoolTolopogyError):
with self.assertRaises(PoolTopologyError):
self.pool.eval('return box.cfg.listen', mode=tarantool.Mode.RO)

self.retry(func=expect_ro_to_fail_if_there_are_no_ro)
Expand Down Expand Up @@ -514,7 +522,7 @@ def test_12_execute(self):

def test_13_failover(self):
warnings.simplefilter('ignore', category=NetworkWarning)
warnings.simplefilter('ignore', category=PoolTolopogyWarning)
warnings.simplefilter('ignore', category=PoolTopologyWarning)

self.set_cluster_ro([False, True, True, True, True])
self.pool = tarantool.ConnectionPool(
Expand Down