def test_remove_older_1(self): clone = None try: manager = Manager(directory) except ZCMError as e: self.fail('Instantiation should not raise exceptions') try: manager.clone() except ZCMError as e: self.fail('Creation should not raise exceptions') try: manager.activate('00000001') except ZCMError as e: self.fail('Creation should not raise exceptions') try: manager.remove('00000000') except ZCMError as e: self.fail('Creation should not raise exceptions') self.assertEqual(manager.path, Path(directory)) self.assertEqual(manager.zfs, zfs) self.assertEqual(manager.active_clone, manager.clones[0]) self.assertEqual(manager.next_id, '00000002') self.assertEqual(len(manager.older_clones), 0) self.assertEqual(len(manager.newer_clones), 0) filesystem = zfs path = Path(directory, '.clones') self.assertTrue(zfs_is_filesystem(filesystem)) self.assertEqual(zfs_get(filesystem, 'mountpoint'), path) self.assertTrue(zfs_get(filesystem, 'mounted')) self.assertTrue(path.is_dir()) id = '00000000' filesystem = '%s/%s' % (zfs, id) path = Path(directory, '.clones', id) self.assertFalse(zfs_exists(filesystem)) self.assertFalse(path.exists()) id = '00000001' filesystem = '%s/%s' % (zfs, id) path = Path(directory) self.assertEqual(manager.clones[0].id, id) self.assertEqual(manager.clones[0].zfs, filesystem) self.assertIsNone(manager.clones[0].origin) self.assertIsNone(manager.clones[0].origin_id) self.assertEqual(manager.clones[0].mountpoint, path) self.assertIsInstance(manager.clones[0].creation, datetime) self.assertTrue(zfs_is_filesystem(filesystem)) self.assertEqual(zfs_get(filesystem, 'mountpoint'), path) self.assertTrue(zfs_get(filesystem, 'mounted')) self.assertTrue(path.is_dir())
def test_activate_options(self): clone = None try: manager = Manager(directory) except ZCMError as e: self.fail('Instantiation should not raise exceptions') try: manager.clone() manager.clone() manager.clone() manager.clone() except ZCMError as e: self.fail('Creation should not raise exceptions') with self.assertRaises(ZCMException): manager.activate('00000002', max_newer=1) with self.assertRaises(ZCMException): manager.activate('00000002', max_older=1) try: manager.activate('00000002', max_older=2, max_newer=2) except ZCMError as e: self.fail('Creation should not raise exceptions') self.assertEqual(manager.path, Path(directory)) self.assertEqual(manager.zfs, zfs) self.assertEqual(manager.active_clone, manager.clones[2]) self.assertEqual(manager.next_id, '00000005') self.assertEqual(len(manager.older_clones), 2) self.assertEqual(len(manager.newer_clones), 2)
def __init__(self, options): manager = Manager(options.path) manager.activate(options.id, options.max_newer, options.max_older, options.max_total, options.auto_remove) if not options.quiet: print('Activated clone ' + options.id)