diff --git a/borgmatic/borg/change_passphrase.py b/borgmatic/borg/change_passphrase.py index 70c0065f..79f9781d 100644 --- a/borgmatic/borg/change_passphrase.py +++ b/borgmatic/borg/change_passphrase.py @@ -41,7 +41,7 @@ def change_passphrase( ) if global_arguments.dry_run: - logger.info(f'{repository_path}: Skipping change password (dry run)') + logger.info('Skipping change password (dry run)') return # If the original passphrase is set programmatically, then Borg won't prompt for a new one! So diff --git a/borgmatic/borg/compact.py b/borgmatic/borg/compact.py index c7fef483..eb16c6fa 100644 --- a/borgmatic/borg/compact.py +++ b/borgmatic/borg/compact.py @@ -43,7 +43,7 @@ def compact_segments( ) if dry_run: - logging.info(f'{repository_path}: Skipping compact (dry run)') + logging.info('Skipping compact (dry run)') return execute_command( diff --git a/borgmatic/borg/create.py b/borgmatic/borg/create.py index 1fb5284d..27ba111f 100644 --- a/borgmatic/borg/create.py +++ b/borgmatic/borg/create.py @@ -295,12 +295,12 @@ def make_base_create_command( # cause Borg to hang. But skip this if the user has explicitly set the "read_special" to True. if stream_processes and not config.get('read_special'): logger.warning( - f'{repository_path}: Ignoring configured "read_special" value of false, as true is needed for database hooks.' + 'Ignoring configured "read_special" value of false, as true is needed for database hooks.' ) borg_environment = environment.make_environment(config) working_directory = borgmatic.config.paths.get_working_directory(config) - logger.debug(f'{repository_path}: Collecting special file paths') + logger.debug('Collecting special file paths') special_file_paths = collect_special_file_paths( dry_run, create_flags + create_positional_arguments, @@ -318,7 +318,7 @@ def make_base_create_command( placeholder=' ...', ) logger.warning( - f'{repository_path}: Excluding special files to prevent Borg from hanging: {truncated_special_file_paths}' + f'Excluding special files to prevent Borg from hanging: {truncated_special_file_paths}' ) patterns_file = write_patterns_file( tuple( diff --git a/borgmatic/borg/export_key.py b/borgmatic/borg/export_key.py index cd0e8cf4..768b52cc 100644 --- a/borgmatic/borg/export_key.py +++ b/borgmatic/borg/export_key.py @@ -60,7 +60,7 @@ def export_key( ) if global_arguments.dry_run: - logger.info(f'{repository_path}: Skipping key export (dry run)') + logger.info('Skipping key export (dry run)') return execute_command( diff --git a/borgmatic/borg/export_tar.py b/borgmatic/borg/export_tar.py index 3adc8ae6..728755d5 100644 --- a/borgmatic/borg/export_tar.py +++ b/borgmatic/borg/export_tar.py @@ -63,7 +63,7 @@ def export_tar_archive( output_log_level = logging.INFO if dry_run: - logging.info(f'{repository_path}: Skipping export to tar file (dry run)') + logging.info('Skipping export to tar file (dry run)') return execute_command( diff --git a/borgmatic/borg/repo_create.py b/borgmatic/borg/repo_create.py index 068ad373..7ccf85ba 100644 --- a/borgmatic/borg/repo_create.py +++ b/borgmatic/borg/repo_create.py @@ -57,7 +57,7 @@ def create_repository( f'Requested encryption mode "{encryption_mode}" does not match existing repository encryption mode "{repository_encryption_mode}"' ) - logger.info(f'{repository_path}: Repository already exists. Skipping creation.') + logger.info('Repository already exists. Skipping creation.') return except subprocess.CalledProcessError as error: if error.returncode not in REPO_INFO_REPOSITORY_NOT_FOUND_EXIT_CODES: @@ -91,7 +91,7 @@ def create_repository( ) if dry_run: - logging.info(f'{repository_path}: Skipping repository creation (dry run)') + logging.info('Skipping repository creation (dry run)') return # Do not capture output here, so as to support interactive prompts. diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index 1e46205b..112a7691 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -161,7 +161,7 @@ def run_configuration(config_filename, config, config_paths, arguments): ) tuple( # Consume the generator so as to trigger logging. log_error_records( - f'{repository.get("label", repository["path"])}: Error running actions for repository', + 'Error running actions for repository', error, levelno=logging.WARNING, log_command_error_output=True, @@ -194,7 +194,7 @@ def run_configuration(config_filename, config, config_paths, arguments): except (OSError, CalledProcessError) as error: if not command.considered_soft_failure(error): encountered_error = error - yield from log_error_records(f'{repository["path"]}: Error pinging monitor', error) + yield from log_error_records('Error pinging monitor', error) if not encountered_error: try: diff --git a/tests/unit/actions/test_restore.py b/tests/unit/actions/test_restore.py index 6fedb367..d930d670 100644 --- a/tests/unit/actions/test_restore.py +++ b/tests/unit/actions/test_restore.py @@ -273,7 +273,7 @@ def test_strip_path_prefix_from_extracted_dump_destination_renames_first_matchin def test_restore_single_dump_extracts_and_restores_single_file_dump(): flexmock(module).should_receive('render_dump_metadata').and_return('test') flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').with_args( - 'make_data_source_dump_patterns', object, object, object, object, object + 'make_data_source_dump_patterns', object, object, object, object ).and_return({'postgresql': flexmock()}) flexmock(module.tempfile).should_receive('mkdtemp').never() flexmock(module.borgmatic.hooks.data_source.dump).should_receive( @@ -313,7 +313,7 @@ def test_restore_single_dump_extracts_and_restores_single_file_dump(): def test_restore_single_dump_extracts_and_restores_directory_dump(): flexmock(module).should_receive('render_dump_metadata').and_return('test') flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').with_args( - 'make_data_source_dump_patterns', object, object, object, object, object + 'make_data_source_dump_patterns', object, object, object, object ).and_return({'postgresql': flexmock()}) flexmock(module.tempfile).should_receive('mkdtemp').once().and_return( '/run/user/0/borgmatic/tmp1234' @@ -355,7 +355,7 @@ def test_restore_single_dump_extracts_and_restores_directory_dump(): def test_restore_single_dump_with_directory_dump_error_cleans_up_temporary_directory(): flexmock(module).should_receive('render_dump_metadata').and_return('test') flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').with_args( - 'make_data_source_dump_patterns', object, object, object, object, object + 'make_data_source_dump_patterns', object, object, object, object ).and_return({'postgresql': flexmock()}) flexmock(module.tempfile).should_receive('mkdtemp').once().and_return( '/run/user/0/borgmatic/tmp1234' @@ -398,7 +398,7 @@ def test_restore_single_dump_with_directory_dump_error_cleans_up_temporary_direc def test_restore_single_dump_with_directory_dump_and_dry_run_skips_directory_move_and_cleanup(): flexmock(module).should_receive('render_dump_metadata').and_return('test') flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').with_args( - 'make_data_source_dump_patterns', object, object, object, object, object + 'make_data_source_dump_patterns', object, object, object, object ).and_return({'postgresql': flexmock()}) flexmock(module.tempfile).should_receive('mkdtemp').once().and_return('/run/borgmatic/tmp1234') flexmock(module.borgmatic.hooks.data_source.dump).should_receive( diff --git a/tests/unit/borg/test_create.py b/tests/unit/borg/test_create.py index 1d103233..a13c4184 100644 --- a/tests/unit/borg/test_create.py +++ b/tests/unit/borg/test_create.py @@ -643,7 +643,7 @@ def test_make_base_create_command_with_stream_processes_ignores_read_special_fal patterns_file = flexmock(name='patterns') flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None) flexmock(module).should_receive('write_patterns_file').with_args( - patterns, '/run/borgmatic', object + patterns, '/run/borgmatic' ).and_return(patterns_file) flexmock(module).should_receive('make_list_filter_flags').and_return('FOO') flexmock(module.flags).should_receive('get_default_archive_name_format').and_return( @@ -666,7 +666,6 @@ def test_make_base_create_command_with_stream_processes_ignores_read_special_fal ), ), '/run/borgmatic', - 'repo', patterns_file=patterns_file, ).and_return(patterns_file).once() flexmock(module).should_receive('make_exclude_flags').and_return(()) @@ -694,7 +693,7 @@ def test_make_base_create_command_with_stream_processes_ignores_read_special_fal def test_make_base_create_command_without_patterns_and_with_stream_processes_ignores_read_special_false_and_excludes_special_files(): flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None) flexmock(module).should_receive('write_patterns_file').with_args( - [], '/run/borgmatic', object + [], '/run/borgmatic' ).and_return(None) flexmock(module).should_receive('make_list_filter_flags').and_return('FOO') flexmock(module.flags).should_receive('get_default_archive_name_format').and_return( @@ -717,7 +716,6 @@ def test_make_base_create_command_without_patterns_and_with_stream_processes_ign ), ), '/run/borgmatic', - 'repo', patterns_file=None, ).and_return(flexmock(name='patterns')).once() flexmock(module).should_receive('make_exclude_flags').and_return(()) diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index bba36928..e5e599e1 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -32,6 +32,7 @@ def test_run_configuration_runs_actions_for_each_repository(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) expected_results = [flexmock(), flexmock()] + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return(expected_results[:1]).and_return( expected_results[1:] ) @@ -47,6 +48,7 @@ def test_run_configuration_with_skip_actions_does_not_raise(): flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO) flexmock(module).should_receive('get_skip_actions').and_return(['compact']) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return(flexmock()).and_return(flexmock()) config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}], 'skip_actions': ['compact']} arguments = {'global': flexmock(monitoring_verbosity=1)} @@ -60,6 +62,7 @@ def test_run_configuration_with_invalid_borg_version_errors(): flexmock(module.borg_version).should_receive('local_borg_version').and_raise(ValueError) flexmock(module.command).should_receive('execute_hook').never() flexmock(module.dispatch).should_receive('call_hooks').never() + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').never() config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'prune': flexmock()} @@ -76,6 +79,7 @@ def test_run_configuration_logs_monitor_start_error(): ).and_return(None).and_return(None) expected_results = [flexmock()] flexmock(module).should_receive('log_error_records').and_return(expected_results) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').never() config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -92,6 +96,7 @@ def test_run_configuration_bails_for_monitor_start_soft_failure(): error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again') flexmock(module.dispatch).should_receive('call_hooks').and_raise(error).and_return(None) flexmock(module).should_receive('log_error_records').never() + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').never() config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -109,6 +114,7 @@ def test_run_configuration_logs_actions_error(): flexmock(module.dispatch).should_receive('call_hooks') expected_results = [flexmock()] flexmock(module).should_receive('log_error_records').and_return(expected_results) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError) config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False)} @@ -125,6 +131,7 @@ def test_run_configuration_skips_remaining_actions_for_actions_soft_failure_but_ flexmock(module.dispatch).should_receive('call_hooks').times(5) error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again') log = flexmock() + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').twice().and_raise(error).and_yield(log) flexmock(module).should_receive('log_error_records').never() flexmock(module.command).should_receive('considered_soft_failure').and_return(True) @@ -145,6 +152,7 @@ def test_run_configuration_logs_monitor_log_error(): ).and_raise(OSError) expected_results = [flexmock()] flexmock(module).should_receive('log_error_records').and_return(expected_results) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return([]) config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -163,6 +171,7 @@ def test_run_configuration_still_pings_monitor_for_monitor_log_soft_failure(): None ).and_raise(error).and_return(None).and_return(None).times(5) flexmock(module).should_receive('log_error_records').never() + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return([]) flexmock(module.command).should_receive('considered_soft_failure').and_return(True) config = {'repositories': [{'path': 'foo'}]} @@ -182,6 +191,7 @@ def test_run_configuration_logs_monitor_finish_error(): ).and_return(None).and_raise(OSError) expected_results = [flexmock()] flexmock(module).should_receive('log_error_records').and_return(expected_results) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return([]) config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -200,6 +210,7 @@ def test_run_configuration_bails_for_monitor_finish_soft_failure(): None ).and_raise(None).and_raise(error) flexmock(module).should_receive('log_error_records').never() + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return([]) flexmock(module.command).should_receive('considered_soft_failure').and_return(True) config = {'repositories': [{'path': 'foo'}]} @@ -216,6 +227,7 @@ def test_run_configuration_does_not_call_monitoring_hooks_if_monitoring_hooks_ar flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.dispatch).should_receive('call_hooks').never() + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_return([]) config = {'repositories': [{'path': 'foo'}]} @@ -233,6 +245,7 @@ def test_run_configuration_logs_on_error_hook_error(): flexmock(module).should_receive('log_error_records').and_return( expected_results[:1] ).and_return(expected_results[1:]) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError) config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -250,6 +263,7 @@ def test_run_configuration_bails_for_on_error_hook_soft_failure(): flexmock(module.command).should_receive('execute_hook').and_raise(error) expected_results = [flexmock()] flexmock(module).should_receive('log_error_records').and_return(expected_results) + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError) config = {'repositories': [{'path': 'foo'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -265,6 +279,7 @@ def test_run_configuration_retries_soft_error(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).and_return([]) flexmock(module).should_receive('log_error_records').and_return([flexmock()]).once() config = {'repositories': [{'path': 'foo'}], 'retries': 1} @@ -279,16 +294,17 @@ def test_run_configuration_retries_hard_error(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).times(2) flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, ).and_return([flexmock()]) error_logs = [flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, ).and_return(error_logs) config = {'repositories': [{'path': 'foo'}], 'retries': 1} @@ -302,13 +318,14 @@ def test_run_configuration_repos_ordered(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).times(2) expected_results = [flexmock(), flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(expected_results[:1]).ordered() flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(expected_results[1:]).ordered() config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}]} arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()} @@ -321,26 +338,27 @@ def test_run_configuration_retries_round_robin(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).times(4) flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, ).and_return([flexmock()]).ordered() flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, ).and_return([flexmock()]).ordered() foo_error_logs = [flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(foo_error_logs).ordered() bar_error_logs = [flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(bar_error_logs).ordered() config = { 'repositories': [{'path': 'foo'}, {'path': 'bar'}], @@ -356,24 +374,25 @@ def test_run_configuration_retries_one_passes(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return( [] ).and_raise(OSError).times(4) flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, ).and_return([flexmock()]).ordered() flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, ).and_return(flexmock()).ordered() error_logs = [flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(error_logs).ordered() config = { 'repositories': [{'path': 'foo'}, {'path': 'bar'}], @@ -389,9 +408,10 @@ def test_run_configuration_retry_wait(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).times(4) flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, @@ -399,7 +419,7 @@ def test_run_configuration_retry_wait(): flexmock(time).should_receive('sleep').with_args(10).and_return().ordered() flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, @@ -407,7 +427,7 @@ def test_run_configuration_retry_wait(): flexmock(time).should_receive('sleep').with_args(20).and_return().ordered() flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, @@ -416,7 +436,7 @@ def test_run_configuration_retry_wait(): flexmock(time).should_receive('sleep').with_args(30).and_return().ordered() error_logs = [flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(error_logs).ordered() config = { 'repositories': [{'path': 'foo'}], @@ -433,17 +453,18 @@ def test_run_configuration_retries_timeout_multiple_repos(): flexmock(module).should_receive('get_skip_actions').and_return([]) flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock()) flexmock(module.command).should_receive('execute_hook') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return( [] ).and_raise(OSError).times(4) flexmock(module).should_receive('log_error_records').with_args( - 'foo: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, ).and_return([flexmock()]).ordered() flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', + 'Error running actions for repository', OSError, levelno=logging.WARNING, log_command_error_output=True, @@ -456,7 +477,7 @@ def test_run_configuration_retries_timeout_multiple_repos(): flexmock(time).should_receive('sleep').with_args(10).and_return().ordered() error_logs = [flexmock()] flexmock(module).should_receive('log_error_records').with_args( - 'bar: Error running actions for repository', OSError + 'Error running actions for repository', OSError ).and_return(error_logs).ordered() config = { 'repositories': [{'path': 'foo'}, {'path': 'bar'}], @@ -1370,6 +1391,7 @@ def test_collect_highlander_action_summary_logs_error_on_run_validate_failure(): def test_collect_configuration_run_summary_logs_info_for_success(): flexmock(module.command).should_receive('execute_hook').never() flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) arguments = {} @@ -1384,6 +1406,7 @@ def test_collect_configuration_run_summary_logs_info_for_success(): def test_collect_configuration_run_summary_executes_hooks_for_create(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)} @@ -1398,6 +1421,7 @@ def test_collect_configuration_run_summary_executes_hooks_for_create(): def test_collect_configuration_run_summary_logs_info_for_success_with_extract(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) arguments = {'extract': flexmock(repository='repo')} @@ -1429,6 +1453,7 @@ def test_collect_configuration_run_summary_logs_extract_with_repository_error(): def test_collect_configuration_run_summary_logs_info_for_success_with_mount(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) arguments = {'mount': flexmock(repository='repo')} @@ -1488,6 +1513,7 @@ def test_collect_configuration_run_summary_logs_pre_hook_error(): def test_collect_configuration_run_summary_logs_post_hook_error(): flexmock(module.command).should_receive('execute_hook').and_return(None).and_raise(ValueError) flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) expected_logs = (flexmock(),) flexmock(module).should_receive('log_error_records').and_return(expected_logs) @@ -1521,6 +1547,7 @@ def test_collect_configuration_run_summary_logs_for_list_with_archive_and_reposi def test_collect_configuration_run_summary_logs_info_for_success_with_list(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) arguments = {'list': flexmock(repository='repo', archive=None)} @@ -1535,6 +1562,7 @@ def test_collect_configuration_run_summary_logs_info_for_success_with_list(): def test_collect_configuration_run_summary_logs_run_configuration_error(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return( [logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))] ) @@ -1552,6 +1580,7 @@ def test_collect_configuration_run_summary_logs_run_configuration_error(): def test_collect_configuration_run_summary_logs_run_umount_error(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return([]) flexmock(module.borg_umount).should_receive('unmount_archive').and_raise(OSError) flexmock(module).should_receive('log_error_records').and_return( @@ -1570,6 +1599,7 @@ def test_collect_configuration_run_summary_logs_run_umount_error(): def test_collect_configuration_run_summary_logs_outputs_merged_json_results(): flexmock(module.validate).should_receive('guard_configuration_contains_repository') + flexmock(module).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('run_configuration').and_return(['foo', 'bar']).and_return( ['baz'] ) diff --git a/tests/unit/config/test_paths.py b/tests/unit/config/test_paths.py index a63c86e1..12975b9d 100644 --- a/tests/unit/config/test_paths.py +++ b/tests/unit/config/test_paths.py @@ -66,7 +66,7 @@ def test_runtime_directory_uses_config_option(): flexmock(module.os).should_receive('makedirs') config = {'user_runtime_directory': '/run', 'borgmatic_source_directory': '/nope'} - with module.Runtime_directory(config, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory(config) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/./borgmatic' @@ -75,7 +75,7 @@ def test_runtime_directory_uses_config_option_without_adding_duplicate_borgmatic flexmock(module.os).should_receive('makedirs') config = {'user_runtime_directory': '/run/borgmatic', 'borgmatic_source_directory': '/nope'} - with module.Runtime_directory(config, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory(config) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/./borgmatic' @@ -85,7 +85,7 @@ def test_runtime_directory_with_relative_config_option_errors(): with pytest.raises(ValueError): with module.Runtime_directory( - config, 'prefix' + config ) as borgmatic_runtime_directory: # noqa: F841 pass @@ -97,7 +97,7 @@ def test_runtime_directory_falls_back_to_xdg_runtime_dir(): ) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/./borgmatic' @@ -108,7 +108,7 @@ def test_runtime_directory_falls_back_to_xdg_runtime_dir_without_adding_duplicat ) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/./borgmatic' @@ -117,7 +117,7 @@ def test_runtime_directory_with_relative_xdg_runtime_dir_errors(): flexmock(module.os).should_receive('makedirs').never() with pytest.raises(ValueError): - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: # noqa: F841 + with module.Runtime_directory({}) as borgmatic_runtime_directory: # noqa: F841 pass @@ -129,7 +129,7 @@ def test_runtime_directory_falls_back_to_runtime_directory(): ) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/./borgmatic' @@ -141,7 +141,7 @@ def test_runtime_directory_falls_back_to_runtime_directory_without_adding_duplic ) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/./borgmatic' @@ -153,7 +153,7 @@ def test_runtime_directory_with_relative_runtime_directory_errors(): flexmock(module.os).should_receive('makedirs').never() with pytest.raises(ValueError): - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: # noqa: F841 + with module.Runtime_directory({}) as borgmatic_runtime_directory: # noqa: F841 pass @@ -171,7 +171,7 @@ def test_runtime_directory_falls_back_to_tmpdir_and_adds_temporary_subdirectory_ ).and_return(temporary_directory) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/borgmatic-1234/./borgmatic' @@ -185,7 +185,7 @@ def test_runtime_directory_with_relative_tmpdir_errors(): flexmock(module.os).should_receive('makedirs').never() with pytest.raises(ValueError): - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: # noqa: F841 + with module.Runtime_directory({}) as borgmatic_runtime_directory: # noqa: F841 pass @@ -204,7 +204,7 @@ def test_runtime_directory_falls_back_to_temp_and_adds_temporary_subdirectory_th ).and_return(temporary_directory) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/run/borgmatic-1234/./borgmatic' @@ -219,7 +219,7 @@ def test_runtime_directory_with_relative_temp_errors(): flexmock(module.os).should_receive('makedirs') with pytest.raises(ValueError): - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: # noqa: F841 + with module.Runtime_directory({}) as borgmatic_runtime_directory: # noqa: F841 pass @@ -238,7 +238,7 @@ def test_runtime_directory_falls_back_to_hard_coded_tmp_path_and_adds_temporary_ ).and_return(temporary_directory) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/tmp/borgmatic-1234/./borgmatic' @@ -257,7 +257,7 @@ def test_runtime_directory_with_erroring_cleanup_does_not_raise(): ).and_return(temporary_directory) flexmock(module.os).should_receive('makedirs') - with module.Runtime_directory({}, 'prefix') as borgmatic_runtime_directory: + with module.Runtime_directory({}) as borgmatic_runtime_directory: assert borgmatic_runtime_directory == '/tmp/borgmatic-1234/./borgmatic' diff --git a/tests/unit/hooks/data_source/test_dump.py b/tests/unit/hooks/data_source/test_dump.py index ffc7819c..d1b48ede 100644 --- a/tests/unit/hooks/data_source/test_dump.py +++ b/tests/unit/hooks/data_source/test_dump.py @@ -48,21 +48,21 @@ def test_remove_data_source_dumps_removes_dump_path(): flexmock(module.os.path).should_receive('exists').and_return(True) flexmock(module.shutil).should_receive('rmtree').with_args('databases').once() - module.remove_data_source_dumps('databases', 'SuperDB', 'test.yaml', dry_run=False) + module.remove_data_source_dumps('databases', 'SuperDB', dry_run=False) def test_remove_data_source_dumps_with_dry_run_skips_removal(): flexmock(module.os.path).should_receive('exists').never() flexmock(module.shutil).should_receive('rmtree').never() - module.remove_data_source_dumps('databases', 'SuperDB', 'test.yaml', dry_run=True) + module.remove_data_source_dumps('databases', 'SuperDB', dry_run=True) def test_remove_data_source_dumps_without_dump_path_present_skips_removal(): flexmock(module.os.path).should_receive('exists').and_return(False) flexmock(module.shutil).should_receive('rmtree').never() - module.remove_data_source_dumps('databases', 'SuperDB', 'test.yaml', dry_run=False) + module.remove_data_source_dumps('databases', 'SuperDB', dry_run=False) def test_convert_glob_patterns_to_borg_pattern_makes_multipart_regular_expression(): diff --git a/tests/unit/hooks/data_source/test_mariadb.py b/tests/unit/hooks/data_source/test_mariadb.py index 2e4bec78..e21979d6 100644 --- a/tests/unit/hooks/data_source/test_mariadb.py +++ b/tests/unit/hooks/data_source/test_mariadb.py @@ -68,7 +68,6 @@ def test_dump_data_sources_dumps_each_database(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -98,7 +97,6 @@ def test_dump_data_sources_dumps_with_password(): assert module.dump_data_sources( [database], {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -123,7 +121,6 @@ def test_dump_data_sources_dumps_all_databases_at_once(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -151,7 +148,6 @@ def test_dump_data_sources_dumps_all_databases_separately_when_format_configured module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -175,7 +171,7 @@ def test_database_names_to_dump_runs_mariadb_with_list_options(): extra_environment=None, ).and_return(('foo\nbar')).once() - assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar') + assert module.database_names_to_dump(database, None, '') == ('foo', 'bar') def test_database_names_to_dump_runs_non_default_mariadb_with_list_options(): @@ -196,7 +192,7 @@ def test_database_names_to_dump_runs_non_default_mariadb_with_list_options(): ), ).and_return(('foo\nbar')).once() - assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar') + assert module.database_names_to_dump(database, None, '') == ('foo', 'bar') def test_execute_dump_command_runs_mariadb_dump(): @@ -455,7 +451,6 @@ def test_dump_data_sources_errors_for_missing_all_databases(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -475,7 +470,6 @@ def test_dump_data_sources_does_not_error_for_missing_all_databases_with_dry_run module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -500,7 +494,6 @@ def test_restore_data_source_dump_runs_mariadb_to_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=extract_process, @@ -529,7 +522,6 @@ def test_restore_data_source_dump_runs_mariadb_with_options(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -560,7 +552,6 @@ def test_restore_data_source_dump_runs_non_default_mariadb_with_options(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -598,7 +589,6 @@ def test_restore_data_source_dump_runs_mariadb_with_hostname_and_port(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -627,7 +617,6 @@ def test_restore_data_source_dump_runs_mariadb_with_username_and_password(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -677,7 +666,6 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -729,7 +717,6 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -751,7 +738,6 @@ def test_restore_data_source_dump_with_dry_run_skips_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=True, extract_process=flexmock(), diff --git a/tests/unit/hooks/data_source/test_mongodb.py b/tests/unit/hooks/data_source/test_mongodb.py index 0e3efd5d..1d2c0c7b 100644 --- a/tests/unit/hooks/data_source/test_mongodb.py +++ b/tests/unit/hooks/data_source/test_mongodb.py @@ -43,7 +43,6 @@ def test_dump_data_sources_runs_mongodump_for_each_database(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -66,7 +65,6 @@ def test_dump_data_sources_with_dry_run_skips_mongodump(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -105,7 +103,6 @@ def test_dump_data_sources_runs_mongodump_with_hostname_and_port(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -151,7 +148,6 @@ def test_dump_data_sources_runs_mongodump_with_username_and_password(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -177,7 +173,6 @@ def test_dump_data_sources_runs_mongodump_with_directory_format(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -213,7 +208,6 @@ def test_dump_data_sources_runs_mongodump_with_options(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -239,7 +233,6 @@ def test_dump_data_sources_runs_mongodumpall_for_all_databases(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -271,7 +264,6 @@ def test_restore_data_source_dump_runs_mongorestore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=extract_process, @@ -311,7 +303,6 @@ def test_restore_data_source_dump_runs_mongorestore_with_hostname_and_port(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -359,7 +350,6 @@ def test_restore_data_source_dump_runs_mongorestore_with_username_and_password() module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -415,7 +405,6 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -471,7 +460,6 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -501,7 +489,6 @@ def test_restore_data_source_dump_runs_mongorestore_with_options(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -539,7 +526,6 @@ def test_restore_databases_dump_runs_mongorestore_with_schemas(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -569,7 +555,6 @@ def test_restore_data_source_dump_runs_psql_for_all_database_dump(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -593,7 +578,6 @@ def test_restore_data_source_dump_with_dry_run_skips_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=True, extract_process=flexmock(), @@ -622,7 +606,6 @@ def test_restore_data_source_dump_without_extract_process_restores_from_disk(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=None, diff --git a/tests/unit/hooks/data_source/test_mysql.py b/tests/unit/hooks/data_source/test_mysql.py index a056e7e5..5eb46e35 100644 --- a/tests/unit/hooks/data_source/test_mysql.py +++ b/tests/unit/hooks/data_source/test_mysql.py @@ -68,7 +68,6 @@ def test_dump_data_sources_dumps_each_database(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -98,7 +97,6 @@ def test_dump_data_sources_dumps_with_password(): assert module.dump_data_sources( [database], {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -123,7 +121,6 @@ def test_dump_data_sources_dumps_all_databases_at_once(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -151,7 +148,6 @@ def test_dump_data_sources_dumps_all_databases_separately_when_format_configured module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -175,7 +171,7 @@ def test_database_names_to_dump_runs_mysql_with_list_options(): extra_environment=None, ).and_return(('foo\nbar')).once() - assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar') + assert module.database_names_to_dump(database, None, '') == ('foo', 'bar') def test_database_names_to_dump_runs_non_default_mysql_with_list_options(): @@ -196,7 +192,7 @@ def test_database_names_to_dump_runs_non_default_mysql_with_list_options(): ), ).and_return(('foo\nbar')).once() - assert module.database_names_to_dump(database, None, 'test.yaml', '') == ('foo', 'bar') + assert module.database_names_to_dump(database, None, '') == ('foo', 'bar') def test_execute_dump_command_runs_mysqldump(): @@ -453,7 +449,6 @@ def test_dump_data_sources_errors_for_missing_all_databases(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -473,7 +468,6 @@ def test_dump_data_sources_does_not_error_for_missing_all_databases_with_dry_run module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -498,7 +492,6 @@ def test_restore_data_source_dump_runs_mysql_to_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=extract_process, @@ -527,7 +520,6 @@ def test_restore_data_source_dump_runs_mysql_with_options(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -556,7 +548,6 @@ def test_restore_data_source_dump_runs_non_default_mysql_with_options(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -594,7 +585,6 @@ def test_restore_data_source_dump_runs_mysql_with_hostname_and_port(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -623,7 +613,6 @@ def test_restore_data_source_dump_runs_mysql_with_username_and_password(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -673,7 +662,6 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=extract_process, @@ -725,7 +713,6 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -747,7 +734,6 @@ def test_restore_data_source_dump_with_dry_run_skips_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=True, extract_process=flexmock(), diff --git a/tests/unit/hooks/data_source/test_postgresql.py b/tests/unit/hooks/data_source/test_postgresql.py index 752f940b..4188f96d 100644 --- a/tests/unit/hooks/data_source/test_postgresql.py +++ b/tests/unit/hooks/data_source/test_postgresql.py @@ -61,7 +61,7 @@ def test_make_extra_environment_without_ssl_mode_does_not_set_ssl_mode(): def test_database_names_to_dump_passes_through_individual_database_name(): database = {'name': 'foo'} - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', ) @@ -69,7 +69,7 @@ def test_database_names_to_dump_passes_through_individual_database_name(): def test_database_names_to_dump_passes_through_individual_database_name_with_format(): database = {'name': 'foo', 'format': 'custom'} - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', ) @@ -77,7 +77,7 @@ def test_database_names_to_dump_passes_through_individual_database_name_with_for def test_database_names_to_dump_passes_through_all_without_format(): database = {'name': 'all'} - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'all', ) @@ -86,7 +86,7 @@ def test_database_names_to_dump_with_all_and_format_and_dry_run_bails(): database = {'name': 'all', 'format': 'custom'} flexmock(module).should_receive('execute_command_and_capture_output').never() - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=True) == () + assert module.database_names_to_dump(database, flexmock(), dry_run=True) == () def test_database_names_to_dump_with_all_and_format_lists_databases(): @@ -95,7 +95,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases(): 'foo,test,\nbar,test,"stuff and such"' ) - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', 'bar', ) @@ -119,7 +119,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_hostnam extra_environment=object, ).and_return('foo,test,\nbar,test,"stuff and such"') - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', 'bar', ) @@ -141,7 +141,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_usernam extra_environment=object, ).and_return('foo,test,\nbar,test,"stuff and such"') - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', 'bar', ) @@ -154,7 +154,7 @@ def test_database_names_to_dump_with_all_and_format_lists_databases_with_options extra_environment=object, ).and_return('foo,test,\nbar,test,"stuff and such"') - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', 'bar', ) @@ -166,7 +166,7 @@ def test_database_names_to_dump_with_all_and_format_excludes_particular_database 'foo,test,\ntemplate0,test,blah' ) - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', ) @@ -194,7 +194,7 @@ def test_database_names_to_dump_with_all_and_psql_command_uses_custom_command(): extra_environment=object, ).and_return('foo,text').once() - assert module.database_names_to_dump(database, flexmock(), flexmock(), dry_run=False) == ( + assert module.database_names_to_dump(database, flexmock(), dry_run=False) == ( 'foo', ) @@ -253,7 +253,6 @@ def test_dump_data_sources_runs_pg_dump_for_each_database(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -273,7 +272,6 @@ def test_dump_data_sources_raises_when_no_database_names_to_dump(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -290,7 +288,6 @@ def test_dump_data_sources_does_not_raise_when_no_database_names_to_dump(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -316,7 +313,6 @@ def test_dump_data_sources_with_duplicate_dump_skips_pg_dump(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -344,7 +340,6 @@ def test_dump_data_sources_with_dry_run_skips_pg_dump(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -390,7 +385,6 @@ def test_dump_data_sources_runs_pg_dump_with_hostname_and_port(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -434,7 +428,6 @@ def test_dump_data_sources_runs_pg_dump_with_username_and_password(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -478,7 +471,6 @@ def test_dump_data_sources_with_username_injection_attack_gets_escaped(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -518,7 +510,6 @@ def test_dump_data_sources_runs_pg_dump_with_directory_format(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -561,7 +552,6 @@ def test_dump_data_sources_runs_pg_dump_with_options(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -591,7 +581,6 @@ def test_dump_data_sources_runs_pg_dumpall_for_all_databases(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -633,7 +622,6 @@ def test_dump_data_sources_runs_non_default_pg_dump(): assert module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -680,7 +668,6 @@ def test_restore_data_source_dump_runs_pg_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=extract_process, @@ -743,7 +730,6 @@ def test_restore_data_source_dump_runs_pg_restore_with_hostname_and_port(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -804,7 +790,6 @@ def test_restore_data_source_dump_runs_pg_restore_with_username_and_password(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -884,7 +869,6 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=extract_process, @@ -964,7 +948,6 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -1026,7 +1009,6 @@ def test_restore_data_source_dump_runs_pg_restore_with_options(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -1066,7 +1048,6 @@ def test_restore_data_source_dump_runs_psql_for_all_database_dump(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'all'}, dry_run=False, extract_process=extract_process, @@ -1111,7 +1092,6 @@ def test_restore_data_source_dump_runs_psql_for_plain_database_dump(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -1181,7 +1161,6 @@ def test_restore_data_source_dump_runs_non_default_pg_restore_and_psql(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -1206,7 +1185,6 @@ def test_restore_data_source_dump_with_dry_run_skips_restore(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=True, extract_process=flexmock(), @@ -1259,7 +1237,6 @@ def test_restore_data_source_dump_without_extract_process_restores_from_disk(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'foo'}, dry_run=False, extract_process=None, @@ -1316,7 +1293,6 @@ def test_restore_data_source_dump_with_schemas_restores_schemas(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=None, diff --git a/tests/unit/hooks/data_source/test_sqlite.py b/tests/unit/hooks/data_source/test_sqlite.py index 02c343a3..03afa3c3 100644 --- a/tests/unit/hooks/data_source/test_sqlite.py +++ b/tests/unit/hooks/data_source/test_sqlite.py @@ -31,7 +31,6 @@ def test_dump_data_sources_logs_and_skips_if_dump_already_exists(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -62,7 +61,6 @@ def test_dump_data_sources_dumps_each_database(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -100,7 +98,6 @@ def test_dump_data_sources_with_path_injection_attack_gets_escaped(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -129,7 +126,6 @@ def test_dump_data_sources_with_non_existent_path_warns_and_dumps_database(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -160,7 +156,6 @@ def test_dump_data_sources_with_name_all_warns_and_dumps_all_databases(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -185,7 +180,6 @@ def test_dump_data_sources_does_not_dump_if_dry_run(): module.dump_data_sources( databases, {}, - 'test.yaml', config_paths=('test.yaml',), borgmatic_runtime_directory='/run/borgmatic', patterns=[], @@ -214,7 +208,6 @@ def test_restore_data_source_dump_restores_database(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -244,7 +237,6 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'database'}, dry_run=False, extract_process=extract_process, @@ -274,7 +266,6 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_ module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source=hook_config[0], dry_run=False, extract_process=extract_process, @@ -293,7 +284,6 @@ def test_restore_data_source_dump_does_not_restore_database_if_dry_run(): module.restore_data_source_dump( hook_config, {}, - 'test.yaml', data_source={'name': 'database'}, dry_run=True, extract_process=extract_process, diff --git a/tests/unit/hooks/test_dispatch.py b/tests/unit/hooks/test_dispatch.py index dde8bd5d..d0eca83d 100644 --- a/tests/unit/hooks/test_dispatch.py +++ b/tests/unit/hooks/test_dispatch.py @@ -27,10 +27,10 @@ def test_call_hook_invokes_module_function_with_arguments_and_returns_value(): 'borgmatic.hooks.monitoring.super_hook' ).and_return(test_module) flexmock(test_module).should_receive('hook_function').with_args( - config['super_hook'], config, 'prefix', 55, value=66 + config['super_hook'], config, 55, value=66 ).and_return(expected_return_value).once() - return_value = module.call_hook('hook_function', config, 'prefix', 'super_hook', 55, value=66) + return_value = module.call_hook('hook_function', config, 'super_hook', 55, value=66) assert return_value == expected_return_value @@ -49,10 +49,10 @@ def test_call_hook_probes_config_with_databases_suffix(): 'borgmatic.hooks.monitoring.super_hook' ).and_return(test_module) flexmock(test_module).should_receive('hook_function').with_args( - config['super_hook_databases'], config, 'prefix', 55, value=66 + config['super_hook_databases'], config, 55, value=66 ).and_return(expected_return_value).once() - return_value = module.call_hook('hook_function', config, 'prefix', 'super_hook', 55, value=66) + return_value = module.call_hook('hook_function', config, 'super_hook', 55, value=66) assert return_value == expected_return_value @@ -71,11 +71,11 @@ def test_call_hook_strips_databases_suffix_from_hook_name(): 'borgmatic.hooks.monitoring.super_hook' ).and_return(test_module) flexmock(test_module).should_receive('hook_function').with_args( - config['super_hook_databases'], config, 'prefix', 55, value=66 + config['super_hook_databases'], config, 55, value=66 ).and_return(expected_return_value).once() return_value = module.call_hook( - 'hook_function', config, 'prefix', 'super_hook_databases', 55, value=66 + 'hook_function', config, 'super_hook_databases', 55, value=66 ) assert return_value == expected_return_value @@ -95,10 +95,10 @@ def test_call_hook_without_hook_config_invokes_module_function_with_arguments_an 'borgmatic.hooks.monitoring.super_hook' ).and_return(test_module) flexmock(test_module).should_receive('hook_function').with_args( - None, config, 'prefix', 55, value=66 + None, config, 55, value=66 ).and_return(expected_return_value).once() - return_value = module.call_hook('hook_function', config, 'prefix', 'super_hook', 55, value=66) + return_value = module.call_hook('hook_function', config, 'super_hook', 55, value=66) assert return_value == expected_return_value @@ -118,7 +118,7 @@ def test_call_hook_without_corresponding_module_raises(): flexmock(test_module).should_receive('hook_function').never() with pytest.raises(ValueError): - module.call_hook('hook_function', config, 'prefix', 'super_hook', 55, value=66) + module.call_hook('hook_function', config, 'super_hook', 55, value=66) def test_call_hook_skips_non_hook_modules(): @@ -134,7 +134,7 @@ def test_call_hook_skips_non_hook_modules(): 'borgmatic.hooks.monitoring.not_a_hook' ).and_return(not_a_hook_module) - return_value = module.call_hook('hook_function', config, 'prefix', 'not_a_hook', 55, value=66) + return_value = module.call_hook('hook_function', config, 'not_a_hook', 55, value=66) assert return_value is None @@ -152,7 +152,7 @@ def test_call_hooks_calls_each_hook_and_collects_return_values(): expected_return_values['super_hook'] ).and_return(expected_return_values['other_hook']) - return_values = module.call_hooks('do_stuff', config, 'prefix', module.Hook_type.MONITORING, 55) + return_values = module.call_hooks('do_stuff', config, module.Hook_type.MONITORING, 55) assert return_values == expected_return_values @@ -168,7 +168,7 @@ def test_call_hooks_calls_skips_return_values_for_unconfigured_hooks(): ).and_return(['super_hook', 'other_hook']) flexmock(module).should_receive('call_hook').and_return(expected_return_values['super_hook']) - return_values = module.call_hooks('do_stuff', config, 'prefix', module.Hook_type.MONITORING, 55) + return_values = module.call_hooks('do_stuff', config, module.Hook_type.MONITORING, 55) assert return_values == expected_return_values @@ -186,7 +186,7 @@ def test_call_hooks_calls_treats_null_hook_as_optionless(): expected_return_values['super_hook'] ).and_return(expected_return_values['other_hook']) - return_values = module.call_hooks('do_stuff', config, 'prefix', module.Hook_type.MONITORING, 55) + return_values = module.call_hooks('do_stuff', config, module.Hook_type.MONITORING, 55) assert return_values == expected_return_values @@ -204,7 +204,7 @@ def test_call_hooks_calls_looks_up_databases_suffix_in_config(): expected_return_values['super_hook'] ).and_return(expected_return_values['other_hook']) - return_values = module.call_hooks('do_stuff', config, 'prefix', module.Hook_type.MONITORING, 55) + return_values = module.call_hooks('do_stuff', config, module.Hook_type.MONITORING, 55) assert return_values == expected_return_values @@ -223,7 +223,7 @@ def test_call_hooks_even_if_unconfigured_calls_each_hook_and_collects_return_val ).and_return(expected_return_values['other_hook']) return_values = module.call_hooks_even_if_unconfigured( - 'do_stuff', config, 'prefix', module.Hook_type.MONITORING, 55 + 'do_stuff', config, module.Hook_type.MONITORING, 55 ) assert return_values == expected_return_values @@ -243,7 +243,7 @@ def test_call_hooks_even_if_unconfigured_calls_each_hook_configured_or_not_and_c ).and_return(expected_return_values['other_hook']) return_values = module.call_hooks_even_if_unconfigured( - 'do_stuff', config, 'prefix', module.Hook_type.MONITORING, 55 + 'do_stuff', config, module.Hook_type.MONITORING, 55 ) assert return_values == expected_return_values diff --git a/tests/unit/test_execute.py b/tests/unit/test_execute.py index 82c94206..7741526f 100644 --- a/tests/unit/test_execute.py +++ b/tests/unit/test_execute.py @@ -186,6 +186,7 @@ def test_execute_command_calls_full_command(): env=None, cwd=None, ).and_return(flexmock(stdout=None)).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command) @@ -207,6 +208,7 @@ def test_execute_command_calls_full_command_with_output_file(): env=None, cwd=None, ).and_return(flexmock(stderr=None)).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command, output_file=output_file) @@ -222,6 +224,7 @@ def test_execute_command_calls_full_command_without_capturing_output(): full_command, stdin=None, stdout=None, stderr=None, shell=False, env=None, cwd=None ).and_return(flexmock(wait=lambda: 0)).once() flexmock(module).should_receive('interpret_exit_code').and_return(module.Exit_status.SUCCESS) + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command, output_file=module.DO_NOT_CAPTURE) @@ -243,6 +246,7 @@ def test_execute_command_calls_full_command_with_input_file(): env=None, cwd=None, ).and_return(flexmock(stdout=None)).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command, input_file=input_file) @@ -263,6 +267,7 @@ def test_execute_command_calls_full_command_with_shell(): env=None, cwd=None, ).and_return(flexmock(stdout=None)).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command, shell=True) @@ -283,6 +288,7 @@ def test_execute_command_calls_full_command_with_extra_environment(): env={'a': 'b', 'c': 'd'}, cwd=None, ).and_return(flexmock(stdout=None)).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command, extra_environment={'c': 'd'}) @@ -303,6 +309,7 @@ def test_execute_command_calls_full_command_with_working_directory(): env=None, cwd='/working', ).and_return(flexmock(stdout=None)).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') output = module.execute_command(full_command, working_directory='/working') @@ -324,6 +331,7 @@ def test_execute_command_without_run_to_completion_returns_process(): env=None, cwd=None, ).and_return(process).once() + flexmock(module.borgmatic.logger).should_receive('Log_prefix').and_return(flexmock()) flexmock(module).should_receive('log_outputs') assert module.execute_command(full_command, run_to_completion=False) == process diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py index cc6619ed..97aeb63a 100644 --- a/tests/unit/test_logger.py +++ b/tests/unit/test_logger.py @@ -177,8 +177,8 @@ def test_multi_stream_handler_logs_to_handler_for_log_level(): def test_console_color_formatter_format_includes_log_message(): flexmock(module).should_receive('add_custom_log_levels') flexmock(module.logging).ANSWER = module.ANSWER - flexmock(module.logging.Formatter).should_receive('format') plain_message = 'uh oh' + flexmock(module.logging.Formatter).should_receive('format').and_return(plain_message) record = flexmock(levelno=logging.CRITICAL) colored_message = module.Console_color_formatter().format(record)