mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Fix bug with custom bootstrap (#2948)
Patroni was falsely applying `--command` argument. Close https://github.com/zalando/patroni/issues/2947
This commit is contained in:
@@ -188,10 +188,9 @@ class Bootstrap(object):
|
||||
params = [] if config.get('no_params') else ['--scope=' + self._postgresql.scope,
|
||||
'--datadir=' + self._postgresql.data_dir]
|
||||
# Add custom parameters specified by the user
|
||||
reserved_args = {'no_params', 'keep_existing_recovery_conf', 'recovery_conf', 'scope', 'datadir'}
|
||||
for arg, val in config.items():
|
||||
if arg not in reserved_args:
|
||||
params.append(f"--{arg}={val}")
|
||||
reserved_args = {'command', 'no_params', 'keep_existing_recovery_conf', 'recovery_conf', 'scope', 'datadir'}
|
||||
params += [f"--{arg}={val}" for arg, val in config.items() if arg not in reserved_args]
|
||||
|
||||
try:
|
||||
logger.info('Running custom bootstrap script: %s', config['command'])
|
||||
if self._postgresql.cancellable.call(shlex.split(config['command']) + params) != 0:
|
||||
|
||||
@@ -179,10 +179,17 @@ class TestBootstrap(BaseTestPostgresql):
|
||||
@patch.object(Postgresql, 'controldata', Mock(return_value={'Database cluster state': 'in production'}))
|
||||
def test_custom_bootstrap(self, mock_cancellable_subprocess_call):
|
||||
self.p.config._config.pop('pg_hba')
|
||||
config = {'method': 'foo', 'foo': {'command': 'bar'}}
|
||||
config = {'method': 'foo', 'foo': {'command': 'bar --arg1=val1'}}
|
||||
|
||||
mock_cancellable_subprocess_call.return_value = 1
|
||||
self.assertFalse(self.b.bootstrap(config))
|
||||
self.assertEqual(mock_cancellable_subprocess_call.call_args_list[0][0][0],
|
||||
['bar', '--arg1=val1', '--scope=batman', '--datadir=' + os.path.join('data', 'test0')])
|
||||
|
||||
mock_cancellable_subprocess_call.reset_mock()
|
||||
config['foo']['no_params'] = 1
|
||||
self.assertFalse(self.b.bootstrap(config))
|
||||
self.assertEqual(mock_cancellable_subprocess_call.call_args_list[0][0][0], ['bar', '--arg1=val1'])
|
||||
|
||||
mock_cancellable_subprocess_call.return_value = 0
|
||||
with patch('multiprocessing.Process', Mock(side_effect=Exception("42"))), \
|
||||
|
||||
Reference in New Issue
Block a user