def test_clean_snapshot(self, zpools): fs, _ = zpools config = [{ 'name': fs.name, 'frequent': 0, 'hourly': 0, 'daily': 0, 'weekly': 0, 'monthly': 0, 'yearly': 0, 'clean': True }] clean_config(config) 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]
def test_clean_recursive(self, zpools): fs, _ = zpools fs.destroy(force=True) sub1 = zfs.create('{:s}/sub1'.format(fs.name)) abc = zfs.create('{:s}/sub1/abc'.format(fs.name)) abc_efg = zfs.create('{:s}/sub1/abc_efg'.format(fs.name)) sub2 = zfs.create('{:s}/sub2'.format(fs.name)) efg = zfs.create('{:s}/sub2/efg'.format(fs.name)) hij = zfs.create('{:s}/sub2/efg/hij'.format(fs.name)) klm = zfs.create('{:s}/sub2/efg/hij/klm'.format(fs.name)) sub3 = zfs.create('{:s}/sub3'.format(fs.name)) 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': '{}/sub2'.format(fs), 'frequent': 0, 'hourly': 1, 'daily': 0, 'weekly': 1, 'monthly': 0, 'yearly': 1, 'clean': True }, { 'name': '{}/sub3'.format(fs), 'frequent': 1, 'hourly': 0, 'daily': 1, 'weekly': 0, 'monthly': 1, 'yearly': 0, 'clean': False }, { 'name': '{}/sub1/abc'.format(fs), 'frequent': 0, 'hourly': 0, 'daily': 0, 'weekly': 1, 'monthly': 1, 'yearly': 1, 'clean': True }, { 'name': '{}/sub2/efg/hij'.format(fs), '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[3][snap_type] # Check sub1/abc_efg snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in abc_efg.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[4][snap_type] # Check sub2/efg/hij/klm snapshots = { 'frequent': [], 'hourly': [], 'daily': [], 'weekly': [], 'monthly': [], 'yearly': [] } for snap in klm.snapshots(): snap_type = snap.name.split('_')[-1] snapshots[snap_type].append(snap) for snap_type, snaps in snapshots.items(): assert len(snaps) == config[4][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