Skip to content

Commit e6bf676

Browse files
committed
fix(scheduler): deis run can fail under some conditions when DEBUG is set
Fixes #583
1 parent 00900e3 commit e6bf676

3 files changed

Lines changed: 56 additions & 6 deletions

File tree

rootfs/api/tests/test_app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def mock_none(*args, **kwargs):
2222
return None
2323

2424

25+
def _mock_run(*args, **kwargs):
26+
return [0, 'mock']
27+
28+
2529
@requests_mock.Mocker(real_http=True, adapter=adapter)
2630
class AppTest(APITestCase):
2731
"""Tests creation of applications"""
@@ -251,9 +255,6 @@ def test_run_without_release_should_error(self, mock_requests):
251255
self.assertEqual(response.data, {'detail': 'No build associated with this '
252256
'release to run this command'})
253257

254-
def _mock_run(*args, **kwargs):
255-
return [0, 'mock']
256-
257258
@mock.patch('api.models.App.run', _mock_run)
258259
@mock.patch('api.models.App.deploy', mock_none)
259260
@mock.patch('api.models.Release.publish', mock_none)

rootfs/api/tests/test_pods.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rest_framework.test import APITransactionTestCase
1313
from unittest import mock
1414
from rest_framework.authtoken.models import Token
15+
from test.support import EnvironmentVarGuard
1516

1617
from api.models import App, Build, Release
1718

@@ -571,7 +572,7 @@ def test_run_command_good(self, mock_requests):
571572
entrypoint = json.loads(response.data['output'])['spec']['containers'][0]['command'][0]
572573
self.assertEqual(entrypoint, '/bin/bash')
573574

574-
# # docker image workflow
575+
# docker image workflow
575576
build.dockerfile = ''
576577
build.sha = ''
577578
build.save()
@@ -582,7 +583,7 @@ def test_run_command_good(self, mock_requests):
582583
entrypoint = json.loads(response.data['output'])['spec']['containers'][0]['command'][0]
583584
self.assertEqual(entrypoint, '/bin/bash')
584585

585-
# # procfile workflow
586+
# procfile workflow
586587
build.sha = 'somereallylongsha'
587588
build.save()
588589
url = "/v2/apps/{app_id}/run".format(**locals())
@@ -592,6 +593,49 @@ def test_run_command_good(self, mock_requests):
592593
entrypoint = json.loads(response.data['output'])['spec']['containers'][0]['command'][0]
593594
self.assertEqual(entrypoint, '/runner/init')
594595

596+
def test_run_not_fail_on_debug(self, mock_requests):
597+
"""
598+
do a run with DEBUG on - https://github.com/deis/controller/issues/583
599+
"""
600+
env = EnvironmentVarGuard()
601+
env['DEBUG'] = 'true'
602+
603+
url = '/v2/apps'
604+
response = self.client.post(url)
605+
self.assertEqual(response.status_code, 201)
606+
app_id = response.data['id']
607+
app = App.objects.get(id=app_id)
608+
609+
# dockerfile + procfile worflow
610+
build = Build.objects.create(
611+
owner=self.user,
612+
app=app,
613+
image="qwerty",
614+
procfile={
615+
'web': 'node server.js',
616+
'worker': 'node worker.js'
617+
},
618+
dockerfile='foo',
619+
sha='somereallylongsha'
620+
)
621+
622+
# create an initial release
623+
Release.objects.create(
624+
version=2,
625+
owner=self.user,
626+
app=app,
627+
config=app.config_set.latest(),
628+
build=build
629+
)
630+
631+
# create a run pod
632+
url = "/v2/apps/{app_id}/run".format(**locals())
633+
body = {'command': 'echo hi'}
634+
response = self.client.post(url, body)
635+
self.assertEqual(response.status_code, 200)
636+
entrypoint = json.loads(response.data['output'])['spec']['containers'][0]['command'][0]
637+
self.assertEqual(entrypoint, '/bin/bash')
638+
595639
def test_scaling_does_not_add_run_proctypes_to_structure(self, mock_requests):
596640
"""Test that app info doesn't show transient "run" proctypes."""
597641
url = '/v2/apps'

rootfs/scheduler/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
"containers": [
8787
{
8888
"name": "$id",
89-
"image": "$image"
89+
"image": "$image",
90+
"env": []
9091
}
9192
],
9293
"restartPolicy": "Never"
@@ -564,6 +565,10 @@ def _set_environment(self, data, **kwargs):
564565
cpu = kwargs.get('cpu', {}).get(app_type)
565566
env = kwargs.get('envs', {})
566567

568+
# create env list if missing
569+
if 'env' not in data:
570+
data['env'] = []
571+
567572
if env:
568573
for key, value in env.items():
569574
data["env"].append({

0 commit comments

Comments
 (0)