mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Log pg_basebackup command in DEBUG level (#3045)
This commit is contained in:
@@ -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:
|
||||
|
||||
+13
-2
@@ -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'}]})
|
||||
|
||||
Reference in New Issue
Block a user