Exemple #1
0
    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)
Exemple #2
0
    def test_clone_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()
            manager.clone()
        except ZCMError as e:
            self.fail('Creation should not raise exceptions')
        with self.assertRaises(ZCMException):
            manager.clone(max_newer=5)
        with self.assertRaises(ZCMException):
            manager.clone(max_total=6)

        self.assertEqual(manager.path, Path(directory))
        self.assertEqual(manager.zfs, zfs)
        self.assertEqual(manager.active_clone, manager.clones[0])
        self.assertEqual(manager.next_id, '00000006')
        self.assertEqual(len(manager.older_clones), 0)
        self.assertEqual(len(manager.newer_clones), 5)
Exemple #3
0
    def test_create_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')

        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), 1)

        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)
        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())

        id = '00000001'
        filesystem = '%s/%s' % (zfs, id)
        path = Path(directory, '.clones', id)
        self.assertEqual(manager.clones[1].id, id)
        self.assertEqual(manager.clones[1].zfs, filesystem)
        self.assertEqual(manager.clones[1].origin,
                         '%s/%s@%s' % (zfs, '00000000', id))
        self.assertEqual(manager.clones[1].origin_id, '00000000')
        self.assertEqual(manager.clones[1].mountpoint, path)
        self.assertIsInstance(manager.clones[1].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 __init__(self, options):
     manager = Manager(options.path)
     clone = manager.clone(options.max_newer, options.max_total,
                           options.auto_remove)
     if not options.quiet:
         if options.json:
             print(json.dumps(clone.to_dictionary(), indent=4))
         else:
             print('Created clone %s at path %s' %
                   (clone.id, clone.mountpoint))