diff --git a/Makefile b/Makefile index 49b3665fa..cbb665f95 100644 --- a/Makefile +++ b/Makefile @@ -67,12 +67,12 @@ test-style: test-unit: cd rootfs \ - && coverage run manage.py test --settings=api.settings.testing --noinput registry api \ + && coverage run manage.py test --settings=api.settings.testing --noinput registry api scheduler.tests \ && coverage report -m test-unit-quick: cd rootfs \ - && ./manage.py test --settings=api.settings.testing --noinput --parallel ${TEST_PROCS} --noinput registry api + && ./manage.py test --settings=api.settings.testing --noinput --parallel ${TEST_PROCS} --noinput registry api scheduler.tests test-functional: @echo "Implement functional tests in _tests directory" diff --git a/rootfs/scheduler/__init__.py b/rootfs/scheduler/__init__.py index 5163d6f70..1f52bbd6f 100644 --- a/rootfs/scheduler/__init__.py +++ b/rootfs/scheduler/__init__.py @@ -590,7 +590,7 @@ def _set_container(self, namespace, container_name, data, **kwargs): # noqa # add in healthchecks healthchecks = kwargs.get('healthcheck', None) - if healthchecks: + if healthchecks and kwargs.get('routable', False): # check if a port is present. if not, auto-populate it # TODO: rip this out when we stop supporting deis config:set HEALTHCHECK_URL if ( diff --git a/rootfs/scheduler/tests/test_scheduler.py b/rootfs/scheduler/tests/test_scheduler.py new file mode 100644 index 000000000..35ecbb0af --- /dev/null +++ b/rootfs/scheduler/tests/test_scheduler.py @@ -0,0 +1,55 @@ +""" +Unit tests for the Deis scheduler module. + +Run the tests with "./manage.py test scheduler" +""" +from django.core.cache import cache +from django.test import TestCase + +from scheduler import mock + + +class SchedulerTest(TestCase): + """Tests scheduler calls""" + + def setUp(self): + self.scheduler_client = mock.MockSchedulerClient() + + def tearDown(self): + # make sure every test has a clean slate for k8s mocking + cache.clear() + + def test_set_container_applies_healthcheck_with_routable(self): + """ + Test that when _set_container is called with the 'routable' kwarg set to True, + a healthcheck is attached to the dictionary. + """ + data = {} + healthcheck = { + 'livenessProbe': { + 'httpGet': { + 'port': 80, + } + } + } + self.scheduler_client._set_container('foo', + 'bar', + data, + routable=True, + healthcheck=healthcheck) + self.assertDictContainsSubset(healthcheck, data) + # clear the dict to call again with routable as false + data = {} + self.scheduler_client._set_container('foo', + 'bar', + data, + routable=False, + healthcheck=healthcheck) + self.assertEqual(data.get('livenessProbe'), None) + # now call without setting 'routable', should default to False + data = {} + self.scheduler_client._set_container('foo', + 'bar', + data, + healthcheck=healthcheck) + self.assertEqual(data.get('livenessProbe'), None)