From 8219f39e21216c97b4c12defef6e0597bbfcf658 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 17 Feb 2023 00:21:19 +0000 Subject: [PATCH] Fix text/plain mime type with healthcheck endpoint Previously if you used an accept header of text/plain when querying the healthcheck endpoint, you would get a 406 Not Acceptable response. This patch corrects that to allow requesting the healthcheck document in text format. Change-Id: I0e2d06b02c06b8c77fb1c2f94207d422066a0c6d (cherry picked from commit 8db655aed2e579ace3e778e100f1baa8cd13000c) (cherry picked from commit 106376d3fd9486aee9fd60a35a504d10b436a754) (cherry picked from commit ffdcfb486c2ca916129b62fcb5e4f18880785317) --- octavia/api/root_controller.py | 2 +- octavia/tests/functional/api/test_healthcheck.py | 14 ++++++++++++++ ...heck-text-plain-mime-type-134485abb8bcea0c.yaml | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/Fix-healthcheck-text-plain-mime-type-134485abb8bcea0c.yaml diff --git a/octavia/api/root_controller.py b/octavia/api/root_controller.py index 88e18f8d81..d0429577aa 100644 --- a/octavia/api/root_controller.py +++ b/octavia/api/root_controller.py @@ -39,7 +39,7 @@ class RootController(object): # Run the oslo middleware healthcheck for /healthcheck @pecan_expose('json') - @pecan_expose(content_type='plain/text') + @pecan_expose(content_type='text/plain') @pecan_expose(content_type='text/html') def healthcheck(self): # pylint: disable=inconsistent-return-statements if CONF.api_settings.healthcheck_enabled: diff --git a/octavia/tests/functional/api/test_healthcheck.py b/octavia/tests/functional/api/test_healthcheck.py index cdf497132b..96111f5389 100644 --- a/octavia/tests/functional/api/test_healthcheck.py +++ b/octavia/tests/functional/api/test_healthcheck.py @@ -114,6 +114,20 @@ class TestHealthCheck(base_db_test.OctaviaDBTestBase): self.assertEqual(200, response.status_code) self.assertEqual('OK', response.text) + def test_healthcheck_get_text_plain(self): + self.conf.config(group='healthcheck', detailed=False) + response = self._get(self._get_enabled_app(), '/healthcheck', + headers={'Accept': 'text/plain'}) + self.assertEqual(200, response.status_code) + self.assertEqual('OK', response.text) + + def test_healthcheck_get_text_plain_detailed(self): + self.conf.config(group='healthcheck', detailed=True) + response = self._get(self._get_enabled_app(), '/healthcheck', + headers={'Accept': 'text/plain'}) + self.assertEqual(200, response.status_code) + self.assertEqual('OK', response.text) + def test_healthcheck_get_json(self): self.conf.config(group='healthcheck', detailed=False) response = self._get(self._get_enabled_app(), '/healthcheck', diff --git a/releasenotes/notes/Fix-healthcheck-text-plain-mime-type-134485abb8bcea0c.yaml b/releasenotes/notes/Fix-healthcheck-text-plain-mime-type-134485abb8bcea0c.yaml new file mode 100644 index 0000000000..8a71895386 --- /dev/null +++ b/releasenotes/notes/Fix-healthcheck-text-plain-mime-type-134485abb8bcea0c.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed the ability to use the 'text/plain' mime type with the healthcheck + endpoint.