Skip to content

Commit 458be25

Browse files
committed
fix(controller): ignore run procs when updating structure field
1 parent 3d59fef commit 458be25

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

controller/api/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ def scale(self, user, structure): # noqa
228228
if to_remove:
229229
self._destroy_containers(to_remove)
230230
# save new structure to the database
231-
vals = self.container_set.values('type').annotate(Count('pk')).order_by()
231+
vals = self.container_set.exclude(type='run').values(
232+
'type').annotate(Count('pk')).order_by()
232233
self.structure = {v['type']: v['pk__count'] for v in vals}
233234
self.save()
234235
return changed

controller/api/tests/test_container.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,52 @@ def test_run_command_good(self):
541541
rc, output = c.run('echo hi')
542542
self.assertEqual(json.loads(output)['entrypoint'], '/runner/init')
543543

544+
def test_scaling_does_not_add_run_proctypes_to_structure(self):
545+
"""Test that app info doesn't show transient "run" proctypes."""
546+
url = '/v1/apps'
547+
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
548+
self.assertEqual(response.status_code, 201)
549+
app_id = response.data['id']
550+
app = App.objects.get(id=app_id)
551+
user = User.objects.get(username='autotest')
552+
# dockerfile + procfile worflow
553+
build = Build.objects.create(owner=user,
554+
app=app,
555+
image="qwerty",
556+
procfile={'web': 'node server.js',
557+
'worker': 'node worker.js'},
558+
dockerfile='foo',
559+
sha='somereallylongsha')
560+
# create an initial release
561+
release = Release.objects.create(version=2,
562+
owner=user,
563+
app=app,
564+
config=app.config_set.latest(),
565+
build=build)
566+
# create a run container manually to simulate how they persist
567+
# when actually created by "deis apps:run".
568+
c = Container.objects.create(owner=user,
569+
app=app,
570+
release=release,
571+
type='run',
572+
num=1)
573+
# scale up
574+
url = "/v1/apps/{app_id}/scale".format(**locals())
575+
body = {'web': 3}
576+
response = self.client.post(url, json.dumps(body), content_type='application/json',
577+
HTTP_AUTHORIZATION='token {}'.format(self.token))
578+
self.assertEqual(response.status_code, 204)
579+
# test that "run" proctype isn't in the app info returned
580+
url = "/v1/apps/{app_id}".format(**locals())
581+
response = self.client.get(url, HTTP_AUTHORIZATION='token {}'.format(self.token))
582+
self.assertEqual(response.status_code, 200)
583+
self.assertNotIn('run', response.data['structure'])
584+
544585
def test_scale_with_unauthorized_user_returns_403(self):
545586
"""An unauthorized user should not be able to access an app's resources.
546587
547588
If an unauthorized user is trying to scale an app he or she does not have access to, it
548-
should return a 403. Currently, it returns a 404. FIXME!
589+
should return a 403.
549590
"""
550591
url = '/v1/apps'
551592
response = self.client.post(url, HTTP_AUTHORIZATION='token {}'.format(self.token))

0 commit comments

Comments
 (0)