diff --git a/features/patroni_api.feature b/features/patroni_api.feature index b9199b00..3febb376 100644 --- a/features/patroni_api.feature +++ b/features/patroni_api.feature @@ -66,7 +66,7 @@ Scenario: check the failover via the API Given I run patronictl.py failover batman --master postgres0 --candidate postgres1 --force Then I receive a response returncode 0 And postgres1 is a leader after 5 seconds - And postgres1 role is the primary after 5 seconds + And postgres1 role is the primary after 10 seconds And postgres0 role is the secondary after 10 seconds And replication works from postgres1 to postgres0 after 20 seconds @@ -74,7 +74,7 @@ Scenario: check the scheduled failover Given I issue a scheduled failover from postgres1 to postgres0 in 1 seconds Then I receive a response returncode 0 And postgres0 is a leader after 20 seconds - And postgres0 role is the primary after 5 seconds + And postgres0 role is the primary after 10 seconds And postgres1 role is the secondary after 10 seconds And replication works from postgres0 to postgres1 after 25 seconds diff --git a/patroni/ctl.py b/patroni/ctl.py index 4288089a..a57c27fb 100644 --- a/patroni/ctl.py +++ b/patroni/ctl.py @@ -812,15 +812,15 @@ def flush(cluster_name, member_names, config_file, dcs, force, role, target): def toggle_pause(config_file, cluster_name, dcs, paused): config, dcs, cluster = ctl_load_config(cluster_name, config_file, dcs) if cluster.is_paused() == paused: - raise PatroniCtlException("Cluster " + ("is already" if paused else "is not") + " paused") + raise PatroniCtlException('Cluster is {0} paused'.format(paused and 'already' or 'not')) - r = request_patroni(cluster.leader.member, 'patch', 'config', {'pause': paused}, auth_header(config)) + r = request_patroni(cluster.leader.member, 'patch', 'config', {'pause': paused or None}, auth_header(config)) if r.status_code == 200: - click.echo("Success: cluster management is " + ("paused" if paused else "resumed")) + click.echo('Success: cluster management is {0}'.format(paused and 'paused' or 'resumed')) else: - click.echo("Failed: " + ("pause" if paused else "resume") - + " cluster management status code={0}, ({1})".format(r.status_code, r.text)) + click.echo('Failed: {0} cluster management status code={1}, ({2})'.format( + paused and 'pause' or 'resume', r.status_code, r.text)) @ctl.command('pause', help='Disable auto failover') diff --git a/patroni/dcs/__init__.py b/patroni/dcs/__init__.py index bbeab3c5..0c403a1c 100644 --- a/patroni/dcs/__init__.py +++ b/patroni/dcs/__init__.py @@ -229,7 +229,7 @@ class Cluster(namedtuple('Cluster', 'initialize,config,leader,last_leader_operat return candidates[randint(0, len(candidates) - 1)] if candidates else self.leader def is_paused(self): - return self.config and self.config.data.get('pause', False) + return self.config and self.config.data.get('pause', False) or False @six.add_metaclass(abc.ABCMeta) diff --git a/tests/test_patroni.py b/tests/test_patroni.py index f9f135cc..d3963a1f 100644 --- a/tests/test_patroni.py +++ b/tests/test_patroni.py @@ -54,7 +54,8 @@ class TestPatroni(unittest.TestCase): with patch.object(Patroni, 'run', Mock(side_effect=SleepException)): self.assertRaises(SleepException, _main) with patch.object(Patroni, 'run', Mock(side_effect=KeyboardInterrupt())): - _main() + with patch('patroni.ha.Ha.is_paused', Mock(return_value=True)): + _main() @patch('patroni.config.Config.save_cache', Mock()) @patch('patroni.config.Config.reload_local_configuration', Mock(return_value=True))