From 9ecff0f64d25ddbb9426423b692f6382c49867a5 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 10 Jun 2016 12:35:04 +0200 Subject: [PATCH] Bugfixes * GET /config was returning latesy "correct" version of dynamic configuration. * PATCH /config was breaking when trying to patch not dict with dict --- patroni/api.py | 6 +++++- patroni/utils.py | 6 +++++- tests/test_api.py | 10 ++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/patroni/api.py b/patroni/api.py index 420067ca..7000fc2f 100644 --- a/patroni/api.py +++ b/patroni/api.py @@ -106,7 +106,11 @@ class RestApiHandler(BaseHTTPRequestHandler): self._write_status_response(200, response) def do_GET_config(self): - self._write_json_response(200, self.server.patroni.config.dynamic_configuration) + cluster = self.server.patroni.ha.dcs.cluster or self.server.patroni.ha.dcs.get_cluster() + if cluster.config: + self._write_json_response(200, cluster.config.data) + else: + self.send_error(502) def _read_json_content(self): if 'content-length' not in self.headers: diff --git a/patroni/utils.py b/patroni/utils.py index 9c63c768..13869098 100644 --- a/patroni/utils.py +++ b/patroni/utils.py @@ -70,7 +70,11 @@ def patch_config(config, data): is_changed = True elif name in config: if isinstance(value, dict): - if patch_config(config[name], value): + if isinstance(config[name], dict): + if patch_config(config[name], value): + is_changed = True + else: + config[name] = value is_changed = True elif str(config[name]) != str(value): config[name] = value diff --git a/tests/test_api.py b/tests/test_api.py index 079fa7f7..8483299b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -118,9 +118,11 @@ class TestRestApiHandler(unittest.TestCase): self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'POST /restart HTTP/1.0')) MockRestApiServer(RestApiHandler, 'POST /restart HTTP/1.0\nAuthorization:') - @patch.object(MockPatroni, 'config') - def test_do_GET_config(self, mock_config): - mock_config.dynamic_configuration = {} + @patch.object(MockHa, 'dcs') + def test_do_GET_config(self, mock_dcs): + mock_dcs.cluster.config.data = {} + self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /config')) + mock_dcs.cluster.config = None self.assertIsNotNone(MockRestApiServer(RestApiHandler, 'GET /config')) @patch.object(MockHa, 'dcs') @@ -132,7 +134,7 @@ class TestRestApiHandler(unittest.TestCase): request += '\nContent-Length: ' self.assertIsNotNone(MockRestApiServer(RestApiHandler, request + '34\n\n{"postgresql":{"use_slots":false}}')) config['ttl'] = 5 - config['postgresql'].update({'use_slots': True, "parameters": None}) + config['postgresql'].update({'use_slots': {'foo': True}, "parameters": None}) config = json.dumps(config) request += str(len(config)) + '\n\n' + config MockRestApiServer(RestApiHandler, request)