diff --git a/patroni/ha.py b/patroni/ha.py index 5894824c..59c57565 100644 --- a/patroni/ha.py +++ b/patroni/ha.py @@ -56,7 +56,7 @@ class _MemberStatus(NamedTuple): # If one of those is not in a response we want to count the node as not healthy/reachable wal: Dict[str, Any] = json.get('wal') or json['xlog'] # abuse difference in primary/replica response format - in_recovery = not bool(wal.get('location')) or json.get('role') in ('master', 'primary') + in_recovery = not (bool(wal.get('location')) or json.get('role') in ('master', 'primary')) timeline = json.get('timeline', 0) dcs_last_seen = json.get('dcs_last_seen', 0) lsn = int(in_recovery and max(wal.get('received_location', 0), wal.get('replayed_location', 0))) diff --git a/tests/test_ha.py b/tests/test_ha.py index 005e922e..7cdb00e1 100644 --- a/tests/test_ha.py +++ b/tests/test_ha.py @@ -885,7 +885,10 @@ class TestHa(PostgresInit): member = Member(0, 'test', 1, {'api_url': 'http://127.0.0.1:8011/patroni'}) self.ha.fetch_node_status(member) member = Member(0, 'test', 1, {'api_url': 'http://localhost:8011/patroni'}) - self.ha.fetch_node_status(member) + self.ha.patroni.request = Mock() + self.ha.patroni.request.return_value.data = b'{"wal":{"location":1},"role":"primary"}' + ret = self.ha.fetch_node_status(member) + self.assertFalse(ret.in_recovery) @patch.object(Rewind, 'pg_rewind', true) @patch.object(Rewind, 'check_leader_is_not_in_recovery', true)