From c1a564b4444a557cda037e57d7766b7b86661b4a Mon Sep 17 00:00:00 2001 From: kgriffs Date: Fri, 30 Aug 2013 14:47:24 -0500 Subject: [PATCH] fix: Claim can return 404 This patch changes the way creating a claim behaves when the queue does not exist. Instead of returning 404, it returns 204, meaning the claim was not able to find any messages to claim. This was done for two reasons: 1. For eventually-consistent backends, a brand new queue may not appear to exist, so this new semantic allows the driver to just try to grab some messages without checking first whether the queue "exists". 2. For backends like MongoDB that require an extra check to determine whether a queue exists, this removes an extra round trip to the DB in order to perform the operation. Note that the SQLite driver was updated in order to be consistent with the new behavior. Change-Id: Icde4ce493a76ef145e99300b67d8344d5092e38d Partial-Bug: #1218990 --- marconi/storage/mongodb/claims.py | 5 +---- marconi/storage/sqlite/claims.py | 5 ++++- marconi/tests/transport/wsgi/test_claims.py | 2 +- marconi/transport/wsgi/claims.py | 3 --- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/marconi/storage/mongodb/claims.py b/marconi/storage/mongodb/claims.py index cb7e1c83f..d24c56d76 100644 --- a/marconi/storage/mongodb/claims.py +++ b/marconi/storage/mongodb/claims.py @@ -118,9 +118,6 @@ class ClaimController(storage.ClaimBase): """ msg_ctrl = self.driver.message_controller - if not self.driver.queue_controller.exists(queue, project): - raise exceptions.QueueDoesNotExist(queue, project) - ttl = metadata['ttl'] grace = metadata['grace'] oid = objectid.ObjectId() @@ -148,7 +145,7 @@ class ClaimController(storage.ClaimBase): ids = [msg['_id'] for msg in msgs] if len(ids) == 0: - return (str(oid), messages) + return (None, messages) now = timeutils.utcnow() diff --git a/marconi/storage/sqlite/claims.py b/marconi/storage/sqlite/claims.py index 4af19dacd..d46358fb4 100644 --- a/marconi/storage/sqlite/claims.py +++ b/marconi/storage/sqlite/claims.py @@ -78,7 +78,10 @@ class ClaimController(base.ClaimBase): project = '' with self.driver('immediate'): - qid = utils.get_qid(self.driver, queue, project) + try: + qid = utils.get_qid(self.driver, queue, project) + except exceptions.QueueDoesNotExist: + return None, iter([]) # Clean up all expired claims in this queue diff --git a/marconi/tests/transport/wsgi/test_claims.py b/marconi/tests/transport/wsgi/test_claims.py index ecdc64bfa..2dddd1765 100644 --- a/marconi/tests/transport/wsgi/test_claims.py +++ b/marconi/tests/transport/wsgi/test_claims.py @@ -201,7 +201,7 @@ class ClaimsBaseTest(base.TestBase): def test_nonexistent(self): self.simulate_post('/v1/queues/nonexistent/claims', self.project_id, body='{"ttl": 100, "grace": 60}') - self.assertEquals(self.srmock.status, falcon.HTTP_404) + self.assertEquals(self.srmock.status, falcon.HTTP_204) # NOTE(cpp-cabrera): regression test against bug #1203842 def test_get_nonexistent_claim_404s(self): diff --git a/marconi/transport/wsgi/claims.py b/marconi/transport/wsgi/claims.py index a65279240..4ff2b2101 100644 --- a/marconi/transport/wsgi/claims.py +++ b/marconi/transport/wsgi/claims.py @@ -76,9 +76,6 @@ class CollectionResource(object): except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(ex)) - except storage_exceptions.DoesNotExist: - raise falcon.HTTPNotFound() - except Exception as ex: LOG.exception(ex) description = _(u'Claim could not be created.')