Add exception for no default share type configured
There is a particular scenario when creating a new Manila share, whether through creating a new share or managing an existing one, where if no share type was explicitly specified and no default share type was configured the error message would not substitute the share type ID into the exception message. This is because, in this case, there was no share type ID to substitute into the string. This patch creates a new exception for explicitly handling the case where there is no default share type and no share type is explicitly given. It gives an appropriate error message about there not being a default share type and that there was no share type explicitly given as well as what would need to be done to remedy the situation. Change-Id: I068b55d4b77dc24b53fe93d870bb84e1aef661a5 Closes-Bug: #1700346
This commit is contained in:
parent
e979d19458
commit
bbb14264cb
@ -3761,6 +3761,10 @@ def _share_type_get(context, id, session=None, inactive=False,
|
|||||||
first())
|
first())
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
|
# The only way that id could be None is if the default share type is
|
||||||
|
# not configured and no other share type was specified.
|
||||||
|
if id is None:
|
||||||
|
raise exception.DefaultShareTypeNotConfigured()
|
||||||
raise exception.ShareTypeNotFound(share_type_id=id)
|
raise exception.ShareTypeNotFound(share_type_id=id)
|
||||||
|
|
||||||
share_type = _dict_with_specs(result)
|
share_type = _dict_with_specs(result)
|
||||||
|
@ -649,6 +649,11 @@ class ShareTypeDoesNotExist(NotFound):
|
|||||||
message = _("Share Type %(share_type)s does not exist.")
|
message = _("Share Type %(share_type)s does not exist.")
|
||||||
|
|
||||||
|
|
||||||
|
class DefaultShareTypeNotConfigured(NotFound):
|
||||||
|
message = _("No default share type is configured. Either configure a "
|
||||||
|
"default share type or explicitly specify a share type.")
|
||||||
|
|
||||||
|
|
||||||
class ShareGroupTypeExists(ManilaException):
|
class ShareGroupTypeExists(ManilaException):
|
||||||
message = _("Share group type %(type_id)s already exists.")
|
message = _("Share group type %(type_id)s already exists.")
|
||||||
|
|
||||||
|
@ -2752,6 +2752,10 @@ class ShareTypeAPITestCase(test.TestCase):
|
|||||||
|
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_share_type_get_with_none_id(self):
|
||||||
|
self.assertRaises(exception.DefaultShareTypeNotConfigured,
|
||||||
|
db_api.share_type_get, self.ctxt, None)
|
||||||
|
|
||||||
|
|
||||||
class MessagesDatabaseAPITestCase(test.TestCase):
|
class MessagesDatabaseAPITestCase(test.TestCase):
|
||||||
|
|
||||||
|
@ -486,6 +486,11 @@ class ManilaExceptionResponseCode404(test.TestCase):
|
|||||||
self.assertIn(share_type_id, e.msg)
|
self.assertIn(share_type_id, e.msg)
|
||||||
self.assertIn(extra_specs_key, e.msg)
|
self.assertIn(extra_specs_key, e.msg)
|
||||||
|
|
||||||
|
def test_default_share_type_not_configured(self):
|
||||||
|
# Verify response code for exception.DefaultShareTypeNotConfigured
|
||||||
|
e = exception.DefaultShareTypeNotConfigured()
|
||||||
|
self.assertEqual(404, e.code)
|
||||||
|
|
||||||
def test_instance_not_found(self):
|
def test_instance_not_found(self):
|
||||||
# verify response code for exception.InstanceNotFound
|
# verify response code for exception.InstanceNotFound
|
||||||
instance_id = "fake_instance_id"
|
instance_id = "fake_instance_id"
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- A new exception will be thrown when a default share type was not
|
||||||
|
configured and no other share type was specified on any sort of
|
||||||
|
share creation.
|
Loading…
Reference in New Issue
Block a user