Пример #1
0
 def __init__(self, options):
     migrate = None
     if options.migrate_zfs:
         migrate = 'ZFS'
     if options.migrate_path:
         migrate = 'PATH'
     Manager.initialize_manager(options.zfs, options.path, migrate)
     if not options.quiet:
         print('ZCM initialized ZFS %s at path %s' %
               (options.zfs, options.path))
Пример #2
0
 def test_migrate_existing_path(self):
     path = Path(directory)
     temp_dir = path.joinpath('my', 'cool', 'subdirectory')
     temp_dir.mkdir(parents=True)
     temp_file = temp_dir.joinpath('file.txt')
     with temp_file.open('w', encoding='utf-8') as f:
         f.write('SOME TEXT')
     with self.assertRaises(ZCMError):
         Manager.initialize_manager(zfs, directory)
     with self.assertRaises(ZCMError):
         Manager.initialize_manager(zfs, directory)
     with self.assertRaises(ZCMError):
         Manager.initialize_manager(zfs, directory, migrate='ZFS')
     try:
         Manager.initialize_manager(zfs, directory, migrate='PATH')
     except ZCMException as e:
         self.fail('Initialization should not raise exceptions')
     manager = None
     try:
         manager = Manager(zfs)
     except ZCMException as e:
         self.fail('Instantiation should not raise exceptions')
     self.assertTrue(temp_file.is_file())
     with temp_file.open('r', encoding='utf-8') as f:
         self.assertEqual(f.read(), 'SOME TEXT')
     try:
         manager.destroy()
     except ZCMException as e:
         self.fail('Destroy should not raise exceptions')
Пример #3
0
 def test_initialize_existing_zfs(self):
     path = Path(directory)
     self.assertIsNotNone(
         zfs_create(zfs, mountpoint=directory, recursive=True))
     temp_dir = path.joinpath('my', 'cool', 'subdirectory')
     temp_dir.mkdir(parents=True)
     temp_file = temp_dir.joinpath('file.txt')
     with temp_file.open('w', encoding='utf-8') as f:
         f.write('SOME TEXT')
     with self.assertRaises(ZCMError):
         Manager.initialize_manager(zfs, directory)
     try:
         zfs_destroy(zfs)
     except ZFSError:
         self.fail('zfs_destroy should not raise exceptions')
     self.assertFalse(temp_file.exists())
     path.rmdir()
Пример #4
0
    def test_initialize(self):
        with self.assertRaises(ZCMError):
            Manager.initialize_manager(zfs, directory)
        clone = None
        try:
            manager = Manager(directory)
        except ZCMError as e:
            self.fail('Instantiation 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, '00000001')
        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)
        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())
Пример #5
0
 def setUp(self):
     try:
         Manager.initialize_manager(zfs, directory)
     except ZCMError:
         pass
     return super().setUp()