diff --git a/manila/api/v2/share_types.py b/manila/api/v2/share_types.py index 2767bf040b..9431ca9e54 100644 --- a/manila/api/v2/share_types.py +++ b/manila/api/v2/share_types.py @@ -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.""" diff --git a/manila/share/share_types.py b/manila/share/share_types.py index 710af6b9af..fc706a20cc 100644 --- a/manila/share/share_types.py +++ b/manila/share/share_types.py @@ -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): diff --git a/manila/tests/api/v1/test_shares.py b/manila/tests/api/v1/test_shares.py index 5ef01d2723..ffaa2f30cd 100644 --- a/manila/tests/api/v1/test_shares.py +++ b/manila/tests/api/v1/test_shares.py @@ -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): diff --git a/manila/tests/api/v2/test_share_types.py b/manila/tests/api/v2/test_share_types.py index a9ab762662..ac6fd64c4b 100644 --- a/manila/tests/api/v2/test_share_types.py +++ b/manila/tests/api/v2/test_share_types.py @@ -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') diff --git a/manila/tests/api/v2/test_shares.py b/manila/tests/api/v2/test_shares.py index e7437e55cf..0d837cdb20 100644 --- a/manila/tests/api/v2/test_shares.py +++ b/manila/tests/api/v2/test_shares.py @@ -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',