From 8db655aed2e579ace3e778e100f1baa8cd13000c Mon Sep 17 00:00:00 2001
From: Michael Johnson <johnsomor@gmail.com>
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
---
 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 7beeacbad0..09d12f38f1 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 a00687b28a..d341587443 100644
--- a/octavia/tests/functional/api/test_healthcheck.py
+++ b/octavia/tests/functional/api/test_healthcheck.py
@@ -118,6 +118,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.