Skip to content

Commit

Permalink
Unify Patroni and Patronictl configuration
Browse files Browse the repository at this point in the history
A Patroni configuration should be enough for Patronictl
The previous dcs_api url style is still supported.
  • Loading branch information
feikesteenbergen committed Apr 22, 2016
1 parent fbf44d3 commit dd61692
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions patroni/ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PatroniCtlException(ClickException):
def parse_dcs(dcs):
"""
Break up the provided dcs string
>>> parse_dcs(None)
>>> parse_dcs('localhost') == {'etcd': {'host': 'localhost:4001'}}
True
>>> parse_dcs('localhost:8500') == {'consul': {'host': 'localhost:8500'}}
Expand All @@ -44,7 +45,7 @@ def parse_dcs(dcs):
"""

if not dcs:
return {}
return None

parsed = urlparse(dcs)
scheme = parsed.scheme
Expand Down Expand Up @@ -80,8 +81,10 @@ def load_config(path, dcs):

if dcs:
config['dcs'] = parse_dcs(dcs)
elif 'dcs_api' in config:
config['dcs'] = parse_dcs(config['dcs_api'])
else:
config['dcs'] = parse_dcs(config.get('dcs_api'))
config = {'dcs': config}

return config

Expand Down
2 changes: 2 additions & 0 deletions tests/test_ctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_rw_config():
load_config(CONFIG_FILE_PATH, None)
load_config(CONFIG_FILE_PATH, '0.0.0.0')

store_config({'dcs_api': None}, CONFIG_FILE_PATH)
load_config(CONFIG_FILE_PATH, None)

@patch('patroni.ctl.load_config', Mock(return_value={'dcs': {'etcd': {'host': 'localhost:4001'}}}))
class TestCtl(unittest.TestCase):
Expand Down

0 comments on commit dd61692

Please sign in to comment.