Skip to content

Commit

Permalink
Bugfix: failover via API didn't work due to change in _MemberStatus
Browse files Browse the repository at this point in the history
Originally fetch_nodes_statuses was returning a tuple, later it was
wrapped into namedtuple _MemberStatus and recently _MemberStatus was
extened with watchdog_failed field, but api.py was still relying on
usual tuple and checking failover limitations on it's own instead of
calling `failover_limitation` method.
  • Loading branch information
Alexander Kukushkin committed Jul 28, 2017
1 parent 895e468 commit 4730df1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions patroni/api.py
Expand Up @@ -300,8 +300,8 @@ def is_failover_possible(self, cluster, leader, candidate):
members = [m for m in cluster.members if m.name != cluster.leader.name and m.api_url]
if not members:
return 'failover is not possible: cluster does not have members except leader'
for _, reachable, _, _, tags in self.server.patroni.ha.fetch_nodes_statuses(members):
if reachable and not tags.get('nofailover', False):
for st in self.server.patroni.ha.fetch_nodes_statuses(members):
if st.failover_limitation() is None:
return None
return 'failover is not possible: no good candidates have been found'

Expand Down
1 change: 1 addition & 0 deletions patroni/ha.py
Expand Up @@ -26,6 +26,7 @@ class _MemberStatus(namedtuple('_MemberStatus', 'member,reachable,in_recovery,wa
in_recovery - `!True` if pg_is_in_recovery() == true
wal_position - value of `replayed_location` or `location` from JSON, dependin on its role.
tags - dictionary with values of different tags (i.e. nofailover)
watchdog_failed - indicates that watchdog is required by configuration but not available or failed
"""
@classmethod
def from_api_response(cls, member, json):
Expand Down
2 changes: 1 addition & 1 deletion patroni/version.py
@@ -1 +1 @@
__version__ = '1.3'
__version__ = '1.3.1'
5 changes: 3 additions & 2 deletions tests/test_api.py
Expand Up @@ -6,6 +6,7 @@
from mock import Mock, patch
from patroni.api import RestApiHandler, RestApiServer
from patroni.dcs import ClusterConfig, Member
from patroni.ha import _MemberStatus
from patroni.utils import tzutc
from six import BytesIO as IO
from six.moves import BaseHTTPServer
Expand Down Expand Up @@ -38,7 +39,7 @@ def postmaster_start_time():


class MockWatchdog(object):
is_healthy = True
is_healthy = False


class MockHa(object):
Expand All @@ -64,7 +65,7 @@ def delete_future_restart():

@staticmethod
def fetch_nodes_statuses(members):
return [[None, True, None, None, {}]]
return [_MemberStatus(None, True, None, None, {}, False)]

@staticmethod
def schedule_future_restart(data):
Expand Down

0 comments on commit 4730df1

Please sign in to comment.