Skip to content

Commit e332ace

Browse files
author
v-reyder
committed
Add negative test for quota api call
1 parent 1b46c80 commit e332ace

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

rootfs/api/models/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def create(self, *args, **kwargs): # noqa
203203
# create required minimum resources in k8s for the application
204204
namespace = self.id
205205
service = self.id
206+
quota_name = '{}-quota'.format(self.id)
206207
try:
207208
self.log('creating Namespace {} and services'.format(namespace), level=logging.DEBUG)
208209
# Create essential resources
@@ -212,8 +213,6 @@ def create(self, *args, **kwargs): # noqa
212213
self._scheduler.ns.create(namespace)
213214

214215
if settings.KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC != '':
215-
quota_name = '{}-quota'.format(namespace)
216-
self.log(settings.KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC)
217216
quota_spec = json.loads(settings.KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC)
218217
self.log('creating Quota {} for namespace {}'.format(quota_name, namespace),
219218
level=logging.DEBUG)

rootfs/api/settings/testing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636

3737
# How long k8s waits for a pod to finish work after a SIGTERM before sending SIGKILL
3838
KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS = int(os.environ.get('KUBERNETES_POD_TERMINATION_GRACE_PERIOD_SECONDS', 2)) # noqa
39+
KUBERNETES_NAMESPACE_DEFAULT_QUOTA_SPEC = '{"spec":{"hard":{"pods":"10"}}}'

rootfs/scheduler/tests/test_quota.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Run the tests with './manage.py test scheduler'
55
"""
66
from scheduler.tests import TestCase
7+
from scheduler import KubeHTTPException
78

89

910
class QuotaTest(TestCase):
@@ -25,3 +26,10 @@ def test_create_quota(self):
2526
data = response.json()
2627
self.assertEqual(data.get('spec', {}), quota['spec'])
2728
self.assertEqual(data['metadata']['namespace'], namespace_name)
29+
30+
def test_create_with_nonexistent_namespace(self):
31+
with self.assertRaises(
32+
KubeHTTPException,
33+
msg='failed to create quota test1 for namespace ghost-namespace: 404 Not Found'
34+
):
35+
self.scheduler.quota.create('ghost-namespace', 'test1', data={})

0 commit comments

Comments
 (0)