Skip to content

Commit ab43b49

Browse files
author
avandras
committed
Pick changes manually that were missed during cherry picking
1 parent d49c0ba commit ab43b49

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

patroni/api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def do_GET_patroni(self) -> None:
477477
Postgres.
478478
"""
479479
response = self.get_postgresql_status(True)
480+
response.pop('latest_end_lsn', None)
480481
self._write_status_response(200, response)
481482

482483
def do_GET_cluster(self) -> None:
@@ -1299,12 +1300,10 @@ def get_postgresql_status(self, retry: bool = False) -> Dict[str, Any]:
12991300
13001301
:returns: a dict with the status of Postgres/Patroni. The keys are:
13011302
1302-
* ``state``: Postgres state among ``stopping``, ``stopped``, ``stop failed``, ``crashed``, ``running``,
1303-
``starting``, ``start failed``, ``restarting``, ``restart failed``, ``initializing new cluster``,
1304-
``initdb failed``, ``running custom bootstrap script``, ``starting after custom bootstrap``,
1305-
``custom bootstrap failed``, ``creating replica``, or ``unknown``;
1303+
* ``state``: one of :class:`~patroni.postgresql.misc.PostgresqlState` or ``unknown``;
13061304
* ``postmaster_start_time``: ``pg_postmaster_start_time()``;
1307-
* ``role``: ``replica`` or ``primary`` based on ``pg_is_in_recovery()`` output;
1305+
* ``role``: :class:`~patroni.postgresql.misc.PostgresqlRole.REPLICA` or
1306+
:class:`~patroni.postgresql.misc.PostgresqlRole.PRIMARY` based on ``pg_is_in_recovery()`` output;
13081307
* ``server_version``: Postgres version without periods, e.g. ``150002`` for Postgres ``15.2``;
13091308
* ``latest_end_lsn``: latest_end_lsn value from ``pg_stat_get_wal_receiver()``, only on replica nodes;
13101309
* ``xlog``: dictionary. Its structure depends on ``role``:

tests/test_api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
import etcd
32
import json
43
import socket
54
import unittest
@@ -20,6 +19,7 @@
2019
from patroni.utils import RetryFailedError, tzutc
2120

2221
from . import MockConnect, psycopg_connect
22+
from .test_etcd import socket_getaddrinfo
2323
from .test_ha import get_cluster_initialized_without_leader
2424

2525
future_restart_time = datetime.datetime.now(tzutc) + datetime.timedelta(days=5)
@@ -34,7 +34,7 @@ def get(*args):
3434

3535
@staticmethod
3636
def query(sql, *params):
37-
return [(postmaster_start_time, 0, '', 0, '', False, postmaster_start_time, 'streaming', None,
37+
return [(postmaster_start_time, 0, '', 0, '', False, postmaster_start_time, 1, 'streaming', None, 0,
3838
'[{"application_name":"walreceiver","client_addr":"1.2.3.4",'
3939
+ '"state":"streaming","sync_state":"async","sync_priority":0}]')]
4040

@@ -245,7 +245,8 @@ def test_do_GET(self):
245245
with patch.object(MockHa, 'restart_scheduled', Mock(return_value=True)):
246246
MockRestApiServer(RestApiHandler, 'GET /primary')
247247
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /primary'))
248-
with patch.object(RestApiServer, 'query', Mock(return_value=[('', 1, '', '', '', '', False, None, None, '')])):
248+
with patch.object(RestApiServer, 'query',
249+
Mock(return_value=[('', 1, '', '', '', '', False, None, 0, None, 0, '')])):
249250
self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /patroni'))
250251
with patch.object(global_config.__class__, 'is_standby_cluster', Mock(return_value=True)), \
251252
patch.object(global_config.__class__, 'is_paused', Mock(return_value=True)):
@@ -719,6 +720,7 @@ def test_reload_config(self):
719720
patch.object(MockRestApiServer, 'server_close', Mock()):
720721
self.srv.reload_config({'listen': ':8008'})
721722

723+
@patch('socket.getaddrinfo', socket_getaddrinfo)
722724
@patch.object(MockPatroni, 'dcs')
723725
def test_check_access(self, mock_dcs):
724726
mock_dcs.cluster = get_cluster_initialized_without_leader()

0 commit comments

Comments
 (0)