|
@@ -216,6 +216,46 @@ def test_dump_data_sources_with_dry_run_skips_commands_and_does_not_touch_source
|
|
assert source_directories == ['/mnt/dataset']
|
|
assert source_directories == ['/mnt/dataset']
|
|
|
|
|
|
|
|
|
|
|
|
+def test_dump_data_sources_ignores_mismatch_between_source_directories_and_contained_source_directories():
|
|
|
|
+ flexmock(module).should_receive('get_datasets_to_backup').and_return(
|
|
|
|
+ (
|
|
|
|
+ flexmock(
|
|
|
|
+ name='dataset',
|
|
|
|
+ mount_point='/mnt/dataset',
|
|
|
|
+ contained_source_directories=('/mnt/dataset/subdir',),
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ flexmock(module.os).should_receive('getpid').and_return(1234)
|
|
|
|
+ full_snapshot_name = 'dataset@borgmatic-1234'
|
|
|
|
+ flexmock(module).should_receive('snapshot_dataset').with_args(
|
|
|
|
+ 'zfs',
|
|
|
|
+ full_snapshot_name,
|
|
|
|
+ ).once()
|
|
|
|
+ snapshot_mount_path = '/run/borgmatic/zfs_snapshots/./mnt/dataset'
|
|
|
|
+ flexmock(module).should_receive('mount_snapshot').with_args(
|
|
|
|
+ 'mount',
|
|
|
|
+ full_snapshot_name,
|
|
|
|
+ module.os.path.normpath(snapshot_mount_path),
|
|
|
|
+ ).once()
|
|
|
|
+ source_directories = ['/hmm']
|
|
|
|
+
|
|
|
|
+ assert (
|
|
|
|
+ module.dump_data_sources(
|
|
|
|
+ hook_config={},
|
|
|
|
+ config={'source_directories': '/mnt/dataset', 'zfs': {}},
|
|
|
|
+ log_prefix='test',
|
|
|
|
+ config_paths=('test.yaml',),
|
|
|
|
+ borgmatic_runtime_directory='/run/borgmatic',
|
|
|
|
+ source_directories=source_directories,
|
|
|
|
+ dry_run=False,
|
|
|
|
+ )
|
|
|
|
+ == []
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ assert source_directories == ['/hmm', os.path.join(snapshot_mount_path, 'subdir')]
|
|
|
|
+
|
|
|
|
+
|
|
def test_get_all_snapshots_parses_list_output():
|
|
def test_get_all_snapshots_parses_list_output():
|
|
flexmock(module.borgmatic.execute).should_receive(
|
|
flexmock(module.borgmatic.execute).should_receive(
|
|
'execute_command_and_capture_output'
|
|
'execute_command_and_capture_output'
|
|
@@ -418,6 +458,36 @@ def test_remove_data_source_dumps_skips_unmount_snapshot_mount_paths_that_are_no
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
+def test_remove_data_source_dumps_skips_unmount_snapshot_mount_paths_after_rmtree_succeeds():
|
|
|
|
+ flexmock(module).should_receive('get_all_dataset_mount_points').and_return(('/mnt/dataset',))
|
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive(
|
|
|
|
+ 'replace_temporary_subdirectory_with_glob'
|
|
|
|
+ ).and_return('/run/borgmatic')
|
|
|
|
+ flexmock(module.glob).should_receive('glob').replace_with(lambda path: [path])
|
|
|
|
+ flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
|
+ '/run/borgmatic/zfs_snapshots'
|
|
|
|
+ ).and_return(True)
|
|
|
|
+ flexmock(module.os.path).should_receive('isdir').with_args(
|
|
|
|
+ '/run/borgmatic/zfs_snapshots/mnt/dataset'
|
|
|
|
+ ).and_return(True).and_return(False)
|
|
|
|
+ flexmock(module.shutil).should_receive('rmtree')
|
|
|
|
+ flexmock(module).should_receive('unmount_snapshot').never()
|
|
|
|
+ flexmock(module).should_receive('get_all_snapshots').and_return(
|
|
|
|
+ ('dataset@borgmatic-1234', 'dataset@other', 'other@other', 'invalid')
|
|
|
|
+ )
|
|
|
|
+ flexmock(module).should_receive('destroy_snapshot').with_args(
|
|
|
|
+ 'zfs', 'dataset@borgmatic-1234'
|
|
|
|
+ ).once()
|
|
|
|
+
|
|
|
|
+ module.remove_data_source_dumps(
|
|
|
|
+ hook_config={},
|
|
|
|
+ config={'source_directories': '/mnt/dataset', 'zfs': {}},
|
|
|
|
+ log_prefix='test',
|
|
|
|
+ borgmatic_runtime_directory='/run/borgmatic',
|
|
|
|
+ dry_run=False,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+
|
|
def test_remove_data_source_dumps_with_dry_run_skips_unmount_and_destroy():
|
|
def test_remove_data_source_dumps_with_dry_run_skips_unmount_and_destroy():
|
|
flexmock(module).should_receive('get_all_dataset_mount_points').and_return(('/mnt/dataset',))
|
|
flexmock(module).should_receive('get_all_dataset_mount_points').and_return(('/mnt/dataset',))
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|
|
flexmock(module.borgmatic.config.paths).should_receive(
|