Merge "Fix default and detailed share type result not correct"
This commit is contained in:
commit
01c811de04
@ -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
|
||||
@ -31,6 +32,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."""
|
||||
|
||||
@ -68,7 +72,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)
|
||||
@ -77,6 +81,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."""
|
||||
|
@ -166,15 +166,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):
|
||||
|
@ -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):
|
||||
|
@ -188,6 +188,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')
|
||||
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user