def test_send_delete_old(self, zpools):
        fs0, fs1 = zpools
        ssh = fs1.ssh

        # Delete old snapshot on source
        fs0.snapshots()[0].destroy(force=True)
        fs0.snapshot('snap7', recursive=True)
        config = [{
            'name': fs0.name,
            'dest': ['ssh:{:d}:{}'.format(PORT, fs1)],
            'dest_keys': [KEY],
            'compress': None
        }]
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'], ssh=ssh)[1:]
        ]
        assert not (set(fs0_children) == set(fs1_children))
        # Assert that snap0 was not deleted from fs1
        for child in set(fs1_children) - set(fs0_children):
            assert child.endswith('snap0')
Exemple #2
0
    def test_send_full(self, zpools):
        """Checks if send_snap totally replicates a filesystem"""
        fs0, fs1 = zpools
        fs0.destroy(force=True)
        fs1.destroy(force=True)
        config = [{'name': fs0.name, 'dest': [fs1.name]}]

        fs0.snapshot('snap0')
        zfs.create('{:s}/sub1'.format(fs0.name))
        fs0.snapshot('snap1', recursive=True)
        zfs.create('{:s}/sub2'.format(fs0.name))
        fs0.snapshot('snap2', recursive=True)
        zfs.create('{:s}/sub3'.format(fs0.name))
        fs0.snapshot('snap3', recursive=True)
        fs0.snapshot('snap4', recursive=True)
        fs0.snapshot('snap5', recursive=True)
        zfs.create('{:s}/sub3/abc'.format(fs0.name))
        fs0.snapshot('snap6', recursive=True)
        zfs.create('{:s}/sub3/abc_abc'.format(fs0.name))
        fs0.snapshot('snap7', recursive=True)
        zfs.create('{:s}/sub3/efg'.format(fs0.name))
        fs0.snapshot('snap8', recursive=True)
        fs0.snapshot('snap9', recursive=True)
        send_config(config)

        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)
Exemple #3
0
    def test_send_raw(self, zpools):
        """Checks if raw_send works"""
        fs0, fs1 = zpools
        fs0.destroy(force=True)
        fs1.destroy(force=True)

        raw_send = ['yes']
        config = [{'name': fs0.name, 'dest': [fs1.name], 'raw_send': raw_send}]

        zfs.create('{:s}/sub1'.format(fs0.name), props={'compression': 'gzip'})
        zfs.create('{:s}/sub2'.format(fs0.name), props={'compression': 'lz4'})
        zfs.create('{:s}/sub3'.format(fs0.name), props={'compression': 'gzip'})
        zfs.create('{:s}/sub3/abc'.format(fs0.name))
        zfs.create('{:s}/sub3/abc_abc'.format(fs0.name))
        zfs.create('{:s}/sub3/efg'.format(fs0.name))
        fs0.snapshot('snap', recursive=True)
        send_config(config)

        fs0_children = set([
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ])
        fs1_children = set([
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ])

        assert set(fs0_children) == set(fs1_children)
    def test_send_delete_sub(self, zpools):
        fs0, fs1 = zpools
        ssh = fs1.ssh

        # Delete subfilesystems
        sub3 = fs1.filesystems()[-1]
        sub3.destroy(force=True)
        fs0.snapshot('snap6', recursive=True)
        sub2 = fs1.filesystems()[-1]
        sub2.destroy(force=True)
        config = [{
            'name': fs0.name,
            'dest': ['ssh:{:d}:{}'.format(PORT, fs1)],
            'dest_keys': [KEY],
            'compress': None
        }]
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'], ssh=ssh)[1:]
        ]
        assert set(fs0_children) == set(fs1_children)
Exemple #5
0
    def test_send_exclude(self, zpools):
        """Checks if exclude rules work"""
        fs0, fs1 = zpools
        fs0.destroy(force=True)
        fs1.destroy(force=True)

        exclude = ['*/sub1', '*/sub3/abc', '*/sub3/efg']
        config = [{'name': fs0.name, 'dest': [fs1.name], 'exclude': [exclude]}]

        zfs.create('{:s}/sub1'.format(fs0.name))
        zfs.create('{:s}/sub2'.format(fs0.name))
        zfs.create('{:s}/sub3'.format(fs0.name))
        zfs.create('{:s}/sub3/abc'.format(fs0.name))
        zfs.create('{:s}/sub3/abc_abc'.format(fs0.name))
        zfs.create('{:s}/sub3/efg'.format(fs0.name))
        fs0.snapshot('snap', recursive=True)
        send_config(config)

        fs0_children = set([
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ])
        fs1_children = set([
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ])
        # remove unwanted datasets/snapshots
        for match in exclude:
            fs0_children -= set(fnmatch.filter(fs0_children, match))
            fs0_children -= set(fnmatch.filter(fs0_children, match + '@snap'))

        assert set(fs0_children) == set(fs1_children)
    def test_send_compress(self, zpools):
        """Checks if send_snap totally replicates a filesystem"""
        fs1, fs0 = zpools # here fs0 is the remote pool
        ssh = fs0.ssh

        fs0.destroy(force=True)
        fs1.destroy(force=True)

        fs0.snapshot('snap0')
        zfs.create('{:s}/sub1'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap1', recursive=True)
        zfs.create('{:s}/sub2'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap2', recursive=True)
        fs0.snapshot('snap3', recursive=True)
        zfs.create('{:s}/sub2/abc'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap4', recursive=True)
        fs0.snapshot('snap5', recursive=True)

        for compression in ['none', 'lzop', 'lz4']:
            fs1.destroy(force=True)
            config = [{'name': 'ssh:{:d}:{}'.format(PORT, fs0), 'key': KEY, 'dest': [fs1.name], 'compress': [compression]}]
            send_config(config)

            fs0_children = [child.name.replace(fs0.name, '') for child in zfs.find(fs0.name, types=['all'], ssh=ssh)[1:]]
            fs1_children = [child.name.replace(fs1.name, '') for child in zfs.find(fs1.name, types=['all'])[1:]]
            assert set(fs0_children) == set(fs1_children)
    def test_send_exclude(self, zpools):
        """Checks if send_snap totally replicates a filesystem"""
        fs1, fs0 = zpools # here fs0 is the remote pool
        ssh = fs0.ssh
        fs0.destroy(force=True)
        fs1.destroy(force=True)

        exclude = ['*/sub1', '*/sub3/abc', '*/sub3/efg']
        config = [{'name': 'ssh:{:d}:{}'.format(PORT, fs0), 'dest': [fs1.name], 'exclude': [exclude]}]

        zfs.create('{:s}/sub1'.format(fs0.name), ssh=ssh)
        zfs.create('{:s}/sub2'.format(fs0.name), ssh=ssh)
        zfs.create('{:s}/sub3'.format(fs0.name), ssh=ssh)
        zfs.create('{:s}/sub3/abc'.format(fs0.name), ssh=ssh)
        zfs.create('{:s}/sub3/abc_abc'.format(fs0.name), ssh=ssh)
        zfs.create('{:s}/sub3/efg'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap', recursive=True)
        send_config(config)

        fs0_children = set([child.name.replace(fs0.name, '') for child in zfs.find(fs0.name, types=['all'], ssh=ssh)[1:]])
        fs1_children = set([child.name.replace(fs1.name, '') for child in zfs.find(fs1.name, types=['all'])[1:]])
        # remove unwanted datasets/snapshots
        for match in exclude:
            fs0_children -= set(fnmatch.filter(fs0_children, match))
            fs0_children -= set(fnmatch.filter(fs0_children, match + '@snap'))

        assert set(fs0_children) == set(fs1_children)
Exemple #8
0
    def test_send_delete_old(self, zpools):
        fs0, fs1 = zpools
        config = [{'name': fs0.name, 'dest': [fs1.name]}]

        # Delete old snapshot on source
        fs0.snapshots()[0].destroy(force=True)
        fs0.snapshot('snap7', recursive=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert not (set(fs0_children) == set(fs1_children))
        # Assert that snap0 was not deleted from fs1
        for child in set(fs1_children) - set(fs0_children):
            assert child.endswith('snap0')
Exemple #9
0
    def test_send_delete_sub(self, zpools):
        fs0, fs1 = zpools
        config = [{'name': fs0.name, 'dest': [fs1.name]}]

        # Delete subfilesystems
        sub3 = fs1.filesystems()[-1]
        sub3.destroy(force=True)
        fs0.snapshot('snap6', recursive=True)
        sub2 = fs1.filesystems()[-1]
        sub2.destroy(force=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)
Exemple #10
0
    def test_send_delete_snapshot(self, zpools):
        fs0, fs1 = zpools
        config = [{'name': fs0.name, 'dest': [fs1.name]}]

        # Delete recent snapshots on dest
        fs1.snapshots()[-1].destroy(force=True)
        fs1.snapshots()[-1].destroy(force=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)

        # Delete recent snapshot on source
        fs0.snapshot('snap4', recursive=True)
        send_config(config)
        fs0.snapshots()[-1].destroy(force=True)
        fs0.snapshot('snap5', recursive=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)
Exemple #11
0
    def test_send_incremental(self, zpools):
        fs1, fs0 = zpools # here fs0 is the remote pool
        ssh = fs0.ssh

        fs0.destroy(force=True)
        fs1.destroy(force=True)

        fs0.snapshot('snap0', recursive=True)
        zfs.create('{:s}/sub1'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap1', recursive=True)
        config = [{'name': 'ssh:{:d}:{}'.format(PORT, fs0), 'key': KEY, 'dest': [fs1.name], 'compress': None}]
        send_config(config)
        fs0_children = [child.name.replace(fs0.name, '') for child in zfs.find(fs0.name, types=['all'], ssh=ssh)[1:]]
        fs1_children = [child.name.replace(fs1.name, '') for child in zfs.find(fs1.name, types=['all'])[1:]]
        assert set(fs0_children) == set(fs1_children)

        zfs.create('{:s}/sub2'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap2', recursive=True)
        config = [{'name': 'ssh:{:d}:{}'.format(PORT, fs0), 'key': KEY, 'dest': [fs1.name], 'compress': None}]
        send_config(config)
        fs0_children = [child.name.replace(fs0.name, '') for child in zfs.find(fs0.name, types=['all'], ssh=ssh)[1:]]
        fs1_children = [child.name.replace(fs1.name, '') for child in zfs.find(fs1.name, types=['all'])[1:]]
        assert set(fs0_children) == set(fs1_children)

        zfs.create('{:s}/sub3'.format(fs0.name), ssh=ssh)
        fs0.snapshot('snap3', recursive=True)
        config = [{'name': 'ssh:{:d}:{}'.format(PORT, fs0), 'key': KEY, 'dest': [fs1.name], 'compress': None}]
        send_config(config)
        fs0_children = [child.name.replace(fs0.name, '') for child in zfs.find(fs0.name, types=['all'], ssh=ssh)[1:]]
        fs1_children = [child.name.replace(fs1.name, '') for child in zfs.find(fs1.name, types=['all'])[1:]]
        assert set(fs0_children) == set(fs1_children)
Exemple #12
0
    def test_send_incremental(self, zpools):
        fs0, fs1 = zpools
        fs0.destroy(force=True)
        fs1.destroy(force=True)
        config = [{'name': fs0.name, 'dest': [fs1.name]}]

        fs0.snapshot('snap0', recursive=True)
        zfs.create('{:s}/sub1'.format(fs0.name))
        fs0.snapshot('snap1', recursive=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)

        zfs.create('{:s}/sub2'.format(fs0.name))
        fs0.snapshot('snap2', recursive=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)

        zfs.create('{:s}/sub3'.format(fs0.name))
        fs0.snapshot('snap3', recursive=True)
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'])[1:]
        ]
        assert set(fs0_children) == set(fs1_children)
Exemple #13
0
    def test_send_delete_snapshot(self, zpools):
        fs0, fs1 = zpools
        ssh = fs1.ssh

        # Delete recent snapshots on dest
        fs1.snapshots()[-1].destroy(force=True)
        fs1.snapshots()[-1].destroy(force=True)
        config = [{
            'name': fs0.name,
            'dest': ['ssh:{:d}:{}'.format(PORT, fs1)],
            'dest_keys': [KEY],
            'compress': None
        }]
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'], ssh=ssh)[1:]
        ]
        assert set(fs0_children) == set(fs1_children)

        # Delete recent snapshot on source
        fs0.snapshot('snap4', recursive=True)
        send_config(config)
        fs0.snapshots()[-1].destroy(force=True)
        fs0.snapshot('snap5', recursive=True)
        config = [{
            'name': fs0.name,
            'dest': ['ssh:{:d}:{}'.format(PORT, fs1)],
            'dest_keys': [KEY],
            'compress': None
        }]
        send_config(config)
        fs0_children = [
            child.name.replace(fs0.name, '')
            for child in zfs.find(fs0.name, types=['all'])[1:]
        ]
        fs1_children = [
            child.name.replace(fs1.name, '')
            for child in zfs.find(fs1.name, types=['all'], ssh=ssh)[1:]
        ]
        assert set(fs0_children) == set(fs1_children)