summaryrefslogtreecommitdiff
path: root/oslo_middleware/tests
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-09-10 15:18:55 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2015-09-17 14:42:13 -0700
commitccff90e5b604904831e2085b173ea9a66d0441b8 (patch)
tree8b63e8197507d3b6f4d481e297a96e22b38c811e /oslo_middleware/tests
parent9c873f48cce637849e08eca158e803cccd4511c6 (diff)
downloadoslo-middleware-ccff90e5b604904831e2085b173ea9a66d0441b8.tar.gz
Allow the healthcheck middleware to provide more detailed responses
It can be quite useful to have admin endpoints for healthcheck middleware provide more information about the health of the system. To enable this kind of information this initial step starts to add a jinja2 template that will produce the existing simple case by default, but when setup with detailed mode it can then produce more information about which checks were performed and there results. It can be expanded in the future to provide more information as desired (possibly showing more useful application level info when in detailed mode). Closes-Bug: #1494531 Change-Id: I9c6dae848985d950c3cf6798695c7669eb245ccb
Diffstat (limited to 'oslo_middleware/tests')
-rw-r--r--oslo_middleware/tests/test_healthcheck.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/oslo_middleware/tests/test_healthcheck.py b/oslo_middleware/tests/test_healthcheck.py
index 13aa5fd..b516d0c 100644
--- a/oslo_middleware/tests/test_healthcheck.py
+++ b/oslo_middleware/tests/test_healthcheck.py
@@ -28,12 +28,17 @@ class HealthcheckTests(test_base.BaseTestCase):
def application(req):
return 'Hello, World!!!'
- def _do_test(self, conf={}, path='/healthcheck',
- expected_code=webob.exc.HTTPOk.code,
- expected_body=b''):
+ def _do_test_request(self, conf={}, path='/healthcheck',
+ accept='text/plain'):
self.app = healthcheck.Healthcheck(self.application, conf)
- req = webob.Request.blank(path)
+ req = webob.Request.blank(path, accept=accept)
res = req.get_response(self.app)
+ return res
+
+ def _do_test(self, conf={}, path='/healthcheck',
+ expected_code=webob.exc.HTTPOk.code,
+ expected_body=b'', accept='text/plain'):
+ res = self._do_test_request(conf=conf, path=path, accept=accept)
self.assertEqual(expected_code, res.status_int)
self.assertEqual(expected_body, res.body)
@@ -69,6 +74,14 @@ class HealthcheckTests(test_base.BaseTestCase):
self._do_test(conf, expected_body=b'OK')
self.assertIn('disable_by_file', self.app._backends.names())
+ def test_disablefile_enabled_html_detailed(self):
+ conf = {'backends': 'disable_by_file',
+ 'disable_by_file_path': '/foobar', 'detailed': True}
+ res = self._do_test_request(conf, accept="text/html")
+ self.assertIn(b'Result of 1 checks:', res.body)
+ self.assertIn(b'<TD>OK</TD>', res.body)
+ self.assertEqual(webob.exc.HTTPOk.code, res.status_int)
+
def test_disablefile_disabled(self):
filename = self.create_tempfiles([('test', 'foobar')])[0]
conf = {'backends': 'disable_by_file',
@@ -78,6 +91,15 @@ class HealthcheckTests(test_base.BaseTestCase):
expected_body=b'DISABLED BY FILE')
self.assertIn('disable_by_file', self.app._backends.names())
+ def test_disablefile_disabled_html_detailed(self):
+ filename = self.create_tempfiles([('test', 'foobar')])[0]
+ conf = {'backends': 'disable_by_file',
+ 'disable_by_file_path': filename, 'detailed': True}
+ res = self._do_test_request(conf, accept="text/html")
+ self.assertIn(b'<TD>DISABLED BY FILE</TD>', res.body)
+ self.assertEqual(webob.exc.HTTPServiceUnavailable.code,
+ res.status_int)
+
def test_two_backends(self):
filename = self.create_tempfiles([('test', 'foobar')])[0]
conf = {'backends': 'disable_by_file,disable_by_file',