From e9be5e846290a7bdaaebdda4e5b3f97c9f15252f Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Thu, 9 Jun 2016 11:40:10 +0200 Subject: [PATCH] Configure exhibitor port via ENV --- docs/ENVIRONMENT.rst | 1 + patroni/config.py | 12 +++++++----- tests/test_config.py | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/ENVIRONMENT.rst b/docs/ENVIRONMENT.rst index 70aae806..d5ea6c1e 100644 --- a/docs/ENVIRONMENT.rst +++ b/docs/ENVIRONMENT.rst @@ -31,6 +31,7 @@ Etcd Exhibitor --------- - **PATRONI\_EXHIBITOR\_HOSTS**: initial list of Exhibitor (ZooKeeper) nodes in format: ['host1', 'host2', 'etc...' ]. This list updates automatically whenever the Exhibitor (ZooKeeper) cluster topology changes. +- **PATRONI\_EXHIBITOR\_PORT**: Exhibitor port. PostgreSQL ---------- diff --git a/patroni/config.py b/patroni/config.py index e4a4b390..07fd508f 100644 --- a/patroni/config.py +++ b/patroni/config.py @@ -8,7 +8,7 @@ from collections import defaultdict from copy import deepcopy from patroni.dcs import ClusterConfig from patroni.postgresql import Postgresql -from patroni.utils import deep_compare, patch_config +from patroni.utils import deep_compare, parse_int, patch_config logger = logging.getLogger(__name__) @@ -219,10 +219,13 @@ class Config(object): if param.startswith('PATRONI_'): name, suffix = (param[8:].rsplit('_', 1) + [''])[:2] if name and suffix: - # PATRONI_(ETCD|CONSUL|ZOOKEEPER|...)_HOSTS? - if suffix in ('HOST', 'HOSTS') and '_' not in name: + # PATRONI_(ETCD|CONSUL|ZOOKEEPER|EXHIBITOR|...)_(HOSTS?|PORT) + if suffix in ('HOST', 'HOSTS', 'PORT') and '_' not in name: value = os.environ.pop(param) - value = value if suffix == 'HOST' else value and _parse_list(value) + if suffix == 'PORT': + value = value and parse_int(value) + elif suffix == 'HOSTS': + value = value and _parse_list(value) if value: ret[name.lower()][suffix.lower()] = value # PATRONI__PASSWORD=, PATRONI__OPTIONS= @@ -252,7 +255,6 @@ class Config(object): elif name not in config: config[name] = deepcopy(value) if value else {} - # restapi server expects to get restapi.auth = 'username:password' if 'authentication' in config['restapi']: restapi = config['restapi'] diff --git a/tests/test_config.py b/tests/test_config.py index d85d4f3a..e6d212d6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -36,6 +36,8 @@ class TestConfig(unittest.TestCase): 'PATRONI_ETCD_HOST': '127.0.0.1:2379', 'PATRONI_CONSUL_HOST': '127.0.0.1:8500', 'PATRONI_ZOOKEEPER_HOSTS': 'host1,host2', + 'PATRONI_EXHIBITOR_HOSTS': 'host1,host2', + 'PATRONI_EXHIBITOR_PORT': '8181', 'PATRONI_foo_HOSTS': '[host1,host2', # Exception in parse_list 'PATRONI_SUPERUSER_USERNAME': 'postgres', 'PATRONI_SUPERUSER_PASSWORD': 'zalando',