def test_execute_hook_with_dry_run_skips_commands(): flexmock(module.execute).should_receive('execute_command').never() module.execute_hook([':', 'true'], None, 'config.yaml', 'pre-backup', dry_run=True)
def test_execute_hook_with_umask_sets_that_umask(): flexmock(module.os).should_receive('umask').with_args(0o77).and_return( 0o22).once() flexmock(module.os).should_receive('umask').with_args(0o22).once() flexmock(module.execute).should_receive('execute_command').with_args( [':'], output_log_level=logging.WARNING, shell=True) module.execute_hook([':'], 77, 'config.yaml', 'pre-backup', dry_run=False)
def test_execute_hook_invokes_each_command(): flexmock(module.execute).should_receive('execute_command').with_args( [':'], output_log_level=logging.WARNING, shell=True).once() module.execute_hook([':'], None, 'config.yaml', 'pre-backup', dry_run=False)
def run_configuration(config_filename, config, arguments): # pragma: no cover ''' Given a config filename, the corresponding parsed config dict, and command-line arguments as a dict from subparser name to a namespace of parsed arguments, execute its defined pruning, backups, consistency checks, and/or other actions. Yield JSON output strings from executing any actions that produce JSON. ''' (location, storage, retention, consistency, hooks) = (config.get(section_name, {}) for section_name in ('location', 'storage', 'retention', 'consistency', 'hooks')) global_arguments = arguments['global'] try: local_path = location.get('local_path', 'borg') remote_path = location.get('remote_path') borg_environment.initialize(storage) if 'create' in arguments: hook.execute_hook( hooks.get('before_backup'), hooks.get('umask'), config_filename, 'pre-backup', global_arguments.dry_run, ) for repository_path in location['repositories']: yield from run_actions( arguments=arguments, location=location, storage=storage, retention=retention, consistency=consistency, local_path=local_path, remote_path=remote_path, repository_path=repository_path, ) if 'create' in arguments: hook.execute_hook( hooks.get('after_backup'), hooks.get('umask'), config_filename, 'post-backup', global_arguments.dry_run, ) except (OSError, CalledProcessError): hook.execute_hook( hooks.get('on_error'), hooks.get('umask'), config_filename, 'on-error', global_arguments.dry_run, ) raise
def test_execute_hook_on_error_logs_as_error(): flexmock(module.execute).should_receive('execute_command').with_args( [':'], output_log_level=logging.ERROR, shell=True).once() module.execute_hook([':'], None, 'config.yaml', 'on-error', dry_run=False)
def test_execute_hook_with_empty_commands_does_not_raise(): module.execute_hook([], None, 'config.yaml', 'post-backup', dry_run=False)