Skip to content

Commit a12c6eb

Browse files
committed
Merge pull request #1285 from deis/hotfix-app-announcers
fix(controller): format command before creating container
2 parents 1ef346d + 155153e commit a12c6eb

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

controller/api/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _get_command(self):
298298
if c_type == 'cmd':
299299
return ''
300300
else:
301-
return 'start {c_type}'
301+
return "start {}".format(c_type)
302302
else:
303303
return ''
304304

@@ -311,10 +311,9 @@ def _command_announceable(self):
311311
@transition(field=state, source=INITIALIZED, target=CREATED)
312312
def create(self):
313313
image = self.release.image
314-
c_type = self.type
315314
self._scheduler.create(name=self._job_id,
316315
image=image,
317-
command=self._command.format(**locals()),
316+
command=self._command,
318317
use_announcer=self._command_announceable())
319318

320319
@close_db_connections

controller/api/tests/test_container.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,30 @@ def test_container_str(self):
325325
"{}.{}.{}".format(container.app, container.type, container.num))
326326
self.assertEqual(str(container),
327327
"{}.{}.{}".format(container.app, container.type, container.num))
328+
329+
def test_container_command_format(self):
330+
# regression test for https://github.com/deis/deis/pull/1285
331+
url = '/api/apps'
332+
body = {'cluster': 'autotest'}
333+
response = self.client.post(url, json.dumps(body), content_type='application/json')
334+
self.assertEqual(response.status_code, 201)
335+
app_id = response.data['id']
336+
# post a new build
337+
url = "/api/apps/{app_id}/builds".format(**locals())
338+
body = {'image': 'autotest/example', 'sha': 'a'*40,
339+
'procfile': json.dumps({'web': 'node server.js', 'worker': 'node worker.js'})}
340+
response = self.client.post(url, json.dumps(body), content_type='application/json')
341+
self.assertEqual(response.status_code, 201)
342+
# scale up
343+
url = "/api/apps/{app_id}/scale".format(**locals())
344+
body = {'web': 1}
345+
response = self.client.post(url, json.dumps(body), content_type='application/json')
346+
self.assertEqual(response.status_code, 204)
347+
url = "/api/apps/{app_id}/containers".format(**locals())
348+
response = self.client.get(url)
349+
# verify that the container._command property got formatted
350+
self.assertEqual(response.status_code, 200)
351+
self.assertEqual(len(response.data['results']), 1)
352+
uuid = response.data['results'][0]['uuid']
353+
container = Container.objects.get(uuid=uuid)
354+
self.assertNotIn('{c_type}', container._command)

0 commit comments

Comments
 (0)