par Benoît Bryon - www.marmelune.net
PyCon FR - Pau - Octobre 2015
des tests en PROD
Hors conditions réelles
Au lancement
Trop tard !
Vue de l'extérieur
import unittest
import hospital
@hospital.healthcheck
class DemoHealthCheck(unittest.TestCase):
def test_predictable(self):
"""Health checks are collected."""
self.assertTrue(True)
healthchecks.py :
+ vos idées
Ce qui varie entre DEV et PROD
par exemple : la configuration.
import urlparse
import hospital
from django.conf import settings
@hospital.healthcheck
def test_celery_broker_ping(self):
"""Celery broker responds to ping."""
parts = urlparse.urlparse(settings.BROKER_URL)
hospital.assert_ping(parts.hostname)
import urlparse
import hospital
from django.conf import settings
@hospital.healthcheck
def test_celery_broker_ping(self):
"""Celery broker responds to ping."""
parts = urlparse.urlparse(settings.BROKER_URL)
hospital.assert_ping(parts.hostname)
Ce qui varie pendant la vie de la PROD
par exemple : les services tiers.
ALERTE ! La fonction "recherche" échoue !
Externe
Interne
Qui ne range pas son frigo
mange des asticots.
Lao Tseu.
sert
hospital-cli
$ hospital-cli yourapp.healthchecks
......
6 tests passed
nose
$ nosetests --all-modules --attr='is_healthcheck' yourapp.healthchecks
pytest
$ py.test -m healthcheck yourapp.healthchecks
hospital-serve
$ hospital-serve yourapp.healthchecks &
Serving on 0.0.0.0:1515
$ curl -i http://localhost:1515/
HTTP/1.0 200 OK
Content-Type: application/json; charset=utf-8
{
"status": "pass",
"summary": { ... },
"details": [ ... ]
}
Ou hospital.wsgi pour Gunicorn, Chaussette, twod.wsgi...