autoland: Ensure heartbeat endpoints do not cache (
Bug 1339175). r?mars
MozReview-Commit-ID: I21V7QdZtMB
--- a/autoland/public-web-api/autolandweb/dockerflow.py
+++ b/autoland/public-web-api/autolandweb/dockerflow.py
@@ -2,31 +2,39 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import tornado.web
class LoadBalancerHeartbeatHandler(tornado.web.RequestHandler):
"""Handler for Dockerflow __lbheartbeat__."""
+ def compute_etag(self):
+ return None
+
async def get(self):
"""Perform health check for load balancer.
Since this is for load balancer checks it should not check
backing services.
"""
self.write({})
self.set_status(200)
+ self.set_header('Cache-Control', 'no-cache')
class HeartbeatHandler(tornado.web.RequestHandler):
"""Handler for Dockerflow __heartbeat__."""
+ def compute_etag(self):
+ return None
+
async def get(self):
"""Perform health check for autoland backend."""
self.write({})
self.set_status(200)
+ self.set_header('Cache-Control', 'no-cache')
DOCKERFLOW_ROUTES = [
(r'/__lbheartbeat__/?$', LoadBalancerHeartbeatHandler),
(r'/__heartbeat__/?$', HeartbeatHandler),
]
--- a/autoland/public-web-api/tests/test_dockerflow_container_api.py
+++ b/autoland/public-web-api/tests/test_dockerflow_container_api.py
@@ -22,15 +22,19 @@ def app():
return make_app(False)
@pytest.mark.gen_test
async def test_loadbalancer_heartbeat_returns_200(http_client, base_url):
lb_heartbeat_url = base_url + '/__lbheartbeat__'
response = await http_client.fetch(lb_heartbeat_url)
assert response.code == 200
+ assert response.headers['Cache-Control'] == 'no-cache'
+ assert len(response.headers.get_list('Etag')) == 0
@pytest.mark.gen_test
async def test_heartbeat_returns_200(http_client, base_url):
lb_heartbeat_url = base_url + '/__heartbeat__'
response = await http_client.fetch(lb_heartbeat_url)
assert response.code == 200
+ assert response.headers['Cache-Control'] == 'no-cache'
+ assert len(response.headers.get_list('Etag')) == 0