From cdec6356a562f98bcc44ce6c85e20d65b205be4e Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Mon, 23 Oct 2017 17:33:51 +0100 Subject: [PATCH] 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 --- README.rst | 30 +++++++++---------- deckhand/control/health.py | 26 ++++++++++++++++ deckhand/service.py | 2 ++ .../unit/control/test_api_initialization.py | 4 ++- tools/functional-tests.sh | 2 -- uwsgi.ini | 12 ++++++++ 6 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 deckhand/control/health.py create mode 100644 uwsgi.ini diff --git a/README.rst b/README.rst index a82a4f19..55e5a5d6 100644 --- a/README.rst +++ b/README.rst @@ -23,37 +23,37 @@ Getting Started To generate a configuration file automatically:: - $ tox -e genconfig + $ tox -e genconfig Resulting deckhand.conf.sample file is output to :path:etc/deckhand/deckhand.conf.sample 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: .. code-block:: ini - [database] + [database] - # - # From oslo.db - # + # + # From oslo.db + # - # The SQLAlchemy connection string to use to connect to the database. - # (string value) - connection = sqlite:///:memory: + # The SQLAlchemy connection string to use to connect to the database. + # (string value) + connection = sqlite:///:memory: To run locally in a development environment:: - $ sudo pip install uwsgi - $ virtualenv -p python3 /var/tmp/deckhand - $ . /var/tmp/deckhand/bin/activate - $ sudo pip install . - $ sudo python setup.py install - $ uwsgi --http :9000 -w deckhand.cmd --callable deckhand_callable --enable-threads -L + $ sudo pip install uwsgi + $ virtualenv -p python3 /var/tmp/deckhand + $ . /var/tmp/deckhand/bin/activate + $ sudo pip install . + $ sudo python setup.py install + $ uwsgi --ini uwsgi.ini Testing ------- diff --git a/deckhand/control/health.py b/deckhand/control/health.py new file mode 100644 index 00000000..12b791c2 --- /dev/null +++ b/deckhand/control/health.py @@ -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 diff --git a/deckhand/service.py b/deckhand/service.py index 72ca302d..028012c1 100644 --- a/deckhand/service.py +++ b/deckhand/service.py @@ -18,6 +18,7 @@ from oslo_log import log from deckhand.control import base from deckhand.control import buckets +from deckhand.control import health from deckhand.control import middleware from deckhand.control import revision_diffing from deckhand.control import revision_documents @@ -35,6 +36,7 @@ def configure_app(app, version=''): v1_0_routes = [ ('bucket/{bucket_name}/documents', buckets.BucketsResource()), + ('health', health.HealthResource()), ('revisions', revisions.RevisionsResource()), ('revisions/{revision_id}', revisions.RevisionsResource()), ('revisions/{revision_id}/diff/{comparison_revision_id}', diff --git a/deckhand/tests/unit/control/test_api_initialization.py b/deckhand/tests/unit/control/test_api_initialization.py index 554dafaf..f004b90b 100644 --- a/deckhand/tests/unit/control/test_api_initialization.py +++ b/deckhand/tests/unit/control/test_api_initialization.py @@ -19,6 +19,7 @@ import mock from deckhand.control import api from deckhand.control import buckets +from deckhand.control import health from deckhand.control import revision_diffing from deckhand.control import revision_documents from deckhand.control import revision_tags @@ -35,7 +36,7 @@ class TestApi(test_base.DeckhandTestCase): def setUp(self): super(TestApi, self).setUp() # 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, versions): 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.call('/api/v1.0/bucket/{bucket_name}/documents', 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/{revision_id}', self.revisions_resource()), diff --git a/tools/functional-tests.sh b/tools/functional-tests.sh index af997a0b..34fb7bd3 100755 --- a/tools/functional-tests.sh +++ b/tools/functional-tests.sh @@ -97,8 +97,6 @@ function gen_paste { function gen_policy { 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_pattern="deckhand\:" diff --git a/uwsgi.ini b/uwsgi.ini new file mode 100644 index 00000000..a94dbcca --- /dev/null +++ b/uwsgi.ini @@ -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