(redis)Fix the 503 error when get/delete messages

Zaqar will return 503 in these three cases with redis backend:
1. Delete a message from a nonexistent queue.
DELETE /v2/queues/{queue_name}/messages/{message_id}
2. Delete messages with ids from a nonexistent queue.
DELETE /v2/queues/{queue_name}/messages?ids={message_ids}
3. Get messages with ids from a nonexistent queue.
GET    /v2/queues/{queue_name}/messages?ids={message_ids}

With mongoDB, zaqar will return 204, 204 and 404. This patch
fixed it to keep the same with mongoDB backend.

Change-Id: I61d8f6f252cb7d56df1e0821a541ce52d89e34dc
Closes-bug: #1590227
This commit is contained in:
wangxiyuan 2016-06-13 11:29:23 +08:00
parent 35d5e1fe36
commit d0a129f26e
2 changed files with 27 additions and 4 deletions

View File

@ -386,7 +386,7 @@ class MessageController(storage.Message, scripting.Mixin):
@utils.retries_on_connection_error @utils.retries_on_connection_error
def bulk_get(self, queue, message_ids, project=None): def bulk_get(self, queue, message_ids, project=None):
if not self._queue_ctrl.exists(queue, project): if not self._queue_ctrl.exists(queue, project):
raise errors.QueueDoesNotExist(queue, project) return iter([])
# NOTE(prashanthr_): Pipelining is used here purely # NOTE(prashanthr_): Pipelining is used here purely
# for performance. # for performance.
@ -440,7 +440,7 @@ class MessageController(storage.Message, scripting.Mixin):
@utils.retries_on_connection_error @utils.retries_on_connection_error
def delete(self, queue, message_id, project=None, claim=None): def delete(self, queue, message_id, project=None, claim=None):
if not self._queue_ctrl.exists(queue, project): if not self._queue_ctrl.exists(queue, project):
raise errors.QueueDoesNotExist(queue, project) return
# NOTE(kgriffs): The message does not exist, so # NOTE(kgriffs): The message does not exist, so
# it is essentially "already" deleted. # it is essentially "already" deleted.
@ -490,8 +490,7 @@ class MessageController(storage.Message, scripting.Mixin):
@utils.retries_on_connection_error @utils.retries_on_connection_error
def bulk_delete(self, queue, message_ids, project=None): def bulk_delete(self, queue, message_ids, project=None):
if not self._queue_ctrl.exists(queue, project): if not self._queue_ctrl.exists(queue, project):
raise errors.QueueDoesNotExist(queue, return
project)
msgset_key = utils.msgset_key(queue, project) msgset_key = utils.msgset_key(queue, project)

View File

@ -14,6 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import collections
import datetime import datetime
import random import random
import time import time
@ -739,6 +740,29 @@ class MessageControllerTest(ControllerBaseTest):
self.assertEqual(1, len(popped_messages)) self.assertEqual(1, len(popped_messages))
def test_delete_message_from_nonexistent_queue(self):
queue_name = 'fake_name'
message_id = 'fake_id'
res = self.controller.delete(queue_name, message_id,
project=self.project)
self.assertIsNone(res)
def test_delete_messages_with_ids_from__nonexistent_queue(self):
queue_name = 'fake_name'
message_ids = ['fake_id1', 'fake_id2']
res = self.controller.bulk_delete(queue_name, message_ids,
project=self.project)
self.assertIsNone(res)
def test_get_messages_with_ids_from__nonexistent_queue(self):
queue_name = 'fake_name'
message_ids = ['fake_id1', 'fake_id2']
res = self.controller.bulk_get(queue_name, message_ids,
project=self.project)
self.assertTrue(isinstance(res, collections.Iterable))
self.assertEqual([], list(res))
class ClaimControllerTest(ControllerBaseTest): class ClaimControllerTest(ControllerBaseTest):
"""Claim Controller base tests. """Claim Controller base tests.