Skip to content

Commit 4c674d0

Browse files
committed
feat(release): throw 409 when identical release is done sequantially
This replaces logging that nothing changed for the release and still going ahead with the release. Now it is a noop operation. Fixes #321
1 parent f085640 commit 4c674d0

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

rootfs/api/models/release.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from registry import publish_release, get_port as docker_get_port, RegistryException
77
from api.utils import dict_diff
8-
from api.models import UuidAuditedModel, DeisException
8+
from api.models import UuidAuditedModel
9+
from api.exceptions import DeisException, AlreadyExists
910
from scheduler import KubeHTTPException
1011

1112
logger = logging.getLogger(__name__)
@@ -423,5 +424,7 @@ def save(self, *args, **kwargs): # noqa
423424
if self.version == 1:
424425
self.summary = "{} created the initial release".format(self.owner)
425426
else:
426-
self.summary = "{} changed nothing".format(self.owner)
427+
# There were no changes to this release
428+
raise AlreadyExists("{} changed nothing - release stopped".format(self.owner))
429+
427430
super(Release, self).save(*args, **kwargs)

rootfs/api/tests/test_release.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,27 @@ def test_release_unset_config(self, mock_requests):
349349
body = {'cpu': json.dumps({'cmd': None})}
350350
response = self.client.post(url, body)
351351
self.assertEqual(response.status_code, 422, response.data)
352+
353+
def test_release_no_change(self, mock_requests):
354+
"""
355+
Test that a release is created when an app is created, and
356+
then has 2 identical config set, causing a 409 as there was
357+
no change
358+
"""
359+
url = '/v2/apps'
360+
response = self.client.post(url)
361+
self.assertEqual(response.status_code, 201, response.data)
362+
app_id = response.data['id']
363+
364+
# check that updating config rolls a new release
365+
url = '/v2/apps/{app_id}/config'.format(**locals())
366+
body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})}
367+
response = self.client.post(url, body)
368+
self.assertEqual(response.status_code, 201, response.data)
369+
self.assertIn('NEW_URL1', response.data['values'])
370+
371+
# trigger identical release
372+
url = '/v2/apps/{app_id}/config'.format(**locals())
373+
body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})}
374+
response = self.client.post(url, body)
375+
self.assertEqual(response.status_code, 409, response.data)

0 commit comments

Comments
 (0)