Chack if candidate is the same as the leader specified in api

This commit is contained in:
Polina Bungina
2023-08-09 12:34:53 +02:00
parent 3c1f2ff7a4
commit 01830ecbd1
2 changed files with 9 additions and 1 deletions
+3
View File
@@ -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
View File
@@ -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'