Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'pg_receivexlog_installed': True,
'pg_receivexlog_compatible': True,
'pg_receivexlog_synchronous': False,
'pg_receivexlog_path': 'fake/path'
}
archiver.receive_wal()
# Test: general failure executing pg_receivexlog
with pytest.raises(ArchiverFailure):
remote_mock.return_value = {
'pg_receivexlog_installed': True,
'pg_receivexlog_compatible': True,
'pg_receivexlog_synchronous': False,
'pg_receivexlog_path': 'fake/path'
}
receivexlog_mock.return_value.execute.side_effect = \
CommandFailedException
archiver.receive_wal()
start_time.strftime('%Y-%m-%d %H:%M:%S %Z')
)
backup_manager.executor.backup(backup_info)
out, err = capsys.readouterr()
gpb_mock.assert_called_once_with(backup_info.backup_id)
assert err == ''
assert 'Starting backup copy via pg_basebackup' in out
assert 'Copy done' in out
assert 'Finalising the backup.' in out
assert backup_info.end_xlog == '0/12000090'
assert backup_info.end_offset == 144
assert backup_info.begin_time == start_time
assert backup_info.begin_wal == '000000010000000000000040'
# Check the CommandFailedException re raising
with pytest.raises(CommandFailedException):
pbc_mock.side_effect = CommandFailedException('test')
backup_manager.executor.backup(backup_info)
)
backup_manager.executor.backup(backup_info)
out, err = capsys.readouterr()
gpb_mock.assert_called_once_with(backup_info.backup_id)
assert err == ''
assert 'Starting backup copy via pg_basebackup' in out
assert 'Copy done' in out
assert 'Finalising the backup.' in out
assert backup_info.end_xlog == '0/12000090'
assert backup_info.end_offset == 144
assert backup_info.begin_time == start_time
assert backup_info.begin_wal == '000000010000000000000040'
# Check the CommandFailedException re raising
with pytest.raises(CommandFailedException):
pbc_mock.side_effect = CommandFailedException('test')
backup_manager.executor.backup(backup_info)
# is executable and runs without errors.
for path_entry in path.split(os.path.pathsep):
for cmd in cls.COMMAND_ALTERNATIVES:
full_path = barman.utils.which(cmd, path_entry)
# It doesn't exist try another
if not full_path:
continue
# It exists, let's try invoking it with `--version` to check if
# it's real or not.
try:
command = Command(full_path, path=path, check=True)
command("--version")
return command
except CommandFailedException:
# It's only a inactive shim
continue
# We don't have such a command
raise CommandFailedException(
'command not in PATH, tried: %s' %
' '.join(cls.COMMAND_ALTERNATIVES))
Gathered information should be used for support and problems detection
:param dict(str,barman.server.Server) servers: list of configured servers
:param list errors_list: list of global errors
"""
# global section. info about barman server
diagnosis = {'global': {}, 'servers': {}}
# barman global config
diagnosis['global']['config'] = dict(barman.__config__._global_config)
diagnosis['global']['config']['errors_list'] = errors_list
try:
command = fs.UnixLocalCommand()
# basic system info
diagnosis['global']['system_info'] = command.get_system_info()
except CommandFailedException as e:
diagnosis['global']['system_info'] = {'error': repr(e)}
diagnosis['global']['system_info']['barman_ver'] = barman.__version__
diagnosis['global']['system_info']['timestamp'] = datetime.datetime.now()
# per server section
for name in sorted(servers):
server = servers[name]
if server is None:
output.error("Unknown server '%s'" % name)
continue
# server configuration
diagnosis['servers'][name] = {}
diagnosis['servers'][name]['config'] = vars(server.config)
del diagnosis['servers'][name]['config']['config']
# server system info
if server.config.ssh_command:
try:
def decompress(self, src, dst):
"""
Decompress using the object defined in the sublcass
:param src: source file to decompress
:param dst: destination of the decompression
"""
try:
with closing(self._decompressor(src)) as istream:
with open(dst, 'wb') as ostream:
shutil.copyfileobj(istream, ostream)
except Exception as e:
# you won't get more information from the compressors anyway
raise CommandFailedException(dict(
ret=None, err=force_str(e), out=None))
return 0
'/postmaster.pid',
'/recovery.conf',
'/tablespace_map',
],
exclude_and_protect=exclude_and_protect,
item_class=controller.PGDATA_CLASS
)
# TODO: Manage different location for configuration files
# TODO: that were not within the data directory
# Execute the copy
try:
controller.copy()
# TODO: Improve the exception output
except CommandFailedException as e:
msg = "data transfer failure"
raise DataTransferFailure.from_command_error(
'rsync', e, msg)
def check_return_value(self, allowed_retval):
"""
Check the current return code and raise CommandFailedException when
it's not in the allowed_retval list
:param list[int] allowed_retval: list of return values considered
success
:raises: CommandFailedException
"""
if self.ret not in allowed_retval:
raise CommandFailedException(dict(
ret=self.ret, out=self.out, err=self.err))
"""
class SyncToBeDeleted(SyncException):
"""
An incomplete backup is to be deleted
"""
class CommandFailedException(CommandException):
"""
Exception representing a failed command
"""
class CommandMaxRetryExceeded(CommandFailedException):
"""
A command with retry_times > 0 has exceeded the number of available retry
"""
class RsyncListFilesFailure(CommandException):
"""
Failure parsing the output of a "rsync --list-only" command
"""
class DataTransferFailure(CommandException):
"""
Used to pass failure details from a data transfer Command
"""