Raise OverQuota when hitting the quota limit

Change-Id: I0a20370413e3a5bce34628cd151f053d604edd64
This commit is contained in:
Erik Olof Gunnar Andersson 2019-10-29 17:53:21 -07:00
parent ac49353899
commit 9ed650205d
3 changed files with 10 additions and 8 deletions

View File

@ -80,6 +80,10 @@ class Forbidden(SenlinException):
msg_fmt = _("You are not authorized to complete this operation.")
class OverQuota(SenlinException):
msg_fmt = _("Quota exceeded for resources.")
class BadRequest(SenlinException):
msg_fmt = _("%(msg)s.")

View File

@ -725,7 +725,7 @@ class EngineService(service.Service):
existing = co.Cluster.count_all(context)
maximum = CONF.max_clusters_per_project
if existing >= maximum:
raise exception.Forbidden()
raise exception.OverQuota()
@request_context
def cluster_create(self, ctx, req):

View File

@ -61,10 +61,9 @@ class ClusterTest(base.SenlinTestCase):
mock_count.return_value = 11
cfg.CONF.set_override('max_clusters_per_project', 11)
ex = self.assertRaises(exc.Forbidden,
ex = self.assertRaises(exc.OverQuota,
self.eng.check_cluster_quota, self.ctx)
self.assertEqual("You are not authorized to complete this "
"operation.",
self.assertEqual("Quota exceeded for resources.",
six.text_type(ex))
def _prepare_request(self, req):
@ -203,7 +202,7 @@ class ClusterTest(base.SenlinTestCase):
@mock.patch.object(service.EngineService, 'check_cluster_quota')
def test_cluster_create_exceeding_quota(self, mock_quota):
mock_quota.side_effect = exc.Forbidden()
mock_quota.side_effect = exc.OverQuota()
req = {'profile_id': 'PROFILE', 'name': 'CLUSTER'}
self._prepare_request(req)
@ -211,9 +210,8 @@ class ClusterTest(base.SenlinTestCase):
self.eng.cluster_create,
self.ctx, req)
self.assertEqual(exc.Forbidden, ex.exc_info[0])
self.assertEqual("You are not authorized to complete this "
"operation.",
self.assertEqual(exc.OverQuota, ex.exc_info[0])
self.assertEqual("Quota exceeded for resources.",
six.text_type(ex.exc_info[1]))
mock_quota.assert_called_once_with(self.ctx)