* GET /config was returning latesy "correct" version of dynamic
  configuration.
* PATCH /config was breaking when trying to patch not dict with dict
This commit is contained in:
Alexander Kukushkin
2016-06-10 12:35:04 +02:00
parent 19037daa05
commit 9ecff0f64d
3 changed files with 16 additions and 6 deletions
+5 -1
View File
@@ -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:
+5 -1
View File
@@ -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
+6 -4
View File
@@ -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)