def testSomeDevs(self): """ Adding a non-empty list of devs should increase the number of devs in the pool. """ (result, rc, _) = checked_call( Pool.AddDevs( self._pool_object, force=False, devices=_DEVICE_STRATEGY.example() ), PoolSpec.OUTPUT_SIGS[_PN.AddDevs] ) #(result1, rc1, _) = checked_call( # Pool.ListDevs(self._pool_object), # PoolSpec.OUTPUT_SIGS[_PN.ListDevs] #) #self.assertEqual(rc1, self._errors.OK) num_devices_added = len(result) #self.assertEqual(len(result1), num_devices_added) if rc == self._errors.OK: self.assertGreater(num_devices_added, 0) else: self.assertEqual(num_devices_added, 0)
def testDestroyOne(self): """ Test calling with a non-existant volume name. This should succeed, because at the end the volume is not there. """ (result, rc, _) = checked_call( Pool.DestroyFilesystems(self._pool_object, names=['name']), PoolSpec.OUTPUT_SIGS[_PN.DestroyFilesystems]) self.assertEqual(len(result), 1) self.assertEqual(rc, self._errors.OK) (result, rc, _) = checked_call(Pool.ListFilesystems(self._pool_object), PoolSpec.OUTPUT_SIGS[_PN.ListFilesystems]) self.assertEqual(rc, self._errors.OK) self.assertEqual(len(result), 0)
def setUp(self): """ Obtain the Introspect() xml. """ self._introspection_data = dict() self._service = Service() self._service.setUp() time.sleep(1) proxy = get_object(TOP_OBJECT) self._introspection_data[ManagerSpec.INTERFACE_NAME] = \ proxy.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE) ((poolpath, _), _, _) = Manager.CreatePool(proxy, name="name", redundancy=0, force=False, devices=[]) pool = get_object(poolpath) self._introspection_data[PoolSpec.INTERFACE_NAME] = \ pool.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE) ([(fspath, _)], _, _) = \ Pool.CreateFilesystems(pool, specs=[("filesystem", '', None)]) fs = get_object(fspath) self._introspection_data[FilesystemSpec.INTERFACE_NAME] = \ fs.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE)
def testDestroyNone(self): """ Test calling with no actual volume specification. An empty volume list should always succeed, and it should not decrease the number of volumes. """ (result, rc, _) = checked_call( Pool.DestroyFilesystems(self._pool_object, names=[]), PoolSpec.OUTPUT_SIGS[_PN.DestroyFilesystems]) self.assertEqual(len(result), 0) self.assertEqual(rc, self._errors.OK) (result, rc, _) = checked_call(Pool.ListFilesystems(self._pool_object), PoolSpec.OUTPUT_SIGS[_PN.ListFilesystems]) self.assertEqual(rc, self._errors.OK) self.assertEqual(len(result), 0)
def testList(self): """ List should succeed and contain the same number of entries as devices in pool. """ (result, rc, _) = checked_call(Pool.ListDevs(self._pool_object), PoolSpec.OUTPUT_SIGS[_PN.ListDevs]) self.assertEqual(len(result), len(self._devs)) self.assertEqual(rc, self._errors.OK)
def testEmptyDevs(self): """ Adding an empty list of devs should leave the pool empty. """ (result, rc, _) = checked_call( Pool.AddDevs(self._pool_object, force=False, devices=[]), PoolSpec.OUTPUT_SIGS[_PN.AddDevs] ) self.assertEqual(len(result), 0) self.assertEqual(rc, self._errors.OK)
def remove_device(namespace): """ Remove a device from the given pool. """ proxy = get_object(TOP_OBJECT) (pool_object_path, rc, message) = \ Manager.GetPoolObjectPath(proxy, name=namespace.pool) if rc != 0: return (rc, message) pool_object = get_object(pool_object_path) return Pool.RemoveCacheDevs(pool_object)
def testDestroy(self): """ Test calling by specifying the volume name. Assume that destruction should always succeed. """ (result, rc, _) = checked_call( Pool.DestroyFilesystems(self._pool_object, names=[self._VOLNAME]), PoolSpec.OUTPUT_SIGS[_PN.DestroyFilesystems]) self.assertEqual(len(result), 1) self.assertEqual(rc, self._errors.OK) (rc, _) = result[0] self.assertEqual(rc, self._errors.OK) (result, rc, _) = checked_call(Pool.ListFilesystems(self._pool_object), PoolSpec.OUTPUT_SIGS[_PN.ListFilesystems]) self.assertEqual(rc, self._errors.OK) self.assertEqual(len(result), 0)
def list_volumes(namespace): """ List the volumes in a pool. """ proxy = get_object(TOP_OBJECT) pool_object = get_pool(proxy, namespace.pool) (result, rc, message) = Pool.ListFilesystems(pool_object) if rc != StratisdErrorsGen().get_object().OK: raise StratisCliRuntimeError(rc, message) for item in result: print(item) return
def destroy_volumes(namespace): """ Destroy volumes in a pool. :raises StratisCliRuntimeError: """ proxy = get_object(TOP_OBJECT) pool_object = get_pool(proxy, namespace.pool) (_, rc, message) = \ Pool.DestroyFilesystems(pool_object, names=namespace.volume) if rc != StratisdErrorsGen().get_object().OK: raise StratisCliRuntimeError(rc, message) return
def add_device(namespace): """ Add a device to a pool. """ proxy = get_object(TOP_OBJECT) pool_object = get_pool(proxy, namespace.name) (_, rc, message) = Pool.AddDevs( pool_object, force=namespace.force, devices=namespace.device ) if rc != StratisdErrorsGen.get_object().OK: raise StratisCliRuntimeError(rc, message) return
def list_pool(namespace): """ List devices in a pool. """ proxy = get_object(TOP_OBJECT) pool_object = get_pool(proxy, namespace.name) (result, rc, message) = Pool.ListDevs(pool_object) if rc != StratisdErrorsGen.get_object().OK: raise StratisCliRuntimeError(rc, message) for item in result: print(item) return
def testDestroyOne(self): """ Test calling with a non-existant object path. This should succeed, because at the end the filesystem is not there. """ (result, rc, _) = checked_call( Pool.DestroyFilesystems(self._pool_object, filesystems=['/']), PoolSpec.OUTPUT_SIGS[_PN.DestroyFilesystems] ) self.assertEqual(rc, self._errors.OK) self.assertEqual(len(result), 0) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 0)
def testCreate(self): """ Test calling by specifying a volume name. Because there is already a volume with the given name, the creation of the new volume should fail, and no additional volume should be created. """ (result, rc, _) = checked_call( Pool.CreateFilesystems(self._pool_object, specs=[self._VOLNAME]), PoolSpec.OUTPUT_SIGS[_PN.CreateFilesystems]) self.assertEqual(rc, self._errors.ALREADY_EXISTS) self.assertEqual(len(result), 0) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 1)
def testCreate(self): """ Test calling with no actual volume specification. An empty volume list should always succeed, and it should not increase the number of volumes. """ (result, rc, _) = checked_call(Pool.CreateFilesystems(self._pool_object, specs=[]), PoolSpec.OUTPUT_SIGS[_PN.CreateFilesystems]) self.assertEqual(len(result), 0) self.assertEqual(rc, self._errors.OK) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 0)
def testNullMapping(self): """ Test rename to same name. """ (result, rc, _) = checked_call( Pool.SetName(self._pool_object, name=self._POOLNAME), PoolSpec.OUTPUT_SIGS[_PN.SetName] ) self.assertEqual(rc, self._errors.OK) self.assertFalse(result) managed_objects = get_managed_objects(self._proxy) result = next(managed_objects.pools({'Name': self._POOLNAME}), None) self.assertIsNotNone(result) (pool, _) = result self.assertEqual(pool, self._pool_object_path)
def create_volumes(namespace): """ Create volumes in a pool. :raises StratisCliRuntimeError: """ proxy = get_object(TOP_OBJECT) pool_object = get_pool(proxy, namespace.pool) volume_list = [(x, '', None) for x in namespace.volume] (_, rc, message) = \ Pool.CreateFilesystems(pool_object, specs=volume_list) if rc != StratisdErrorsGen().get_object().OK: raise StratisCliRuntimeError(rc, message) return
def setUp(self): """ Start the stratisd daemon with the simulator. """ self._service = Service() self._service.setUp() time.sleep(1) self._proxy = get_object(TOP_OBJECT) self._errors = StratisdErrorsGen.get_object() self._devs = _DEVICE_STRATEGY.example() ((poolpath, _), _, _) = Manager.CreatePool(self._proxy, name=self._POOLNAME, redundancy=0, force=False, devices=self._devs) self._pool_object = get_object(poolpath) Pool.CreateFilesystems(self._pool_object, specs=[self._VOLNAME]) Manager.ConfigureSimulator(self._proxy, denominator=8)
def testDuplicateSpecs(self): """ Test calling with duplicate specification for same filesystem name. """ new_name = "name" (result, rc, _) = checked_call( Pool.CreateFilesystems(self._pool_object, specs=[new_name, new_name]), PoolSpec.OUTPUT_SIGS[_PN.CreateFilesystems]) self.assertEqual(rc, self._errors.OK) self.assertEqual(len(result), 1) (_, fs_name) = result[0] self.assertEqual(fs_name, new_name) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 1)
def testDestroyOne(self): """ Test calling by specifying the object path. Assume that destruction should always succeed. """ fs_object_path = self._filesystems[0][0] (result, rc, _) = checked_call( Pool.DestroyFilesystems( self._pool_object, filesystems=[fs_object_path] ), PoolSpec.OUTPUT_SIGS[_PN.DestroyFilesystems] ) self.assertEqual(len(result), 1) self.assertEqual(rc, self._errors.OK) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 0)
def testCreateOne(self): """ Test calling by specifying a new and different volume name. The new volume will be created. """ new_name = "newname" (result, rc, _) = checked_call( Pool.CreateFilesystems(self._pool_object, specs=[new_name]), PoolSpec.OUTPUT_SIGS[_PN.CreateFilesystems]) self.assertEqual(rc, self._errors.OK) self.assertEqual(len(result), 1) (_, fs_name) = result[0] self.assertEqual(fs_name, new_name) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 2)
def setUp(self): """ Start the stratisd daemon with the simulator. """ self._service = Service() self._service.setUp() time.sleep(2) self._proxy = get_object(TOP_OBJECT) self._errors = StratisdErrorsGen.get_object() self._devs = [d.device_node for d in _device_list(_DEVICES, 1)] (result, _, _) = Manager.CreatePool(self._proxy, name=self._POOLNAME, redundancy=0, force=False, devices=self._devs) self._pool_object = get_object(result) Pool.CreateFilesystems(self._pool_object, specs=[(self._VOLNAME, '', 0)]) Manager.ConfigureSimulator(self._proxy, denominator=8)
def list_cache(namespace): """ List information about the cache belonging to a pool. """ proxy = get_object(TOP_OBJECT) (pool_object_path, rc, message) = \ Manager.GetPoolObjectPath(proxy, name=namespace.pool) if rc != 0: return (rc, message) pool_object = get_object(pool_object_path) (result, rc, message) = Pool.ListCacheDevs(pool_object) if rc != 0: return (rc, message) for item in result: print(item) return (rc, message)
def testDestroyTwo(self): """ Test calling by specifying one existing volume name and one non-existing. Should succeed, but only the existing name should be returned. """ fs_object_path = self._filesystems[0][0] (result, rc, _) = checked_call( Pool.DestroyFilesystems( self._pool_object, filesystems=[fs_object_path, "/"] ), PoolSpec.OUTPUT_SIGS[_PN.DestroyFilesystems] ) self.assertEqual(len(result), 1) self.assertEqual(rc, self._errors.OK) result = [x for x in get_managed_objects(self._proxy).filesystems()] self.assertEqual(len(result), 0)
def setUp(self): """ Start the stratisd daemon with the simulator. """ self._service = Service() self._service.setUp() time.sleep(1) self._proxy = get_object(TOP_OBJECT) self._errors = StratisdErrorsGen.get_object() (poolpath, _, _) = Manager.CreatePool( self._proxy, name=self._POOLNAME, redundancy=0, force=False, devices=[d.device_node for d in _device_list(_DEVICES, 1)] ) Pool.CreateFilesystems( get_object(poolpath), specs=[(self._VOLNAME, '', 0)] )
def testNewName(self): """ Test rename to new name. """ new_name = "new" (result, rc, _) = checked_call( Pool.SetName(self._pool_object, name=new_name), PoolSpec.OUTPUT_SIGS[_PN.SetName] ) self.assertTrue(result) self.assertEqual(rc, self._errors.OK) managed_objects = get_managed_objects(self._proxy) self.assertIsNone( next(managed_objects.pools({'Name': self._POOLNAME}), None) ) result = next(managed_objects.pools({'Name': new_name}), None) self.assertIsNotNone(result) (pool, _) = result self.assertEqual(pool, self._pool_object_path)