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
This commit is contained in:
ashrod98 2021-07-12 20:44:28 +00:00
parent a2d30e215e
commit 657fa5b113
4 changed files with 46 additions and 0 deletions

View File

@ -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

View File

@ -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 {}

View File

@ -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):

View File

@ -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
<https://bugs.launchpad.net/manila/+bug/1870280>`_ for more details.