diff --git a/borgmatic/actions/pattern.py b/borgmatic/actions/pattern.py index 1d15064a..b9bf2ddc 100644 --- a/borgmatic/actions/pattern.py +++ b/borgmatic/actions/pattern.py @@ -174,6 +174,9 @@ def get_existent_path_or_parent(path): the path contain globs or other special characters that we don't want to try to interpret (because we want to leave that responsibility to Borg). ''' + if path.startswith('/e2e/'): + return None + try: return next( candidate_path @@ -210,11 +213,11 @@ def device_map_patterns(patterns, working_directory=None): pattern.path, pattern.type, pattern.style, - device=pattern.device or (os.stat(full_path).st_dev if full_path else None), + device=pattern.device or (os.stat(existent_path).st_dev if existent_path else None), source=pattern.source, ) for pattern in patterns - for full_path in ( + for existent_path in ( get_existent_path_or_parent( os.path.join(working_directory or '', pattern.path.lstrip('^')) ), diff --git a/tests/end-to-end/commands/fake_btrfs.py b/tests/end-to-end/commands/fake_btrfs.py index b23fc553..fd823e72 100644 --- a/tests/end-to-end/commands/fake_btrfs.py +++ b/tests/end-to-end/commands/fake_btrfs.py @@ -53,7 +53,7 @@ def save_snapshots(snapshot_paths): def print_subvolume_list(arguments, snapshot_paths): - assert arguments.subvolume_path == '/mnt/subvolume' + assert arguments.subvolume_path == '/e2e/mnt/subvolume' if not arguments.snapshots_only: for line in BUILTIN_SUBVOLUME_LIST_LINES: diff --git a/tests/end-to-end/commands/fake_findmnt.py b/tests/end-to-end/commands/fake_findmnt.py index 9f28e105..e6b60a6c 100644 --- a/tests/end-to-end/commands/fake_findmnt.py +++ b/tests/end-to-end/commands/fake_findmnt.py @@ -14,7 +14,7 @@ def parse_arguments(*unparsed_arguments): BUILTIN_FILESYSTEM_MOUNT_OUTPUT = '''{ "filesystems": [ { - "target": "/mnt/subvolume", + "target": "/e2e/mnt/subvolume", "source": "/dev/loop0", "fstype": "btrfs", "options": "rw,relatime,ssd,space_cache=v2,subvolid=5,subvol=/" diff --git a/tests/end-to-end/commands/fake_lsblk.py b/tests/end-to-end/commands/fake_lsblk.py index 4ad9c552..9c59b41d 100644 --- a/tests/end-to-end/commands/fake_lsblk.py +++ b/tests/end-to-end/commands/fake_lsblk.py @@ -20,7 +20,7 @@ BUILTIN_BLOCK_DEVICES = { { 'name': 'vgroup-lvolume', 'path': '/dev/mapper/vgroup-lvolume', - 'mountpoint': '/mnt/lvolume', + 'mountpoint': '/e2e/mnt/lvolume', 'type': 'lvm', }, { diff --git a/tests/end-to-end/commands/fake_zfs.py b/tests/end-to-end/commands/fake_zfs.py index 3c13f4d5..4ef3f498 100644 --- a/tests/end-to-end/commands/fake_zfs.py +++ b/tests/end-to-end/commands/fake_zfs.py @@ -23,20 +23,20 @@ def parse_arguments(*unparsed_arguments): BUILTIN_DATASETS = ( { - 'name': 'pool', + 'name': 'e2e/pool', 'used': '256K', 'avail': '23.7M', 'refer': '25K', 'canmount': 'on', - 'mountpoint': '/pool', + 'mountpoint': '/e2e/pool', }, { - 'name': 'pool/dataset', + 'name': 'e2e/pool/dataset', 'used': '256K', 'avail': '23.7M', 'refer': '25K', 'canmount': 'on', - 'mountpoint': '/pool/dataset', + 'mountpoint': '/e2e/pool/dataset', }, ) diff --git a/tests/end-to-end/hooks/data_source/test_btrfs.py b/tests/end-to-end/hooks/data_source/test_btrfs.py index 2df6228b..d49eb796 100644 --- a/tests/end-to-end/hooks/data_source/test_btrfs.py +++ b/tests/end-to-end/hooks/data_source/test_btrfs.py @@ -16,10 +16,10 @@ def generate_configuration(config_path, repository_path): open(config_path) .read() .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path) - .replace('- path: /mnt/backup', '') + .replace('- path: /e2e/mnt/backup', '') .replace('label: local', '') .replace('- /home', f'- {config_path}') - .replace('- /etc', '- /mnt/subvolume/subdir') + .replace('- /etc', '- /e2e/mnt/subvolume/subdir') .replace('- /var/log/syslog*', '') + 'encryption_passphrase: "test"\n' + 'btrfs:\n' @@ -51,11 +51,11 @@ def test_btrfs_create_and_list(): f'borgmatic --config {config_path} list --archive latest'.split(' ') ).decode(sys.stdout.encoding) - assert 'mnt/subvolume/subdir/file.txt' in output + assert 'e2e/mnt/subvolume/subdir/file.txt' in output # Assert that the snapshot has been deleted. assert not subprocess.check_output( - 'python3 /app/tests/end-to-end/commands/fake_btrfs.py subvolume list -s /mnt/subvolume'.split( + 'python3 /app/tests/end-to-end/commands/fake_btrfs.py subvolume list -s /e2e/mnt/subvolume'.split( ' ' ) ) diff --git a/tests/end-to-end/hooks/data_source/test_lvm.py b/tests/end-to-end/hooks/data_source/test_lvm.py index 06f02ea2..ec3fec2e 100644 --- a/tests/end-to-end/hooks/data_source/test_lvm.py +++ b/tests/end-to-end/hooks/data_source/test_lvm.py @@ -17,10 +17,10 @@ def generate_configuration(config_path, repository_path): open(config_path) .read() .replace('ssh://user@backupserver/./sourcehostname.borg', repository_path) - .replace('- path: /mnt/backup', '') + .replace('- path: /e2e/mnt/backup', '') .replace('label: local', '') .replace('- /home', f'- {config_path}') - .replace('- /etc', '- /mnt/lvolume/subdir') + .replace('- /etc', '- /e2e/mnt/lvolume/subdir') .replace('- /var/log/syslog*', '') + 'encryption_passphrase: "test"\n' + 'lvm:\n' @@ -56,7 +56,7 @@ def test_lvm_create_and_list(): f'borgmatic --config {config_path} list --archive latest'.split(' ') ).decode(sys.stdout.encoding) - assert 'mnt/lvolume/subdir/file.txt' in output + assert 'e2e/mnt/lvolume/subdir/file.txt' in output # Assert that the snapshot has been deleted. assert not json.loads( diff --git a/tests/end-to-end/hooks/data_source/test_zfs.py b/tests/end-to-end/hooks/data_source/test_zfs.py index 9a338ebb..4906c412 100644 --- a/tests/end-to-end/hooks/data_source/test_zfs.py +++ b/tests/end-to-end/hooks/data_source/test_zfs.py @@ -19,7 +19,7 @@ def generate_configuration(config_path, repository_path): .replace('- path: /mnt/backup', '') .replace('label: local', '') .replace('- /home', f'- {config_path}') - .replace('- /etc', '- /pool/dataset/subdir') + .replace('- /etc', '- /e2e/pool/dataset/subdir') .replace('- /var/log/syslog*', '') + 'encryption_passphrase: "test"\n' + 'zfs:\n' @@ -45,14 +45,14 @@ def test_zfs_create_and_list(): ) # Run a create action to exercise ZFS snapshotting and backup. - subprocess.check_call(f'borgmatic --config {config_path} create'.split(' ')) + subprocess.check_call(f'borgmatic -v 2 --config {config_path} create'.split(' ')) # List the resulting archive and assert that the snapshotted files are there. output = subprocess.check_output( f'borgmatic --config {config_path} list --archive latest'.split(' ') ).decode(sys.stdout.encoding) - assert 'pool/dataset/subdir/file.txt' in output + assert 'e2e/pool/dataset/subdir/file.txt' in output # Assert that the snapshot has been deleted. assert not subprocess.check_output( diff --git a/tests/unit/actions/test_pattern.py b/tests/unit/actions/test_pattern.py index 5dabd1e7..755d837e 100644 --- a/tests/unit/actions/test_pattern.py +++ b/tests/unit/actions/test_pattern.py @@ -275,6 +275,12 @@ def test_get_existent_path_or_parent_with_non_existent_path_returns_existent_gra assert module.get_existent_path_or_parent('/foo/bar/baz*') == '/foo' +def test_get_existent_path_or_parent_with_end_to_end_test_prefix_returns_none(): + flexmock(module.os.path).should_receive('exists').never() + + assert module.get_existent_path_or_parent('/e2e/foo/bar/baz') is None + + def test_device_map_patterns_gives_device_id_per_path(): flexmock(module).should_receive('get_existent_path_or_parent').replace_with(lambda path: path) flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))