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/efg'.format(fs0.name)) fs0.snapshot('snap7', recursive=True) fs0.snapshot('snap8', 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)
def test_take_snapshot_recursive(self, zpools): _, fs = zpools ssh = fs.ssh fs.destroy(force=True) config = [{ 'name': 'ssh:{:d}:{}'.format(PORT, fs), 'key': KEY, 'frequent': 1, 'hourly': 1, 'daily': 1, 'weekly': 1, 'monthly': 1, 'yearly': 1, 'snap': True }] take_config(config) fs.snapshots()[-1].destroy(force=True) fs.snapshots()[-1].destroy(force=True) sub1 = zfs.create('{:s}/sub1'.format(fs.name), ssh=ssh) take_config(config) # Check fs snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in fs.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub1 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub1.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type]
def test_send_incremental(self, zpools): fs0, fs1 = zpools ssh = fs1.ssh fs0.destroy(force=True) fs1.destroy(force=True) config = [{ 'name': fs0.name, 'dest': ['ssh:{:d}:{}'.format(PORT, fs1)], 'dest_keys': [KEY] }] 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'], ssh=ssh)[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'], ssh=ssh)[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'], ssh=ssh)[1:] ] assert set(fs0_children) == set(fs1_children)
def test_clean_recursive(self, zpools): fs, _ = zpools fs.destroy(force=True) zfs.create('{:s}/sub1'.format(fs.name)) zfs.create('{:s}/sub1/abc'.format(fs.name)) zfs.create('{:s}/sub2'.format(fs.name)) zfs.create('{:s}/sub2/efg'.format(fs.name)) zfs.create('{:s}/sub2/efg/hij'.format(fs.name)) zfs.create('{:s}/sub3'.format(fs.name)) sub1, sub2, sub3 = fs.filesystems() abc = sub1.filesystems()[0] efg = sub2.filesystems()[0] hij = efg.filesystems()[0] config = [{ 'name': fs.name, 'frequent': 1, 'hourly': 1, 'daily': 1, 'weekly': 1, 'monthly': 1, 'yearly': 1, 'snap': True }] take_config(config) config = [{ 'name': fs.name, 'frequent': 1, 'hourly': 0, 'daily': 1, 'weekly': 0, 'monthly': 0, 'yearly': 0, 'clean': True }, { 'name': '{:s}/sub2'.format(fs.name), 'frequent': 0, 'hourly': 1, 'daily': 0, 'weekly': 1, 'monthly': 0, 'yearly': 1, 'clean': True }, { 'name': '{:s}/sub3'.format(fs.name), 'frequent': 1, 'hourly': 0, 'daily': 1, 'weekly': 0, 'monthly': 1, 'yearly': 0, 'clean': False }, { 'name': '{:s}/sub2/efg/hij'.format(fs.name), 'frequent': 0, 'hourly': 0, 'daily': 0, 'weekly': 0, 'monthly': 0, 'yearly': 0, 'clean': True }] clean_config(config) # Check parent filesystem snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in fs.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub1 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub1.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub1/abc snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in abc.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub2 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub2.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[1][snap_type] # Check sub2/efg snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in efg.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[1][snap_type] # Check sub2/efg/hij snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in hij.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[3][snap_type] # Check sub3 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub3.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == 1
def test_clean_recursive(self, zpools): _, fs = zpools ssh = fs.ssh fs.destroy(force=True) sub1 = zfs.create('{:s}/sub1'.format(fs.name), ssh=ssh) abc = zfs.create('{:s}/sub1/abc'.format(fs.name), ssh=ssh) sub2 = zfs.create('{:s}/sub2'.format(fs.name), ssh=ssh) efg = zfs.create('{:s}/sub2/efg'.format(fs.name), ssh=ssh) hij = zfs.create('{:s}/sub2/efg/hij'.format(fs.name), ssh=ssh) sub3 = zfs.create('{:s}/sub3'.format(fs.name), ssh=ssh) config = [{ 'name': 'ssh:{:d}:{}'.format(PORT, fs), 'key': KEY, 'frequent': 1, 'hourly': 1, 'daily': 1, 'weekly': 1, 'monthly': 1, 'yearly': 1, 'snap': True }] take_config(config) config = [{ 'name': 'ssh:{:d}:{}'.format(PORT, fs), 'key': KEY, 'frequent': 1, 'hourly': 0, 'daily': 1, 'weekly': 0, 'monthly': 0, 'yearly': 0, 'clean': True }, { 'name': 'ssh:{:d}:{}/sub2'.format(PORT, fs), 'key': KEY, 'frequent': 0, 'hourly': 1, 'daily': 0, 'weekly': 1, 'monthly': 0, 'yearly': 1, 'clean': True }, { 'name': 'ssh:{:d}:{}/sub3'.format(PORT, fs), 'key': KEY, 'frequent': 1, 'hourly': 0, 'daily': 1, 'weekly': 0, 'monthly': 1, 'yearly': 0, 'clean': False }, { 'name': 'ssh:{:d}:{}/sub2/efg/hij'.format(PORT, fs), 'key': KEY, 'frequent': 0, 'hourly': 0, 'daily': 0, 'weekly': 0, 'monthly': 0, 'yearly': 0, 'clean': True }] clean_config(config) # Check parent filesystem snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in fs.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub1 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub1.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub1/abc snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in abc.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[0][snap_type] # Check sub2 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub2.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[1][snap_type] # Check sub2/efg snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in efg.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[1][snap_type] # Check sub2/efg/hij snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in hij.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[3][snap_type] # Check sub3 snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in sub3.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == 1