当前位置: 首页>>代码示例>>Python>>正文


Python VDiskController.clean_devicename方法代码示例

本文整理汇总了Python中ovs.lib.vdisk.VDiskController.clean_devicename方法的典型用法代码示例。如果您正苦于以下问题:Python VDiskController.clean_devicename方法的具体用法?Python VDiskController.clean_devicename怎么用?Python VDiskController.clean_devicename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ovs.lib.vdisk.VDiskController的用法示例。


在下文中一共展示了VDiskController.clean_devicename方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: devicename_exists

# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import clean_devicename [as 别名]
    def devicename_exists(self, vpool, name=None, names=None):
        """
        Checks whether a given name can be created on the vpool
        :param vpool: vPool object
        :type vpool: VPool
        :param name: Candidate name
        :type name: str
        :param names: Candidate names
        :type names: list
        :return: Whether the devicename exists
        :rtype: bool
        """
        error_message = None
        if not (name is None) ^ (names is None):
            error_message = 'Either the name (string) or the names (list of strings) parameter must be passed'
        if name is not None and not isinstance(name, basestring):
            error_message = 'The name parameter must be a string'
        if names is not None and not isinstance(names, list):
            error_message = 'The names parameter must be a list of strings'
        if error_message is not None:
            raise HttpNotAcceptableException(error_description=error_message,
                                             error='impossible_request')

        if name is not None:
            devicename = VDiskController.clean_devicename(name)
            return VDiskList.get_by_devicename_and_vpool(devicename, vpool) is not None
        for name in names:
            devicename = VDiskController.clean_devicename(name)
            if VDiskList.get_by_devicename_and_vpool(devicename, vpool) is not None:
                return True
        return False
开发者ID:grimpy,项目名称:openvstorage,代码行数:33,代码来源:vpools.py

示例2: test_clean_devicename

# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import clean_devicename [as 别名]
 def test_clean_devicename(self):
     """
     Validates whether a devicename is properly cleaned
     * Test several names and validate the returned devicename
     """
     test = {'Foo Bar': '/Foo_Bar.raw',
             '/Foo Bar .raw': '/Foo_Bar_.raw',
             'foo-bar.rawtest': '/foo-bar.rawtest.raw',
             'test///folder': '/test/folder.raw',
             'foobar-flat.vmdk': '/foobar-flat.vmdk.raw',
             '//test.raw': '/test.raw',
             'test/.raw': '/test/.raw.raw',
             '//d\'[email protected]#%xfoo Bar/te_b --asdfS SA AS lolz///f.wrv.': '/dxfoo_Bar/te_b_--asdfS_SA_AS_lolz/f.wrv..raw'}
     for raw, expected in test.iteritems():
         result = VDiskController.clean_devicename(raw)
         self.assertEqual(result, expected)
开发者ID:grimpy,项目名称:openvstorage,代码行数:18,代码来源:test_vdisk.py

示例3: test_create_new

# 需要导入模块: from ovs.lib.vdisk import VDiskController [as 别名]
# 或者: from ovs.lib.vdisk.VDiskController import clean_devicename [as 别名]
    def test_create_new(self):
        """
        Test the create new volume functionality
            - Attempt to create a vDisk larger than 2 TiB
            - Create a vDisk of exactly 2 TiB
            - Attempt to create a vDisk with identical name
            - Attempt to create a vDisk with identical devicename
            - Create a vDisk with identical name on another vPool
        """
        structure = Helper.build_service_structure(
            {'vpools': [1, 2],
             'storagerouters': [1, 2],
             'storagedrivers': [(1, 1, 1), (2, 2, 1)],  # (<id>, <vpool_id>, <storagerouter_id>)
             'mds_services': [(1, 1), (2, 2)]}  # (<id>, <storagedriver_id>)
        )
        vpools = structure['vpools']
        mds_services = structure['mds_services']
        storagedrivers = structure['storagedrivers']
        storagerouters = structure['storagerouters']
        size_64_tib = 64 * 1024 ** 4

        # Verify maximum size of 64TiB
        vdisk_name_1 = 'vdisk_1'
        vdisk_name_2 = 'vdisk_2'
        with self.assertRaises(ValueError):
            VDiskController.create_new(volume_name=vdisk_name_1, volume_size=size_64_tib + 1, storagedriver_guid=storagedrivers[1].guid)
        self.assertTrue(expr=len(VDiskList.get_vdisks()) == 0, msg='Expected to find 0 vDisks after failure 1')

        # Create volume of maximum size
        VDiskController.create_new(volume_name=vdisk_name_1, volume_size=size_64_tib, storagedriver_guid=storagedrivers[1].guid)
        vdisks = VDiskList.get_vdisks()
        self.assertTrue(expr=len(vdisks) == 1, msg='Expected to find 1 vDisk')
        self.assertTrue(expr=vdisks[0].storagerouter_guid == storagerouters[1].guid, msg='Storage Router does not match expected value')
        self.assertTrue(expr=vdisks[0].size == size_64_tib, msg='Size does not match expected value')
        self.assertTrue(expr=vdisks[0].name == vdisk_name_1, msg='Name does not match expected value')
        self.assertTrue(expr=vdisks[0].vpool == vpools[1], msg='vPool does not match expected value')
        self.assertTrue(expr=vdisks[0].devicename == VDiskController.clean_devicename(vdisk_name_1), msg='Devicename does not match expected value')

        # Attempt to create same volume on same vPool
        with self.assertRaises(RuntimeError):
            VDiskController.create_new(volume_name=vdisk_name_1, volume_size=size_64_tib, storagedriver_guid=storagedrivers[1].guid)
        self.assertTrue(expr=len(VDiskList.get_vdisks()) == 1, msg='Expected to find 1 vDisk after failure 2')

        # Attempt to create volume with identical devicename on same vPool
        with self.assertRaises(RuntimeError):
            VDiskController.create_new(volume_name='{0}%^$'.format(vdisk_name_1), volume_size=size_64_tib, storagedriver_guid=storagedrivers[1].guid)
        self.assertTrue(expr=len(VDiskList.get_vdisks()) == 1, msg='Expected to find 1 vDisk after failure 3')

        # Create same volume on another vPool
        vdisk2 = VDisk(VDiskController.create_new(volume_name=vdisk_name_2, volume_size=size_64_tib, storagedriver_guid=storagedrivers[2].guid))
        vdisks = VDiskList.get_vdisks()
        self.assertTrue(expr=len(vdisks) == 2, msg='Expected to find 2 vDisks')
        self.assertTrue(expr=vdisk2.storagerouter_guid == storagerouters[1].guid, msg='Storage Router does not match expected value')
        self.assertTrue(expr=vdisk2.size == size_64_tib, msg='Size does not match expected value')
        self.assertTrue(expr=vdisk2.name == vdisk_name_2, msg='Name does not match expected value')
        self.assertTrue(expr=vdisk2.vpool == vpools[2], msg='vPool does not match expected value')
        self.assertTrue(expr=vdisk2.devicename == VDiskController.clean_devicename(vdisk_name_2), msg='Devicename does not match expected value')

        # Attempt to create vDisk on Storage Driver without MDS service
        mds_services[1].service.storagerouter = storagerouters[2]
        mds_services[1].service.save()
        with self.assertRaises(RuntimeError):
            VDiskController.create_new(volume_name='vdisk_3', volume_size=size_64_tib, storagedriver_guid=storagedrivers[1].guid)
        self.assertTrue(expr=len(VDiskList.get_vdisks()) == 2, msg='Expected to find 2 vDisks after failure 4')
开发者ID:grimpy,项目名称:openvstorage,代码行数:66,代码来源:test_vdisk.py


注:本文中的ovs.lib.vdisk.VDiskController.clean_devicename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。