Implement health endpoint for WSGI driver
Change-Id: I8ab7dd2aecd6421817ad5a49ab0186afcdc2ff6e Implements: blueprint v1-api
This commit is contained in:
parent
05054b5be9
commit
e6ec550978
@ -59,22 +59,32 @@ class TestBase(util.TestBase):
|
||||
self.srmock)
|
||||
|
||||
def simulate_get(self, *args, **kwargs):
|
||||
"""Simulate a GET request."""
|
||||
kwargs['method'] = 'GET'
|
||||
return self.simulate_request(*args, **kwargs)
|
||||
|
||||
def simulate_head(self, *args, **kwargs):
|
||||
"""Simulate a HEAD request."""
|
||||
kwargs['method'] = 'HEAD'
|
||||
return self.simulate_request(*args, **kwargs)
|
||||
|
||||
def simulate_put(self, *args, **kwargs):
|
||||
"""Simulate a PUT request."""
|
||||
kwargs['method'] = 'PUT'
|
||||
return self.simulate_request(*args, **kwargs)
|
||||
|
||||
def simulate_post(self, *args, **kwargs):
|
||||
"""Simulate a POST request."""
|
||||
kwargs['method'] = 'POST'
|
||||
return self.simulate_request(*args, **kwargs)
|
||||
|
||||
def simulate_delete(self, *args, **kwargs):
|
||||
"""Simulate a DELETE request."""
|
||||
kwargs['method'] = 'DELETE'
|
||||
return self.simulate_request(*args, **kwargs)
|
||||
|
||||
def simulate_patch(self, *args, **kwargs):
|
||||
"""Simulate a PATCH request."""
|
||||
kwargs['method'] = 'PATCH'
|
||||
return self.simulate_request(*args, **kwargs)
|
||||
|
||||
|
34
marconi/tests/transport/wsgi/test_health.py
Normal file
34
marconi/tests/transport/wsgi/test_health.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2013 Rackspace, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
#
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import falcon
|
||||
|
||||
from marconi.tests.transport.wsgi import base
|
||||
|
||||
|
||||
class TestHealth(base.TestBase):
|
||||
|
||||
config_filename = 'wsgi_sqlite.conf'
|
||||
|
||||
def test_get(self):
|
||||
response = self.simulate_get('/v1/health')
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
self.assertEquals(response, [])
|
||||
|
||||
def test_head(self):
|
||||
response = self.simulate_head('/v1/health')
|
||||
self.assertEquals(self.srmock.status, falcon.HTTP_204)
|
||||
self.assertEquals(response, [])
|
@ -21,6 +21,7 @@ import marconi.openstack.common.log as logging
|
||||
from marconi import transport
|
||||
from marconi.transport import auth
|
||||
from marconi.transport.wsgi import claims
|
||||
from marconi.transport.wsgi import health
|
||||
from marconi.transport.wsgi import messages
|
||||
from marconi.transport.wsgi import queues
|
||||
from marconi.transport.wsgi import stats
|
||||
@ -46,6 +47,11 @@ class Driver(transport.DriverBase):
|
||||
def __init__(self, storage):
|
||||
super(Driver, self).__init__(storage)
|
||||
|
||||
self._init_routes()
|
||||
self._init_middleware()
|
||||
|
||||
def _init_routes(self):
|
||||
"""Initialize URI routes to resources."""
|
||||
self.app = falcon.API(before=_extract_project_id)
|
||||
|
||||
queue_controller = self.storage.queue_controller
|
||||
@ -81,15 +87,24 @@ class Driver(transport.DriverBase):
|
||||
self.app.add_route('/v1/queues/{queue_name}'
|
||||
'/claims/{claim_id}', claim_item)
|
||||
|
||||
# Health
|
||||
self.app.add_route('/v1/health', health.HealthResource())
|
||||
|
||||
def _init_middleware(self):
|
||||
"""Initialize WSGI middlewarez."""
|
||||
|
||||
# NOTE(flaper87): Install Auth
|
||||
if GLOBAL_CFG.auth_strategy:
|
||||
strategy = auth.strategy(GLOBAL_CFG.auth_strategy)
|
||||
self.app = strategy.install(self.app, PROJECT_CFG.conf)
|
||||
|
||||
def listen(self):
|
||||
"""Self-host using 'bind' and 'port' from the WSGI config group."""
|
||||
|
||||
msg = _('Serving on host %(bind)s:%(port)s')
|
||||
msg %= {'bind': WSGI_CFG.bind, 'port': WSGI_CFG.port}
|
||||
LOG.debug(msg)
|
||||
LOG.info(msg)
|
||||
|
||||
httpd = simple_server.make_server(WSGI_CFG.bind, WSGI_CFG.port,
|
||||
self.app)
|
||||
httpd.serve_forever()
|
||||
|
26
marconi/transport/wsgi/health.py
Normal file
26
marconi/transport/wsgi/health.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2013 Rackspace, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
#
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import falcon
|
||||
|
||||
|
||||
class HealthResource(object):
|
||||
|
||||
def on_get(self, req, resp, project_id):
|
||||
resp.status = falcon.HTTP_204
|
||||
|
||||
def on_head(self, req, resp, project_id):
|
||||
resp.status = falcon.HTTP_204
|
Loading…
x
Reference in New Issue
Block a user