Add health resource for ucp-integration API convention

It is a UCP API convention to include a health resource in order
for other components to access and validate Deckhand's health status [0].

As such, this PS accomplishes that goal. Also add uwsgi.ini file to
instantiate the webserver using a more complex configuration that
can be overriden more easily.

[0] https://github.com/att-comdev/ucp-integration/blob/master/docs/api-conventions.md#health-check-api

Change-Id: Ice24cec6d0b98c16af62d9436925083d4092a032
This commit is contained in:
Felipe Monteiro 2017-10-23 17:33:51 +01:00
parent 8aec0390f8
commit cdec6356a5
6 changed files with 58 additions and 18 deletions

View File

@ -23,37 +23,37 @@ Getting Started
To generate a configuration file automatically:: To generate a configuration file automatically::
$ tox -e genconfig $ tox -e genconfig
Resulting deckhand.conf.sample file is output to Resulting deckhand.conf.sample file is output to
:path:etc/deckhand/deckhand.conf.sample :path:etc/deckhand/deckhand.conf.sample
Copy the config file to a directory discoverably by ``oslo.conf``:: Copy the config file to a directory discoverably by ``oslo.conf``::
$ cp etc/deckhand/deckhand.conf.sample ~/deckhand.conf $ cp etc/deckhand/deckhand.conf.sample ~/deckhand.conf
To setup an in-memory database for testing: To setup an in-memory database for testing:
.. code-block:: ini .. code-block:: ini
[database] [database]
# #
# From oslo.db # From oslo.db
# #
# The SQLAlchemy connection string to use to connect to the database. # The SQLAlchemy connection string to use to connect to the database.
# (string value) # (string value)
connection = sqlite:///:memory: connection = sqlite:///:memory:
To run locally in a development environment:: To run locally in a development environment::
$ sudo pip install uwsgi $ sudo pip install uwsgi
$ virtualenv -p python3 /var/tmp/deckhand $ virtualenv -p python3 /var/tmp/deckhand
$ . /var/tmp/deckhand/bin/activate $ . /var/tmp/deckhand/bin/activate
$ sudo pip install . $ sudo pip install .
$ sudo python setup.py install $ sudo python setup.py install
$ uwsgi --http :9000 -w deckhand.cmd --callable deckhand_callable --enable-threads -L $ uwsgi --ini uwsgi.ini
Testing Testing
------- -------

View File

@ -0,0 +1,26 @@
# Copyright 2017 AT&T Intellectual Property. All other rights reserved.
#
# 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 deckhand.control.base import BaseResource
class HealthResource(BaseResource):
"""A resource that allows other UCP components to access and validate
Deckhand's health status. The response must be returned within 30 seconds
for Deckhand to be deemed "healthy".
"""
def on_get(self, req, resp):
resp.status = falcon.HTTP_204

View File

@ -18,6 +18,7 @@ from oslo_log import log
from deckhand.control import base from deckhand.control import base
from deckhand.control import buckets from deckhand.control import buckets
from deckhand.control import health
from deckhand.control import middleware from deckhand.control import middleware
from deckhand.control import revision_diffing from deckhand.control import revision_diffing
from deckhand.control import revision_documents from deckhand.control import revision_documents
@ -35,6 +36,7 @@ def configure_app(app, version=''):
v1_0_routes = [ v1_0_routes = [
('bucket/{bucket_name}/documents', buckets.BucketsResource()), ('bucket/{bucket_name}/documents', buckets.BucketsResource()),
('health', health.HealthResource()),
('revisions', revisions.RevisionsResource()), ('revisions', revisions.RevisionsResource()),
('revisions/{revision_id}', revisions.RevisionsResource()), ('revisions/{revision_id}', revisions.RevisionsResource()),
('revisions/{revision_id}/diff/{comparison_revision_id}', ('revisions/{revision_id}/diff/{comparison_revision_id}',

View File

@ -19,6 +19,7 @@ import mock
from deckhand.control import api from deckhand.control import api
from deckhand.control import buckets from deckhand.control import buckets
from deckhand.control import health
from deckhand.control import revision_diffing from deckhand.control import revision_diffing
from deckhand.control import revision_documents from deckhand.control import revision_documents
from deckhand.control import revision_tags from deckhand.control import revision_tags
@ -35,7 +36,7 @@ class TestApi(test_base.DeckhandTestCase):
def setUp(self): def setUp(self):
super(TestApi, self).setUp() super(TestApi, self).setUp()
# Mock the API resources. # Mock the API resources.
for resource in (buckets, revision_diffing, revision_documents, for resource in (buckets, health, revision_diffing, revision_documents,
revision_tags, revisions, rollback, validations, revision_tags, revisions, rollback, validations,
versions): versions):
class_names = self._get_module_class_names(resource) class_names = self._get_module_class_names(resource)
@ -75,6 +76,7 @@ class TestApi(test_base.DeckhandTestCase):
mock_falcon_api.add_route.assert_has_calls([ mock_falcon_api.add_route.assert_has_calls([
mock.call('/api/v1.0/bucket/{bucket_name}/documents', mock.call('/api/v1.0/bucket/{bucket_name}/documents',
self.buckets_resource()), self.buckets_resource()),
mock.call('/api/v1.0/health', self.health_resource()),
mock.call('/api/v1.0/revisions', self.revisions_resource()), mock.call('/api/v1.0/revisions', self.revisions_resource()),
mock.call('/api/v1.0/revisions/{revision_id}', mock.call('/api/v1.0/revisions/{revision_id}',
self.revisions_resource()), self.revisions_resource()),

View File

@ -97,8 +97,6 @@ function gen_paste {
function gen_policy { function gen_policy {
log_section Creating policy file with liberal permissions log_section Creating policy file with liberal permissions
oslopolicy-sample-generator --config-file=etc/deckhand/policy-generator.conf
policy_file='etc/deckhand/policy.yaml.sample' policy_file='etc/deckhand/policy.yaml.sample'
policy_pattern="deckhand\:" policy_pattern="deckhand\:"

12
uwsgi.ini Normal file
View File

@ -0,0 +1,12 @@
[uwsgi]
strict=true
# HTTP
http=:9000 # Update endpoint as needed.
http-keepalive=true
wsgi=deckhand.cmd
callable=deckhand_callable
# Misc.
enable-threads=true
disable-logging=true