mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-08-06 08:13:01 +02:00
Elevate command stderr to error logs, add "--log-json" support for borgmatic logs, and log Borg output at varying log levels based on verbosities (#485, #858, #1204).
Reviewed-on: https://projects.torsion.org/borgmatic-collective/borgmatic/pulls/1207
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
2.0.14.dev0
|
||||
2.1.0.dev0
|
||||
* #485: When running commands (database clients, command hooks, etc.), elevate stderr output to
|
||||
show up as borgmatic error logs.
|
||||
* #858: With the "--log-json" flag, log borgmatic's own logs as JSON, not just Borg's.
|
||||
* #1204: When verbosity levels differ between console/monitoring/syslog/file, log Borg's output to
|
||||
each one at a different level. Previously, it was logged at the maximum level of all the
|
||||
verbosities.
|
||||
* #1208: Fix for the "restore" action incorrectly extracting more database dumps than the
|
||||
"--database" flag specifies.
|
||||
* #1210: Fix an error when running the "spot" check or "extract" action with the "progress" option
|
||||
@@ -6,6 +12,9 @@
|
||||
* #1211: Fix an error about the runtime directory getting excluded by tweaking its logic and
|
||||
lowering the error to a warning.
|
||||
* #1212: Fix an error when restoring multiple directory-format database dumps at once.
|
||||
* When syslog verbosity is enabled, log to systemd's journal (if present) with
|
||||
structured data. See the documentation for more information:
|
||||
https://torsion.org/borgmatic/reference/command-line/logging/#systemd-journal
|
||||
|
||||
2.0.13
|
||||
* #1054: Allow the Btrfs hook to create and delete snapshots even when running
|
||||
|
||||
@@ -29,7 +29,7 @@ def break_lock(
|
||||
(local_path, 'break-lock')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -32,7 +32,7 @@ def change_passphrase(
|
||||
(local_path, 'key', 'change-passphrase')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -176,7 +176,13 @@ def check_archives(
|
||||
+ make_check_name_flags(checks_subset, archive_filter_flags)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ (
|
||||
('--log-json',)
|
||||
if (
|
||||
config.get('log_json') or not (check_arguments.repair or config.get('progress'))
|
||||
)
|
||||
else ()
|
||||
)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ verbosity_flags
|
||||
+ (('--progress',) if config.get('progress') else ())
|
||||
|
||||
@@ -31,7 +31,7 @@ def compact_segments(
|
||||
(local_path, 'compact')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--progress',) if config.get('progress') else ())
|
||||
+ (('--cleanup-commits',) if cleanup_commits else ())
|
||||
|
||||
@@ -231,8 +231,8 @@ def make_base_create_command(
|
||||
+ (('--files-cache', files_cache) if files_cache else ())
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
|
||||
+ (
|
||||
('--list', '--filter', list_filter_flags)
|
||||
if config.get('list_details') and not json and not config.get('progress')
|
||||
|
||||
@@ -38,7 +38,7 @@ def make_delete_command(
|
||||
+ borgmatic.borg.flags.make_flags('dry-run', global_arguments.dry_run)
|
||||
+ borgmatic.borg.flags.make_flags('remote-path', remote_path)
|
||||
+ borgmatic.borg.flags.make_flags('umask', config.get('umask'))
|
||||
+ borgmatic.borg.flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ borgmatic.borg.flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ borgmatic.borg.flags.make_flags('list', config.get('list_details'))
|
||||
+ (
|
||||
|
||||
@@ -48,7 +48,7 @@ def export_key(
|
||||
(local_path, 'key', 'export')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -41,7 +41,7 @@ def export_tar_archive(
|
||||
(local_path, 'export-tar')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--list',) if config.get('list_details') else ())
|
||||
|
||||
@@ -49,7 +49,7 @@ def extract_last_archive_dry_run(
|
||||
full_extract_command = (
|
||||
(local_path, 'extract', '--dry-run')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ verbosity_flags
|
||||
+ list_flag
|
||||
@@ -124,7 +124,7 @@ def extract_archive(
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ numeric_ids_flags
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -44,7 +44,7 @@ def import_key(
|
||||
(local_path, 'key', 'import')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -40,7 +40,7 @@ def make_info_command(
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('umask', config.get('umask'))
|
||||
+ flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ (
|
||||
(
|
||||
|
||||
@@ -53,7 +53,7 @@ def make_list_command(
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('umask', config.get('umask'))
|
||||
+ flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ flags.make_flags('format', list_arguments.format or config.get('file_list_format'))
|
||||
+ flags.make_flags_from_arguments(list_arguments, excludes=MAKE_FLAGS_EXCLUDES)
|
||||
|
||||
@@ -32,7 +32,7 @@ def mount_archive(
|
||||
(local_path, 'mount')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -72,9 +72,9 @@ def prune_archives(
|
||||
full_command = (
|
||||
(local_path, 'prune')
|
||||
+ make_prune_flags(config, prune_arguments, local_borg_version)
|
||||
+ ('--log-json',)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (
|
||||
('--stats',)
|
||||
|
||||
@@ -46,7 +46,7 @@ def recreate_archive(
|
||||
recreate_command = (
|
||||
(local_path, 'recreate')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ ('--log-json',)
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait is not None else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import shlex
|
||||
|
||||
import borgmatic.borg.environment
|
||||
import borgmatic.borg.flags
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -25,7 +26,7 @@ def make_rename_command(
|
||||
+ borgmatic.borg.flags.make_flags('dry-run', dry_run)
|
||||
+ borgmatic.borg.flags.make_flags('remote-path', remote_path)
|
||||
+ borgmatic.borg.flags.make_flags('umask', config.get('umask'))
|
||||
+ borgmatic.borg.flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ borgmatic.borg.flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ (tuple(shlex.split(extra_borg_options)) if extra_borg_options else ())
|
||||
+ borgmatic.borg.flags.make_repository_archive_flags(
|
||||
|
||||
@@ -81,6 +81,7 @@ def create_repository(
|
||||
if feature.available(feature.Feature.REPO_CREATE, local_borg_version)
|
||||
else ('init',)
|
||||
)
|
||||
+ ('--log-json',)
|
||||
+ (('--encryption', encryption_mode) if encryption_mode else ())
|
||||
+ (('--other-repo', source_repository) if source_repository else ())
|
||||
+ (('--copy-crypt-key',) if copy_crypt_key else ())
|
||||
@@ -89,7 +90,6 @@ def create_repository(
|
||||
+ (('--make-parent-dirs',) if make_parent_directories else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--log-json',) if config.get('log_json') else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
|
||||
@@ -51,7 +51,7 @@ def make_repo_delete_command(
|
||||
+ borgmatic.borg.flags.make_flags('dry-run', global_arguments.dry_run)
|
||||
+ borgmatic.borg.flags.make_flags('remote-path', remote_path)
|
||||
+ borgmatic.borg.flags.make_flags('umask', config.get('umask'))
|
||||
+ borgmatic.borg.flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ borgmatic.borg.flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ borgmatic.borg.flags.make_flags('list', config.get('list_details'))
|
||||
+ (
|
||||
|
||||
@@ -49,7 +49,7 @@ def display_repository_info(
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('umask', config.get('umask'))
|
||||
+ flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ flags.make_flags('lock-wait', lock_wait)
|
||||
+ (('--json',) if repo_info_arguments.json else ())
|
||||
+ (tuple(shlex.split(extra_borg_options)) if extra_borg_options else ())
|
||||
|
||||
@@ -77,7 +77,7 @@ def get_latest_archive(
|
||||
),
|
||||
*flags.make_flags('remote-path', remote_path),
|
||||
*flags.make_flags('umask', config.get('umask')),
|
||||
*flags.make_flags('log-json', config.get('log_json')),
|
||||
*('--log-json',),
|
||||
*flags.make_flags('lock-wait', config.get('lock_wait')),
|
||||
*(
|
||||
flags.make_flags('consider-checkpoints', consider_checkpoints)
|
||||
@@ -153,7 +153,7 @@ def make_repo_list_command(
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('umask', config.get('umask'))
|
||||
+ flags.make_flags('log-json', config.get('log_json'))
|
||||
+ ('--log-json',)
|
||||
+ flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ (
|
||||
(
|
||||
|
||||
@@ -33,7 +33,7 @@ def transfer_archives(
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('umask', config.get('umask'))
|
||||
+ flags.make_flags('log-json', config.get('log_json'))
|
||||
+ (('--log-json',) if (config.get('log_json') or not config.get('progress')) else ())
|
||||
+ flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ flags.make_flags('progress', config.get('progress'))
|
||||
+ (
|
||||
|
||||
@@ -15,6 +15,7 @@ def unmount_archive(config, mount_point, local_path='borg'):
|
||||
extra_borg_options = config.get('extra_borg_options', {}).get('umount', '')
|
||||
full_command = (
|
||||
(local_path, 'umount')
|
||||
+ ('--log-json',)
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (tuple(shlex.split(extra_borg_options)) if extra_borg_options else ())
|
||||
|
||||
@@ -660,6 +660,7 @@ def load_configurations(config_filenames, arguments, overrides=None, resolve_env
|
||||
levelno=logging.DEBUG,
|
||||
levelname='DEBUG',
|
||||
msg=f'{config_filename}: Loading configuration file',
|
||||
name=logger.name,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -682,6 +683,7 @@ def load_configurations(config_filenames, arguments, overrides=None, resolve_env
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg=f'{config_filename}: Insufficient permissions to read configuration file',
|
||||
name=logger.name,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -694,10 +696,16 @@ def load_configurations(config_filenames, arguments, overrides=None, resolve_env
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg=f'{config_filename}: Error parsing configuration file',
|
||||
name=logger.name,
|
||||
),
|
||||
),
|
||||
logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=str(error)),
|
||||
dict(
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg=str(error),
|
||||
name=logger.name,
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
@@ -710,7 +718,7 @@ def log_record(suppress_log=False, **kwargs):
|
||||
Create a log record based on the given makeLogRecord() arguments, one of which must be
|
||||
named "levelno". Log the record (unless suppress log is set) and return it.
|
||||
'''
|
||||
record = logging.makeLogRecord(kwargs)
|
||||
record = logging.makeLogRecord(dict(kwargs, name=logger.name))
|
||||
if suppress_log:
|
||||
return record
|
||||
|
||||
@@ -823,6 +831,7 @@ def collect_highlander_action_summary_logs(configs, arguments, configuration_par
|
||||
levelno=logging.ANSWER,
|
||||
levelname='ANSWER',
|
||||
msg='Bootstrap successful',
|
||||
name=logger.name,
|
||||
),
|
||||
)
|
||||
except (
|
||||
@@ -845,6 +854,7 @@ def collect_highlander_action_summary_logs(configs, arguments, configuration_par
|
||||
levelno=logging.ANSWER,
|
||||
levelname='ANSWER',
|
||||
msg='Generate successful',
|
||||
name=logger.name,
|
||||
),
|
||||
)
|
||||
except (
|
||||
@@ -863,6 +873,7 @@ def collect_highlander_action_summary_logs(configs, arguments, configuration_par
|
||||
levelno=logging.CRITICAL,
|
||||
levelname='CRITICAL',
|
||||
msg='Configuration validation failed',
|
||||
name=logger.name,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -876,6 +887,7 @@ def collect_highlander_action_summary_logs(configs, arguments, configuration_par
|
||||
levelno=logging.ANSWER,
|
||||
levelname='ANSWER',
|
||||
msg='All configuration files are valid',
|
||||
name=logger.name,
|
||||
),
|
||||
)
|
||||
except (
|
||||
@@ -968,6 +980,7 @@ def collect_configuration_run_summary_logs(configs, config_paths, arguments, log
|
||||
levelno=logging.INFO,
|
||||
levelname='INFO',
|
||||
msg=f'{config_filename}: Successfully ran configuration file',
|
||||
name=logger.name,
|
||||
),
|
||||
)
|
||||
if results:
|
||||
@@ -1067,6 +1080,23 @@ def get_singular_option_value(configs, option_name):
|
||||
return None
|
||||
|
||||
|
||||
def display_summary(summary_logs, log_json): # pragma: no cover
|
||||
summary_logs_max_level = max(log.levelno for log in summary_logs)
|
||||
|
||||
for message in ('summary:',) if log_json else ('', 'summary:'):
|
||||
log_record(
|
||||
levelno=summary_logs_max_level,
|
||||
levelname=logging.getLevelName(summary_logs_max_level),
|
||||
msg=message,
|
||||
)
|
||||
|
||||
for log in summary_logs:
|
||||
logger.handle(log)
|
||||
|
||||
if summary_logs_max_level >= logging.CRITICAL:
|
||||
exit_with_help_link()
|
||||
|
||||
|
||||
def main(extra_summary_logs=()): # pragma: no cover
|
||||
configure_signals()
|
||||
configure_delayed_logging()
|
||||
@@ -1126,6 +1156,7 @@ def main(extra_summary_logs=()): # pragma: no cover
|
||||
getattr(sub_arguments, 'json', False) for sub_arguments in arguments.values()
|
||||
)
|
||||
log_file_path = get_singular_option_value(configs, 'log_file')
|
||||
log_json = get_singular_option_value(configs, 'log_json')
|
||||
|
||||
try:
|
||||
configure_logging(
|
||||
@@ -1135,7 +1166,8 @@ def main(extra_summary_logs=()): # pragma: no cover
|
||||
verbosity_to_log_level(get_verbosity(configs, 'monitoring_verbosity')),
|
||||
log_file_path,
|
||||
get_singular_option_value(configs, 'log_file_format'),
|
||||
color_enabled=should_do_markup(configs, any_json_flags),
|
||||
log_json,
|
||||
color_enabled=should_do_markup(configs, any_json_flags or log_json),
|
||||
)
|
||||
except (FileNotFoundError, PermissionError) as error:
|
||||
configure_logging(logging.CRITICAL)
|
||||
@@ -1163,17 +1195,5 @@ def main(extra_summary_logs=()): # pragma: no cover
|
||||
)
|
||||
)
|
||||
)
|
||||
summary_logs_max_level = max(log.levelno for log in summary_logs)
|
||||
|
||||
for message in ('', 'summary:'):
|
||||
log_record(
|
||||
levelno=summary_logs_max_level,
|
||||
levelname=logging.getLevelName(summary_logs_max_level),
|
||||
msg=message,
|
||||
)
|
||||
|
||||
for log in summary_logs:
|
||||
logger.handle(log)
|
||||
|
||||
if summary_logs_max_level >= logging.CRITICAL:
|
||||
exit_with_help_link()
|
||||
display_summary(summary_logs, log_json)
|
||||
|
||||
+168
-76
@@ -1,5 +1,7 @@
|
||||
import collections
|
||||
import contextlib
|
||||
import enum
|
||||
import json
|
||||
import logging
|
||||
import select
|
||||
import subprocess
|
||||
@@ -78,55 +80,121 @@ def command_for_process(process):
|
||||
return process.args if isinstance(process.args, str) else ' '.join(process.args)
|
||||
|
||||
|
||||
def output_buffer_for_process(process, exclude_stdouts):
|
||||
def output_buffers_for_process(process, exclude_stdouts):
|
||||
'''
|
||||
Given a process as an instance of subprocess.Popen and a sequence of stdouts to exclude, return
|
||||
either the process's stdout or stderr. The idea is that if stdout is excluded for a process, we
|
||||
still have stderr to log.
|
||||
the process stdout and stderr as a tuple—but exclude the stdout if it's in the given stdouts to
|
||||
exclude.
|
||||
'''
|
||||
return process.stderr if process.stdout in exclude_stdouts else process.stdout
|
||||
return tuple(
|
||||
buffer for buffer in (process.stdout, process.stderr) if buffer not in exclude_stdouts
|
||||
)
|
||||
|
||||
|
||||
def append_last_lines(last_lines, captured_output, line, output_log_level):
|
||||
def borg_log_line_to_record(line, log_level):
|
||||
'''
|
||||
Given a rolling list of last lines, a list of captured output, a line to append, and an output
|
||||
log level, append the line to the last lines and (if necessary) the captured output. Then log
|
||||
the line at the requested output log level.
|
||||
Given a single Borg log entry and a log level, return the line converted to a logging.LogRecord
|
||||
instance.
|
||||
|
||||
If it can't be parsed, then fall back to making a record out of the raw line and the given log
|
||||
level.
|
||||
'''
|
||||
last_lines.append(line)
|
||||
with contextlib.suppress(json.JSONDecodeError, TypeError, KeyError, AttributeError):
|
||||
log_data = json.loads(line)
|
||||
|
||||
return logging.makeLogRecord(
|
||||
dict(
|
||||
levelno=logging._nameToLevel.get(log_data.get('levelname')),
|
||||
created=log_data.get('time'),
|
||||
msg=log_data.get('message'),
|
||||
levelname=log_data.get('levelname'),
|
||||
name=log_data.get('name'),
|
||||
)
|
||||
)
|
||||
|
||||
return log_line_to_record(line, log_level)
|
||||
|
||||
|
||||
def log_line_to_record(line, log_level):
|
||||
'''
|
||||
Given a log data dict for a single Borg log entry and a log level, return it converted to a
|
||||
logging.LogRecord instance.
|
||||
'''
|
||||
return logging.makeLogRecord(
|
||||
dict(
|
||||
msg=line,
|
||||
levelno=log_level,
|
||||
levelname=logging.getLevelName(log_level),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def parse_log_line(line, log_level, came_from_stderr, borg_local_path, command):
|
||||
'''
|
||||
Given a raw output line from an external program, whether this line came from stderr, the Borg
|
||||
local path, and the command as a sequence, return a logging.LogRecord instance containing its
|
||||
parsed data.
|
||||
|
||||
If the command being run is Borg, and the log line is JSON-formatted log data, then grab the log
|
||||
level from it and log the parsed JSON to be consumed later by a Python logging.Formatter.
|
||||
|
||||
But for non-Borg commands, elevate stderr-sourced logs to ERROR. The one exception is if the log
|
||||
came from stderr and the string "warning:" appears at the start of the log line. In that case,
|
||||
just elevate the log level to a WARN.
|
||||
'''
|
||||
if borg_local_path and command[0] == borg_local_path:
|
||||
return borg_log_line_to_record(line, log_level)
|
||||
|
||||
if came_from_stderr:
|
||||
return log_line_to_record(
|
||||
line, logging.WARNING if line.lower().startswith('warning:') else logging.ERROR
|
||||
)
|
||||
|
||||
return log_line_to_record(line, log_level)
|
||||
|
||||
|
||||
def handle_log_record(log_record, last_lines, captured_output):
|
||||
'''
|
||||
Given a log record to be logged, a rolling list of last lines, and a list of captured output,
|
||||
append the record's message to the last lines and (if its log level is None) the captured
|
||||
output. Then log the line.
|
||||
'''
|
||||
log_message = log_record.getMessage()
|
||||
last_lines.append(log_message)
|
||||
|
||||
if len(last_lines) > ERROR_OUTPUT_MAX_LINE_COUNT:
|
||||
last_lines.pop(0)
|
||||
|
||||
if output_log_level is None:
|
||||
captured_output.append(line)
|
||||
else:
|
||||
logger.log(output_log_level, line)
|
||||
if log_record.levelno is None:
|
||||
captured_output.append(log_message)
|
||||
return
|
||||
|
||||
logger.handle(log_record)
|
||||
|
||||
|
||||
def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, borg_exit_codes): # noqa: PLR0912
|
||||
'''
|
||||
Given a sequence of subprocess.Popen() instances for multiple processes, log the output for each
|
||||
process with the requested log level. Additionally, raise a CalledProcessError if a process
|
||||
exits with an error (or a warning for exit code 1, if that process does not match the Borg local
|
||||
path).
|
||||
Given a sequence of subprocess.Popen() instances for multiple processes, log the outputs (stderr
|
||||
and stdout). Use the requested output log level for stdout, but always log stderr to the ERROR
|
||||
log level. Additionally, raise a CalledProcessError if a process exits with an error (or a
|
||||
warning for exit code 1, if that process does not match the Borg local path).
|
||||
|
||||
If output log level is None, then instead of logging, capture output for each process and return
|
||||
it as a dict from the process to its output. Use the given Borg local path and exit code
|
||||
configuration to decide what's an error and what's a warning.
|
||||
If the output log level is None, then instead of logging, capture output for each process and
|
||||
return it as a dict from the process to its output. If the output log level is not None, return
|
||||
an empty dict.
|
||||
|
||||
For simplicity, it's assumed that the output buffer for each process is its stdout. But if any
|
||||
stdouts are given to exclude, then for any matching processes, log from their stderr instead.
|
||||
|
||||
Note that stdout for a process can be None if output is intentionally not captured. In which
|
||||
case it won't be logged.
|
||||
Use the given Borg local path and exit code configuration to decide what's an error and what's a
|
||||
warning. If any stdouts are given to exclude, then for any matching processes, ignore those
|
||||
buffers. Also note that stdout for a process can be None if output is intentionally not
|
||||
captured, in which case it won't be logged.
|
||||
'''
|
||||
# Map from output buffer to sequence of last lines.
|
||||
buffer_last_lines = collections.defaultdict(list)
|
||||
process_for_output_buffer = {
|
||||
output_buffer_for_process(process, exclude_stdouts): process
|
||||
buffer: process
|
||||
for process in processes
|
||||
if process.stdout or process.stderr
|
||||
for buffer in output_buffers_for_process(process, exclude_stdouts)
|
||||
}
|
||||
output_buffers = list(process_for_output_buffer.keys())
|
||||
captured_outputs = collections.defaultdict(list)
|
||||
@@ -158,13 +226,24 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, b
|
||||
if not line or not ready_process:
|
||||
break
|
||||
|
||||
# Keep the last few lines of output in case the process errors, and we need the
|
||||
command = (
|
||||
ready_process.args.split(' ')
|
||||
if isinstance(ready_process.args, str)
|
||||
else ready_process.args
|
||||
)
|
||||
|
||||
# Keep the last few lines of output in case the process errors and we need the
|
||||
# output for the exception below.
|
||||
append_last_lines(
|
||||
buffer_last_lines[ready_buffer],
|
||||
captured_outputs[ready_process],
|
||||
line,
|
||||
output_log_level,
|
||||
handle_log_record(
|
||||
parse_log_line(
|
||||
line=line,
|
||||
log_level=output_log_level,
|
||||
came_from_stderr=(ready_buffer == ready_process.stderr),
|
||||
borg_local_path=borg_local_path,
|
||||
command=command,
|
||||
),
|
||||
last_lines=buffer_last_lines[ready_buffer],
|
||||
captured_output=captured_outputs[ready_process],
|
||||
)
|
||||
|
||||
if not still_running:
|
||||
@@ -186,21 +265,26 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, b
|
||||
if exit_status in {Exit_status.ERROR, Exit_status.WARNING}:
|
||||
# If an error occurs, include its output in the raised exception so that we don't
|
||||
# inadvertently hide error output.
|
||||
output_buffer = output_buffer_for_process(process, exclude_stdouts)
|
||||
last_lines = buffer_last_lines[output_buffer] if output_buffer else []
|
||||
for output_buffer in output_buffers_for_process(process, exclude_stdouts):
|
||||
last_lines = buffer_last_lines[output_buffer] if output_buffer else []
|
||||
|
||||
# Collect any straggling output lines that came in since we last gathered output.
|
||||
while output_buffer: # pragma: no cover
|
||||
line = output_buffer.readline().rstrip().decode()
|
||||
if not line:
|
||||
break
|
||||
# Collect any straggling output lines that came in since we last gathered output.
|
||||
while output_buffer: # pragma: no cover
|
||||
line = output_buffer.readline().rstrip().decode()
|
||||
if not line:
|
||||
break
|
||||
|
||||
append_last_lines(
|
||||
last_lines,
|
||||
captured_outputs[process],
|
||||
line,
|
||||
output_log_level,
|
||||
)
|
||||
handle_log_record(
|
||||
parse_log_line(
|
||||
line=line,
|
||||
log_level=output_log_level,
|
||||
came_from_stderr=(output_buffer == process.stderr),
|
||||
borg_local_path=borg_local_path,
|
||||
command=command,
|
||||
),
|
||||
last_lines=last_lines,
|
||||
captured_output=captured_outputs[process],
|
||||
)
|
||||
|
||||
if len(last_lines) == ERROR_OUTPUT_MAX_LINE_COUNT:
|
||||
last_lines.insert(0, '...')
|
||||
@@ -222,12 +306,12 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path, b
|
||||
still_running = False
|
||||
break
|
||||
|
||||
if captured_outputs:
|
||||
if output_log_level is None:
|
||||
return {
|
||||
process: '\n'.join(output_lines) for process, output_lines in captured_outputs.items()
|
||||
}
|
||||
|
||||
return None
|
||||
return {}
|
||||
|
||||
|
||||
SECRET_COMMAND_FLAG_NAMES = {'--password'}
|
||||
@@ -300,16 +384,16 @@ def execute_command(
|
||||
close_fds=False, # Necessary for passing credentials via anonymous pipe.
|
||||
):
|
||||
'''
|
||||
Execute the given command (a sequence of command/argument strings) and log its output at the
|
||||
given log level. If an open output file object is given, then write stdout to the file and only
|
||||
log stderr. If an open input file object is given, then read stdin from the file. If shell is
|
||||
True, execute the command within a shell. If an environment variables dict is given, then pass
|
||||
it into the command. If a working directory is given, use that as the present working directory
|
||||
when running the command. If a Borg local path is given, and the command matches it (regardless
|
||||
of arguments), treat exit code 1 as a warning instead of an error. But if Borg exit codes are
|
||||
given as a sequence of exit code configuration dicts, then use that configuration to decide
|
||||
what's an error and what's a warning. If run to completion is False, then return the process for
|
||||
the command without executing it to completion.
|
||||
Execute the given command (a sequence of command/argument strings) and log its stdout output at
|
||||
the given log level. If an open output file object is given, then write stdout to the file and
|
||||
only log stderr. If an open input file object is given, then read stdin from the file. If shell
|
||||
is True, execute the command within a shell. If an environment variables dict is given, then
|
||||
pass it into the command. If a working directory is given, use that as the present working
|
||||
directory when running the command. If a Borg local path is given, and the command matches it
|
||||
(regardless of arguments), treat exit code 1 as a warning instead of an error. But if Borg exit
|
||||
codes are given as a sequence of exit code configuration dicts, then use that configuration to
|
||||
decide what's an error and what's a warning. If run to completion is False, then return the
|
||||
process for the command without executing it to completion.
|
||||
|
||||
Raise subprocesses.CalledProcessError if an error occurs while running the command.
|
||||
'''
|
||||
@@ -321,7 +405,7 @@ def execute_command(
|
||||
command,
|
||||
stdin=input_file,
|
||||
stdout=None if do_not_capture else (output_file or subprocess.PIPE),
|
||||
stderr=None if do_not_capture else (subprocess.PIPE if output_file else subprocess.STDOUT),
|
||||
stderr=None if do_not_capture else subprocess.PIPE,
|
||||
shell=shell,
|
||||
env=environment,
|
||||
cwd=working_directory,
|
||||
@@ -355,14 +439,14 @@ def execute_command_and_capture_output(
|
||||
):
|
||||
'''
|
||||
Execute the given command (a sequence of command/argument strings), capturing and returning its
|
||||
output (stdout). If an input file descriptor is given, then pipe it to the command's stdin. If
|
||||
capture stderr is True, then capture and return stderr in addition to stdout. If shell is True,
|
||||
execute the command within a shell. If an environment variables dict is given, then pass it into
|
||||
the command. If a working directory is given, use that as the present working directory when
|
||||
running the command. If a Borg local path is given, and the command matches it (regardless of
|
||||
arguments), treat exit code 1 as a warning instead of an error. But if Borg exit codes are given
|
||||
as a sequence of exit code configuration dicts, then use that configuration to decide what's an
|
||||
error and what's a warning.
|
||||
output (stdout) as a string. If an input file descriptor is given, then pipe it to the command's
|
||||
stdin. If capture stderr is True, then capture and return stderr in addition to stdout. If shell
|
||||
is True, execute the command within a shell. If an environment variables dict is given, then
|
||||
pass it into the command. If a working directory is given, use that as the present working
|
||||
directory when running the command. If a Borg local path is given, and the command matches it
|
||||
(regardless of arguments), treat exit code 1 as a warning instead of an error. But if Borg exit
|
||||
codes are given as a sequence of exit code configuration dicts, then use that configuration to
|
||||
decide what's an error and what's a warning.
|
||||
|
||||
Raise subprocesses.CalledProcessError if an error occurs while running the command.
|
||||
'''
|
||||
@@ -370,10 +454,11 @@ def execute_command_and_capture_output(
|
||||
command = ' '.join(full_command) if shell else full_command
|
||||
|
||||
try:
|
||||
output = subprocess.check_output( # noqa: S603
|
||||
process = subprocess.Popen( # noqa: S603
|
||||
command,
|
||||
stdin=input_file,
|
||||
stderr=subprocess.STDOUT if capture_stderr else None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=shell,
|
||||
env=environment,
|
||||
cwd=working_directory,
|
||||
@@ -386,9 +471,18 @@ def execute_command_and_capture_output(
|
||||
):
|
||||
raise
|
||||
|
||||
output = error.output
|
||||
return error.output.decode() if error.output is not None else None
|
||||
|
||||
return output.decode() if output is not None else None
|
||||
with borgmatic.logger.Log_prefix(None): # Log command output without any prefix.
|
||||
captured_outputs = log_outputs(
|
||||
(process,),
|
||||
(input_file,),
|
||||
None,
|
||||
borg_local_path,
|
||||
borg_exit_codes,
|
||||
)
|
||||
|
||||
return captured_outputs.get(process, '')
|
||||
|
||||
|
||||
def execute_command_with_processes(
|
||||
@@ -405,8 +499,8 @@ def execute_command_with_processes(
|
||||
close_fds=False, # Necessary for passing credentials via anonymous pipe.
|
||||
):
|
||||
'''
|
||||
Execute the given command (a sequence of command/argument strings) and log its output at the
|
||||
given log level. Simultaneously, continue to poll one or more active processes so that they
|
||||
Execute the given command (a sequence of command/argument strings) and log its stdout output at
|
||||
the given log level. Simultaneously, continue to poll one or more active processes so that they
|
||||
run as well. This is useful, for instance, for processes that are streaming output to a named
|
||||
pipe that the given command is consuming from.
|
||||
|
||||
@@ -432,9 +526,7 @@ def execute_command_with_processes(
|
||||
command,
|
||||
stdin=input_file,
|
||||
stdout=None if do_not_capture else (output_file or subprocess.PIPE),
|
||||
stderr=(
|
||||
None if do_not_capture else (subprocess.PIPE if output_file else subprocess.STDOUT)
|
||||
),
|
||||
stderr=None if do_not_capture else subprocess.PIPE,
|
||||
shell=shell,
|
||||
env=environment,
|
||||
cwd=working_directory,
|
||||
@@ -460,6 +552,6 @@ def execute_command_with_processes(
|
||||
)
|
||||
|
||||
if output_log_level is None:
|
||||
return captured_outputs.get(command_process)
|
||||
return captured_outputs.get(command_process, '')
|
||||
|
||||
return None
|
||||
|
||||
+105
-19
@@ -1,7 +1,9 @@
|
||||
import enum
|
||||
import json
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
|
||||
|
||||
@@ -85,6 +87,57 @@ class Multi_stream_handler(logging.Handler):
|
||||
handler.setLevel(level)
|
||||
|
||||
|
||||
DEFAULT_JOURNALD_PRIORITY = 6
|
||||
|
||||
|
||||
class JournaldHandler(logging.Handler):
|
||||
def __init__(self, journald_socket_path):
|
||||
super().__init__()
|
||||
|
||||
add_custom_log_levels()
|
||||
|
||||
self.journald_socket_path = journald_socket_path
|
||||
self.log_level_to_journald_priority = {
|
||||
logging.CRITICAL: 2,
|
||||
logging.ERROR: 3,
|
||||
logging.WARNING: 4,
|
||||
logging.ANSWER: 5,
|
||||
logging.INFO: 6,
|
||||
logging.DEBUG: 7,
|
||||
}
|
||||
|
||||
def emit(self, record):
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||
|
||||
try:
|
||||
message_parts = []
|
||||
entry = dict(
|
||||
MESSAGE=record.getMessage(),
|
||||
PRIORITY=self.log_level_to_journald_priority.get(
|
||||
record.levelno, DEFAULT_JOURNALD_PRIORITY
|
||||
),
|
||||
SYSLOG_IDENTIFIER='borgmatic',
|
||||
SYSLOG_PID=os.getpid(),
|
||||
)
|
||||
|
||||
for key, value in entry.items():
|
||||
encoded_key = key.upper().encode('utf-8')
|
||||
encoded_value = str(value).encode('utf-8')
|
||||
|
||||
# Multi-line and single-line values use different formats on the wire.
|
||||
if b'\n' in encoded_value:
|
||||
message_parts.extend((encoded_key, b'\n'))
|
||||
message_parts.extend(
|
||||
(len(encoded_value).to_bytes(8, 'little'), encoded_value, b'\n')
|
||||
)
|
||||
else:
|
||||
message_parts.extend((encoded_key, b'=', encoded_value, b'\n'))
|
||||
|
||||
sock.sendto(b''.join(message_parts), self.journald_socket_path)
|
||||
finally:
|
||||
sock.close()
|
||||
|
||||
|
||||
class Log_prefix_formatter(logging.Formatter):
|
||||
def __init__(self, fmt='{prefix}{message}', *args, style='{', **kwargs):
|
||||
self.prefix = None
|
||||
@@ -97,6 +150,29 @@ class Log_prefix_formatter(logging.Formatter):
|
||||
return super().format(record)
|
||||
|
||||
|
||||
def log_record_to_json(record):
|
||||
'''
|
||||
Given a logging.LogRecord, return it as a JSON-encoded string containing relevant attributes.
|
||||
'''
|
||||
return json.dumps(
|
||||
dict(
|
||||
type='log_message',
|
||||
time=record.created,
|
||||
message=record.getMessage(),
|
||||
levelname=record.levelname,
|
||||
name=record.name,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Json_formatter(logging.Formatter):
|
||||
def __init__(self, fmt='{message}', *args, style='{', **kwargs):
|
||||
super().__init__(*args, fmt=fmt, style=style, **kwargs)
|
||||
|
||||
def format(self, record): # noqa: PLR6301
|
||||
return log_record_to_json(record)
|
||||
|
||||
|
||||
class Color(enum.Enum):
|
||||
RESET = 0
|
||||
RED = 31
|
||||
@@ -321,6 +397,10 @@ def flush_delayed_logging(target_handlers):
|
||||
root_logger.removeHandler(delayed_handler)
|
||||
|
||||
|
||||
JOURNALD_SOCKET_PATH = '/run/systemd/journal/socket'
|
||||
SYSLOG_PATHS = ('/dev/log', '/var/run/syslog', '/var/run/log')
|
||||
|
||||
|
||||
def configure_logging(
|
||||
console_log_level,
|
||||
syslog_log_level=None,
|
||||
@@ -328,6 +408,7 @@ def configure_logging(
|
||||
monitoring_log_level=None,
|
||||
log_file=None,
|
||||
log_file_format=None,
|
||||
log_json=False,
|
||||
color_enabled=True,
|
||||
):
|
||||
'''
|
||||
@@ -364,7 +445,9 @@ def configure_logging(
|
||||
},
|
||||
)
|
||||
|
||||
if color_enabled:
|
||||
if log_json:
|
||||
console_handler.setFormatter(Json_formatter())
|
||||
elif color_enabled:
|
||||
console_handler.setFormatter(Console_color_formatter())
|
||||
else:
|
||||
console_handler.setFormatter(Log_prefix_formatter())
|
||||
@@ -373,29 +456,32 @@ def configure_logging(
|
||||
handlers = [console_handler]
|
||||
|
||||
if syslog_log_level != logging.DISABLED:
|
||||
syslog_path = None
|
||||
|
||||
if os.path.exists('/dev/log'):
|
||||
syslog_path = '/dev/log'
|
||||
elif os.path.exists('/var/run/syslog'):
|
||||
syslog_path = '/var/run/syslog'
|
||||
elif os.path.exists('/var/run/log'):
|
||||
syslog_path = '/var/run/log'
|
||||
|
||||
if syslog_path:
|
||||
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
|
||||
syslog_handler.setFormatter(
|
||||
Log_prefix_formatter(
|
||||
'borgmatic: {levelname} {prefix}{message}',
|
||||
),
|
||||
if os.path.exists(JOURNALD_SOCKET_PATH):
|
||||
journald_handler = JournaldHandler(JOURNALD_SOCKET_PATH)
|
||||
journald_handler.setLevel(syslog_log_level)
|
||||
handlers.append(journald_handler)
|
||||
else:
|
||||
syslog_path = next(
|
||||
(path for path in SYSLOG_PATHS if os.path.exists(path)),
|
||||
None,
|
||||
)
|
||||
syslog_handler.setLevel(syslog_log_level)
|
||||
handlers.append(syslog_handler)
|
||||
|
||||
if syslog_path:
|
||||
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
|
||||
syslog_handler.setFormatter(
|
||||
Log_prefix_formatter(
|
||||
'borgmatic: {levelname} {prefix}{message}',
|
||||
),
|
||||
)
|
||||
syslog_handler.setLevel(syslog_log_level)
|
||||
handlers.append(syslog_handler)
|
||||
|
||||
if log_file and log_file_log_level != logging.DISABLED:
|
||||
file_handler = logging.handlers.WatchedFileHandler(log_file)
|
||||
file_handler.setFormatter(
|
||||
Log_prefix_formatter(
|
||||
Json_formatter()
|
||||
if log_json
|
||||
else Log_prefix_formatter(
|
||||
log_file_format or '[{asctime}] {levelname}: {prefix}{message}',
|
||||
),
|
||||
)
|
||||
|
||||
@@ -34,6 +34,13 @@ Additionally, for the `create` action in particular, you can include the
|
||||
that are new or changed since the last backup.
|
||||
|
||||
|
||||
### JSON logging
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 2.1.0</span>With the
|
||||
`--log-json` flag, borgmatic logs both its own logs and Borg's output as JSON.
|
||||
The `--log-json` flag applies to console output and any log file (see below).
|
||||
|
||||
|
||||
## Logging to syslog
|
||||
|
||||
By default, borgmatic only logs its output to the console. You can enable
|
||||
@@ -66,6 +73,40 @@ systemd, try running `journalctl -xe`. Otherwise, try viewing
|
||||
logged to syslog by default whenever run at a non-interactive console.
|
||||
|
||||
|
||||
### Systemd journal
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 2.1.0</span>If the syslog
|
||||
verbosity is set and systemd's journal is present, then borgmatic sends
|
||||
structured logs to the journal instead of plain text. This allows you to query
|
||||
logs by particular fields. For instance:
|
||||
|
||||
```bash
|
||||
journalctl --catalog --pager-end SYSLOG_IDENTIFIER=borgmatic
|
||||
```
|
||||
|
||||
Or to view just borgmatic warning and error logs:
|
||||
|
||||
```bash
|
||||
journalctl --catalog --pager-end SYSLOG_IDENTIFIER=borgmatic --priority warning..alert
|
||||
```
|
||||
|
||||
The fields borgmatic sends are:
|
||||
|
||||
* `MESSAGE`: the log message
|
||||
* `PRIORITY`: the [numeric priority level](https://wiki.archlinux.org/title/Systemd/Journal#Priority_level) for the log entry
|
||||
* `SYSLOG_IDENTIFIER`: `borgmatic`
|
||||
* `SYSLOG_PID`: borgmatic's process ID
|
||||
|
||||
You can also output these structured logs as JSON:
|
||||
|
||||
```bash
|
||||
journalctl --output=json SYSLOG_IDENTIFIER=borgmatic
|
||||
```
|
||||
|
||||
Note that systemd's journal adds its own fields to the JSON on top of the fields
|
||||
that borgmatic logs.
|
||||
|
||||
|
||||
### Rate limiting
|
||||
|
||||
If you are using rsyslog or systemd's journal, be aware that by default they
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "borgmatic"
|
||||
version = "2.0.14.dev0"
|
||||
version = "2.1.0.dev0"
|
||||
authors = [
|
||||
{ name="Dan Helfman", email="witten@torsion.org" },
|
||||
]
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import logging
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import rename as module
|
||||
from tests.unit.test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def insert_logging_mock(log_level):
|
||||
'''
|
||||
Mock the isEnabledFor from Python logging.
|
||||
'''
|
||||
logging = flexmock(module.logging.Logger)
|
||||
logging.should_receive('isEnabledFor').replace_with(lambda level: level >= log_level)
|
||||
logging.should_receive('getEffectiveLevel').replace_with(lambda: log_level)
|
||||
|
||||
|
||||
def test_make_rename_command_includes_log_info():
|
||||
@@ -18,7 +28,7 @@ def test_make_rename_command_includes_log_info():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rename', '--info', 'repo::old_archive', 'new_archive')
|
||||
assert command == ('borg', 'rename', '--info', '--log-json', 'repo::old_archive', 'new_archive')
|
||||
|
||||
|
||||
def test_make_rename_command_includes_log_debug():
|
||||
@@ -35,7 +45,15 @@ def test_make_rename_command_includes_log_debug():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rename', '--debug', '--show-rc', 'repo::old_archive', 'new_archive')
|
||||
assert command == (
|
||||
'borg',
|
||||
'rename',
|
||||
'--debug',
|
||||
'--show-rc',
|
||||
'--log-json',
|
||||
'repo::old_archive',
|
||||
'new_archive',
|
||||
)
|
||||
|
||||
|
||||
def test_make_rename_command_includes_dry_run():
|
||||
@@ -50,7 +68,14 @@ def test_make_rename_command_includes_dry_run():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rename', '--dry-run', 'repo::old_archive', 'new_archive')
|
||||
assert command == (
|
||||
'borg',
|
||||
'rename',
|
||||
'--dry-run',
|
||||
'--log-json',
|
||||
'repo::old_archive',
|
||||
'new_archive',
|
||||
)
|
||||
|
||||
|
||||
def test_make_rename_command_includes_remote_path():
|
||||
@@ -70,6 +95,7 @@ def test_make_rename_command_includes_remote_path():
|
||||
'rename',
|
||||
'--remote-path',
|
||||
'borg1',
|
||||
'--log-json',
|
||||
'repo::old_archive',
|
||||
'new_archive',
|
||||
)
|
||||
@@ -87,7 +113,15 @@ def test_make_rename_command_includes_umask():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rename', '--umask', '077', 'repo::old_archive', 'new_archive')
|
||||
assert command == (
|
||||
'borg',
|
||||
'rename',
|
||||
'--umask',
|
||||
'077',
|
||||
'--log-json',
|
||||
'repo::old_archive',
|
||||
'new_archive',
|
||||
)
|
||||
|
||||
|
||||
def test_make_rename_command_includes_log_json():
|
||||
@@ -117,7 +151,15 @@ def test_make_rename_command_includes_lock_wait():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rename', '--lock-wait', '5', 'repo::old_archive', 'new_archive')
|
||||
assert command == (
|
||||
'borg',
|
||||
'rename',
|
||||
'--log-json',
|
||||
'--lock-wait',
|
||||
'5',
|
||||
'repo::old_archive',
|
||||
'new_archive',
|
||||
)
|
||||
|
||||
|
||||
def test_make_rename_command_includes_extra_borg_options():
|
||||
@@ -135,6 +177,7 @@ def test_make_rename_command_includes_extra_borg_options():
|
||||
assert command == (
|
||||
'borg',
|
||||
'rename',
|
||||
'--log-json',
|
||||
'--extra',
|
||||
'value with space',
|
||||
'repo::old_archive',
|
||||
|
||||
@@ -9,54 +9,120 @@ from borgmatic import execute as module
|
||||
|
||||
|
||||
def test_log_outputs_logs_each_line_separately():
|
||||
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'hi').once()
|
||||
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'there').once()
|
||||
hi_record = flexmock(
|
||||
msg='hi',
|
||||
levelno=logging.INFO,
|
||||
levelname='INFO',
|
||||
getMessage=lambda: 'hi',
|
||||
)
|
||||
flexmock(module).should_receive('log_line_to_record').with_args('hi', logging.INFO).and_return(
|
||||
hi_record
|
||||
)
|
||||
flexmock(module.logger).should_receive('handle').with_args(hi_record).once()
|
||||
there_record = flexmock(
|
||||
msg='there',
|
||||
levelno=logging.INFO,
|
||||
levelname='INFO',
|
||||
getMessage=lambda: 'there',
|
||||
)
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
'there', logging.INFO
|
||||
).and_return(there_record)
|
||||
flexmock(module.logger).should_receive('handle').with_args(there_record).once()
|
||||
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
|
||||
|
||||
hi_process = subprocess.Popen(['echo', 'hi'], stdout=subprocess.PIPE)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
hi_process,
|
||||
(),
|
||||
).and_return(hi_process.stdout)
|
||||
).and_return((hi_process.stdout,))
|
||||
|
||||
there_process = subprocess.Popen(['echo', 'there'], stdout=subprocess.PIPE)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
there_process,
|
||||
(),
|
||||
).and_return(there_process.stdout)
|
||||
).and_return((there_process.stdout,))
|
||||
|
||||
module.log_outputs(
|
||||
(hi_process, there_process),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(hi_process, there_process),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
def test_log_outputs_logs_stderr_as_error():
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(str, logging.INFO).never()
|
||||
error_record = flexmock(
|
||||
msg='error',
|
||||
levelno=logging.ERROR,
|
||||
levelname='ERROR',
|
||||
getMessage=lambda: 'error',
|
||||
)
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
'error', logging.ERROR
|
||||
).and_return(error_record)
|
||||
flexmock(module.logger).should_receive('handle').with_args(error_record).once()
|
||||
|
||||
echo_process = subprocess.Popen(
|
||||
'echo error >&2', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True
|
||||
)
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
echo_process,
|
||||
(),
|
||||
).and_return((echo_process.stdout, echo_process.stderr))
|
||||
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(echo_process,),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
def test_log_outputs_skips_logs_for_process_with_none_stdout():
|
||||
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'hi').never()
|
||||
flexmock(module.logger).should_receive('log').with_args(logging.INFO, 'there').once()
|
||||
flexmock(module).should_receive('log_line_to_record').with_args('hi', logging.INFO).never()
|
||||
there_record = flexmock(
|
||||
msg='there',
|
||||
levelno=logging.INFO,
|
||||
levelname='INFO',
|
||||
getMessage=lambda: 'there',
|
||||
)
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
'there', logging.INFO
|
||||
).and_return(there_record)
|
||||
flexmock(module.logger).should_receive('handle').with_args(there_record).once()
|
||||
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
|
||||
|
||||
hi_process = subprocess.Popen(['echo', 'hi'], stdout=None)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
hi_process,
|
||||
(),
|
||||
).and_return(hi_process.stdout)
|
||||
).and_return((hi_process.stdout,))
|
||||
|
||||
there_process = subprocess.Popen(['echo', 'there'], stdout=subprocess.PIPE)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
there_process,
|
||||
(),
|
||||
).and_return(there_process.stdout)
|
||||
).and_return((there_process.stdout,))
|
||||
|
||||
module.log_outputs(
|
||||
(hi_process, there_process),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(hi_process, there_process),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
@@ -65,16 +131,16 @@ def test_log_outputs_returns_output_without_logging_for_output_log_level_none():
|
||||
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
|
||||
|
||||
hi_process = subprocess.Popen(['echo', 'hi'], stdout=subprocess.PIPE)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
hi_process,
|
||||
(),
|
||||
).and_return(hi_process.stdout)
|
||||
).and_return((hi_process.stdout,))
|
||||
|
||||
there_process = subprocess.Popen(['echo', 'there'], stdout=subprocess.PIPE)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
there_process,
|
||||
(),
|
||||
).and_return(there_process.stdout)
|
||||
).and_return((there_process.stdout,))
|
||||
|
||||
captured_outputs = module.log_outputs(
|
||||
(hi_process, there_process),
|
||||
@@ -93,7 +159,7 @@ def test_log_outputs_includes_error_output_in_exception():
|
||||
flexmock(module).should_receive('command_for_process').and_return('grep')
|
||||
|
||||
process = subprocess.Popen(['grep'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
|
||||
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError) as error:
|
||||
module.log_outputs(
|
||||
@@ -112,7 +178,6 @@ def test_log_outputs_logs_multiline_error_output():
|
||||
Make sure that all error output lines get logged, not just (for instance) the first few lines
|
||||
of a process' traceback.
|
||||
'''
|
||||
flexmock(module.logger).should_receive('log')
|
||||
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.ERROR)
|
||||
flexmock(module).should_receive('command_for_process').and_return('grep')
|
||||
|
||||
@@ -121,8 +186,8 @@ def test_log_outputs_logs_multiline_error_output():
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
|
||||
flexmock(module.logger).should_call('log').at_least().times(3)
|
||||
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
|
||||
flexmock(module.logger).should_call('handle').at_least().times(3)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
module.log_outputs(
|
||||
@@ -140,7 +205,7 @@ def test_log_outputs_skips_error_output_in_exception_for_process_with_none_stdou
|
||||
flexmock(module).should_receive('command_for_process').and_return('grep')
|
||||
|
||||
process = subprocess.Popen(['grep'], stdout=None)
|
||||
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
|
||||
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError) as error:
|
||||
module.log_outputs(
|
||||
@@ -183,13 +248,13 @@ def test_log_outputs_kills_other_processes_and_raises_when_one_errors():
|
||||
'borg',
|
||||
None,
|
||||
).and_return(module.Exit_status.SUCCESS)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(process, ()).and_return(
|
||||
process.stdout,
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(process, ()).and_return(
|
||||
(process.stdout,),
|
||||
)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
other_process,
|
||||
(),
|
||||
).and_return(other_process.stdout)
|
||||
).and_return((other_process.stdout,))
|
||||
flexmock(other_process).should_receive('kill').once()
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError) as error:
|
||||
@@ -233,21 +298,24 @@ def test_log_outputs_kills_other_processes_and_returns_when_one_exits_with_warni
|
||||
'borg',
|
||||
None,
|
||||
).and_return(module.Exit_status.SUCCESS)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(process, ()).and_return(
|
||||
process.stdout,
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(process, ()).and_return(
|
||||
(process.stdout,),
|
||||
)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
other_process,
|
||||
(),
|
||||
).and_return(other_process.stdout)
|
||||
).and_return((other_process.stdout,))
|
||||
flexmock(other_process).should_receive('kill').once()
|
||||
|
||||
module.log_outputs(
|
||||
(process, other_process),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(process, other_process),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
@@ -276,22 +344,25 @@ def test_log_outputs_vents_other_processes_when_one_exits():
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
process,
|
||||
(process.stdout,),
|
||||
).and_return(process.stderr)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
).and_return((process.stderr,))
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
other_process,
|
||||
(process.stdout,),
|
||||
).and_return(other_process.stdout)
|
||||
).and_return((other_process.stdout,))
|
||||
flexmock(process.stdout).should_call('readline').at_least().once()
|
||||
|
||||
module.log_outputs(
|
||||
(process, other_process),
|
||||
exclude_stdouts=(process.stdout,),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(process, other_process),
|
||||
exclude_stdouts=(process.stdout,),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
@@ -314,21 +385,24 @@ def test_log_outputs_does_not_error_when_one_process_exits():
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
process,
|
||||
(process.stdout,),
|
||||
).and_return(process.stderr)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(
|
||||
).and_return((process.stderr,))
|
||||
flexmock(module).should_receive('output_buffers_for_process').with_args(
|
||||
other_process,
|
||||
(process.stdout,),
|
||||
).and_return(other_process.stdout)
|
||||
).and_return((other_process.stdout,))
|
||||
|
||||
module.log_outputs(
|
||||
(process, other_process),
|
||||
exclude_stdouts=(process.stdout,),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(process, other_process),
|
||||
exclude_stdouts=(process.stdout,),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
@@ -349,7 +423,7 @@ def test_log_outputs_truncates_long_error_output():
|
||||
'borg',
|
||||
None,
|
||||
).and_return(module.Exit_status.ERROR)
|
||||
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
|
||||
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError) as error:
|
||||
flexmock(module, ERROR_OUTPUT_MAX_LINE_COUNT=0).log_outputs(
|
||||
@@ -369,14 +443,17 @@ def test_log_outputs_with_no_output_logs_nothing():
|
||||
flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS)
|
||||
|
||||
process = subprocess.Popen(['true'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
|
||||
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
|
||||
|
||||
module.log_outputs(
|
||||
(process,),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(process,),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
|
||||
@@ -386,12 +463,15 @@ def test_log_outputs_with_unfinished_process_re_polls():
|
||||
|
||||
process = subprocess.Popen(['true'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
flexmock(process).should_receive('poll').and_return(None).and_return(0).times(3)
|
||||
flexmock(module).should_receive('output_buffer_for_process').and_return(process.stdout)
|
||||
flexmock(module).should_receive('output_buffers_for_process').and_return((process.stdout,))
|
||||
|
||||
module.log_outputs(
|
||||
(process,),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
assert (
|
||||
module.log_outputs(
|
||||
(process,),
|
||||
exclude_stdouts=(),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
== {}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
import borgmatic.logger as module
|
||||
|
||||
|
||||
def test_json_formatter_format_does_not_raise():
|
||||
module.Json_formatter().format(
|
||||
flexmock(
|
||||
created=12345,
|
||||
levelno=module.logging.INFO,
|
||||
levelname='INFO',
|
||||
name='borg.something',
|
||||
getMessage=lambda: 'All done',
|
||||
)
|
||||
)
|
||||
@@ -23,7 +23,7 @@ def insert_execute_command_mock(command, working_directory=None, borg_exit_codes
|
||||
|
||||
def test_break_lock_calls_borg_with_required_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--log-json', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -35,7 +35,7 @@ def test_break_lock_calls_borg_with_required_flags():
|
||||
|
||||
def test_break_lock_calls_borg_with_local_path():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'break-lock', 'repo'))
|
||||
insert_execute_command_mock(('borg1', 'break-lock', '--log-json', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -48,7 +48,7 @@ def test_break_lock_calls_borg_with_local_path():
|
||||
|
||||
def test_break_lock_calls_borg_using_exit_codes():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'break-lock', 'repo'))
|
||||
insert_execute_command_mock(('borg1', 'break-lock', '--log-json', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -61,7 +61,9 @@ def test_break_lock_calls_borg_using_exit_codes():
|
||||
|
||||
def test_break_lock_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--remote-path', 'borg1', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'break-lock', '--remote-path', 'borg1', '--log-json', 'repo')
|
||||
)
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -74,7 +76,7 @@ def test_break_lock_calls_borg_with_remote_path_flags():
|
||||
|
||||
def test_break_lock_calls_borg_with_umask_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--umask', '0770', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--umask', '0770', '--log-json', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -84,21 +86,9 @@ def test_break_lock_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_break_lock_calls_borg_with_log_json_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--log-json', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_break_lock_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--lock-wait', '5', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--log-json', '--lock-wait', '5', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -110,7 +100,9 @@ def test_break_lock_calls_borg_with_lock_wait_flags():
|
||||
|
||||
def test_break_lock_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--extra', 'value with space', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'break-lock', '--log-json', '--extra', 'value with space', 'repo')
|
||||
)
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
@@ -122,7 +114,7 @@ def test_break_lock_calls_borg_with_extra_borg_options():
|
||||
|
||||
def test_break_lock_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--info', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--log-json', '--info', 'repo'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.break_lock(
|
||||
@@ -135,7 +127,9 @@ def test_break_lock_with_log_info_calls_borg_with_info_parameter():
|
||||
|
||||
def test_break_lock_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--debug', '--show-rc', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'break-lock', '--log-json', '--debug', '--show-rc', 'repo')
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.break_lock(
|
||||
@@ -148,7 +142,9 @@ def test_break_lock_with_log_debug_calls_borg_with_debug_flags():
|
||||
|
||||
def test_break_lock_calls_borg_with_working_directory():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', 'repo'), working_directory='/working/dir')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'break-lock', '--log-json', 'repo'), working_directory='/working/dir'
|
||||
)
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
|
||||
@@ -34,7 +34,7 @@ def insert_execute_command_mock(
|
||||
|
||||
def test_change_passphrase_calls_borg_with_required_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'key', 'change-passphrase', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'change-passphrase', '--log-json', 'repo'))
|
||||
|
||||
module.change_passphrase(
|
||||
repository_path='repo',
|
||||
@@ -47,7 +47,7 @@ def test_change_passphrase_calls_borg_with_required_flags():
|
||||
|
||||
def test_change_passphrase_calls_borg_with_local_path():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'key', 'change-passphrase', 'repo'))
|
||||
insert_execute_command_mock(('borg1', 'key', 'change-passphrase', '--log-json', 'repo'))
|
||||
|
||||
module.change_passphrase(
|
||||
repository_path='repo',
|
||||
@@ -64,7 +64,7 @@ def test_change_passphrase_calls_borg_using_exit_codes():
|
||||
borg_exit_codes = flexmock()
|
||||
config = {'borg_exit_codes': borg_exit_codes}
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
|
||||
config=config,
|
||||
borg_exit_codes=borg_exit_codes,
|
||||
)
|
||||
@@ -81,7 +81,7 @@ def test_change_passphrase_calls_borg_using_exit_codes():
|
||||
def test_change_passphrase_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--remote-path', 'borg1', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--remote-path', 'borg1', '--log-json', 'repo'),
|
||||
)
|
||||
|
||||
module.change_passphrase(
|
||||
@@ -98,24 +98,7 @@ def test_change_passphrase_calls_borg_with_umask_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
config = {'umask': '0770'}
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--umask', '0770', 'repo'),
|
||||
config=config,
|
||||
)
|
||||
|
||||
module.change_passphrase(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
change_passphrase_arguments=flexmock(),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
)
|
||||
|
||||
|
||||
def test_change_passphrase_calls_borg_with_log_json_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
config = {'log_json': True}
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--umask', '0770', '--log-json', 'repo'),
|
||||
config=config,
|
||||
)
|
||||
|
||||
@@ -132,7 +115,7 @@ def test_change_passphrase_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
config = {'lock_wait': '5'}
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--lock-wait', '5', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--log-json', '--lock-wait', '5', 'repo'),
|
||||
config=config,
|
||||
)
|
||||
|
||||
@@ -149,7 +132,7 @@ def test_change_passphrase_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
config = {'extra_borg_options': {'key_change_passphrase': '--extra "value with space"'}}
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--extra', 'value with space', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--log-json', '--extra', 'value with space', 'repo'),
|
||||
config=config,
|
||||
)
|
||||
|
||||
@@ -164,7 +147,9 @@ def test_change_passphrase_calls_borg_with_extra_borg_options():
|
||||
|
||||
def test_change_passphrase_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'key', 'change-passphrase', '--info', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--log-json', '--info', 'repo')
|
||||
)
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.change_passphrase(
|
||||
@@ -179,7 +164,7 @@ def test_change_passphrase_with_log_info_calls_borg_with_info_parameter():
|
||||
def test_change_passphrase_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', '--debug', '--show-rc', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--log-json', '--debug', '--show-rc', 'repo'),
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
@@ -209,7 +194,7 @@ def test_change_passphrase_with_dry_run_skips_borg_call():
|
||||
def test_change_passphrase_calls_borg_without_passphrase():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
|
||||
config={'option': 'foo'},
|
||||
)
|
||||
|
||||
@@ -230,7 +215,7 @@ def test_change_passphrase_calls_borg_with_working_directory():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
config = {'working_directory': '/working/dir'}
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'change-passphrase', 'repo'),
|
||||
('borg', 'key', 'change-passphrase', '--log-json', 'repo'),
|
||||
config=config,
|
||||
working_directory='/working/dir',
|
||||
)
|
||||
|
||||
+104
-49
@@ -356,6 +356,42 @@ def test_check_archives_with_progress_passes_through_to_borg():
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_json_and_progress_passes_through_both_to_borg():
|
||||
config = {'log_json': True, 'progress': True}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(
|
||||
{'repository'},
|
||||
(),
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--log-json', '--progress', 'repo'),
|
||||
output_file=module.DO_NOT_CAPTURE,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
checks={'repository'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_repair_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(
|
||||
@@ -392,6 +428,42 @@ def test_check_archives_with_repair_passes_through_to_borg():
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_json_and_repair_passes_through_both_to_borg():
|
||||
config = {'log_json': True}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(
|
||||
{'repository'},
|
||||
(),
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--repair', '--log-json', 'repo'),
|
||||
output_file=module.DO_NOT_CAPTURE,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=True,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
checks={'repository'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_max_duration_flag_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(
|
||||
@@ -402,7 +474,7 @@ def test_check_archives_with_max_duration_flag_passes_through_to_borg():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--max-duration', '33', 'repo'),
|
||||
('borg', 'check', '--max-duration', '33', '--log-json', 'repo'),
|
||||
output_file=None,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -438,7 +510,7 @@ def test_check_archives_with_max_duration_option_passes_through_to_borg():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--max-duration', '33', 'repo'),
|
||||
('borg', 'check', '--max-duration', '33', '--log-json', 'repo'),
|
||||
output_file=None,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -474,9 +546,9 @@ def test_check_archives_with_max_duration_option_and_archives_check_runs_reposit
|
||||
(),
|
||||
).and_return(('--repository-only',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--archives-only', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--archives-only', '--log-json', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
@@ -507,9 +579,9 @@ def test_check_archives_with_max_duration_flag_and_archives_check_runs_repositor
|
||||
(),
|
||||
).and_return(('--repository-only',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--archives-only', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--archives-only', '--log-json', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
@@ -541,9 +613,11 @@ def test_check_archives_with_max_duration_option_and_data_check_runs_repository_
|
||||
(),
|
||||
).and_return(('--repository-only',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--archives-only', '--verify-data', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
|
||||
('borg', 'check', '--archives-only', '--verify-data', '--log-json', 'repo')
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
@@ -575,9 +649,11 @@ def test_check_archives_with_max_duration_flag_and_data_check_runs_repository_ch
|
||||
(),
|
||||
).and_return(('--repository-only',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--archives-only', '--verify-data', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', 'repo'),
|
||||
('borg', 'check', '--archives-only', '--verify-data', '--log-json', 'repo')
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--max-duration', '33', '--repository-only', '--log-json', 'repo'),
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
@@ -608,7 +684,7 @@ def test_check_archives_with_max_duration_flag_overrides_max_duration_option():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--max-duration', '44', 'repo'),
|
||||
('borg', 'check', '--max-duration', '44', '--log-json', 'repo'),
|
||||
output_file=None,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -647,7 +723,7 @@ def test_check_archives_calls_borg_with_parameters(checks):
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -674,7 +750,7 @@ def test_check_archives_with_data_check_implies_archives_check_calls_borg_with_p
|
||||
(),
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -702,7 +778,7 @@ def test_check_archives_with_log_info_passes_through_to_borg():
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', '--info', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -730,7 +806,7 @@ def test_check_archives_with_log_debug_passes_through_to_borg():
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', '--debug', '--show-rc', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -755,7 +831,7 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'check', 'repo'))
|
||||
insert_execute_command_mock(('borg1', 'check', '--log-json', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -782,7 +858,9 @@ def test_check_archives_with_exit_codes_calls_borg_using_them():
|
||||
config = {'borg_exit_codes': borg_exit_codes}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'), borg_exit_codes=borg_exit_codes)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--log-json', 'repo'), borg_exit_codes=borg_exit_codes
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -807,7 +885,7 @@ def test_check_archives_with_remote_path_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', '--log-json', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -833,32 +911,7 @@ def test_check_archives_with_umask_passes_through_to_borg():
|
||||
config = {'umask': '077'}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--umask', '077', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
checks=checks,
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_json_passes_through_to_borg():
|
||||
checks = {'repository'}
|
||||
config = {'log_json': True}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--umask', '077', '--log-json', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -883,7 +936,7 @@ def test_check_archives_with_lock_wait_passes_through_to_borg():
|
||||
config = {'lock_wait': 5}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', '--lock-wait', '5', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -909,7 +962,7 @@ def test_check_archives_with_retention_prefix():
|
||||
config = {'prefix': prefix}
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
@@ -937,7 +990,7 @@ def test_check_archives_with_extra_borg_options_passes_through_to_borg():
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--extra', '--options', 'value with space', 'repo'),
|
||||
('borg', 'check', '--log-json', '--extra', '--options', 'value with space', 'repo'),
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
@@ -968,7 +1021,7 @@ def test_check_archives_with_match_archives_passes_through_to_borg():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--match-archives', 'foo-*', 'repo'),
|
||||
('borg', 'check', '--match-archives', 'foo-*', '--log-json', 'repo'),
|
||||
output_file=None,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -1003,7 +1056,9 @@ def test_check_archives_calls_borg_with_working_directory():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'), working_directory='/working/dir')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'check', '--log-json', 'repo'), working_directory='/working/dir'
|
||||
)
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
|
||||
@@ -32,7 +32,7 @@ COMPACT_COMMAND = ('borg', 'compact')
|
||||
|
||||
def test_compact_segments_calls_borg_with_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, 'repo'), logging.INFO)
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--log-json', 'repo'), logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -45,7 +45,7 @@ def test_compact_segments_calls_borg_with_flags():
|
||||
|
||||
def test_compact_segments_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--info', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--log-json', '--info', 'repo'), logging.INFO)
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
@@ -59,7 +59,9 @@ def test_compact_segments_with_log_info_calls_borg_with_info_flag():
|
||||
|
||||
def test_compact_segments_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--debug', '--show-rc', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--log-json', '--debug', '--show-rc', 'repo'), logging.INFO
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.compact_segments(
|
||||
@@ -112,7 +114,7 @@ def test_compact_segments_with_dry_run_executes_borg_call_when_feature_available
|
||||
|
||||
def test_compact_segments_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', *COMPACT_COMMAND[1:], 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(('borg1', *COMPACT_COMMAND[1:], '--log-json', 'repo'), logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -128,7 +130,7 @@ def test_compact_segments_with_exit_codes_calls_borg_using_them():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, 'repo'),
|
||||
(*COMPACT_COMMAND, '--log-json', 'repo'),
|
||||
logging.INFO,
|
||||
borg_exit_codes=borg_exit_codes,
|
||||
)
|
||||
@@ -144,7 +146,9 @@ def test_compact_segments_with_exit_codes_calls_borg_using_them():
|
||||
|
||||
def test_compact_segments_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--remote-path', 'borg1', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--remote-path', 'borg1', '--log-json', 'repo'), logging.INFO
|
||||
)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -169,9 +173,26 @@ def test_compact_segments_with_progress_calls_borg_with_progress_flag():
|
||||
)
|
||||
|
||||
|
||||
def test_compact_segments_with_log_json_and_progress_calls_borg_with_both_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--log-json', '--progress', 'repo'), logging.INFO
|
||||
)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={'log_json': True, 'progress': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--cleanup-commits', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--log-json', '--cleanup-commits', 'repo'), logging.INFO
|
||||
)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -185,7 +206,9 @@ def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_f
|
||||
|
||||
def test_compact_segments_with_threshold_calls_borg_with_threshold_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--threshold', '20', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--log-json', '--threshold', '20', 'repo'), logging.INFO
|
||||
)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -199,7 +222,9 @@ def test_compact_segments_with_threshold_calls_borg_with_threshold_flag():
|
||||
def test_compact_segments_with_umask_calls_borg_with_umask_flags():
|
||||
config = {'umask': '077'}
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--umask', '077', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--umask', '077', '--log-json', 'repo'), logging.INFO
|
||||
)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -210,23 +235,12 @@ def test_compact_segments_with_umask_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_compact_segments_with_log_json_calls_borg_with_log_json_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--log-json', 'repo'), logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
config = {'lock_wait': 5}
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock((*COMPACT_COMMAND, '--lock-wait', '5', 'repo'), logging.INFO)
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--log-json', '--lock-wait', '5', 'repo'), logging.INFO
|
||||
)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
@@ -240,7 +254,7 @@ def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, '--extra', '--options', 'value with space', 'repo'),
|
||||
(*COMPACT_COMMAND, '--log-json', '--extra', '--options', 'value with space', 'repo'),
|
||||
logging.INFO,
|
||||
)
|
||||
|
||||
@@ -256,7 +270,7 @@ def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options(
|
||||
def test_compact_segments_calls_borg_with_working_directory():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(
|
||||
(*COMPACT_COMMAND, 'repo'),
|
||||
(*COMPACT_COMMAND, '--log-json', 'repo'),
|
||||
logging.INFO,
|
||||
working_directory='/working/dir',
|
||||
)
|
||||
|
||||
+108
-51
@@ -320,7 +320,7 @@ def test_make_base_create_produces_borg_command():
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -357,7 +357,7 @@ def test_make_base_create_command_includes_patterns_file_in_borg_command():
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', *pattern_flags)
|
||||
assert create_flags == ('borg', 'create', *pattern_flags, '--log-json')
|
||||
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
||||
assert pattern_file == mock_pattern_file
|
||||
|
||||
@@ -390,7 +390,7 @@ def test_make_base_create_command_with_store_config_false_omits_config_files():
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -459,7 +459,76 @@ def test_make_base_create_command_includes_configuration_option_as_command_flag(
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', *option_flags)
|
||||
assert create_flags == ('borg', 'create', *option_flags, '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
|
||||
def test_make_base_create_command_with_progress_omits_log_json_from_borg_command():
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('FOO')
|
||||
flexmock(module.flags).should_receive('get_default_archive_name_format').and_return(
|
||||
'{hostname}',
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
|
||||
)
|
||||
flexmock(module).should_receive('validate_planned_backup_paths').and_return(())
|
||||
|
||||
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': ['exclude'],
|
||||
'progress': True,
|
||||
},
|
||||
patterns=[Pattern('foo'), Pattern('bar')],
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
|
||||
def test_make_base_create_command_with_log_json_and_progress_includes_log_json_in_borg_command():
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('FOO')
|
||||
flexmock(module.flags).should_receive('get_default_archive_name_format').and_return(
|
||||
'{hostname}',
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
|
||||
)
|
||||
flexmock(module).should_receive('validate_planned_backup_paths').and_return(())
|
||||
|
||||
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': ['exclude'],
|
||||
'log_json': True,
|
||||
'progress': True,
|
||||
},
|
||||
patterns=[Pattern('foo'), Pattern('bar')],
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -492,7 +561,7 @@ def test_make_base_create_command_includes_dry_run_in_borg_command():
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--dry-run')
|
||||
assert create_flags == ('borg', 'create', '--log-json', '--dry-run')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -526,7 +595,7 @@ def test_make_base_create_command_includes_comment_in_borg_command():
|
||||
comment='a comment',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--comment', 'a comment')
|
||||
assert create_flags == ('borg', 'create', '--comment', 'a comment', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -559,7 +628,7 @@ def test_make_base_create_command_includes_local_path_in_borg_command():
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg1', 'create')
|
||||
assert create_flags == ('borg1', 'create', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -592,40 +661,7 @@ def test_make_base_create_command_includes_remote_path_in_borg_command():
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--remote-path', 'borg1')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
|
||||
def test_make_base_create_command_includes_log_json_in_borg_command():
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('FOO')
|
||||
flexmock(module.flags).should_receive('get_default_archive_name_format').and_return(
|
||||
'{hostname}',
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
(f'repo::{DEFAULT_ARCHIVE_NAME}',),
|
||||
)
|
||||
flexmock(module).should_receive('validate_planned_backup_paths').and_return(())
|
||||
|
||||
(create_flags, create_positional_arguments, pattern_file) = module.make_base_create_command(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'log_json': True,
|
||||
},
|
||||
patterns=[Pattern('foo'), Pattern('bar')],
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_flags == ('borg', 'create', '--remote-path', 'borg1', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -658,7 +694,7 @@ def test_make_base_create_command_includes_list_flags_in_borg_command():
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--list', '--filter', 'FOO')
|
||||
assert create_flags == ('borg', 'create', '--log-json', '--list', '--filter', 'FOO')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -723,7 +759,14 @@ def test_make_base_create_command_with_stream_processes_ignores_read_special_fal
|
||||
stream_processes=flexmock(),
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--patterns-from', 'patterns', '--read-special')
|
||||
assert create_flags == (
|
||||
'borg',
|
||||
'create',
|
||||
'--patterns-from',
|
||||
'patterns',
|
||||
'--read-special',
|
||||
'--log-json',
|
||||
)
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert pattern_file
|
||||
|
||||
@@ -786,7 +829,14 @@ def test_make_base_create_command_without_patterns_and_with_stream_processes_ign
|
||||
stream_processes=flexmock(),
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--read-special', '--patterns-from', 'patterns')
|
||||
assert create_flags == (
|
||||
'borg',
|
||||
'create',
|
||||
'--read-special',
|
||||
'--log-json',
|
||||
'--patterns-from',
|
||||
'patterns',
|
||||
)
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert pattern_file
|
||||
|
||||
@@ -821,7 +871,7 @@ def test_make_base_create_command_with_stream_processes_and_read_special_true_sk
|
||||
stream_processes=flexmock(),
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--read-special')
|
||||
assert create_flags == ('borg', 'create', '--read-special', '--log-json')
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
@@ -854,7 +904,7 @@ def test_make_base_create_command_includes_archive_name_format_in_borg_command()
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == ('repo::ARCHIVE_NAME',)
|
||||
assert not pattern_file
|
||||
|
||||
@@ -886,7 +936,7 @@ def test_make_base_create_command_includes_default_archive_name_format_in_borg_c
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == ('repo::{hostname}',)
|
||||
assert not pattern_file
|
||||
|
||||
@@ -919,7 +969,7 @@ def test_make_base_create_command_includes_archive_name_format_with_placeholders
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == (repository_archive_pattern,)
|
||||
assert not pattern_file
|
||||
|
||||
@@ -952,7 +1002,7 @@ def test_make_base_create_command_includes_repository_and_archive_name_format_wi
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == (repository_archive_pattern,)
|
||||
assert not pattern_file
|
||||
|
||||
@@ -981,7 +1031,7 @@ def test_make_base_create_command_includes_archive_suffix_in_borg_command():
|
||||
archive_suffix='.checkpoint',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create')
|
||||
assert create_flags == ('borg', 'create', '--log-json')
|
||||
assert create_positional_arguments == (f'repo::{DEFAULT_ARCHIVE_NAME}.checkpoint',)
|
||||
assert not pattern_file
|
||||
|
||||
@@ -1014,7 +1064,14 @@ def test_make_base_create_command_includes_extra_borg_options_in_borg_command():
|
||||
borgmatic_runtime_directory='/run/borgmatic',
|
||||
)
|
||||
|
||||
assert create_flags == ('borg', 'create', '--extra', '--options', 'value with space')
|
||||
assert create_flags == (
|
||||
'borg',
|
||||
'create',
|
||||
'--log-json',
|
||||
'--extra',
|
||||
'--options',
|
||||
'value with space',
|
||||
)
|
||||
assert create_positional_arguments == REPO_ARCHIVE
|
||||
assert not pattern_file
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def test_make_delete_command_includes_log_info():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--info', 'repo')
|
||||
assert command == ('borg', 'delete', '--info', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_log_debug():
|
||||
@@ -49,7 +49,7 @@ def test_make_delete_command_includes_log_debug():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--debug', '--show-rc', 'repo')
|
||||
assert command == ('borg', 'delete', '--debug', '--show-rc', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_dry_run():
|
||||
@@ -74,7 +74,7 @@ def test_make_delete_command_includes_dry_run():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--dry-run', 'repo')
|
||||
assert command == ('borg', 'delete', '--dry-run', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_remote_path():
|
||||
@@ -99,7 +99,7 @@ def test_make_delete_command_includes_remote_path():
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--remote-path', 'borg1', 'repo')
|
||||
assert command == ('borg', 'delete', '--remote-path', 'borg1', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_umask():
|
||||
@@ -122,32 +122,7 @@ def test_make_delete_command_includes_umask():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--umask', '077', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_log_json():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'log-json',
|
||||
True,
|
||||
).and_return(('--log-json',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',),
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_details=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--log-json', 'repo')
|
||||
assert command == ('borg', 'delete', '--umask', '077', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_lock_wait():
|
||||
@@ -172,7 +147,7 @@ def test_make_delete_command_includes_lock_wait():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--lock-wait', '5', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--lock-wait', '5', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_extra_borg_options():
|
||||
@@ -193,7 +168,7 @@ def test_make_delete_command_includes_extra_borg_options():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--extra', 'value with space', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--extra', 'value with space', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_with_list_config_calls_borg_with_list_flag():
|
||||
@@ -218,7 +193,7 @@ def test_make_delete_command_with_list_config_calls_borg_with_list_flag():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--list', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--list', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_force():
|
||||
@@ -239,7 +214,7 @@ def test_make_delete_command_includes_force():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--force', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--force', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_force_twice():
|
||||
@@ -260,7 +235,7 @@ def test_make_delete_command_includes_force_twice():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--force', '--force', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--force', '--force', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_archive():
|
||||
@@ -288,7 +263,7 @@ def test_make_delete_command_includes_archive():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--match-archives', 'archive', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--match-archives', 'archive', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_match_archives():
|
||||
@@ -316,7 +291,7 @@ def test_make_delete_command_includes_match_archives():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--match-archives', 'sh:foo*', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
||||
|
||||
LOGGING_ANSWER = flexmock()
|
||||
|
||||
@@ -35,7 +35,7 @@ def insert_execute_command_mock(
|
||||
def test_export_key_calls_borg_with_required_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -49,7 +49,7 @@ def test_export_key_calls_borg_with_required_flags():
|
||||
def test_export_key_calls_borg_with_local_path():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg1', 'key', 'export', 'repo'))
|
||||
insert_execute_command_mock(('borg1', 'key', 'export', '--log-json', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -65,7 +65,9 @@ def test_export_key_calls_borg_using_exit_codes():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', 'repo'), borg_exit_codes=borg_exit_codes)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', '--log-json', 'repo'), borg_exit_codes=borg_exit_codes
|
||||
)
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -79,7 +81,9 @@ def test_export_key_calls_borg_using_exit_codes():
|
||||
def test_export_key_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--remote-path', 'borg1', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', '--remote-path', 'borg1', '--log-json', 'repo')
|
||||
)
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -94,7 +98,7 @@ def test_export_key_calls_borg_with_remote_path_flags():
|
||||
def test_export_key_calls_borg_with_umask_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--umask', '0770', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--umask', '0770', '--log-json', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -105,24 +109,10 @@ def test_export_key_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_export_key_calls_borg_with_log_json_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
export_arguments=flexmock(paper=False, qr_html=False, path=None),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
)
|
||||
|
||||
|
||||
def test_export_key_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--lock-wait', '5', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--lock-wait', '5', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -136,7 +126,9 @@ def test_export_key_calls_borg_with_lock_wait_flags():
|
||||
def test_export_key_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--extra', 'value with space', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', '--log-json', '--extra', 'value with space', 'repo')
|
||||
)
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -150,7 +142,7 @@ def test_export_key_calls_borg_with_extra_borg_options():
|
||||
def test_export_key_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--info', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--info', 'repo'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.export_key(
|
||||
@@ -165,7 +157,9 @@ def test_export_key_with_log_info_calls_borg_with_info_parameter():
|
||||
def test_export_key_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--debug', '--show-rc', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', '--log-json', '--debug', '--show-rc', 'repo')
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.export_key(
|
||||
@@ -180,7 +174,7 @@ def test_export_key_with_log_debug_calls_borg_with_debug_flags():
|
||||
def test_export_key_calls_borg_with_paper_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--paper', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--paper', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -194,7 +188,7 @@ def test_export_key_calls_borg_with_paper_flags():
|
||||
def test_export_key_calls_borg_with_paper_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--paper', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--paper', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -208,7 +202,7 @@ def test_export_key_calls_borg_with_paper_flag():
|
||||
def test_export_key_calls_borg_with_qr_html_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--qr-html', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', '--qr-html', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -222,7 +216,9 @@ def test_export_key_calls_borg_with_qr_html_flag():
|
||||
def test_export_key_calls_borg_with_path_argument():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').with_args('dest').and_return(False)
|
||||
insert_execute_command_mock(('borg', 'key', 'export', 'repo', 'dest'), output_file=None)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', '--log-json', 'repo', 'dest'), output_file=None
|
||||
)
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -251,7 +247,7 @@ def test_export_key_with_already_existent_path_raises():
|
||||
def test_export_key_with_stdout_path_calls_borg_without_path_argument():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'export', '--log-json', 'repo'))
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -279,7 +275,9 @@ def test_export_key_with_dry_run_skips_borg_call():
|
||||
def test_export_key_calls_borg_with_working_directory():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'export', 'repo'), working_directory='/working/dir')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', '--log-json', 'repo'), working_directory='/working/dir'
|
||||
)
|
||||
|
||||
module.export_key(
|
||||
repository_path='repo',
|
||||
@@ -296,7 +294,7 @@ def test_export_key_calls_borg_with_path_argument_and_working_directory():
|
||||
False,
|
||||
).once()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'export', 'repo', 'dest'),
|
||||
('borg', 'key', 'export', '--log-json', 'repo', 'dest'),
|
||||
output_file=None,
|
||||
working_directory='/working/dir',
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_export_tar_archive_calls_borg_with_path_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', 'repo::archive', 'test.tar', 'path1', 'path2'),
|
||||
('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar', 'path1', 'path2'),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -59,7 +59,7 @@ def test_export_tar_archive_calls_borg_with_local_path_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg1', 'export-tar', 'repo::archive', 'test.tar'),
|
||||
('borg1', 'export-tar', '--log-json', 'repo::archive', 'test.tar'),
|
||||
borg_local_path='borg1',
|
||||
)
|
||||
|
||||
@@ -84,7 +84,7 @@ def test_export_tar_archive_calls_borg_using_exit_codes():
|
||||
)
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar'),
|
||||
borg_exit_codes=borg_exit_codes,
|
||||
)
|
||||
|
||||
@@ -107,7 +107,7 @@ def test_export_tar_archive_calls_borg_with_remote_path_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--remote-path', 'borg1', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--remote-path', 'borg1', '--log-json', 'repo::archive', 'test.tar'),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -130,7 +130,7 @@ def test_export_tar_archive_calls_borg_with_umask_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--umask', '0770', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--umask', '0770', '--log-json', 'repo::archive', 'test.tar'),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -145,26 +145,6 @@ def test_export_tar_archive_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_export_tar_archive_calls_borg_with_log_json_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar'))
|
||||
|
||||
module.export_tar_archive(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
paths=None,
|
||||
destination_path='test.tar',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_export_tar_archive_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
@@ -172,7 +152,7 @@ def test_export_tar_archive_calls_borg_with_lock_wait_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--lock-wait', '5', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--log-json', '--lock-wait', '5', 'repo::archive', 'test.tar'),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -194,7 +174,15 @@ def test_export_tar_archive_calls_borg_with_extra_borg_options():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--extra', 'value with space', 'repo::archive', 'test.tar'),
|
||||
(
|
||||
'borg',
|
||||
'export-tar',
|
||||
'--log-json',
|
||||
'--extra',
|
||||
'value with space',
|
||||
'repo::archive',
|
||||
'test.tar',
|
||||
),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -215,7 +203,9 @@ def test_export_tar_archive_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'export-tar', '--info', 'repo::archive', 'test.tar'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--log-json', '--info', 'repo::archive', 'test.tar')
|
||||
)
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -237,7 +227,7 @@ def test_export_tar_archive_with_log_debug_calls_borg_with_debug_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--debug', '--show-rc', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--log-json', '--debug', '--show-rc', 'repo::archive', 'test.tar'),
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
@@ -280,7 +270,7 @@ def test_export_tar_archive_calls_borg_with_tar_filter_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--tar-filter', 'bzip2', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--log-json', '--tar-filter', 'bzip2', 'repo::archive', 'test.tar'),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -303,7 +293,7 @@ def test_export_tar_archive_calls_borg_with_list_flag():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--list', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--log-json', '--list', 'repo::archive', 'test.tar'),
|
||||
output_log_level=logging.ANSWER,
|
||||
)
|
||||
|
||||
@@ -326,7 +316,15 @@ def test_export_tar_archive_calls_borg_with_strip_components_flag():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--strip-components', '5', 'repo::archive', 'test.tar'),
|
||||
(
|
||||
'borg',
|
||||
'export-tar',
|
||||
'--log-json',
|
||||
'--strip-components',
|
||||
'5',
|
||||
'repo::archive',
|
||||
'test.tar',
|
||||
),
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
@@ -348,7 +346,9 @@ def test_export_tar_archive_skips_abspath_for_remote_repository_flag():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('server:repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'export-tar', 'server:repo::archive', 'test.tar'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--log-json', 'server:repo::archive', 'test.tar')
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
dry_run=False,
|
||||
@@ -368,7 +368,9 @@ def test_export_tar_archive_calls_borg_with_stdout_destination_path():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'export-tar', 'repo::archive', '-'), capture=False)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', '--log-json', 'repo::archive', '-'), capture=False
|
||||
)
|
||||
|
||||
module.export_tar_archive(
|
||||
dry_run=False,
|
||||
@@ -389,7 +391,7 @@ def test_export_tar_archive_calls_borg_with_working_directory():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'export-tar', 'repo::archive', 'test.tar'),
|
||||
('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar'),
|
||||
working_directory='/working/dir',
|
||||
)
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ def insert_execute_command_mock(command, destination_path=None, borg_exit_codes=
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_last_archive():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'extract', '--dry-run', '--log-json', 'repo::archive'))
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
@@ -50,7 +50,9 @@ def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
|
||||
|
||||
def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(('borg', 'extract', '--dry-run', '--info', 'repo::archive'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--log-json', '--info', 'repo::archive')
|
||||
)
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
@@ -68,7 +70,16 @@ def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_paramet
|
||||
def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--debug', '--show-rc', '--list', 'repo::archive'),
|
||||
(
|
||||
'borg',
|
||||
'extract',
|
||||
'--dry-run',
|
||||
'--log-json',
|
||||
'--debug',
|
||||
'--show-rc',
|
||||
'--list',
|
||||
'repo::archive',
|
||||
),
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -86,7 +97,7 @@ def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_param
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_via_local_path():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(('borg1', 'extract', '--dry-run', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg1', 'extract', '--dry-run', '--log-json', 'repo::archive'))
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
@@ -105,7 +116,7 @@ def test_extract_last_archive_dry_run_calls_borg_using_exit_codes():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', 'repo::archive'),
|
||||
('borg', 'extract', '--dry-run', '--log-json', 'repo::archive'),
|
||||
borg_exit_codes=borg_exit_codes,
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -124,7 +135,7 @@ def test_extract_last_archive_dry_run_calls_borg_using_exit_codes():
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--remote-path', 'borg1', 'repo::archive'),
|
||||
('borg', 'extract', '--dry-run', '--remote-path', 'borg1', '--log-json', 'repo::archive'),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
@@ -140,26 +151,10 @@ def test_extract_last_archive_dry_run_calls_borg_with_remote_path_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_log_json_flag():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(('borg', 'extract', '--dry-run', '--log-json', 'repo::archive'))
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--lock-wait', '5', 'repo::archive'),
|
||||
('borg', 'extract', '--dry-run', '--log-json', '--lock-wait', '5', 'repo::archive'),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
@@ -177,7 +172,15 @@ def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_flags():
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.repo_list).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--extra', 'value with space', 'repo::archive'),
|
||||
(
|
||||
'borg',
|
||||
'extract',
|
||||
'--dry-run',
|
||||
'--log-json',
|
||||
'--extra',
|
||||
'value with space',
|
||||
'repo::archive',
|
||||
),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
@@ -193,7 +196,9 @@ def test_extract_last_archive_dry_run_calls_borg_with_extra_borg_options():
|
||||
|
||||
def test_extract_archive_calls_borg_with_path_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', 'repo::archive', 'path1', 'path2'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--log-json', 'repo::archive', 'path1', 'path2')
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -216,7 +221,7 @@ def test_extract_archive_calls_borg_with_path_flags():
|
||||
|
||||
def test_extract_archive_calls_borg_with_local_path():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg1', 'extract', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg1', 'extract', '--log-json', 'repo::archive'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -242,7 +247,7 @@ def test_extract_archive_calls_borg_with_exit_codes():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', 'repo::archive'),
|
||||
('borg', 'extract', '--log-json', 'repo::archive'),
|
||||
borg_exit_codes=borg_exit_codes,
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
@@ -267,7 +272,9 @@ def test_extract_archive_calls_borg_with_exit_codes():
|
||||
|
||||
def test_extract_archive_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--remote-path', 'borg1', 'repo::archive'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--remote-path', 'borg1', '--log-json', 'repo::archive')
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -298,7 +305,7 @@ def test_extract_archive_calls_borg_with_remote_path_flags():
|
||||
)
|
||||
def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available, option_flag):
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', option_flag, 'repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'extract', option_flag, '--log-json', 'repo::archive'))
|
||||
flexmock(module.feature).should_receive('available').and_return(feature_available)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -321,7 +328,9 @@ def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available
|
||||
|
||||
def test_extract_archive_calls_borg_with_umask_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--umask', '0770', 'repo::archive'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--umask', '0770', '--log-json', 'repo::archive')
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -342,29 +351,11 @@ def test_extract_archive_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_log_json_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--log-json', 'repo::archive'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
|
||||
module.extract_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
paths=None,
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--lock-wait', '5', 'repo::archive'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--log-json', '--lock-wait', '5', 'repo::archive')
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -387,7 +378,9 @@ def test_extract_archive_calls_borg_with_lock_wait_flags():
|
||||
|
||||
def test_extract_archive_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--extra', 'value with space', 'repo::archive'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--log-json', '--extra', 'value with space', 'repo::archive')
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -410,7 +403,7 @@ def test_extract_archive_calls_borg_with_extra_borg_options():
|
||||
|
||||
def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--info', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'extract', '--log-json', '--info', 'repo::archive'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
@@ -435,7 +428,7 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
||||
def test_extract_archive_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--debug', '--list', '--show-rc', 'repo::archive'),
|
||||
('borg', 'extract', '--log-json', '--debug', '--list', '--show-rc', 'repo::archive'),
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
@@ -460,7 +453,7 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_flags():
|
||||
|
||||
def test_extract_archive_calls_borg_with_dry_run_parameter():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'extract', '--log-json', '--dry-run', 'repo::archive'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -483,7 +476,9 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
|
||||
|
||||
def test_extract_archive_calls_borg_with_destination_path():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', 'repo::archive'), destination_path='/dest')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--log-json', 'repo::archive'), destination_path='/dest'
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -507,7 +502,9 @@ def test_extract_archive_calls_borg_with_destination_path():
|
||||
|
||||
def test_extract_archive_calls_borg_with_strip_components():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--strip-components', '5', 'repo::archive'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--log-json', '--strip-components', '5', 'repo::archive')
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
@@ -535,6 +532,7 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all():
|
||||
(
|
||||
'borg',
|
||||
'extract',
|
||||
'--log-json',
|
||||
'--strip-components',
|
||||
'2',
|
||||
'repo::archive',
|
||||
@@ -569,6 +567,7 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all_wi
|
||||
(
|
||||
'borg',
|
||||
'extract',
|
||||
'--log-json',
|
||||
'--strip-components',
|
||||
'2',
|
||||
'repo::archive',
|
||||
@@ -654,13 +653,45 @@ def test_extract_archive_calls_borg_with_progress_flag():
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_with_log_json_and_progress_calls_borg_with_both_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'extract', '--log-json', '--progress', 'repo::archive'),
|
||||
output_file=module.DO_NOT_CAPTURE,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
flexmock(module.borgmatic.config.validate).should_receive(
|
||||
'normalize_repository_path',
|
||||
).and_return('repo')
|
||||
|
||||
module.extract_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
paths=None,
|
||||
config={'log_json': True, 'progress': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_extract_to_stdout_returns_process():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
process = flexmock()
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'extract', '--stdout', 'repo::archive'),
|
||||
('borg', 'extract', '--log-json', '--stdout', 'repo::archive'),
|
||||
output_file=module.subprocess.PIPE,
|
||||
run_to_completion=False,
|
||||
environment=None,
|
||||
@@ -735,7 +766,7 @@ def test_extract_archive_skips_abspath_for_remote_repository():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'extract', 'server:repo::archive'),
|
||||
('borg', 'extract', '--log-json', 'server:repo::archive'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -764,7 +795,7 @@ def test_extract_archive_skips_abspath_for_remote_repository():
|
||||
def test_extract_archive_uses_configured_working_directory_in_repo_path_and_destination_path():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '/working/dir/repo::archive'),
|
||||
('borg', 'extract', '--log-json', '/working/dir/repo::archive'),
|
||||
destination_path='/working/dir/dest',
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
@@ -789,7 +820,7 @@ def test_extract_archive_uses_configured_working_directory_in_repo_path_and_dest
|
||||
|
||||
def test_extract_archive_uses_configured_working_directory_in_repo_path_when_destination_path_is_not_set():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '/working/dir/repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'extract', '--log-json', '/working/dir/repo::archive'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('/working/dir/repo::archive',),
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_import_key_calls_borg_with_required_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -48,7 +48,7 @@ def test_import_key_calls_borg_with_local_path():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg1', 'key', 'import', 'repo'))
|
||||
insert_execute_command_mock(('borg1', 'key', 'import', '--log-json', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -65,7 +65,9 @@ def test_import_key_calls_borg_using_exit_codes():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', 'repo'), borg_exit_codes=borg_exit_codes)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', '--log-json', 'repo'), borg_exit_codes=borg_exit_codes
|
||||
)
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -80,7 +82,9 @@ def test_import_key_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--remote-path', 'borg1', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', '--remote-path', 'borg1', '--log-json', 'repo')
|
||||
)
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -96,7 +100,7 @@ def test_import_key_calls_borg_with_umask_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--umask', '0770', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--umask', '0770', '--log-json', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -107,26 +111,11 @@ def test_import_key_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_import_key_calls_borg_with_log_json_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
import_arguments=flexmock(paper=False, path=None),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
)
|
||||
|
||||
|
||||
def test_import_key_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--lock-wait', '5', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', '--lock-wait', '5', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -141,7 +130,9 @@ def test_import_key_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--extra', 'value with space', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', '--log-json', '--extra', 'value with space', 'repo')
|
||||
)
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -156,7 +147,7 @@ def test_import_key_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--info', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', '--info', 'repo'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.import_key(
|
||||
@@ -172,7 +163,9 @@ def test_import_key_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--debug', '--show-rc', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', '--log-json', '--debug', '--show-rc', 'repo')
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.import_key(
|
||||
@@ -188,7 +181,7 @@ def test_import_key_calls_borg_with_paper_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(('--paper',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--paper', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', '--paper', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -203,7 +196,9 @@ def test_import_key_calls_borg_with_path_argument():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').with_args('source').and_return(True)
|
||||
insert_execute_command_mock(('borg', 'key', 'import', 'repo', 'source'), input_file=None)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', '--log-json', 'repo', 'source'), input_file=None
|
||||
)
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -234,7 +229,7 @@ def test_import_key_with_stdin_path_calls_borg_without_path_argument():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'key', 'import', '--log-json', 'repo'))
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -264,7 +259,9 @@ def test_import_key_calls_borg_with_working_directory():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.os.path).should_receive('exists').never()
|
||||
insert_execute_command_mock(('borg', 'key', 'import', 'repo'), working_directory='/working/dir')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', '--log-json', 'repo'), working_directory='/working/dir'
|
||||
)
|
||||
|
||||
module.import_key(
|
||||
repository_path='repo',
|
||||
@@ -282,7 +279,7 @@ def test_import_key_calls_borg_with_path_argument_and_working_directory():
|
||||
True,
|
||||
).once()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'key', 'import', 'repo', 'source'),
|
||||
('borg', 'key', 'import', '--log-json', 'repo', 'source'),
|
||||
input_file=None,
|
||||
working_directory='/working/dir',
|
||||
)
|
||||
|
||||
@@ -28,7 +28,7 @@ def test_make_info_command_constructs_borg_info_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--log-json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_log_info_passes_through_to_command():
|
||||
@@ -52,7 +52,7 @@ def test_make_info_command_with_log_info_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--info', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--info', '--log-json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_log_info_and_json_omits_borg_logging_flags():
|
||||
@@ -76,7 +76,7 @@ def test_make_info_command_with_log_info_and_json_omits_borg_logging_flags():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--json', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--log-json', '--json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_log_debug_passes_through_to_command():
|
||||
@@ -100,7 +100,7 @@ def test_make_info_command_with_log_debug_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--debug', '--show-rc', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--debug', '--show-rc', '--log-json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_log_debug_and_json_omits_borg_logging_flags():
|
||||
@@ -123,7 +123,7 @@ def test_make_info_command_with_log_debug_and_json_omits_borg_logging_flags():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--json', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--log-json', '--json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_json_passes_through_to_command():
|
||||
@@ -146,7 +146,7 @@ def test_make_info_command_with_json_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--json', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--log-json', '--json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_archive_uses_match_archives_flags():
|
||||
@@ -169,7 +169,15 @@ def test_make_info_command_with_archive_uses_match_archives_flags():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--match-archives', 'archive', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--match-archives',
|
||||
'archive',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_info_command_with_local_path_passes_through_to_command():
|
||||
@@ -192,7 +200,7 @@ def test_make_info_command_with_local_path_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg1', 'info', '--repo', 'repo')
|
||||
assert command == ('borg1', 'info', '--log-json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_remote_path_passes_through_to_command():
|
||||
@@ -219,7 +227,7 @@ def test_make_info_command_with_remote_path_passes_through_to_command():
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--remote-path', 'borg1', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--remote-path', 'borg1', '--log-json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_umask_passes_through_to_command():
|
||||
@@ -244,33 +252,7 @@ def test_make_info_command_with_umask_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--umask', '077', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_log_json_passes_through_to_command():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json',),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None,
|
||||
None,
|
||||
'2.3.4',
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
|
||||
command = module.make_info_command(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--log-json', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--umask', '077', '--log-json', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_lock_wait_passes_through_to_command():
|
||||
@@ -297,7 +279,7 @@ def test_make_info_command_with_lock_wait_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--lock-wait', '5', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--log-json', '--lock-wait', '5', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_extra_borg_options_passes_through_to_command():
|
||||
@@ -321,7 +303,15 @@ def test_make_info_command_with_extra_borg_options_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--extra', 'value with space', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--extra',
|
||||
'value with space',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_info_command_transforms_prefix_into_match_archives_flags():
|
||||
@@ -348,7 +338,15 @@ def test_make_info_command_transforms_prefix_into_match_archives_flags():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--match-archives',
|
||||
'sh:foo*',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_info_command_prefers_prefix_over_archive_name_format():
|
||||
@@ -375,7 +373,15 @@ def test_make_info_command_prefers_prefix_over_archive_name_format():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--match-archives',
|
||||
'sh:foo*',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_info_command_transforms_archive_name_format_into_match_archives_flags():
|
||||
@@ -398,7 +404,15 @@ def test_make_info_command_transforms_archive_name_format_into_match_archives_fl
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--match-archives', 'sh:bar-*', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--match-archives',
|
||||
'sh:bar-*',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_info_command_with_match_archives_option_passes_through_to_command():
|
||||
@@ -425,7 +439,15 @@ def test_make_info_command_with_match_archives_option_passes_through_to_command(
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--match-archives',
|
||||
'sh:foo-*',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_info_command_with_match_archives_flag_passes_through_to_command():
|
||||
@@ -449,7 +471,15 @@ def test_make_info_command_with_match_archives_flag_passes_through_to_command():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--match-archives',
|
||||
'sh:foo-*',
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('argument_name', ('sort_by', 'first', 'last'))
|
||||
@@ -483,7 +513,7 @@ def test_make_info_command_passes_arguments_through_to_command(argument_name):
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'info', flag_name, 'value', '--repo', 'repo')
|
||||
assert command == ('borg', 'info', '--log-json', flag_name, 'value', '--repo', 'repo')
|
||||
|
||||
|
||||
def test_make_info_command_with_date_based_matching_passes_through_to_command():
|
||||
@@ -521,6 +551,7 @@ def test_make_info_command_with_date_based_matching_passes_through_to_command():
|
||||
assert command == (
|
||||
'borg',
|
||||
'info',
|
||||
'--log-json',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
@@ -536,6 +567,7 @@ def test_make_info_command_with_date_based_matching_passes_through_to_command():
|
||||
|
||||
def test_display_archives_info_calls_two_commands():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_info_command')
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
@@ -554,6 +586,7 @@ def test_display_archives_info_calls_two_commands():
|
||||
|
||||
def test_display_archives_info_with_json_calls_json_command_only():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_info_command')
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
@@ -576,6 +609,7 @@ def test_display_archives_info_with_json_calls_json_command_only():
|
||||
|
||||
def test_display_archives_info_calls_borg_with_working_directory():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_info_command')
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
|
||||
|
||||
@@ -23,7 +23,7 @@ def test_make_list_command_includes_log_info():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--info', 'repo')
|
||||
assert command == ('borg', 'list', '--info', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_json_but_not_info():
|
||||
@@ -40,7 +40,7 @@ def test_make_list_command_includes_json_but_not_info():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_log_debug():
|
||||
@@ -57,7 +57,7 @@ def test_make_list_command_includes_log_debug():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_json_but_not_debug():
|
||||
@@ -74,7 +74,7 @@ def test_make_list_command_includes_json_but_not_debug():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_json():
|
||||
@@ -90,25 +90,7 @@ def test_make_list_command_includes_json():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_log_json():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(()).and_return(
|
||||
('--log-json',),
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_list_command(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, format=None, json=False),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--log-json', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_lock_wait():
|
||||
@@ -126,7 +108,7 @@ def test_make_list_command_includes_lock_wait():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--lock-wait', '5', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_format():
|
||||
@@ -144,7 +126,7 @@ def test_make_list_command_includes_format():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--format', 'stuff', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--format', 'stuff', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_extra_borg_options():
|
||||
@@ -160,7 +142,7 @@ def test_make_list_command_includes_extra_borg_options():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--extra', 'value with space', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--extra', 'value with space', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_archive():
|
||||
@@ -178,7 +160,7 @@ def test_make_list_command_includes_archive():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', 'repo::archive')
|
||||
assert command == ('borg', 'list', '--log-json', 'repo::archive')
|
||||
|
||||
|
||||
def test_make_list_command_includes_archive_and_path():
|
||||
@@ -196,7 +178,7 @@ def test_make_list_command_includes_archive_and_path():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', 'repo::archive', 'var/lib')
|
||||
assert command == ('borg', 'list', '--log-json', 'repo::archive', 'var/lib')
|
||||
|
||||
|
||||
def test_make_list_command_includes_local_path():
|
||||
@@ -213,7 +195,7 @@ def test_make_list_command_includes_local_path():
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
assert command == ('borg2', 'list', 'repo')
|
||||
assert command == ('borg2', 'list', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_remote_path():
|
||||
@@ -237,7 +219,7 @@ def test_make_list_command_includes_remote_path():
|
||||
remote_path='borg2',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--remote-path', 'borg2', 'repo')
|
||||
assert command == ('borg', 'list', '--remote-path', 'borg2', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_umask():
|
||||
@@ -255,7 +237,7 @@ def test_make_list_command_includes_umask():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--umask', '077', 'repo')
|
||||
assert command == ('borg', 'list', '--umask', '077', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_short():
|
||||
@@ -271,7 +253,7 @@ def test_make_list_command_includes_short():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--short', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--short', 'repo')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -310,7 +292,14 @@ def test_make_list_command_includes_additional_flags(argument_name):
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'list',
|
||||
'--log-json',
|
||||
'--' + argument_name.replace('_', '-'),
|
||||
'value',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_find_paths_considers_none_as_empty_paths():
|
||||
@@ -382,12 +371,12 @@ def test_list_archive_calls_borg_with_flags():
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(())
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive'),
|
||||
('borg', 'list', '--log-json', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -449,12 +438,12 @@ def test_list_archive_calls_borg_with_local_path():
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg2',
|
||||
remote_path=None,
|
||||
).and_return(('borg2', 'list', 'repo::archive'))
|
||||
).and_return(('borg2', 'list', '--log-json', 'repo::archive'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(())
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg2', 'list', 'repo::archive'),
|
||||
('borg2', 'list', '--log-json', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -499,12 +488,12 @@ def test_list_archive_calls_borg_using_exit_codes():
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(())
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive'),
|
||||
('borg', 'list', '--log-json', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -539,23 +528,23 @@ def test_list_archive_calls_borg_multiple_times_with_find_paths():
|
||||
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.repo_list).should_receive('make_repo_list_command').and_return(
|
||||
('borg', 'list', 'repo'),
|
||||
('borg', 'list', '--log-json', 'repo'),
|
||||
)
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', 'repo'),
|
||||
('borg', 'list', '--log-json', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).and_return('archive1\narchive2').once()
|
||||
flexmock(module).should_receive('make_list_command').and_return(
|
||||
('borg', 'list', 'repo::archive1'),
|
||||
).and_return(('borg', 'list', 'repo::archive2'))
|
||||
('borg', 'list', '--log-json', 'repo::archive1'),
|
||||
).and_return(('borg', 'list', '--log-json', 'repo::archive2'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(glob_paths)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive1', *glob_paths),
|
||||
('borg', 'list', '--log-json', 'repo::archive1', *glob_paths),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -563,7 +552,7 @@ def test_list_archive_calls_borg_multiple_times_with_find_paths():
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive2', *glob_paths),
|
||||
('borg', 'list', '--log-json', 'repo::archive2', *glob_paths),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -606,12 +595,12 @@ def test_list_archive_calls_borg_with_archive():
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(())
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive'),
|
||||
('borg', 'list', '--log-json', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -734,12 +723,12 @@ def test_list_archive_with_archive_ignores_archive_filter_flag(
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(())
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive'),
|
||||
('borg', 'list', '--log-json', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -832,7 +821,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', '--repo', 'repo', 'archive1'))
|
||||
).and_return(('borg', 'list', '--log-json', '--repo', 'repo', 'archive1'))
|
||||
|
||||
flexmock(module).should_receive('make_list_command').with_args(
|
||||
repository_path='repo',
|
||||
@@ -851,12 +840,12 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', '--repo', 'repo', 'archive2'))
|
||||
).and_return(('borg', 'list', '--log-json', '--repo', 'repo', 'archive2'))
|
||||
|
||||
flexmock(module).should_receive('make_find_paths').and_return(glob_paths)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', '--repo', 'repo', 'archive1', *glob_paths),
|
||||
('borg', 'list', '--log-json', '--repo', 'repo', 'archive1', *glob_paths),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -864,7 +853,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', '--repo', 'repo', 'archive2', *glob_paths),
|
||||
('borg', 'list', '--log-json', '--repo', 'repo', 'archive2', *glob_paths),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -916,14 +905,14 @@ def test_list_archive_calls_borg_with_working_directory():
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
).and_return(('borg', 'list', '--log-json', 'repo::archive'))
|
||||
flexmock(module).should_receive('make_find_paths').and_return(())
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
|
||||
'/working/dir',
|
||||
)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo::archive'),
|
||||
('borg', 'list', '--log-json', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory='/working/dir',
|
||||
|
||||
@@ -24,7 +24,7 @@ def insert_execute_command_mock(command, working_directory=None, borg_exit_codes
|
||||
def test_mount_archive_calls_borg_with_required_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt'))
|
||||
insert_execute_command_mock(('borg', 'mount', '--log-json', 'repo', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
@@ -46,7 +46,7 @@ def test_mount_archive_with_borg_features_calls_borg_with_repository_and_match_a
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--repo', 'repo', '--match-archives', 'archive', '/mnt'),
|
||||
('borg', 'mount', '--log-json', '--repo', 'repo', '--match-archives', 'archive', '/mnt'),
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
@@ -65,7 +65,7 @@ def test_mount_archive_without_archive_calls_borg_with_repository_flags_only():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(('borg', 'mount', '--log-json', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
@@ -83,7 +83,9 @@ def test_mount_archive_calls_borg_with_path_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--log-json', 'repo::archive', '/mnt', 'path1', 'path2')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(
|
||||
mount_point='/mnt',
|
||||
@@ -106,7 +108,7 @@ def test_mount_archive_calls_borg_with_local_path():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg1', 'mount', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(('borg1', 'mount', '--log-json', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
@@ -127,7 +129,7 @@ def test_mount_archive_calls_borg_using_exit_codes():
|
||||
)
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', 'repo::archive', '/mnt'),
|
||||
('borg', 'mount', '--log-json', 'repo::archive', '/mnt'),
|
||||
borg_exit_codes=borg_exit_codes,
|
||||
)
|
||||
|
||||
@@ -148,7 +150,7 @@ def test_mount_archive_calls_borg_with_remote_path_flags():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt'),
|
||||
('borg', 'mount', '--remote-path', 'borg1', '--log-json', 'repo::archive', '/mnt'),
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
@@ -168,7 +170,9 @@ def test_mount_archive_calls_borg_with_umask_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--umask', '0770', '--log-json', 'repo::archive', '/mnt')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
@@ -181,30 +185,14 @@ def test_mount_archive_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_mount_archive_calls_borg_with_log_json_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--log-json', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_arguments=mount_arguments,
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_mount_archive_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--lock-wait', '5', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--log-json', '--lock-wait', '5', 'repo::archive', '/mnt')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
@@ -223,7 +211,7 @@ def test_mount_archive_calls_borg_with_extra_borg_options():
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--extra', 'value with space', 'repo::archive', '/mnt')
|
||||
('borg', 'mount', '--log-json', '--extra', 'value with space', 'repo::archive', '/mnt')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
@@ -242,7 +230,7 @@ def test_mount_archive_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(('borg', 'mount', '--log-json', '--info', 'repo::archive', '/mnt'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
@@ -261,7 +249,9 @@ def test_mount_archive_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--log-json', '--debug', '--show-rc', 'repo::archive', '/mnt')
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
@@ -283,7 +273,7 @@ def test_mount_archive_calls_borg_with_foreground_parameter():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'mount', '--foreground', 'repo::archive', '/mnt'),
|
||||
('borg', 'mount', '--log-json', '--foreground', 'repo::archive', '/mnt'),
|
||||
output_file=module.DO_NOT_CAPTURE,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -307,7 +297,9 @@ def test_mount_archive_calls_borg_with_options_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--log-json', '-o', 'super_mount', 'repo::archive', '/mnt')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(
|
||||
mount_point='/mnt',
|
||||
@@ -349,6 +341,7 @@ def test_mount_archive_with_date_based_matching_calls_borg_with_date_based_flags
|
||||
(
|
||||
'borg',
|
||||
'mount',
|
||||
'--log-json',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
@@ -392,7 +385,9 @@ def test_mount_archive_with_date_based_matching_calls_borg_with_date_based_flags
|
||||
def test_mount_archive_calls_borg_with_working_directory():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt'), working_directory='/working/dir')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--log-json', 'repo', '/mnt'), working_directory='/working/dir'
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
|
||||
@@ -221,7 +221,17 @@ def test_make_prune_flags_ignores_keep_exclude_tags_in_config():
|
||||
assert result == ('--keep-daily', '1')
|
||||
|
||||
|
||||
PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
|
||||
PRUNE_COMMAND = (
|
||||
'borg',
|
||||
'prune',
|
||||
'--keep-daily',
|
||||
'1',
|
||||
'--keep-weekly',
|
||||
'2',
|
||||
'--keep-monthly',
|
||||
'3',
|
||||
'--log-json',
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_calls_borg_with_flags():
|
||||
@@ -454,28 +464,6 @@ def test_prune_archives_with_umask_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.feature).should_receive('available').with_args(
|
||||
module.feature.Feature.NO_PRUNE_STATS,
|
||||
'1.2.3',
|
||||
).and_return(False)
|
||||
insert_execute_command_mock((*PRUNE_COMMAND, '--log-json', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(statistics=False, list_details=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
@@ -561,6 +549,7 @@ def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flag
|
||||
'2',
|
||||
'--keep-monthly',
|
||||
'3',
|
||||
'--log-json',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
|
||||
@@ -72,7 +72,7 @@ def test_recreate_calls_borg_with_required_flags():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -107,7 +107,9 @@ def test_recreate_with_remote_path():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--remote-path', 'borg1', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--remote-path', 'borg1', '--log-json', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -142,7 +144,9 @@ def test_recreate_with_lock_wait():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--lock-wait', '5', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--lock-wait', '5', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -177,7 +181,7 @@ def test_recreate_with_extra_borg_options():
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--extra', 'value with space', '--repo', 'repo')
|
||||
('borg', 'recreate', '--log-json', '--extra', 'value with space', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -212,7 +216,7 @@ def test_recreate_with_log_info():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--info', '--repo', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--info', '--repo', 'repo'))
|
||||
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
@@ -248,7 +252,9 @@ def test_recreate_with_log_debug():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--debug', '--show-rc', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--debug', '--show-rc', '--repo', 'repo')
|
||||
)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -269,40 +275,6 @@ def test_recreate_with_log_debug():
|
||||
)
|
||||
|
||||
|
||||
def test_recreate_with_log_json():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_list_filter_flags').and_return('')
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive(
|
||||
'make_repository_archive_flags',
|
||||
).and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
recreate_arguments=flexmock(
|
||||
list=None,
|
||||
target=None,
|
||||
comment=None,
|
||||
timestamp=None,
|
||||
match_archives=None,
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path='borg',
|
||||
patterns=None,
|
||||
)
|
||||
|
||||
|
||||
def test_recreate_with_list_config_calls_borg_with_list_flag():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.pattern).should_receive('write_patterns_file').and_return(None)
|
||||
@@ -320,7 +292,7 @@ def test_recreate_with_list_config_calls_borg_with_list_flag():
|
||||
'AME+-',
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--list', '--filter', 'AME+-', '--repo', 'repo'),
|
||||
('borg', 'recreate', '--log-json', '--list', '--filter', 'AME+-', '--repo', 'repo'),
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -357,7 +329,7 @@ def test_recreate_with_patterns_from_flag():
|
||||
mock_patterns_file = flexmock(name='patterns_file')
|
||||
flexmock(module).should_receive('write_patterns_file').and_return(mock_patterns_file)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--patterns-from', 'patterns_file', '--repo', 'repo'),
|
||||
('borg', 'recreate', '--log-json', '--patterns-from', 'patterns_file', '--repo', 'repo'),
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -394,7 +366,9 @@ def test_recreate_with_exclude_flags():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_exclude_flags').and_return(
|
||||
('--exclude', 'pattern'),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--exclude', 'pattern', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--exclude', 'pattern', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -428,7 +402,9 @@ def test_recreate_with_target_flag():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--target', 'new-archive', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--target', 'new-archive', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -463,7 +439,15 @@ def test_recreate_with_comment_flag():
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--comment', shlex.quote('This is a test comment'), '--repo', 'repo'),
|
||||
(
|
||||
'borg',
|
||||
'recreate',
|
||||
'--log-json',
|
||||
'--comment',
|
||||
shlex.quote('This is a test comment'),
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -499,7 +483,7 @@ def test_recreate_with_timestamp_flag():
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--timestamp', '2023-10-01T12:00:00', '--repo', 'repo'),
|
||||
('borg', 'recreate', '--log-json', '--timestamp', '2023-10-01T12:00:00', '--repo', 'repo'),
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -534,7 +518,9 @@ def test_recreate_with_compression_flag():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--compression', 'lz4', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--compression', 'lz4', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -569,7 +555,7 @@ def test_recreate_with_chunker_params_flag():
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--chunker-params', '19,23,21,4095', '--repo', 'repo'),
|
||||
('borg', 'recreate', '--log-json', '--chunker-params', '19,23,21,4095', '--repo', 'repo'),
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -604,7 +590,9 @@ def test_recreate_with_recompress_flag():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--recompress', 'always', '--repo', 'repo'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--recompress', 'always', '--repo', 'repo')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -638,7 +626,7 @@ def test_recreate_with_match_archives_star():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -672,7 +660,7 @@ def test_recreate_with_match_archives_regex():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -706,7 +694,7 @@ def test_recreate_with_match_archives_shell():
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', '--repo', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -740,7 +728,9 @@ def test_recreate_with_match_archives_and_feature_available_calls_borg_with_matc
|
||||
('--repo', 'repo'),
|
||||
)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
|
||||
insert_execute_command_mock(('borg', 'recreate', '--repo', 'repo', '--match-archives', 'foo-*'))
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--log-json', '--repo', 'repo', '--match-archives', 'foo-*')
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -775,7 +765,7 @@ def test_recreate_with_archives_flag_and_feature_available_calls_borg_with_match
|
||||
)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
|
||||
insert_execute_command_mock(
|
||||
('borg', 'recreate', '--repo', 'repo', '--match-archives', 'archive'),
|
||||
('borg', 'recreate', '--log-json', '--repo', 'repo', '--match-archives', 'archive'),
|
||||
)
|
||||
|
||||
module.recreate_archive(
|
||||
@@ -806,7 +796,7 @@ def test_recreate_with_match_archives_and_feature_not_available_calls_borg_witho
|
||||
('repo',),
|
||||
)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_archive_flags').never()
|
||||
insert_execute_command_mock(('borg', 'recreate', 'repo'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', 'repo'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
@@ -836,7 +826,7 @@ def test_recreate_with_archives_flags_and_feature_not_available_calls_borg_with_
|
||||
'make_repository_archive_flags',
|
||||
).and_return(('repo::archive',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').never()
|
||||
insert_execute_command_mock(('borg', 'recreate', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'recreate', '--log-json', 'repo::archive'))
|
||||
|
||||
module.recreate_archive(
|
||||
repository='repo',
|
||||
|
||||
@@ -9,7 +9,7 @@ from borgmatic.borg import repo_create as module
|
||||
from ..test_verbosity import insert_logging_mock
|
||||
|
||||
REPO_INFO_SOME_UNKNOWN_EXIT_CODE = -999
|
||||
REPO_CREATE_COMMAND = ('borg', 'repo-create', '--encryption', 'repokey')
|
||||
REPO_CREATE_COMMAND = ('borg', 'repo-create', '--log-json', '--encryption', 'repokey')
|
||||
|
||||
|
||||
def insert_repo_info_command_found_mock():
|
||||
@@ -352,27 +352,6 @@ def test_create_repository_with_log_debug_calls_borg_with_debug_flag():
|
||||
)
|
||||
|
||||
|
||||
def test_create_repository_with_log_json_calls_borg_with_log_json_flag():
|
||||
insert_repo_info_command_not_found_mock()
|
||||
insert_repo_create_command_mock((*REPO_CREATE_COMMAND, '--log-json', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
||||
def test_create_repository_with_lock_wait_calls_borg_with_lock_wait_flag():
|
||||
insert_repo_info_command_not_found_mock()
|
||||
insert_repo_create_command_mock((*REPO_CREATE_COMMAND, '--lock-wait', '5', '--repo', 'repo'))
|
||||
|
||||
@@ -25,7 +25,7 @@ def test_make_repo_delete_command_with_feature_available_runs_borg_repo_delete()
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_without_feature_available_runs_borg_delete():
|
||||
@@ -46,7 +46,7 @@ def test_make_repo_delete_command_without_feature_available_runs_borg_delete():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_log_info():
|
||||
@@ -68,7 +68,7 @@ def test_make_repo_delete_command_includes_log_info():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--info', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--info', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_log_debug():
|
||||
@@ -90,7 +90,7 @@ def test_make_repo_delete_command_includes_log_debug():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--debug', '--show-rc', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--debug', '--show-rc', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_dry_run():
|
||||
@@ -115,7 +115,7 @@ def test_make_repo_delete_command_includes_dry_run():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--dry-run', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--dry-run', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_remote_path():
|
||||
@@ -140,7 +140,7 @@ def test_make_repo_delete_command_includes_remote_path():
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--remote-path', 'borg1', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--remote-path', 'borg1', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_umask():
|
||||
@@ -163,32 +163,7 @@ def test_make_repo_delete_command_includes_umask():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--umask', '077', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_log_json():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'log-json',
|
||||
True,
|
||||
).and_return(('--log-json',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',),
|
||||
)
|
||||
|
||||
command = module.make_repo_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
repo_delete_arguments=flexmock(list_details=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--log-json', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--umask', '077', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_lock_wait():
|
||||
@@ -213,7 +188,7 @@ def test_make_repo_delete_command_includes_lock_wait():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--lock-wait', '5', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--log-json', '--lock-wait', '5', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_without_feature_available_includes_delete_extra_borg_options():
|
||||
@@ -234,7 +209,7 @@ def test_make_repo_delete_command_without_feature_available_includes_delete_extr
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--extra', 'value with space', 'repo')
|
||||
assert command == ('borg', 'delete', '--log-json', '--extra', 'value with space', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_with_feature_available_includes_delete_extra_borg_options():
|
||||
@@ -255,7 +230,7 @@ def test_make_repo_delete_command_with_feature_available_includes_delete_extra_b
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--extra', 'value with space', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--log-json', '--extra', 'value with space', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_list():
|
||||
@@ -280,7 +255,7 @@ def test_make_repo_delete_command_includes_list():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--list', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--log-json', '--list', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_force():
|
||||
@@ -301,7 +276,7 @@ def test_make_repo_delete_command_includes_force():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--force', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--log-json', '--force', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_delete_command_includes_force_twice():
|
||||
@@ -322,11 +297,12 @@ def test_make_repo_delete_command_includes_force_twice():
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-delete', '--force', '--force', 'repo')
|
||||
assert command == ('borg', 'repo-delete', '--log-json', '--force', '--force', 'repo')
|
||||
|
||||
|
||||
def test_delete_repository_with_defaults_does_not_capture_output():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
@@ -356,6 +332,7 @@ def test_delete_repository_with_defaults_does_not_capture_output():
|
||||
|
||||
def test_delete_repository_with_force_captures_output():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
@@ -385,6 +362,7 @@ def test_delete_repository_with_force_captures_output():
|
||||
|
||||
def test_delete_repository_with_cache_only_captures_output():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
@@ -414,6 +392,7 @@ def test_delete_repository_with_cache_only_captures_output():
|
||||
|
||||
def test_delete_repository_calls_borg_with_working_directory():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_repo_delete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
|
||||
@@ -23,7 +23,7 @@ def test_display_repository_info_calls_borg_with_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -31,7 +31,7 @@ def test_display_repository_info_calls_borg_with_flags():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -59,7 +59,7 @@ def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -67,7 +67,7 @@ def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', 'repo'),
|
||||
('borg', 'info', '--log-json', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -100,7 +100,7 @@ def test_display_repository_info_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -108,7 +108,7 @@ def test_display_repository_info_with_log_info_calls_borg_with_info_flag():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--info', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -141,7 +141,7 @@ def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_out
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -177,7 +177,7 @@ def test_display_repository_info_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--debug', '--show-rc', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--debug', '--show-rc', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -185,7 +185,7 @@ def test_display_repository_info_with_log_debug_calls_borg_with_debug_flag():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--debug', '--show-rc', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--debug', '--show-rc', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -219,7 +219,7 @@ def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_ou
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -255,7 +255,7 @@ def test_display_repository_info_with_json_calls_borg_with_json_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -290,7 +290,7 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg1', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg1', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -298,7 +298,7 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg1', 'repo-info', '--repo', 'repo'),
|
||||
('borg1', 'repo-info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -333,7 +333,7 @@ def test_display_repository_info_with_exit_codes_calls_borg_using_them():
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
borg_exit_codes = flexmock()
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -341,7 +341,7 @@ def test_display_repository_info_with_exit_codes_calls_borg_using_them():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -374,7 +374,7 @@ def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_fl
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--remote-path', 'borg1', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--remote-path', 'borg1', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -382,7 +382,7 @@ def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_fl
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--remote-path', 'borg1', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--remote-path', 'borg1', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -416,7 +416,7 @@ def test_display_repository_info_with_umask_calls_borg_with_umask_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--umask', '077', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--umask', '077', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -424,7 +424,7 @@ def test_display_repository_info_with_umask_calls_borg_with_umask_flags():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--umask', '077', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--umask', '077', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -442,50 +442,6 @@ def test_display_repository_info_with_umask_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_display_repository_info_with_log_json_calls_borg_with_log_json_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_flags').replace_with(
|
||||
lambda name, value: (f'--{name}', value) if value else (),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json',),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
|
||||
module.display_repository_info(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='2.3.4',
|
||||
repo_info_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
@@ -503,7 +459,7 @@ def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags(
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--lock-wait', '5', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--lock-wait', '5', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -511,7 +467,7 @@ def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags(
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--lock-wait', '5', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--lock-wait', '5', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -545,7 +501,7 @@ def test_display_repository_info_without_feature_available_calls_borg_with_info_
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'info', '--extra', 'value with space', '--json', '--repo', 'repo'),
|
||||
('borg', 'info', '--log-json', '--extra', 'value with space', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -553,7 +509,7 @@ def test_display_repository_info_without_feature_available_calls_borg_with_info_
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--extra', 'value with space', '--repo', 'repo'),
|
||||
('borg', 'info', '--log-json', '--extra', 'value with space', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -587,7 +543,16 @@ def test_display_repository_info_with_feature_available_calls_borg_with_repo_inf
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--extra', 'value with space', '--json', '--repo', 'repo'),
|
||||
(
|
||||
'borg',
|
||||
'repo-info',
|
||||
'--log-json',
|
||||
'--extra',
|
||||
'value with space',
|
||||
'--json',
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -595,7 +560,7 @@ def test_display_repository_info_with_feature_available_calls_borg_with_repo_inf
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--extra', 'value with space', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--extra', 'value with space', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
@@ -630,7 +595,7 @@ def test_display_repository_info_calls_borg_with_working_directory():
|
||||
'/working/dir',
|
||||
)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-info', '--json', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--json', '--repo', 'repo'),
|
||||
environment=None,
|
||||
working_directory='/working/dir',
|
||||
borg_local_path='borg',
|
||||
@@ -638,7 +603,7 @@ def test_display_repository_info_calls_borg_with_working_directory():
|
||||
).and_return('[]')
|
||||
flexmock(module.flags).should_receive('warn_for_aggressive_archive_flags')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'repo-info', '--repo', 'repo'),
|
||||
('borg', 'repo-info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
environment=None,
|
||||
working_directory='/working/dir',
|
||||
|
||||
@@ -119,7 +119,7 @@ def test_get_latest_archive_calls_borg_with_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
environment=None,
|
||||
@@ -148,7 +148,7 @@ def test_get_latest_archive_with_log_info_calls_borg_without_info_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -178,7 +178,7 @@ def test_get_latest_archive_with_log_debug_calls_borg_without_debug_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -208,7 +208,7 @@ def test_get_latest_archive_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg1', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg1', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg1',
|
||||
@@ -239,7 +239,7 @@ def test_get_latest_archive_with_exit_codes_calls_borg_using_them():
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
borg_exit_codes = flexmock()
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -271,7 +271,7 @@ def test_get_latest_archive_with_remote_path_calls_borg_with_remote_path_flags()
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', '--remote-path', 'borg1', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--remote-path', 'borg1', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -304,7 +304,7 @@ def test_get_latest_archive_with_umask_calls_borg_with_umask_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', '--umask', '077', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--umask', '077', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -332,7 +332,7 @@ def test_get_latest_archive_without_archives_raises():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -348,38 +348,6 @@ def test_get_latest_archive_without_archives_raises():
|
||||
)
|
||||
|
||||
|
||||
def test_get_latest_archive_with_log_json_calls_borg_with_log_json_flag():
|
||||
expected_archive = {'name': 'archive-name', 'id': 'd34db33f'}
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json',)
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('last', 1).and_return(
|
||||
('--last', '1')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).and_return(json.dumps({'archives': [expected_archive]}))
|
||||
|
||||
assert (
|
||||
module.get_latest_archive(
|
||||
'repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
||||
|
||||
def test_get_latest_archive_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
expected_archive = {'name': 'archive-name', 'id': 'd34db33f'}
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
@@ -394,7 +362,7 @@ def test_get_latest_archive_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', '--lock-wait', 'okay', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', '--lock-wait', 'okay', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -426,6 +394,7 @@ def test_get_latest_archive_calls_borg_with_list_extra_borg_options():
|
||||
(
|
||||
'borg',
|
||||
'list',
|
||||
'--log-json',
|
||||
*BORG_LIST_LATEST_ARGUMENTS[:-1],
|
||||
'--extra',
|
||||
'value with space',
|
||||
@@ -462,6 +431,7 @@ def test_get_latest_archive_with_feature_available_calls_borg_with_repo_list_ext
|
||||
(
|
||||
'borg',
|
||||
'repo-list',
|
||||
'--log-json',
|
||||
*BORG_LIST_LATEST_ARGUMENTS[:-1],
|
||||
'--extra',
|
||||
'value with space',
|
||||
@@ -498,7 +468,7 @@ def test_get_latest_archive_with_consider_checkpoints_calls_borg_with_consider_c
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', '--consider-checkpoints', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', '--consider-checkpoints', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -531,7 +501,7 @@ def test_get_latest_archive_with_consider_checkpoints_and_feature_available_call
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'repo-list', *BORG_REPO_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'repo-list', '--log-json', *BORG_REPO_LIST_LATEST_ARGUMENTS),
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
@@ -563,7 +533,7 @@ def test_get_latest_archive_calls_borg_with_working_directory():
|
||||
'/working/dir',
|
||||
)
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
('borg', 'list', '--log-json', *BORG_LIST_LATEST_ARGUMENTS),
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
environment=None,
|
||||
@@ -608,7 +578,7 @@ def test_make_repo_list_command_includes_log_info():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--info', 'repo')
|
||||
assert command == ('borg', 'list', '--info', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_json_but_not_info():
|
||||
@@ -638,7 +608,7 @@ def test_make_repo_list_command_includes_json_but_not_info():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_log_debug():
|
||||
@@ -668,7 +638,7 @@ def test_make_repo_list_command_includes_log_debug():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_json_but_not_debug():
|
||||
@@ -698,7 +668,7 @@ def test_make_repo_list_command_includes_json_but_not_debug():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_json():
|
||||
@@ -727,38 +697,7 @@ def test_make_repo_list_command_includes_json():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_log_json():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
|
||||
('--log-json',),
|
||||
).and_return(()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None,
|
||||
None,
|
||||
'1.2.3',
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_repo_list_command(
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='1.2.3',
|
||||
repo_list_arguments=flexmock(
|
||||
archive=None,
|
||||
paths=None,
|
||||
format=None,
|
||||
json=False,
|
||||
prefix=None,
|
||||
match_archives=None,
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--log-json', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_lock_wait():
|
||||
@@ -789,7 +728,7 @@ def test_make_repo_list_command_includes_lock_wait():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
|
||||
assert command == ('borg', 'list', '--lock-wait', '5', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_list_extra_borg_options():
|
||||
@@ -818,7 +757,7 @@ def test_make_repo_list_command_includes_list_extra_borg_options():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--extra', 'value with space', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--extra', 'value with space', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_with_feature_available_includes_repo_list_extra_borg_options():
|
||||
@@ -847,7 +786,7 @@ def test_make_repo_list_command_with_feature_available_includes_repo_list_extra_
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'repo-list', '--extra', 'value with space', 'repo')
|
||||
assert command == ('borg', 'repo-list', '--log-json', '--extra', 'value with space', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_local_path():
|
||||
@@ -877,7 +816,7 @@ def test_make_repo_list_command_includes_local_path():
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
assert command == ('borg2', 'list', 'repo')
|
||||
assert command == ('borg2', 'list', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_remote_path():
|
||||
@@ -909,7 +848,7 @@ def test_make_repo_list_command_includes_remote_path():
|
||||
remote_path='borg2',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--remote-path', 'borg2', 'repo')
|
||||
assert command == ('borg', 'list', '--remote-path', 'borg2', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_umask():
|
||||
@@ -940,7 +879,7 @@ def test_make_repo_list_command_includes_umask():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--umask', '077', 'repo')
|
||||
assert command == ('borg', 'list', '--umask', '077', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_transforms_prefix_into_match_archives():
|
||||
@@ -966,7 +905,7 @@ def test_make_repo_list_command_transforms_prefix_into_match_archives():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_prefers_prefix_over_archive_name_format():
|
||||
@@ -988,7 +927,7 @@ def test_make_repo_list_command_prefers_prefix_over_archive_name_format():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_transforms_archive_name_format_into_match_archives():
|
||||
@@ -1017,7 +956,7 @@ def test_make_repo_list_command_transforms_archive_name_format_into_match_archiv
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:bar-*', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--match-archives', 'sh:bar-*', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_format_from_command_line():
|
||||
@@ -1049,7 +988,7 @@ def test_make_repo_list_command_includes_format_from_command_line():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--format', 'stuff', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--format', 'stuff', 'repo')
|
||||
|
||||
|
||||
def test_make_repo_list_command_includes_short():
|
||||
@@ -1079,7 +1018,7 @@ def test_make_repo_list_command_includes_short():
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--short', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--short', 'repo')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -1124,7 +1063,14 @@ def test_make_repo_list_command_includes_additional_flags(argument_name):
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
|
||||
assert command == (
|
||||
'borg',
|
||||
'list',
|
||||
'--log-json',
|
||||
'--' + argument_name.replace('_', '-'),
|
||||
'value',
|
||||
'repo',
|
||||
)
|
||||
|
||||
|
||||
def test_make_repo_list_command_with_match_archives_calls_borg_with_match_archives_flags():
|
||||
@@ -1159,7 +1105,7 @@ def test_make_repo_list_command_with_match_archives_calls_borg_with_match_archiv
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'foo-*', 'repo')
|
||||
assert command == ('borg', 'list', '--log-json', '--match-archives', 'foo-*', 'repo')
|
||||
|
||||
|
||||
def test_list_repository_calls_two_commands():
|
||||
@@ -1238,6 +1184,7 @@ def test_make_repo_list_command_with_date_based_matching_calls_borg_with_date_ba
|
||||
assert command == (
|
||||
'borg',
|
||||
'list',
|
||||
'--log-json',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
|
||||
@@ -18,7 +18,7 @@ def test_transfer_archives_calls_borg_with_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -55,7 +55,7 @@ def test_transfer_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--repo', 'repo', '--dry-run'),
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo', '--dry-run'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -89,7 +89,7 @@ def test_transfer_archives_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--info', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -123,7 +123,7 @@ def test_transfer_archives_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--debug', '--show-rc', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--debug', '--show-rc', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -162,7 +162,7 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--match-archives', 'archive', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--match-archives', 'archive', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -200,7 +200,7 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--match-archives', 'sh:foo*', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--match-archives', 'sh:foo*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -238,7 +238,7 @@ def test_transfer_archives_with_archive_name_format_calls_borg_with_match_archiv
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -272,7 +272,7 @@ def test_transfer_archives_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg2', 'transfer', '--repo', 'repo'),
|
||||
('borg2', 'transfer', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -308,7 +308,7 @@ def test_transfer_archives_with_exit_codes_calls_borg_using_them():
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
borg_exit_codes = flexmock()
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -346,7 +346,7 @@ def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--remote-path', 'borg2', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--remote-path', 'borg2', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -383,7 +383,7 @@ def test_transfer_archives_with_umask_calls_borg_with_umask_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--umask', '077', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--umask', '077', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -407,43 +407,6 @@ def test_transfer_archives_with_umask_calls_borg_with_umask_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_log_json_calls_borg_with_log_json_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json',),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={'log_json': True},
|
||||
local_borg_version='2.3.4',
|
||||
transfer_arguments=flexmock(
|
||||
archive=None,
|
||||
progress=None,
|
||||
match_archives=None,
|
||||
source_repository=None,
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
@@ -458,7 +421,7 @@ def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--lock-wait', '5', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--lock-wait', '5', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -493,7 +456,7 @@ def test_transfer_archives_calls_borg_with_extra_borg_options():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--extra', 'value with space', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--extra', 'value with space', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -554,6 +517,43 @@ def test_transfer_archives_with_progress_calls_borg_with_progress_flags():
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_log_json_and_progress_calls_borg_with_both_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('progress', True).and_return(
|
||||
('--progress',),
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--log-json', '--progress', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.DO_NOT_CAPTURE,
|
||||
environment=None,
|
||||
working_directory=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
)
|
||||
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
config={'log_json': True, 'progress': True},
|
||||
local_borg_version='2.3.4',
|
||||
transfer_arguments=flexmock(
|
||||
archive=None,
|
||||
progress=None,
|
||||
match_archives=None,
|
||||
source_repository=None,
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('argument_name', ('upgrader', 'sort_by', 'first', 'last'))
|
||||
def test_transfer_archives_passes_through_arguments_to_borg(argument_name):
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
@@ -568,7 +568,7 @@ def test_transfer_archives_passes_through_arguments_to_borg(argument_name):
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', flag_name, 'value', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', flag_name, 'value', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -605,7 +605,7 @@ def test_transfer_archives_with_source_repository_calls_borg_with_other_repo_fla
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--repo', 'repo', '--other-repo', 'other'),
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo', '--other-repo', 'other'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
@@ -643,6 +643,7 @@ def test_transfer_archives_with_date_based_matching_calls_borg_with_date_based_f
|
||||
(
|
||||
'borg',
|
||||
'transfer',
|
||||
'--log-json',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
@@ -692,7 +693,7 @@ def test_transfer_archives_calls_borg_with_working_directory():
|
||||
'/working/dir',
|
||||
)
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--repo', 'repo'),
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
environment=None,
|
||||
|
||||
@@ -25,20 +25,20 @@ def insert_execute_command_mock(
|
||||
|
||||
|
||||
def test_unmount_archive_calls_borg_with_required_parameters():
|
||||
insert_execute_command_mock(('borg', 'umount', '/mnt'))
|
||||
insert_execute_command_mock(('borg', 'umount', '--log-json', '/mnt'))
|
||||
|
||||
module.unmount_archive(config={}, mount_point='/mnt')
|
||||
|
||||
|
||||
def test_unmount_archive_with_log_info_calls_borg_with_info_parameter():
|
||||
insert_execute_command_mock(('borg', 'umount', '--info', '/mnt'))
|
||||
insert_execute_command_mock(('borg', 'umount', '--log-json', '--info', '/mnt'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.unmount_archive(config={}, mount_point='/mnt')
|
||||
|
||||
|
||||
def test_unmount_archive_with_log_debug_calls_borg_with_debug_parameters():
|
||||
insert_execute_command_mock(('borg', 'umount', '--debug', '--show-rc', '/mnt'))
|
||||
insert_execute_command_mock(('borg', 'umount', '--log-json', '--debug', '--show-rc', '/mnt'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.unmount_archive(config={}, mount_point='/mnt')
|
||||
@@ -46,7 +46,8 @@ def test_unmount_archive_with_log_debug_calls_borg_with_debug_parameters():
|
||||
|
||||
def test_unmount_archive_calls_borg_with_extra_borg_options():
|
||||
insert_execute_command_mock(
|
||||
('borg', 'umount', '--extra', 'value with space', '/mnt'), borg_local_path='borg'
|
||||
('borg', 'umount', '--log-json', '--extra', 'value with space', '/mnt'),
|
||||
borg_local_path='borg',
|
||||
)
|
||||
|
||||
module.unmount_archive(
|
||||
@@ -55,19 +56,23 @@ def test_unmount_archive_calls_borg_with_extra_borg_options():
|
||||
|
||||
|
||||
def test_unmount_archive_calls_borg_with_local_path():
|
||||
insert_execute_command_mock(('borg1', 'umount', '/mnt'), borg_local_path='borg1')
|
||||
insert_execute_command_mock(('borg1', 'umount', '--log-json', '/mnt'), borg_local_path='borg1')
|
||||
|
||||
module.unmount_archive(config={}, mount_point='/mnt', local_path='borg1')
|
||||
|
||||
|
||||
def test_unmount_archive_calls_borg_with_exit_codes():
|
||||
borg_exit_codes = flexmock()
|
||||
insert_execute_command_mock(('borg', 'umount', '/mnt'), borg_exit_codes=borg_exit_codes)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'umount', '--log-json', '/mnt'), borg_exit_codes=borg_exit_codes
|
||||
)
|
||||
|
||||
module.unmount_archive(config={'borg_exit_codes': borg_exit_codes}, mount_point='/mnt')
|
||||
|
||||
|
||||
def test_unmount_archive_calls_borg_with_working_directory():
|
||||
insert_execute_command_mock(('borg', 'umount', '/mnt'), working_directory='/working/dir')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'umount', '--log-json', '/mnt'), working_directory='/working/dir'
|
||||
)
|
||||
|
||||
module.unmount_archive(config={'working_directory': '/working/dir'}, mount_point='/mnt')
|
||||
|
||||
+204
-75
@@ -68,63 +68,178 @@ def test_command_for_process_passes_through_string_command():
|
||||
assert module.command_for_process(process) == 'foo bar baz'
|
||||
|
||||
|
||||
def test_output_buffer_for_process_returns_stderr_when_stdout_excluded():
|
||||
def test_output_buffers_for_process_returns_stdout_and_stderr_by_default():
|
||||
stdout = flexmock()
|
||||
stderr = flexmock()
|
||||
process = flexmock(stdout=stdout, stderr=stderr)
|
||||
|
||||
assert module.output_buffer_for_process(process, exclude_stdouts=[flexmock(), stdout]) == stderr
|
||||
|
||||
|
||||
def test_output_buffer_for_process_returns_stdout_when_not_excluded():
|
||||
stdout = flexmock()
|
||||
process = flexmock(stdout=stdout)
|
||||
|
||||
assert (
|
||||
module.output_buffer_for_process(process, exclude_stdouts=[flexmock(), flexmock()])
|
||||
== stdout
|
||||
assert module.output_buffers_for_process(process, exclude_stdouts=[flexmock(), flexmock()]) == (
|
||||
stdout,
|
||||
stderr,
|
||||
)
|
||||
|
||||
|
||||
def test_append_last_lines_under_max_line_count_appends():
|
||||
last_lines = ['last']
|
||||
flexmock(module.logger).should_receive('log').once()
|
||||
def test_output_buffers_for_process_returns_stderr_only_when_stdout_excluded():
|
||||
stdout = flexmock()
|
||||
stderr = flexmock()
|
||||
process = flexmock(stdout=stdout, stderr=stderr)
|
||||
|
||||
module.append_last_lines(
|
||||
assert module.output_buffers_for_process(process, exclude_stdouts=[flexmock(), stdout]) == (
|
||||
stderr,
|
||||
)
|
||||
|
||||
|
||||
def test_borg_log_line_to_record_parses_line():
|
||||
flexmock(module).should_receive('log_line_to_record').never()
|
||||
line = '{"levelname": "INFO", "time": 12345, "message": "All done", "name": "borg.something"}'
|
||||
|
||||
record = module.borg_log_line_to_record(line, module.logging.INFO)
|
||||
|
||||
assert record.levelno == module.logging.INFO
|
||||
assert record.created == 12345
|
||||
assert record.msg == 'All done'
|
||||
assert record.levelname == 'INFO'
|
||||
assert record.name == 'borg.something'
|
||||
|
||||
|
||||
def test_borg_log_line_to_record_with_invalid_json_falls_back_to_raw_line():
|
||||
record = flexmock()
|
||||
line = '{invalid'
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
line, module.logging.INFO
|
||||
).and_return(record).once()
|
||||
|
||||
assert module.borg_log_line_to_record(line, module.logging.INFO) == record
|
||||
|
||||
|
||||
def test_borg_log_line_to_record_with_non_dict_json_falls_back_to_raw_line():
|
||||
record = flexmock()
|
||||
line = '[]'
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
line, module.logging.INFO
|
||||
).and_return(record).once()
|
||||
|
||||
assert module.borg_log_line_to_record(line, module.logging.INFO) == record
|
||||
|
||||
|
||||
def test_log_line_to_record_makes_log_record():
|
||||
line = 'All done'
|
||||
|
||||
record = module.log_line_to_record(line, module.logging.INFO)
|
||||
|
||||
assert record.msg == line
|
||||
assert record.levelno == module.logging.INFO
|
||||
assert record.levelname == 'INFO'
|
||||
|
||||
|
||||
def test_parse_log_line_with_borg_command_parses_borg_log_line():
|
||||
record = flexmock()
|
||||
flexmock(module).should_receive('borg_log_line_to_record').and_return(record).once()
|
||||
flexmock(module).should_receive('log_line_to_record').never()
|
||||
|
||||
assert (
|
||||
module.parse_log_line(
|
||||
'All done',
|
||||
module.logging.INFO,
|
||||
came_from_stderr=False,
|
||||
borg_local_path='borg',
|
||||
command=['borg', 'do-stuff'],
|
||||
)
|
||||
== record
|
||||
)
|
||||
|
||||
|
||||
def test_parse_log_line_without_borg_command_parses_plain_log_line():
|
||||
record = flexmock()
|
||||
flexmock(module).should_receive('borg_log_line_to_record').never()
|
||||
flexmock(module).should_receive('log_line_to_record').and_return(record).once()
|
||||
|
||||
assert (
|
||||
module.parse_log_line(
|
||||
'All done',
|
||||
module.logging.INFO,
|
||||
came_from_stderr=False,
|
||||
borg_local_path='borg',
|
||||
command=['totally-not-borg', 'do-stuff'],
|
||||
)
|
||||
== record
|
||||
)
|
||||
|
||||
|
||||
def test_parse_log_line_with_came_from_stderr_makes_error_record():
|
||||
record = flexmock()
|
||||
flexmock(module).should_receive('borg_log_line_to_record').never()
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
'All done', module.logging.ERROR
|
||||
).and_return(record).once()
|
||||
|
||||
assert (
|
||||
module.parse_log_line(
|
||||
'All done',
|
||||
module.logging.INFO,
|
||||
came_from_stderr=True,
|
||||
borg_local_path='borg',
|
||||
command=['totally-not-borg', 'do-stuff'],
|
||||
)
|
||||
== record
|
||||
)
|
||||
|
||||
|
||||
def test_parse_log_line_with_came_from_stderr_and_warning_prefix_makes_warning_record():
|
||||
record = flexmock()
|
||||
flexmock(module).should_receive('borg_log_line_to_record').never()
|
||||
flexmock(module).should_receive('log_line_to_record').with_args(
|
||||
'warning: All done', module.logging.WARNING
|
||||
).and_return(record).once()
|
||||
|
||||
assert (
|
||||
module.parse_log_line(
|
||||
'warning: All done',
|
||||
module.logging.INFO,
|
||||
came_from_stderr=True,
|
||||
borg_local_path='borg',
|
||||
command=['totally-not-borg', 'do-stuff'],
|
||||
)
|
||||
== record
|
||||
)
|
||||
|
||||
|
||||
def test_handle_log_record_under_max_line_count_appends():
|
||||
last_lines = ['last']
|
||||
flexmock(module.logger).should_receive('handle').once()
|
||||
|
||||
module.handle_log_record(
|
||||
flexmock(levelno=module.logging.INFO, getMessage=lambda: 'line'),
|
||||
last_lines,
|
||||
captured_output=flexmock(),
|
||||
line='line',
|
||||
output_log_level=flexmock(),
|
||||
)
|
||||
|
||||
assert last_lines == ['last', 'line']
|
||||
|
||||
|
||||
def test_append_last_lines_over_max_line_count_trims_and_appends():
|
||||
def test_handle_log_record_over_max_line_count_trims_and_appends():
|
||||
original_last_lines = [str(number) for number in range(module.ERROR_OUTPUT_MAX_LINE_COUNT)]
|
||||
last_lines = list(original_last_lines)
|
||||
flexmock(module.logger).should_receive('log').once()
|
||||
flexmock(module.logger).should_receive('handle').once()
|
||||
|
||||
module.append_last_lines(
|
||||
module.handle_log_record(
|
||||
flexmock(levelno=module.logging.INFO, getMessage=lambda: 'line'),
|
||||
last_lines,
|
||||
captured_output=flexmock(),
|
||||
line='line',
|
||||
output_log_level=flexmock(),
|
||||
)
|
||||
|
||||
assert last_lines == [*original_last_lines[1:], 'line']
|
||||
|
||||
|
||||
def test_append_last_lines_with_output_log_level_none_appends_captured_output():
|
||||
def test_handle_log_record_with_output_log_level_none_appends_captured_output():
|
||||
last_lines = ['last']
|
||||
captured_output = ['captured']
|
||||
flexmock(module.logger).should_receive('log').never()
|
||||
flexmock(module.logger).should_receive('handle').never()
|
||||
|
||||
module.append_last_lines(
|
||||
module.handle_log_record(
|
||||
flexmock(levelno=None, getMessage=lambda: 'line'),
|
||||
last_lines,
|
||||
captured_output=captured_output,
|
||||
line='line',
|
||||
output_log_level=None,
|
||||
)
|
||||
|
||||
assert captured_output == ['captured', 'line']
|
||||
@@ -204,7 +319,7 @@ def test_execute_command_calls_full_command():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -270,7 +385,7 @@ def test_execute_command_calls_full_command_with_input_file():
|
||||
full_command,
|
||||
stdin=input_file,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -291,7 +406,7 @@ def test_execute_command_calls_full_command_with_shell():
|
||||
' '.join(full_command),
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=True,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -312,7 +427,7 @@ def test_execute_command_calls_full_command_with_environment():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env={'a': 'b'},
|
||||
cwd=None,
|
||||
@@ -333,7 +448,7 @@ def test_execute_command_calls_full_command_with_working_directory():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd='/working',
|
||||
@@ -355,65 +470,70 @@ def test_execute_command_without_run_to_completion_returns_process():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
close_fds=False,
|
||||
).and_return(process).once()
|
||||
flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock())
|
||||
flexmock(module).should_receive('log_outputs')
|
||||
flexmock(module).should_receive('log_outputs').and_return({process: 'out'})
|
||||
|
||||
assert module.execute_command(full_command, run_to_completion=False) == process
|
||||
|
||||
|
||||
def test_execute_command_and_capture_output_returns_stdout():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
process = flexmock()
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
full_command,
|
||||
stdin=None,
|
||||
stderr=None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
close_fds=False,
|
||||
).and_return(flexmock(decode=lambda: expected_output)).once()
|
||||
).and_return(process).once()
|
||||
flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock())
|
||||
flexmock(module).should_receive('log_outputs').and_return({process: 'out'})
|
||||
|
||||
output = module.execute_command_and_capture_output(full_command)
|
||||
|
||||
assert output == expected_output
|
||||
assert output == 'out'
|
||||
|
||||
|
||||
def test_execute_command_and_capture_output_with_capture_stderr_returns_stderr():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
process = flexmock()
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
full_command,
|
||||
stdin=None,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
close_fds=False,
|
||||
).and_return(flexmock(decode=lambda: expected_output)).once()
|
||||
).and_return(process).once()
|
||||
flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock())
|
||||
flexmock(module).should_receive('log_outputs').and_return({process: 'out'})
|
||||
|
||||
output = module.execute_command_and_capture_output(full_command, capture_stderr=True)
|
||||
|
||||
assert output == expected_output
|
||||
assert output == 'out'
|
||||
|
||||
|
||||
def test_execute_command_and_capture_output_returns_output_when_process_error_is_not_considered_an_error():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
err_output = b'[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
full_command,
|
||||
stdin=None,
|
||||
stderr=None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -425,22 +545,22 @@ def test_execute_command_and_capture_output_returns_output_when_process_error_is
|
||||
|
||||
output = module.execute_command_and_capture_output(full_command)
|
||||
|
||||
assert output == expected_output
|
||||
assert output == '[]'
|
||||
|
||||
|
||||
def test_execute_command_and_capture_output_raises_when_command_errors():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
full_command,
|
||||
stdin=None,
|
||||
stderr=None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
close_fds=False,
|
||||
).and_raise(subprocess.CalledProcessError(2, full_command, expected_output)).once()
|
||||
).and_raise(subprocess.CalledProcessError(2, full_command, 'error')).once()
|
||||
flexmock(module).should_receive('interpret_exit_code').and_return(
|
||||
module.Exit_status.ERROR,
|
||||
).once()
|
||||
@@ -451,36 +571,42 @@ def test_execute_command_and_capture_output_raises_when_command_errors():
|
||||
|
||||
def test_execute_command_and_capture_output_returns_output_with_shell():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
process = flexmock()
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
'foo bar',
|
||||
stdin=None,
|
||||
stderr=None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=True,
|
||||
env=None,
|
||||
cwd=None,
|
||||
close_fds=False,
|
||||
).and_return(flexmock(decode=lambda: expected_output)).once()
|
||||
).and_return(process).once()
|
||||
flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock())
|
||||
flexmock(module).should_receive('log_outputs').and_return({process: 'out'})
|
||||
|
||||
output = module.execute_command_and_capture_output(full_command, shell=True)
|
||||
|
||||
assert output == expected_output
|
||||
assert output == 'out'
|
||||
|
||||
|
||||
def test_execute_command_and_capture_output_returns_output_with_environment():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
process = flexmock()
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
full_command,
|
||||
stdin=None,
|
||||
stderr=None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=False,
|
||||
env={'a': 'b'},
|
||||
cwd=None,
|
||||
close_fds=False,
|
||||
).and_return(flexmock(decode=lambda: expected_output)).once()
|
||||
).and_return(process).once()
|
||||
flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock())
|
||||
flexmock(module).should_receive('log_outputs').and_return({process: 'out'})
|
||||
|
||||
output = module.execute_command_and_capture_output(
|
||||
full_command,
|
||||
@@ -488,22 +614,25 @@ def test_execute_command_and_capture_output_returns_output_with_environment():
|
||||
environment={'a': 'b'},
|
||||
)
|
||||
|
||||
assert output == expected_output
|
||||
assert output == 'out'
|
||||
|
||||
|
||||
def test_execute_command_and_capture_output_returns_output_with_working_directory():
|
||||
full_command = ['foo', 'bar']
|
||||
expected_output = '[]'
|
||||
flexmock(module).should_receive('log_command')
|
||||
flexmock(module.subprocess).should_receive('check_output').with_args(
|
||||
process = flexmock()
|
||||
flexmock(module.subprocess).should_receive('Popen').with_args(
|
||||
full_command,
|
||||
stdin=None,
|
||||
stderr=None,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd='/working',
|
||||
close_fds=False,
|
||||
).and_return(flexmock(decode=lambda: expected_output)).once()
|
||||
).and_return(process).once()
|
||||
flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock())
|
||||
flexmock(module).should_receive('log_outputs').and_return({process: 'out'})
|
||||
|
||||
output = module.execute_command_and_capture_output(
|
||||
full_command,
|
||||
@@ -511,7 +640,7 @@ def test_execute_command_and_capture_output_returns_output_with_working_director
|
||||
working_directory='/working',
|
||||
)
|
||||
|
||||
assert output == expected_output
|
||||
assert output == 'out'
|
||||
|
||||
|
||||
def test_execute_command_with_processes_calls_full_command():
|
||||
@@ -522,7 +651,7 @@ def test_execute_command_with_processes_calls_full_command():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -545,7 +674,7 @@ def test_execute_command_with_processes_returns_output_with_output_log_level_non
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -618,7 +747,7 @@ def test_execute_command_with_processes_calls_full_command_with_input_file():
|
||||
full_command,
|
||||
stdin=input_file,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -640,7 +769,7 @@ def test_execute_command_with_processes_calls_full_command_with_shell():
|
||||
' '.join(full_command),
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=True,
|
||||
env=None,
|
||||
cwd=None,
|
||||
@@ -662,7 +791,7 @@ def test_execute_command_with_processes_calls_full_command_with_environment():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env={'a': 'b'},
|
||||
cwd=None,
|
||||
@@ -684,7 +813,7 @@ def test_execute_command_with_processes_calls_full_command_with_working_director
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd='/working',
|
||||
@@ -713,7 +842,7 @@ def test_execute_command_with_processes_kills_processes_on_error():
|
||||
full_command,
|
||||
stdin=None,
|
||||
stdout=module.subprocess.PIPE,
|
||||
stderr=module.subprocess.STDOUT,
|
||||
stderr=module.subprocess.PIPE,
|
||||
shell=False,
|
||||
env=None,
|
||||
cwd=None,
|
||||
|
||||
+156
-4
@@ -182,6 +182,67 @@ def test_multi_stream_handler_logs_to_handler_for_log_level():
|
||||
multi_handler.emit(flexmock(levelno=module.logging.ERROR))
|
||||
|
||||
|
||||
LOGGING_ANSWER = flexmock()
|
||||
|
||||
|
||||
def test_journald_handler_serializes_log_record_to_socket():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = LOGGING_ANSWER
|
||||
flexmock(module.os).should_receive('getpid').and_return(12345)
|
||||
socket = flexmock()
|
||||
socket.should_receive('sendto').with_args(
|
||||
b'MESSAGE=All done\nPRIORITY=6\nSYSLOG_IDENTIFIER=borgmatic\nSYSLOG_PID=12345\n',
|
||||
'/socket/path',
|
||||
).once()
|
||||
socket.should_receive('close')
|
||||
flexmock(module.socket).should_receive('socket').and_return(socket)
|
||||
|
||||
module.JournaldHandler('/socket/path').emit(
|
||||
flexmock(
|
||||
levelno=module.logging.INFO,
|
||||
getMessage=lambda: 'All done',
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_journald_handler_serializes_multi_line_log_record_to_socket():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = LOGGING_ANSWER
|
||||
flexmock(module.os).should_receive('getpid').and_return(12345)
|
||||
socket = flexmock()
|
||||
socket.should_receive('sendto').with_args(
|
||||
b'MESSAGE\n'
|
||||
b'\x08\x00\x00\x00\x00\x00\x00\x00' # Message length, serialized.
|
||||
b'All\ndone\nPRIORITY=6\nSYSLOG_IDENTIFIER=borgmatic\nSYSLOG_PID=12345\n',
|
||||
'/socket/path',
|
||||
).once()
|
||||
socket.should_receive('close')
|
||||
flexmock(module.socket).should_receive('socket').and_return(socket)
|
||||
|
||||
module.JournaldHandler('/socket/path').emit(
|
||||
flexmock(
|
||||
levelno=module.logging.INFO,
|
||||
getMessage=lambda: 'All\ndone',
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_log_record_to_json_formats_record_as_json():
|
||||
assert (
|
||||
module.log_record_to_json(
|
||||
flexmock(
|
||||
created=12345,
|
||||
levelno=module.logging.INFO,
|
||||
levelname='INFO',
|
||||
name='borg.something',
|
||||
extra='ignored',
|
||||
getMessage=lambda: 'All done',
|
||||
)
|
||||
)
|
||||
== '{"type": "log_message", "time": 12345, "message": "All done", "levelname": "INFO", "name": "borg.something"}'
|
||||
)
|
||||
|
||||
|
||||
def test_console_color_formatter_format_includes_log_message():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
@@ -447,7 +508,9 @@ def test_flush_delayed_logging_flushes_delayed_logging_handler():
|
||||
def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_linux():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module.logging).DISABLED = module.DISABLED
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -458,8 +521,15 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_linux(
|
||||
level=logging.DEBUG,
|
||||
handlers=list,
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args(
|
||||
module.JOURNALD_SOCKET_PATH
|
||||
).and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(True)
|
||||
syslog_handler = logging.handlers.SysLogHandler()
|
||||
syslog_handler = flexmock(
|
||||
level=module.logging.DEBUG,
|
||||
setLevel=lambda log_level: None,
|
||||
setFormatter=lambda formatter: None,
|
||||
)
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').with_args(
|
||||
address='/dev/log',
|
||||
).and_return(syslog_handler).once()
|
||||
@@ -470,7 +540,9 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_linux(
|
||||
def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_macos():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module.logging).DISABLED = module.DISABLED
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -481,9 +553,16 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_macos(
|
||||
level=logging.DEBUG,
|
||||
handlers=list,
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args(
|
||||
module.JOURNALD_SOCKET_PATH
|
||||
).and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/var/run/syslog').and_return(True)
|
||||
syslog_handler = logging.handlers.SysLogHandler()
|
||||
syslog_handler = flexmock(
|
||||
level=module.logging.DEBUG,
|
||||
setLevel=lambda log_level: None,
|
||||
setFormatter=lambda formatter: None,
|
||||
)
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').with_args(
|
||||
address='/var/run/syslog',
|
||||
).and_return(syslog_handler).once()
|
||||
@@ -494,7 +573,9 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_macos(
|
||||
def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_freebsd():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module.logging).DISABLED = module.DISABLED
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -505,10 +586,17 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_freebs
|
||||
level=logging.DEBUG,
|
||||
handlers=list,
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args(
|
||||
module.JOURNALD_SOCKET_PATH
|
||||
).and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/var/run/syslog').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/var/run/log').and_return(True)
|
||||
syslog_handler = logging.handlers.SysLogHandler()
|
||||
syslog_handler = flexmock(
|
||||
level=module.logging.DEBUG,
|
||||
setLevel=lambda log_level: None,
|
||||
setFormatter=lambda formatter: None,
|
||||
)
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').with_args(
|
||||
address='/var/run/log',
|
||||
).and_return(syslog_handler).once()
|
||||
@@ -516,10 +604,40 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_freebs
|
||||
module.configure_logging(logging.INFO, syslog_log_level=logging.DEBUG)
|
||||
|
||||
|
||||
def test_configure_logging_with_journald_probes_for_log_socket():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module.logging).DISABLED = module.DISABLED
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
flexmock(module).should_receive('interactive_console').and_return(False)
|
||||
flexmock(module).should_receive('flush_delayed_logging')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.DEBUG,
|
||||
handlers=list,
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args(
|
||||
module.JOURNALD_SOCKET_PATH
|
||||
).and_return(True)
|
||||
journald_handler = flexmock(level=module.logging.DEBUG, setLevel=lambda log_level: None)
|
||||
flexmock(module).should_receive('JournaldHandler').with_args(
|
||||
module.JOURNALD_SOCKET_PATH
|
||||
).and_return(journald_handler).once()
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').never()
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').never()
|
||||
|
||||
module.configure_logging(logging.INFO, syslog_log_level=logging.DEBUG)
|
||||
|
||||
|
||||
def test_configure_logging_without_syslog_log_level_skips_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -539,6 +657,7 @@ def test_configure_logging_skips_syslog_if_not_found():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -558,6 +677,7 @@ def test_configure_logging_skips_log_file_if_log_file_logging_is_disabled():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).DISABLED = module.DISABLED
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -583,6 +703,7 @@ def test_configure_logging_to_log_file_instead_of_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -612,6 +733,7 @@ def test_configure_logging_to_both_log_file_and_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -622,6 +744,9 @@ def test_configure_logging_to_both_log_file_and_syslog():
|
||||
level=logging.DEBUG,
|
||||
handlers=list,
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args(
|
||||
module.JOURNALD_SOCKET_PATH
|
||||
).and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(True)
|
||||
syslog_handler = logging.handlers.SysLogHandler()
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').with_args(
|
||||
@@ -647,6 +772,7 @@ def test_configure_logging_to_log_file_formats_with_custom_log_format():
|
||||
'{message}',
|
||||
).once()
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -677,6 +803,7 @@ def test_configure_logging_skips_log_file_if_argument_is_none():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
@@ -693,10 +820,11 @@ def test_configure_logging_skips_log_file_if_argument_is_none():
|
||||
module.configure_logging(console_log_level=logging.INFO, log_file=None)
|
||||
|
||||
|
||||
def test_configure_logging_uses_console_no_color_formatter_if_color_disabled():
|
||||
def test_configure_logging_with_color_disabled_uses_console_no_color_formatter():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').never()
|
||||
flexmock(module).should_receive('Console_color_formatter').never()
|
||||
flexmock(module).should_receive('Log_prefix_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
@@ -712,3 +840,27 @@ def test_configure_logging_uses_console_no_color_formatter_if_color_disabled():
|
||||
flexmock(module.logging.handlers).should_receive('WatchedFileHandler').never()
|
||||
|
||||
module.configure_logging(console_log_level=logging.INFO, log_file=None, color_enabled=False)
|
||||
|
||||
|
||||
def test_configure_logging_with_log_json_uses_json_formatter():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Json_formatter').and_return(fake_formatter).once()
|
||||
flexmock(module).should_receive('Console_color_formatter').never()
|
||||
flexmock(module).should_receive('Log_prefix_formatter').never()
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module).should_receive('flush_delayed_logging')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.INFO,
|
||||
handlers=list,
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(False)
|
||||
flexmock(module.logging.handlers).should_receive('WatchedFileHandler').never()
|
||||
|
||||
module.configure_logging(
|
||||
console_log_level=logging.INFO, log_file=None, log_json=True, color_enabled=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user