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

Commit

Permalink
fix(api): create TLS object on app create (#1043)
Browse files Browse the repository at this point in the history
This PR creates a TLS object when an application is created, fixing the issue where a server error
is shown after `deis tls:info` is called after `deis create`.
  • Loading branch information
Matthew Fisher authored Sep 7, 2016
1 parent 98d809a commit 2f5c019
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rootfs/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from api.models.release import Release
from api.models.config import Config
from api.models.domain import Domain
from api.models.tls import TLS
from api.models.appsettings import AppSettings

from scheduler import KubeHTTPException, KubeException
Expand Down Expand Up @@ -228,6 +229,10 @@ def create(self, *args, **kwargs): # noqa
self.appsettings_set.latest()
except AppSettings.DoesNotExist:
AppSettings.objects.create(owner=self.owner, app=self)
try:
self.tls_set.latest()
except TLS.DoesNotExist:
TLS.objects.create(owner=self.owner, app=self)
# Attach the platform specific application sub domain to the k8s service
# Only attach it on first release in case a customer has remove the app domain
if rel.version == 1 and not Domain.objects.filter(domain=self.id).exists():
Expand Down
11 changes: 11 additions & 0 deletions rootfs/api/tests/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ def test_tls_enforced(self, mock_requests):
'/v2/apps/{app_id}/tls'.format(**locals()),
data)
self.assertEqual(response.status_code, 400, response.data)

def test_tls_created_on_app_create(self, mock_requests):
"""
Ensure that a TLS object is created for an App with default values.
See https://github.com/deis/controller/issues/1042
"""
app_id = self.create_app()
response = self.client.get('/v2/apps/{}/tls'.format(app_id))
self.assertEqual(response.status_code, 200, response.data)
self.assertEqual(response.data['https_enforced'], None)

0 comments on commit 2f5c019

Please sign in to comment.