Merge "Three ways to set Thin/Thick Type in Huawei driver"

This commit is contained in:
Jenkins 2016-02-26 03:41:28 +00:00 committed by Gerrit Code Review
commit 38b05940ea
4 changed files with 115 additions and 37 deletions

View File

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

View File

@ -598,7 +598,7 @@ class V3StorageConnection(driver.HuaweiBase):
fileparam = {
"NAME": name.replace("-", "_"),
"DESCRIPTION": "",
"ALLOCTYPE": constants.ALLOC_TYPE_THIN_FLAG,
"ALLOCTYPE": extra_specs['LUNType'],
"CAPACITY": size,
"PARENTID": poolinfo['ID'],
"INITIALALLOCCAPACITY": units.Ki * 20,
@ -614,26 +614,7 @@ class V3StorageConnection(driver.HuaweiBase):
"ENABLECOMPRESSION": extra_specs['compression'],
}
if 'LUNType' in extra_specs:
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 fileparam['ALLOCTYPE'] == constants.ALLOC_TYPE_THICK_FLAG:
if (extra_specs['dedupe'] or
extra_specs['compression']):
err_msg = _(
@ -744,10 +725,10 @@ class V3StorageConnection(driver.HuaweiBase):
opts = huawei_utils.get_share_extra_specs_params(
share['share_type_id'])
smartx_opts = constants.OPTS_CAPABILITIES
if opts is not None:
smart = smartx.SmartX()
smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts)
if opts is None:
opts = constants.OPTS_CAPABILITIES
smart = smartx.SmartX(self.helper)
smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts)
fileParam = self._init_filesys_para(share, poolinfo, smartx_opts)
fsid = self.helper._create_filesystem(fileParam)
@ -906,7 +887,7 @@ class V3StorageConnection(driver.HuaweiBase):
# SmartDedupe&SmartCompression
smartx_opts = constants.OPTS_CAPABILITIES
if opts is not None:
smart = smartx.SmartX()
smart = smartx.SmartX(self.helper)
smartx_opts, qos = smart.get_smartx_extra_specs_opts(opts)
old_compression = fs['COMPRESSION']

View File

@ -106,6 +106,9 @@ class SmartQos(object):
class SmartX(object):
def __init__(self, helper):
self.helper = helper
def get_smartx_extra_specs_opts(self, opts):
opts = self.get_capabilities_opts(opts, 'dedupe')
opts = self.get_capabilities_opts(opts, 'compression')
@ -124,10 +127,29 @@ class SmartX(object):
return opts
def get_smartprovisioning_opts(self, opts):
if strutils.bool_from_string(opts['thin_provisioning']):
opts['LUNType'] = 1
thin_provision = opts.get('thin_provisioning')
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:
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

View File

@ -30,6 +30,7 @@ from manila import context
from manila import db
from manila import exception
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.v3 import connection
from manila.share.drivers.huawei.v3 import helper
@ -322,6 +323,7 @@ class FakeHuaweiNasHelper(helper.RestHelper):
self.test_multi_url_flag = 0
self.cache_exist = True
self.partition_exist = True
self.alloc_type = None
def _change_file_mode(self, filepath):
pass
@ -368,6 +370,8 @@ class FakeHuaweiNasHelper(helper.RestHelper):
"USERCONSUMEDCAPACITY":"2097152"}]}"""
if url == "/filesystem":
request_data = jsonutils.loads(data)
self.alloc_type = request_data.get('ALLOCTYPE')
data = """{"error":{"code":0},"data":{
"ID":"4"}}"""
@ -1188,7 +1192,11 @@ class HuaweiShareDriverTestCase(test.TestCase):
self.assertRaises(exception.InvalidInput,
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.driver.plugin.configuration.manila_huawei_conf_file = (
self.fake_conf_file)
@ -1260,7 +1268,7 @@ class HuaweiShareDriverTestCase(test.TestCase):
self.assertRaises(exception.InvalidShare,
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']
self.mock_object(db,
'share_type_get',
@ -1273,6 +1281,72 @@ class HuaweiShareDriverTestCase(test.TestCase):
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_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):
self.driver.plugin.helper.shrink_share_flag = False
@ -3331,10 +3405,6 @@ class HuaweiShareDriverTestCase(test.TestCase):
waitinterval_text = doc.createTextNode('')
waitinterval.appendChild(waitinterval_text)
alloctype = doc.createElement('AllocType')
alloctype_text = doc.createTextNode(alloctype_value)
alloctype.appendChild(alloctype_text)
NFSClient = doc.createElement('NFSClient')
virtualip = doc.createElement('IP')
@ -3356,10 +3426,15 @@ class HuaweiShareDriverTestCase(test.TestCase):
lun.appendChild(NFSClient)
lun.appendChild(CIFSClient)
lun.appendChild(timeout)
lun.appendChild(alloctype)
lun.appendChild(waitinterval)
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.setAttribute('Type', '0')
prefetch.setAttribute('Value', '0')