[ADD] Health checks for load balancers.

https://tools.ietf.org/html/draft-inadarei-api-health-check-04

closes odoo/odoo#56522

Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
This commit is contained in:
Adam Heinz
2021-08-11 14:01:02 +00:00
parent ebcffc7c88
commit 542ed0e6cf
6 changed files with 48 additions and 2 deletions
+12 -1
View File
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
from odoo import exceptions, _
from odoo.http import Controller, request, route
@@ -42,3 +44,12 @@ class BusController(Controller):
@route('/longpolling/im_status', type="json", auth="user")
def im_status(self, partner_ids):
return request.env['res.partner'].with_context(active_test=False).search([('id', 'in', partner_ids)]).read(['im_status'])
@route('/longpolling/health', type='http', auth='none', save_session=False)
def health(self):
data = json.dumps({
'status': 'pass',
})
headers = [('Content-Type', 'application/json'),
('Cache-Control', 'no-store')]
return request.make_response(data, headers)
+1
View File
@@ -1 +1,2 @@
from . import test_assetsbundle
from . import test_health
+12
View File
@@ -0,0 +1,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase
class TestBusController(HttpCase):
def test_health(self):
response = self.url_open('/longpolling/health')
self.assertEqual(response.status_code, 200)
payload = response.json()
self.assertEqual(payload['status'], 'pass')
self.assertNotIn('session_id', response.cookies)
+10
View File
@@ -903,6 +903,16 @@ class Home(http.Controller):
return request.redirect(self._login_redirect(uid))
@http.route('/web/health', type='http', auth='none', save_session=False)
def health(self):
data = json.dumps({
'status': 'pass',
})
headers = [('Content-Type', 'application/json'),
('Cache-Control', 'no-store')]
return request.make_response(data, headers)
class WebClient(http.Controller):
@http.route('/web/webclient/locale/<string:lang>', type='http', auth="none")
+1 -1
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_health
from . import test_image
from . import test_js
from . import test_menu
+12
View File
@@ -0,0 +1,12 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests import HttpCase
class TestWebController(HttpCase):
def test_health(self):
response = self.url_open('/web/health')
self.assertEqual(response.status_code, 200)
payload = response.json()
self.assertEqual(payload['status'], 'pass')
self.assertNotIn('session_id', response.cookies)