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.
This commit is contained in:
Alexander Kukushkin
2020-08-07 09:36:56 +02:00
committed by GitHub
parent f1c6b0bebe
commit a9915fb3c9
2 changed files with 4 additions and 0 deletions
+2
View File
@@ -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=(',', ':'))
+2
View File
@@ -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):