diff --git a/patroni/postgresql/bootstrap.py b/patroni/postgresql/bootstrap.py index 779410c1..0f3c4ba5 100644 --- a/patroni/postgresql/bootstrap.py +++ b/patroni/postgresql/bootstrap.py @@ -334,6 +334,13 @@ class Bootstrap(object): not_allowed_options = ('pgdata', 'format', 'wal-method', 'xlog-method', 'gzip', 'version', 'compress', 'dbname', 'host', 'port', 'username', 'password') user_options = self.process_user_options('basebackup', options, not_allowed_options, logger.error) + cmd = [ + self._postgresql.pgcommand("pg_basebackup"), + "--pgdata=" + self._postgresql.data_dir, + "-X", + "stream", + "--dbname=" + conn_url, + ] + user_options for bbfailures in range(0, maxfailures): if self._postgresql.cancellable.is_cancelled: @@ -341,9 +348,8 @@ class Bootstrap(object): if not self._postgresql.data_directory_empty(): self._postgresql.remove_data_directory() try: - ret = self._postgresql.cancellable.call([self._postgresql.pgcommand('pg_basebackup'), - '--pgdata=' + self._postgresql.data_dir, '-X', 'stream', - '--dbname=' + conn_url] + user_options, env=env) + logger.debug('calling: %r', cmd) + ret = self._postgresql.cancellable.call(cmd, env=env) if ret == 0: break else: diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 9a7622c0..eaedc705 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -92,9 +92,20 @@ class TestBootstrap(BaseTestPostgresql): mock_cancellable_subprocess_call.return_value = 1 self.assertEqual(self.b.create_replica(self.leader), 1) + @patch.object(CancellableSubprocess, 'call', Mock(return_value=0)) + @patch.object(Postgresql, 'data_directory_empty', Mock(return_value=True)) def test_basebackup(self): - self.p.cancellable.cancel() - self.b.basebackup(None, None, {'foo': 'bar'}) + with patch('patroni.postgresql.bootstrap.logger.debug') as mock_debug: + self.p.cancellable.cancel() + self.b.basebackup("", None, {'foo': 'bar'}) + mock_debug.assert_not_called() + + self.p.cancellable.reset_is_cancelled() + self.b.basebackup("", None, {'foo': 'bar'}) + mock_debug.assert_called_with( + 'calling: %r', + ['pg_basebackup', f'--pgdata={self.p.data_dir}', '-X', 'stream', '--dbname=', '--foo=bar'], + ) def test__initdb(self): self.assertRaises(Exception, self.b.bootstrap, {'initdb': [{'pgdata': 'bar'}]})