mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Chack if candidate is the same as the leader specified in api
This commit is contained in:
@@ -1038,6 +1038,9 @@ class RestApiHandler(BaseHTTPRequestHandler):
|
||||
logger.warning('received failover request with leader specifed - performing switchover')
|
||||
action = 'switchover'
|
||||
|
||||
if not data and leader == candidate:
|
||||
data = 'Switchover target and source are the same'
|
||||
|
||||
if not data and not scheduled_at:
|
||||
data = self.is_failover_possible(cluster, leader, candidate, action)
|
||||
if data:
|
||||
|
||||
+6
-1
@@ -526,7 +526,6 @@ class TestRestApiHandler(unittest.TestCase):
|
||||
response_mock.assert_called_with(
|
||||
400, 'Switchover is possible only to a specific candidate in a paused state')
|
||||
|
||||
# Switchover without a candidate specified
|
||||
# No healthy nodes to promote in both sync and async mode
|
||||
for is_synchronous_mode, response in (
|
||||
(True, 'switchover is not possible: can not find sync_standby'),
|
||||
@@ -538,6 +537,12 @@ class TestRestApiHandler(unittest.TestCase):
|
||||
|
||||
# [Switchover to the candidate specified]
|
||||
|
||||
# Candidate to promote is the same as the leader specified
|
||||
with patch.object(RestApiHandler, 'write_response') as response_mock:
|
||||
request = post + '53\n\n{"leader": "postgresql2", "candidate": "postgresql2"}'
|
||||
MockRestApiServer(RestApiHandler, request)
|
||||
response_mock.assert_called_with(400, 'Switchover target and source are the same')
|
||||
|
||||
# Current leader is different from the one specified
|
||||
with patch.object(RestApiHandler, 'write_response') as response_mock:
|
||||
cluster.leader.name = 'postgresql2'
|
||||
|
||||
Reference in New Issue
Block a user