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.
This commit is contained in:
Oleksii Kliukin
2016-08-08 16:15:57 +02:00
parent 53f991df0f
commit d9102d2703
2 changed files with 10 additions and 10 deletions
+10 -6
View File
@@ -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')
-4
View File
@@ -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