summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/api/test_healthcheck.py
diff options
context:
space:
mode:
authorJim Rollenhagen <jim@jimrollenhagen.com>2018-02-09 11:30:24 -0800
committerJim Rollenhagen <jim@jimrollenhagen.com>2018-02-12 14:48:05 -0500
commit6f439414bdcef9fc02f844f475ec798d48d42558 (patch)
treef7ae5f852c320a3b89fdafffc61998caf5e3469a /ironic/tests/unit/api/test_healthcheck.py
parent9a2ebde83f268fbcca3386fdfabf8a973e76fb36 (diff)
downloadironic-6f439414bdcef9fc02f844f475ec798d48d42558.tar.gz
Add optional healthcheck middleware
This adds the healthcheck middleware from oslo, configurable via the [healthcheck]/enabled option. This middleware adds a status check at `/healthcheck`. This is useful for load balancers to determine if a service is up (and add or remove it from rotation), or for monitoring tools to see the health of the server. This endpoint is unauthenticated, as not all load balancers or monitoring tools support authenticating with a health check endpoint. Change-Id: I7929d5f4502c3f84b1cf30526c94a458081a6a29 Closes-Bug: #1748515
Diffstat (limited to 'ironic/tests/unit/api/test_healthcheck.py')
-rw-r--r--ironic/tests/unit/api/test_healthcheck.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/ironic/tests/unit/api/test_healthcheck.py b/ironic/tests/unit/api/test_healthcheck.py
new file mode 100644
index 000000000..364ba8cf8
--- /dev/null
+++ b/ironic/tests/unit/api/test_healthcheck.py
@@ -0,0 +1,39 @@
+# 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.
+"""
+Tests to assert that audit middleware works as expected.
+"""
+
+import mock
+from oslo_config import cfg
+from oslo_middleware import healthcheck
+
+from ironic.tests.unit.api import base
+
+
+CONF = cfg.CONF
+
+
+class TestHealthcheckMiddleware(base.BaseApiTest):
+ """Provide a basic smoke test to ensure healthcheck middleware works."""
+
+ @mock.patch.object(healthcheck, 'Healthcheck')
+ def test_enable(self, mock_healthcheck):
+ CONF.set_override('enabled', True, group='healthcheck')
+ self._make_app()
+ mock_healthcheck.assert_called_once_with(mock.ANY, CONF)
+
+ @mock.patch.object(healthcheck, 'Healthcheck')
+ def test_disable(self, mock_healthcheck):
+ CONF.set_override('enabled', False, group='healthcheck')
+ self._make_app()
+ self.assertFalse(mock_healthcheck.called)