From 84c574e1ecbdec11f860a11eed675f6789a698db Mon Sep 17 00:00:00 2001 From: Waynerv Date: Fri, 21 Jul 2023 20:30:22 +0800 Subject: [PATCH] Run archive_command through shell (#2766) Close #2764 --- patroni/postgresql/rewind.py | 2 +- tests/test_rewind.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/patroni/postgresql/rewind.py b/patroni/postgresql/rewind.py index f70ad065..ff6fc751 100644 --- a/patroni/postgresql/rewind.py +++ b/patroni/postgresql/rewind.py @@ -370,7 +370,7 @@ class Rewind(object): # it is the author of archive_command, who is responsible # for not overriding the WALs already present in archive logger.info('Trying to archive %s: %s', wal, cmd) - if self._postgresql.cancellable.call(shlex.split(cmd)) == 0: + if self._postgresql.cancellable.call([cmd], shell=True) == 0: new_name = os.path.join(status_dir, wal + '.done') try: shutil.move(old_name, new_name) diff --git a/tests/test_rewind.py b/tests/test_rewind.py index b5858d8e..a4fafcff 100644 --- a/tests/test_rewind.py +++ b/tests/test_rewind.py @@ -239,7 +239,7 @@ class TestRewind(BaseTestPostgresql): with patch('os.listdir', Mock(return_value=['000000000000000000000000.ready'])): # successful archive_command call - with patch.object(CancellableSubprocess, 'call', Mock(return_value=0)): + with patch.object(CancellableSubprocess, 'call', Mock(return_value=0)) as mock_subprocess_call: get_guc_value_res = [ 'on', 'command %f', 'always', 'command %f', @@ -252,6 +252,10 @@ class TestRewind(BaseTestPostgresql): '000000000000000000000000', 'command 000000000000000000000000'), mock_logger_info.call_args[0]) mock_logger_info.reset_mock() + mock_subprocess_call.assert_called_once() + self.assertEqual(mock_subprocess_call.call_args.args[0], ['command 000000000000000000000000']) + self.assertEqual(mock_subprocess_call.call_args.kwargs['shell'], True) + mock_subprocess_call.reset_mock() # failed archive_command call with patch.object(CancellableSubprocess, 'call', Mock(return_value=1)):