Merge "Change exception thrown by db method"

This commit is contained in:
Jenkins 2014-09-17 03:52:14 +00:00 committed by Gerrit Code Review
commit 642f9af68c
3 changed files with 23 additions and 1 deletions

View File

@ -1748,7 +1748,16 @@ def share_server_get_by_host_and_share_net_valid(context, host, share_net_id,
.filter(models.ShareServer.status.in_(
(constants.STATUS_CREATING, constants.STATUS_ACTIVE))).first()
if result is None:
raise exception.ShareServerNotFound(share_server_id=id)
filters_description = ('share_network_id is "%(share_net_id)s",'
' host is "%(host)s" and status in'
' "%(status_cr)s" or "%(status_act)s"') % {
'share_net_id': share_net_id,
'host': host,
'status_cr': constants.STATUS_CREATING,
'status_act': constants.STATUS_ACTIVE,
}
raise exception.ShareServerNotFoundByFilters(
filters_description=filters_description)
result['backend_details'] = share_server_backend_details_get(
context, result['id'], session=session)
return result

View File

@ -173,6 +173,11 @@ class ShareServerNotFound(NotFound):
message = _("Share Server %(share_server_id)s could not be found.")
class ShareServerNotFoundByFilters(ShareServerNotFound):
message = _("Share Server could not be found by "
"filters: %(filters_description)s.")
class ShareServerInUse(InUse):
message = _("Share Server %(share_server_id)s is in use.")

View File

@ -247,6 +247,14 @@ class ManilaExceptionResponseCode404(test.TestCase):
self.assertEqual(e.code, 404)
self.assertIn(share_server_id, e.msg)
def test_share_server_not_found_by_filters(self):
# Verify response code for exception.ShareServerNotFoundByFilters
filters_description = "host = fakeHost"
e = exception.ShareServerNotFoundByFilters(
filters_description=filters_description)
self.assertEqual(e.code, 404)
self.assertIn(filters_description, e.msg)
def test_service_not_found(self):
# Verify response code for exception.ServiceNotFound
service_id = "fake_service_id"