From 531c7e5f93194a86f1f437b4f9c5e992da9b9f67 Mon Sep 17 00:00:00 2001 From: Zhihao Yuan Date: Thu, 11 Jul 2013 17:21:19 -0400 Subject: [PATCH] fix(wsgi): a non-existing queue stats returns 404 Fixes: Bug#1192180 Change-Id: Iaf1e77b8ce01b33de63979164ea23ea086bf81d4 --- marconi/tests/transport/wsgi/test_queue_lifecycle.py | 4 ++++ marconi/transport/wsgi/stats.py | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/marconi/tests/transport/wsgi/test_queue_lifecycle.py b/marconi/tests/transport/wsgi/test_queue_lifecycle.py index 1d0c948b0..e932ea8bd 100644 --- a/marconi/tests/transport/wsgi/test_queue_lifecycle.py +++ b/marconi/tests/transport/wsgi/test_queue_lifecycle.py @@ -33,6 +33,10 @@ class QueueLifecycleBaseTest(base.TestBase): path = '/v1/queues/gumshoe' for project_id in ('480924', 'foo', '', None): + # Stats + self.simulate_get(path + '/stats', project_id) + self.assertEquals(self.srmock.status, falcon.HTTP_404) + # Create doc = '{"messages": {"ttl": 600}}' self.simulate_put(path, project_id, body=doc) diff --git a/marconi/transport/wsgi/stats.py b/marconi/transport/wsgi/stats.py index 41a1cda46..cb46c6694 100644 --- a/marconi/transport/wsgi/stats.py +++ b/marconi/transport/wsgi/stats.py @@ -16,7 +16,9 @@ import falcon import marconi.openstack.common.log as logging +from marconi.storage import exceptions as storage_exceptions from marconi.transport import helpers +from marconi.transport.wsgi import exceptions as wsgi_exceptions LOG = logging.getLogger(__name__) @@ -38,8 +40,10 @@ class Resource(object): resp.body = helpers.to_json(resp_dict) resp.status = falcon.HTTP_200 + except storage_exceptions.DoesNotExist: + raise falcon.HTTPNotFound() + except Exception as ex: LOG.exception(ex) - title = _('Service temporarily unavailable') - msg = _('Please try again in a few seconds.') - raise falcon.HTTPServiceUnavailable(title, msg, 30) + description = _('Queue stats could not be read.') + raise wsgi_exceptions.HTTPServiceUnavailable(description)