Change exception thrown by db method

Change exception in db method, because previous one had necessary
parameter which is undefined in db function. The undefined parameter
in the previous exception caused a new exception to be thrown.

Change-Id: I52ccb813d33d7c382f9447252fc5a1017ff625ac
Closes-Bug: #1364394
This commit is contained in:
Vladimir Vechkanov 2014-09-11 03:18:29 -04:00
parent f5d8792553
commit 8e045b6ded
3 changed files with 23 additions and 1 deletions

View File

@ -1747,7 +1747,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"