Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
feat(release): throw 409 when identical release is done sequantially
Browse files Browse the repository at this point in the history
This replaces logging that nothing changed for the release and still going ahead with the release. Now it is a noop operation.

Fixes #321
  • Loading branch information
helgi committed Jun 20, 2016
1 parent f085640 commit 4c674d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rootfs/api/models/release.py
Expand Up @@ -5,7 +5,8 @@

from registry import publish_release, get_port as docker_get_port, RegistryException
from api.utils import dict_diff
from api.models import UuidAuditedModel, DeisException
from api.models import UuidAuditedModel
from api.exceptions import DeisException, AlreadyExists
from scheduler import KubeHTTPException

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -423,5 +424,7 @@ def save(self, *args, **kwargs): # noqa
if self.version == 1:
self.summary = "{} created the initial release".format(self.owner)
else:
self.summary = "{} changed nothing".format(self.owner)
# There were no changes to this release
raise AlreadyExists("{} changed nothing - release stopped".format(self.owner))

super(Release, self).save(*args, **kwargs)
24 changes: 24 additions & 0 deletions rootfs/api/tests/test_release.py
Expand Up @@ -349,3 +349,27 @@ def test_release_unset_config(self, mock_requests):
body = {'cpu': json.dumps({'cmd': None})}
response = self.client.post(url, body)
self.assertEqual(response.status_code, 422, response.data)

def test_release_no_change(self, mock_requests):
"""
Test that a release is created when an app is created, and
then has 2 identical config set, causing a 409 as there was
no change
"""
url = '/v2/apps'
response = self.client.post(url)
self.assertEqual(response.status_code, 201, response.data)
app_id = response.data['id']

# check that updating config rolls a new release
url = '/v2/apps/{app_id}/config'.format(**locals())
body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})}
response = self.client.post(url, body)
self.assertEqual(response.status_code, 201, response.data)
self.assertIn('NEW_URL1', response.data['values'])

# trigger identical release
url = '/v2/apps/{app_id}/config'.format(**locals())
body = {'values': json.dumps({'NEW_URL1': 'http://localhost:8080/'})}
response = self.client.post(url, body)
self.assertEqual(response.status_code, 409, response.data)

0 comments on commit 4c674d0

Please sign in to comment.