mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
A few iprovements in patronictl (#601)
* make switchover work with an old patroni * exclude leader from candidates when interactively running failover
This commit is contained in:
@@ -3,6 +3,20 @@
|
||||
Release notes
|
||||
=============
|
||||
|
||||
Version 1.4.1
|
||||
-------------
|
||||
|
||||
**Fixes in patronictl**
|
||||
|
||||
- Don't show current leader in suggested list of members to failover to. (Alexander Kukushkin)
|
||||
|
||||
patronictl failover could still work when there is leader in the cluster and it should be excluded from the list of member where it is possible to failover to.
|
||||
|
||||
- Make patronictl switchover compatible with the old Patroni api (Alexander)
|
||||
|
||||
In case if POST /switchover REST API call has failed with status code 501 it will do it once again, but to /failover endpoint.
|
||||
|
||||
|
||||
Version 1.4
|
||||
-----------
|
||||
|
||||
|
||||
+12
-8
@@ -546,15 +546,14 @@ def _do_failover_or_switchover(obj, action, cluster_name, master, candidate, for
|
||||
dcs = get_dcs(obj, cluster_name)
|
||||
cluster = dcs.get_cluster()
|
||||
|
||||
if action == 'switchover':
|
||||
if cluster.leader is None:
|
||||
raise PatroniCtlException('This cluster has no master')
|
||||
if action == 'switchover' and cluster.leader is None:
|
||||
raise PatroniCtlException('This cluster has no master')
|
||||
|
||||
if master is None:
|
||||
if force:
|
||||
master = cluster.leader.member.name
|
||||
else:
|
||||
master = click.prompt('Master', type=str, default=cluster.leader.member.name)
|
||||
if master is None:
|
||||
if force or action == 'failover':
|
||||
master = cluster.leader and cluster.leader.name
|
||||
else:
|
||||
master = click.prompt('Master', type=str, default=cluster.leader.member.name)
|
||||
|
||||
if master is not None and cluster.leader and cluster.leader.member.name != master:
|
||||
raise PatroniCtlException('Member {0} is not the leader of cluster {1}'.format(master, cluster_name))
|
||||
@@ -610,6 +609,11 @@ def _do_failover_or_switchover(obj, action, cluster_name, master, candidate, for
|
||||
member = cluster.leader.member if cluster.leader else cluster.get_member(candidate, False)
|
||||
|
||||
r = request_patroni(member, 'post', action, failover_value, auth_header(obj))
|
||||
|
||||
# probably old patroni, which doesn't support switchover yet
|
||||
if r.status_code == 501 and action == 'switchover' and 'Server does not support this operation' in r.text:
|
||||
r = request_patroni(member, 'post', 'failover', failover_value, auth_header(obj))
|
||||
|
||||
if r.status_code in (200, 202):
|
||||
logging.debug(r)
|
||||
cluster = dcs.get_cluster()
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__ = '1.4'
|
||||
__version__ = '1.4.1'
|
||||
|
||||
@@ -129,6 +129,11 @@ class TestCtl(unittest.TestCase):
|
||||
result = self.runner.invoke(ctl, ['switchover', 'dummy'], input='leader\nother\n\ny')
|
||||
assert 'Switchover failed' in result.output
|
||||
|
||||
mocked.return_value.status_code = 501
|
||||
mocked.return_value.text = 'Server does not support this operation'
|
||||
result = self.runner.invoke(ctl, ['switchover', 'dummy'], input='leader\nother\n\ny')
|
||||
assert 'Switchover failed' in result.output
|
||||
|
||||
# No members available
|
||||
mock_get_dcs.return_value.get_cluster = get_cluster_initialized_with_only_leader
|
||||
result = self.runner.invoke(ctl, ['switchover', 'dummy'], input='leader\nother\n\ny')
|
||||
|
||||
Reference in New Issue
Block a user