From a9915fb3c9e4a06e05c7215e5904cc322ed1fff6 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 7 Aug 2020 09:36:56 +0200 Subject: [PATCH] Explicitly disallow patching non-existent config (#1639) For DCS other than `kubernetes` it was failing with exception due to the `cluster.config` being `None`, but on Kubernetes it was happily creating the config annotation and preventing writing bootstrap configuration after the bootstrap finished. --- patroni/api.py | 2 ++ tests/test_api.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/patroni/api.py b/patroni/api.py index a9a286ec..bd3ece9b 100644 --- a/patroni/api.py +++ b/patroni/api.py @@ -196,6 +196,8 @@ class RestApiHandler(BaseHTTPRequestHandler): request = self._read_json_content() if request: cluster = self.server.patroni.dcs.get_cluster() + if not (cluster.config and cluster.config.modify_index): + return self.send_error(503) data = cluster.config.data.copy() if patch_config(data, request): value = json.dumps(data, separators=(',', ':')) diff --git a/tests/test_api.py b/tests/test_api.py index bc68cb30..a8723565 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -250,6 +250,8 @@ class TestRestApiHandler(unittest.TestCase): MockRestApiServer(RestApiHandler, request) mock_dcs.set_config_value.return_value = False MockRestApiServer(RestApiHandler, request) + mock_dcs.get_cluster.return_value.config = None + MockRestApiServer(RestApiHandler, request) @patch.object(MockPatroni, 'dcs') def test_do_PUT_config(self, mock_dcs):