From 657fa5b113ce1c0cd35a21d7eac4d446af9ce2d3 Mon Sep 17 00:00:00 2001 From: ashrod98 Date: Mon, 12 Jul 2021 20:44:28 +0000 Subject: [PATCH] Add missing share-type user message Attempting to create a share without identifying a share type results in an error.This adds a user message informing the user that no default share type was identified while attempting to create a share. Closes-Bug: #1870280 Change-Id: Ib417499d4394b939eb289460ac8dbb6b22d789f4 --- manila/message/message_field.py | 5 ++++ manila/scheduler/drivers/filter.py | 10 ++++++++ manila/tests/scheduler/drivers/test_filter.py | 24 +++++++++++++++++++ ...re-type-user-message-902275047410bdbf.yaml | 7 ++++++ 4 files changed, 46 insertions(+) create mode 100644 releasenotes/notes/fix-1870280-share-type-user-message-902275047410bdbf.yaml diff --git a/manila/message/message_field.py b/manila/message/message_field.py index 4640228d3f..ef6a36aa47 100644 --- a/manila/message/message_field.py +++ b/manila/message/message_field.py @@ -127,6 +127,10 @@ class Detail(object): "insufficient privileges or wrong credentials. Please check your " "user, password, ou and domain.")) + NO_DEFAULT_SHARE_TYPE = ( + '024', + _("No default share type has been made available. " + "You must specify a share type for creating shares.")) ALL = ( UNKNOWN_ERROR, NO_VALID_HOST, @@ -151,6 +155,7 @@ class Detail(object): UNSUPPORTED_CLIENT_ACCESS, UNSUPPORTED_ADD_UDPATE_SECURITY_SERVICE, SECURITY_SERVICE_FAILED_AUTH, + NO_DEFAULT_SHARE_TYPE, ) # Exception and detail mappings diff --git a/manila/scheduler/drivers/filter.py b/manila/scheduler/drivers/filter.py index db7c1ad6b3..de0b8b4b92 100644 --- a/manila/scheduler/drivers/filter.py +++ b/manila/scheduler/drivers/filter.py @@ -25,6 +25,8 @@ from oslo_log import log from manila import exception from manila.i18n import _ +from manila.message import api as message_api +from manila.message import message_field from manila.scheduler.drivers import base from manila.scheduler import scheduler_options from manila.share import share_types @@ -40,6 +42,7 @@ class FilterScheduler(base.Scheduler): self.cost_function_cache = None self.options = scheduler_options.SchedulerOptions() self.max_attempts = self._max_attempts() + self.message_api = message_api.API() def _get_configuration_options(self): """Fetch options dictionary. Broken out for testing.""" @@ -141,6 +144,13 @@ class FilterScheduler(base.Scheduler): " and specify in request body or" " set default_share_type in manila.conf.") LOG.error(msg) + self.message_api.create( + context, + message_field.Action.CREATE, + context.project_id, + resource_type=message_field.Resource.SHARE, + resource_id=request_spec.get('share_id', None), + detail=message_field.Detail.NO_DEFAULT_SHARE_TYPE) raise exception.InvalidParameterValue(err=msg) share_type['extra_specs'] = share_type.get('extra_specs') or {} diff --git a/manila/tests/scheduler/drivers/test_filter.py b/manila/tests/scheduler/drivers/test_filter.py index 685876a72f..6a7641f892 100644 --- a/manila/tests/scheduler/drivers/test_filter.py +++ b/manila/tests/scheduler/drivers/test_filter.py @@ -24,6 +24,7 @@ from oslo_utils import strutils from manila.common import constants from manila import context from manila import exception +from manila.message import message_field from manila.scheduler.drivers import base from manila.scheduler.drivers import filter from manila.scheduler import host_manager @@ -65,6 +66,29 @@ class FilterSchedulerTestCase(test_base.SchedulerTestCase): # no "share_proto" was specified in the request_spec self.assertNotIn('storage_protocol', retval[0]) + def test___format_filter_properties_no_default_share_type_provided(self): + + sched = fakes.FakeFilterScheduler() + create_mock_message = self.mock_object(sched.message_api, 'create') + fake_context = context.RequestContext('user', 'project') + request_spec = { + 'share_properties': {'project_id': 'string', 'size': 1}, + 'share_instance_properties': {}, + 'share_type': None, + 'share_id': 'fake-id1', + } + self.assertRaises(exception.InvalidParameterValue, + sched._format_filter_properties, + fake_context, {}, request_spec) + + create_mock_message.assert_called_once_with( + fake_context, + message_field.Action.CREATE, + fake_context.project_id, + resource_type=message_field.Resource.SHARE, + resource_id='fake-id1', + detail=message_field.Detail.NO_DEFAULT_SHARE_TYPE) + @ddt.data(True, False) def test__format_filter_properties_backend_specified_for_replica( self, has_share_backend_name): diff --git a/releasenotes/notes/fix-1870280-share-type-user-message-902275047410bdbf.yaml b/releasenotes/notes/fix-1870280-share-type-user-message-902275047410bdbf.yaml new file mode 100644 index 0000000000..c62e2db79a --- /dev/null +++ b/releasenotes/notes/fix-1870280-share-type-user-message-902275047410bdbf.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + New user message now alerts users when attempting to create a new + share without identifying a share type, either through request body + or by setting a default share type. See `bug #1870280 + `_ for more details.