mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
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:
@@ -196,6 +196,8 @@ class RestApiHandler(BaseHTTPRequestHandler):
|
|||||||
request = self._read_json_content()
|
request = self._read_json_content()
|
||||||
if request:
|
if request:
|
||||||
cluster = self.server.patroni.dcs.get_cluster()
|
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()
|
data = cluster.config.data.copy()
|
||||||
if patch_config(data, request):
|
if patch_config(data, request):
|
||||||
value = json.dumps(data, separators=(',', ':'))
|
value = json.dumps(data, separators=(',', ':'))
|
||||||
|
|||||||
@@ -250,6 +250,8 @@ class TestRestApiHandler(unittest.TestCase):
|
|||||||
MockRestApiServer(RestApiHandler, request)
|
MockRestApiServer(RestApiHandler, request)
|
||||||
mock_dcs.set_config_value.return_value = False
|
mock_dcs.set_config_value.return_value = False
|
||||||
MockRestApiServer(RestApiHandler, request)
|
MockRestApiServer(RestApiHandler, request)
|
||||||
|
mock_dcs.get_cluster.return_value.config = None
|
||||||
|
MockRestApiServer(RestApiHandler, request)
|
||||||
|
|
||||||
@patch.object(MockPatroni, 'dcs')
|
@patch.object(MockPatroni, 'dcs')
|
||||||
def test_do_PUT_config(self, mock_dcs):
|
def test_do_PUT_config(self, mock_dcs):
|
||||||
|
|||||||
Reference in New Issue
Block a user