Three ways to set Thin/Thick Type in Huawei driver

1.If thin_provisioning is set in the share type extra-specs,
  it will be used(thin share will be created if "capabilities:
  thin_provisioning=<is> True", thick share will be created if
  "capabilities:thin_provisioning=<is> False")
2.If "thin_provisioning" is not present in the share_type, the config value
  of "AllocType" in the config file will be used(thin share will be created
  if "AllocType=Thin", thick share will be created if "AllocType=Thick")
3.If two of aboves are not present, then thick share will be created by default.

Change-Id: I8153aa79fb04a4221675d7ec2e4b24947ec6f9d7
Closes-Bug: #1542133
This commit is contained in:
zhaohua 2016-02-05 11:16:06 +08:00
parent 4a61faa065
commit c2d285e089
4 changed files with 115 additions and 37 deletions

View File

@ -72,7 +72,7 @@ OPTS_CAPABILITIES = {
'compression': False, 'compression': False,
'huawei_smartcache': False, 'huawei_smartcache': False,
'huawei_smartpartition': False, 'huawei_smartpartition': False,
'thin_provisioning': False, 'thin_provisioning': None,
'qos': False, 'qos': False,
} }

View File

@ -598,7 +598,7 @@ class V3StorageConnection(driver.HuaweiBase):
fileparam = { fileparam = {
"NAME": name.replace("-", "_"), "NAME": name.replace("-", "_"),
"DESCRIPTION": "", "DESCRIPTION": "",
"ALLOCTYPE": constants.ALLOC_TYPE_THIN_FLAG, "ALLOCTYPE": extra_specs['LUNType'],
"CAPACITY": size, "CAPACITY": size,
"PARENTID": poolinfo['ID'], "PARENTID": poolinfo['ID'],
"INITIALALLOCCAPACITY": units.Ki * 20, "INITIALALLOCCAPACITY": units.Ki * 20,
@ -614,26 +614,7 @@ class V3StorageConnection(driver.HuaweiBase):
"ENABLECOMPRESSION": extra_specs['compression'], "ENABLECOMPRESSION": extra_specs['compression'],
} }
if 'LUNType' in extra_specs: if fileparam['ALLOCTYPE'] == constants.ALLOC_TYPE_THICK_FLAG:
fileparam['ALLOCTYPE'] = extra_specs['LUNType']
else:
root = self.helper._read_xml()
fstype = root.findtext('Filesystem/AllocType')
if fstype:
fstype = fstype.strip().strip('\n')
if fstype == 'Thin':
fileparam['ALLOCTYPE'] = constants.ALLOC_TYPE_THIN_FLAG
elif fstype == 'Thick':
fileparam['ALLOCTYPE'] = constants.ALLOC_TYPE_THICK_FLAG
else:
err_msg = (_(
'Config file is wrong. AllocType type must be set to'
' "Thin" or "Thick". AllocType:%(fetchtype)s') %
{'fetchtype': fstype})
LOG.error(err_msg)
raise exception.InvalidShare(reason=err_msg)
if fileparam['ALLOCTYPE'] == 0:
if (extra_specs['dedupe'] or if (extra_specs['dedupe'] or
extra_specs['compression']): extra_specs['compression']):
err_msg = _( err_msg = _(
@ -744,10 +725,10 @@ class V3StorageConnection(driver.HuaweiBase):
opts = huawei_utils.get_share_extra_specs_params( opts = huawei_utils.get_share_extra_specs_params(
share['share_type_id']) share['share_type_id'])
smartx_opts = constants.OPTS_CAPABILITIES if opts is None:
if opts is not None: opts = constants.OPTS_CAPABILITIES
smart = smartx.SmartX() smart = smartx.SmartX(self.helper)
smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts) smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts)
fileParam = self._init_filesys_para(share, poolinfo, smartx_opts) fileParam = self._init_filesys_para(share, poolinfo, smartx_opts)
fsid = self.helper._create_filesystem(fileParam) fsid = self.helper._create_filesystem(fileParam)
@ -906,7 +887,7 @@ class V3StorageConnection(driver.HuaweiBase):
# SmartDedupe&SmartCompression # SmartDedupe&SmartCompression
smartx_opts = constants.OPTS_CAPABILITIES smartx_opts = constants.OPTS_CAPABILITIES
if opts is not None: if opts is not None:
smart = smartx.SmartX() smart = smartx.SmartX(self.helper)
smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts) smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts)
old_compression = fs['COMPRESSION'] old_compression = fs['COMPRESSION']

View File

@ -106,6 +106,9 @@ class SmartQos(object):
class SmartX(object): class SmartX(object):
def __init__(self, helper):
self.helper = helper
def get_smartx_extra_specs_opts(self, opts): def get_smartx_extra_specs_opts(self, opts):
opts = self.get_capabilities_opts(opts, 'dedupe') opts = self.get_capabilities_opts(opts, 'dedupe')
opts = self.get_capabilities_opts(opts, 'compression') opts = self.get_capabilities_opts(opts, 'compression')
@ -124,10 +127,29 @@ class SmartX(object):
return opts return opts
def get_smartprovisioning_opts(self, opts): def get_smartprovisioning_opts(self, opts):
if strutils.bool_from_string(opts['thin_provisioning']): thin_provision = opts.get('thin_provisioning')
opts['LUNType'] = 1 if thin_provision is None:
root = self.helper._read_xml()
fstype = root.findtext('Filesystem/AllocType')
if fstype:
fstype = fstype.strip().strip('\n')
if fstype == 'Thin':
opts['LUNType'] = constants.ALLOC_TYPE_THIN_FLAG
elif fstype == 'Thick':
opts['LUNType'] = constants.ALLOC_TYPE_THICK_FLAG
else:
err_msg = (_(
'Huawei config file is wrong. AllocType type must be '
'set to "Thin" or "Thick". AllocType:%(fetchtype)s') %
{'fetchtype': fstype})
raise exception.InvalidShare(reason=err_msg)
else:
opts['LUNType'] = constants.ALLOC_TYPE_THICK_FLAG
else: else:
opts['LUNType'] = 0 if strutils.bool_from_string(thin_provision):
opts['LUNType'] = constants.ALLOC_TYPE_THIN_FLAG
else:
opts['LUNType'] = constants.ALLOC_TYPE_THICK_FLAG
return opts return opts

View File

@ -30,6 +30,7 @@ from manila import context
from manila import db from manila import db
from manila import exception from manila import exception
from manila.share import configuration as conf from manila.share import configuration as conf
from manila.share.drivers.huawei import constants
from manila.share.drivers.huawei import huawei_nas from manila.share.drivers.huawei import huawei_nas
from manila.share.drivers.huawei.v3 import connection from manila.share.drivers.huawei.v3 import connection
from manila.share.drivers.huawei.v3 import helper from manila.share.drivers.huawei.v3 import helper
@ -322,6 +323,7 @@ class FakeHuaweiNasHelper(helper.RestHelper):
self.test_multi_url_flag = 0 self.test_multi_url_flag = 0
self.cache_exist = True self.cache_exist = True
self.partition_exist = True self.partition_exist = True
self.alloc_type = None
def _change_file_mode(self, filepath): def _change_file_mode(self, filepath):
pass pass
@ -368,6 +370,8 @@ class FakeHuaweiNasHelper(helper.RestHelper):
"USERCONSUMEDCAPACITY":"2097152"}]}""" "USERCONSUMEDCAPACITY":"2097152"}]}"""
if url == "/filesystem": if url == "/filesystem":
request_data = jsonutils.loads(data)
self.alloc_type = request_data.get('ALLOCTYPE')
data = """{"error":{"code":0},"data":{ data = """{"error":{"code":0},"data":{
"ID":"4"}}""" "ID":"4"}}"""
@ -1186,7 +1190,11 @@ class HuaweiShareDriverTestCase(test.TestCase):
self.assertRaises(exception.InvalidInput, self.assertRaises(exception.InvalidInput,
self.driver.get_backend_driver) self.driver.get_backend_driver)
def test_create_share_nfs_alloctype_fail(self): def test_create_share_alloctype_fail(self):
share_type = self.fake_type_not_extra['test_with_extra']
self.mock_object(db,
'share_type_get',
mock.Mock(return_value=share_type))
self.recreate_fake_conf_file(alloctype_value='alloctype_fail') self.recreate_fake_conf_file(alloctype_value='alloctype_fail')
self.driver.plugin.configuration.manila_huawei_conf_file = ( self.driver.plugin.configuration.manila_huawei_conf_file = (
self.fake_conf_file) self.fake_conf_file)
@ -1258,7 +1266,7 @@ class HuaweiShareDriverTestCase(test.TestCase):
self.assertRaises(exception.InvalidShare, self.assertRaises(exception.InvalidShare,
self.driver.check_for_setup_error) self.driver.check_for_setup_error)
def test_create_share_nfs_alloctype_thin_success(self): def test_create_share_alloctype_thin_success(self):
share_type = self.fake_type_not_extra['test_with_extra'] share_type = self.fake_type_not_extra['test_with_extra']
self.mock_object(db, self.mock_object(db,
'share_type_get', 'share_type_get',
@ -1271,6 +1279,72 @@ class HuaweiShareDriverTestCase(test.TestCase):
location = self.driver.create_share(self._context, self.share_nfs, location = self.driver.create_share(self._context, self.share_nfs,
self.share_server) self.share_server)
self.assertEqual("100.115.10.68:/share_fake_uuid", location) self.assertEqual("100.115.10.68:/share_fake_uuid", location)
self.assertEqual(constants.ALLOC_TYPE_THIN_FLAG,
self.driver.plugin.helper.alloc_type)
def test_create_share_alloctype_thick_success(self):
share_type = self.fake_type_not_extra['test_with_extra']
self.mock_object(db,
'share_type_get',
mock.Mock(return_value=share_type))
self.driver.plugin.helper.login()
self.recreate_fake_conf_file(alloctype_value='Thick')
self.driver.plugin.configuration.manila_huawei_conf_file = (
self.fake_conf_file)
self.driver.plugin.helper.login()
location = self.driver.create_share(self._context, self.share_nfs,
self.share_server)
self.assertEqual("100.115.10.68:/share_fake_uuid", location)
self.assertEqual(constants.ALLOC_TYPE_THICK_FLAG,
self.driver.plugin.helper.alloc_type)
def test_create_share_no_alloctype_no_extra(self):
share_type = self.fake_type_not_extra['test_with_extra']
self.mock_object(db,
'share_type_get',
mock.Mock(return_value=share_type))
self.driver.plugin.helper.login()
self.recreate_fake_conf_file(alloctype_value=None)
self.driver.plugin.configuration.manila_huawei_conf_file = (
self.fake_conf_file)
self.driver.plugin.helper.login()
location = self.driver.create_share(self._context, self.share_nfs,
self.share_server)
self.assertEqual("100.115.10.68:/share_fake_uuid", location)
self.assertEqual(constants.ALLOC_TYPE_THICK_FLAG,
self.driver.plugin.helper.alloc_type)
def test_create_share_with_extra_thin(self):
share_type = {
'extra_specs': {
'capabilities:thin_provisioning': '<is> True'
},
}
self.mock_object(db,
'share_type_get',
mock.Mock(return_value=share_type))
self.driver.plugin.helper.login()
location = self.driver.create_share(self._context, self.share_nfs,
self.share_server)
self.assertEqual("100.115.10.68:/share_fake_uuid", location)
self.assertEqual(constants.ALLOC_TYPE_THIN_FLAG,
self.driver.plugin.helper.alloc_type)
def test_create_share_with_extra_thick(self):
share_type = {
'extra_specs': {
'capabilities:thin_provisioning': '<is> False'
},
}
self.mock_object(db,
'share_type_get',
mock.Mock(return_value=share_type))
self.driver.plugin.helper.login()
location = self.driver.create_share(self._context, self.share_nfs,
self.share_server)
self.assertEqual("100.115.10.68:/share_fake_uuid", location)
self.assertEqual(constants.ALLOC_TYPE_THICK_FLAG,
self.driver.plugin.helper.alloc_type)
def test_shrink_share_success(self): def test_shrink_share_success(self):
self.driver.plugin.helper.shrink_share_flag = False self.driver.plugin.helper.shrink_share_flag = False
@ -3329,10 +3403,6 @@ class HuaweiShareDriverTestCase(test.TestCase):
waitinterval_text = doc.createTextNode('') waitinterval_text = doc.createTextNode('')
waitinterval.appendChild(waitinterval_text) waitinterval.appendChild(waitinterval_text)
alloctype = doc.createElement('AllocType')
alloctype_text = doc.createTextNode(alloctype_value)
alloctype.appendChild(alloctype_text)
NFSClient = doc.createElement('NFSClient') NFSClient = doc.createElement('NFSClient')
virtualip = doc.createElement('IP') virtualip = doc.createElement('IP')
@ -3354,10 +3424,15 @@ class HuaweiShareDriverTestCase(test.TestCase):
lun.appendChild(NFSClient) lun.appendChild(NFSClient)
lun.appendChild(CIFSClient) lun.appendChild(CIFSClient)
lun.appendChild(timeout) lun.appendChild(timeout)
lun.appendChild(alloctype)
lun.appendChild(waitinterval) lun.appendChild(waitinterval)
lun.appendChild(storagepool) lun.appendChild(storagepool)
if alloctype_value:
alloctype = doc.createElement('AllocType')
alloctype_text = doc.createTextNode(alloctype_value)
alloctype.appendChild(alloctype_text)
lun.appendChild(alloctype)
prefetch = doc.createElement('Prefetch') prefetch = doc.createElement('Prefetch')
prefetch.setAttribute('Type', '0') prefetch.setAttribute('Type', '0')
prefetch.setAttribute('Value', '0') prefetch.setAttribute('Value', '0')