From d9102d27038536eeda38c85af03ff31ea64fedc8 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Mon, 8 Aug 2016 16:15:57 +0200 Subject: [PATCH] Remove the necessity of creating a RESTAPI object. - We don't want to export RestApi object, since it initializes the socket and listens on it. - Change get_dcs, so that the explicit scope passed to it will take priority over the one in the configuration file. --- patroni/ctl.py | 16 ++++++++++------ tests/test_ctl.py | 4 ---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/patroni/ctl.py b/patroni/ctl.py index f6fedfc3..e8797989 100644 --- a/patroni/ctl.py +++ b/patroni/ctl.py @@ -20,7 +20,7 @@ import yaml from click import ClickException from patroni.config import Config from patroni.dcs import get_dcs as _get_dcs -from patroni.exceptions import PatroniException, DCSError +from patroni.exceptions import PatroniException from patroni.postgresql import Postgresql, get_conn_kwargs from patroni.api import RestApiServer from prettytable import PrettyTable @@ -106,7 +106,7 @@ def ctl(ctx): def get_dcs(config, scope): - config.setdefault('scope', scope) + config['scope'] = scope config.setdefault('name', scope) try: return _get_dcs(config) @@ -654,10 +654,15 @@ def touch_member(config, dcs): p.set_state('running') p.set_role('master') - api = RestApiServer(None, config['restapi']) + def restapi_connection_string(config): + protocol = 'https' if config.get('certfile') else 'http' + connect_address = config.get('connect_address') + listen = config['listen'] + return '{0}://{1}/patroni'.format(protocol, connect_address or listen) + data = { 'conn_url': p.connection_string, - 'api_url': api.connection_string, + 'api_url': restapi_connection_string(config['restapi']), 'state': p.state, 'role': p.role } @@ -671,8 +676,7 @@ def set_defaults(config, cluster_name): config['postgresql'].setdefault('scope', cluster_name) config['postgresql'].setdefault('listen', '127.0.0.1') config['postgresql']['authentication'] = {'replication': None} - config['restapi']['listen'] = (config['restapi']['listen'] - if ':' in config['restapi'].get('listen', ".") else '127.0.0.1:5432') + config['restapi']['listen'] = ':' in config['restapi']['listen'] and config['restapi']['listen'] or '127.0.0.1:8008' @ctl.command('scaffold', help='Create a structure for the cluster in DCS') diff --git a/tests/test_ctl.py b/tests/test_ctl.py index 270dff1f..3c6cf2c0 100644 --- a/tests/test_ctl.py +++ b/tests/test_ctl.py @@ -309,10 +309,6 @@ class TestCtl(unittest.TestCase): mock_get_dcs.return_value.touch_member = Mock(return_value=True) mock_get_dcs.return_value.attempt_to_acquire_leader = Mock(return_value=True) - RestApiServer._BaseServer__is_shut_down = Mock() - RestApiServer._BaseServer__shutdown_request = True - RestApiServer.socket = 0 - with patch.object(self.e, 'initialize', return_value=False): result = self.runner.invoke(ctl, ['scaffold', 'alpha']) assert result.exception