Fix default and detailed share type result not correct

When request default share type and show share type detailed,
the share type results is not correct, because the values of
attribute required_extra_specs is always empty.

Change-Id: I68fc4e2ba30bbd87b5417fe48688edd96cbcee5d
Closes-Bug: #1733742
(cherry picked from commit 6af780c1e4)
This commit is contained in:
junboli 2017-12-22 14:14:52 +08:00 committed by junbo.li
parent a512bea283
commit dafe199194
5 changed files with 44 additions and 4 deletions

View File

@ -15,6 +15,7 @@
"""The share type API controller module.."""
from oslo_log import log
from oslo_utils import strutils
from oslo_utils import uuidutils
import six
@ -30,6 +31,9 @@ from manila import rpc
from manila.share import share_types
LOG = log.getLogger(__name__)
class ShareTypesController(wsgi.Controller):
"""The share types API controller for the OpenStack API."""
@ -67,7 +71,7 @@ class ShareTypesController(wsgi.Controller):
"""Return a single share type item."""
context = req.environ['manila.context']
try:
share_type = share_types.get_share_type(context, id)
share_type = self._show_share_type_details(context, id)
except exception.NotFound:
msg = _("Share type not found.")
raise exc.HTTPNotFound(explanation=msg)
@ -76,6 +80,19 @@ class ShareTypesController(wsgi.Controller):
req.cache_db_share_type(share_type)
return self._view_builder.show(req, share_type)
def _show_share_type_details(self, context, id):
share_type = share_types.get_share_type(context, id)
required_extra_specs = {}
try:
required_extra_specs = share_types.get_valid_required_extra_specs(
share_type['extra_specs'])
except exception.InvalidExtraSpec:
LOG.exception('Share type %(share_type_id)s has invalid required'
' extra specs.', {'share_type_id': id})
share_type['required_extra_specs'] = required_extra_specs
return share_type
@wsgi.Controller.authorize
def default(self, req):
"""Return default volume type."""

View File

@ -165,15 +165,22 @@ def get_default_share_type(ctxt=None):
if ctxt is None:
ctxt = context.get_admin_context()
share_type = {}
try:
return get_share_type_by_name(ctxt, name)
share_type = get_share_type_by_name(ctxt, name)
required_extra_specs = get_valid_required_extra_specs(
share_type['extra_specs'])
share_type['required_extra_specs'] = required_extra_specs
return share_type
except exception.ShareTypeNotFoundByName as e:
# Couldn't find share type with the name in default_share_type
# flag, record this issue and move on
# TODO(zhiteng) consider add notification to warn admin
LOG.exception('Default share type is not found, '
'please check default_share_type config: %s',
e)
'please check default_share_type config: %s', e)
except exception.InvalidExtraSpec as ex:
LOG.exception('Default share type has invalid required extra'
' specs: %s', ex)
def get_share_type_extra_specs(share_type_id, key=False):

View File

@ -78,7 +78,14 @@ class ShareAPITest(test.TestCase):
self.vt = {
'id': 'fake_volume_type_id',
'name': 'fake_volume_type_name',
'required_extra_specs': {
'driver_handles_share_servers': 'False'
},
'extra_specs': {
'driver_handles_share_servers': 'False'
}
}
CONF.set_default("default_share_type", None)
def _get_expected_share_detailed_response(self, values=None, admin=False):

View File

@ -184,6 +184,9 @@ class ShareTypesAPITest(test.TestCase):
self.assertEqual(2, len(res_dict))
self.assertEqual('1', res_dict['share_type']['id'])
self.assertEqual('share_type_1', res_dict['share_type']['name'])
expect = {constants.ExtraSpecs.DRIVER_HANDLES_SHARE_SERVERS: "true"}
self.assertEqual(expect,
res_dict['share_type']['required_extra_specs'])
policy.check_policy.assert_called_once_with(
req.environ['manila.context'], self.resource_name, 'show')

View File

@ -87,6 +87,12 @@ class ShareAPITest(test.TestCase):
self.vt = {
'id': 'fake_volume_type_id',
'name': 'fake_volume_type_name',
'required_extra_specs': {
'driver_handles_share_servers': 'False'
},
'extra_specs': {
'driver_handles_share_servers': 'False'
}
}
self.snapshot = {
'id': '2',