Support quota hard_limit values of zero

Without this, the API fails with a 4xx error complaining
about an invalid field if the default cluster quota is
zero and you GET the quota for a project when the project
doesn't have an explicit quota set.  Furthermore, zero is
a meaningful value for an explicit quota.

Change-Id: I648bffab68e83f9573f852a12486f7ba11e4370b
This commit is contained in:
Stephen Crawley 2020-11-25 16:38:24 +11:00 committed by Sam Morrison
parent fa298eeab1
commit e93fdc07dd
2 changed files with 12 additions and 1 deletions

View File

@ -42,7 +42,7 @@ class Quota(base.APIBase):
id = wsme.wsattr(wtypes.IntegerType(minimum=1))
"""unique id"""
hard_limit = wsme.wsattr(wtypes.IntegerType(minimum=1), default=1)
hard_limit = wsme.wsattr(wtypes.IntegerType(minimum=0), default=1)
"""The hard limit for total number of clusters. Default to 1 if not set"""
project_id = wsme.wsattr(wtypes.StringType(min_length=1, max_length=255),

View File

@ -222,6 +222,17 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(201, response.status_int)
self.assertEqual(quota_dict['project_id'], response.json['project_id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
def test_create_zero_quota(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data(hard_limit=0)
response = self.post_json('/quotas', quota_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
self.assertEqual(quota_dict['project_id'], response.json['project_id'])
self.assertEqual(quota_dict['hard_limit'], response.json['hard_limit'])
@mock.patch.object(clients.OpenStackClients, 'keystone')
def test_create_quota_project_id_not_found(self, mock_keystone):
keystone = mock.MagicMock()