Merge "Add jsonschema validation for karbor quotas API"
This commit is contained in:
commit
d565afe9d0
|
@ -0,0 +1,27 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Schema for Karbor V1 Quota class API.
|
||||
|
||||
"""
|
||||
|
||||
from karbor.api.validation import parameter_types
|
||||
|
||||
update = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'quota_class': parameter_types.metadata,
|
||||
},
|
||||
'required': ['quota_class'],
|
||||
'additionalProperties': False,
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Schema for Karbor V1 Quotas API.
|
||||
|
||||
"""
|
||||
|
||||
from karbor.api.validation import parameter_types
|
||||
|
||||
|
||||
update = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'quota': parameter_types.metadata,
|
||||
},
|
||||
'required': ['quota'],
|
||||
'additionalProperties': False,
|
||||
}
|
|
@ -19,6 +19,8 @@ from webob import exc
|
|||
|
||||
from karbor.api import common
|
||||
from karbor.api.openstack import wsgi
|
||||
from karbor.api.schemas import quota_classes as quota_class_schema
|
||||
from karbor.api import validation
|
||||
from karbor import db
|
||||
from karbor import exception
|
||||
from karbor.i18n import _
|
||||
|
@ -74,6 +76,7 @@ class QuotaClassesController(wsgi.Controller):
|
|||
return self._view_builder.detail_list(req, quota_class,
|
||||
quota_class_name)
|
||||
|
||||
@validation.schema(quota_class_schema.update)
|
||||
def update(self, req, id, body):
|
||||
context = req.environ['karbor.context']
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ from webob import exc
|
|||
|
||||
from karbor.api import common
|
||||
from karbor.api.openstack import wsgi
|
||||
from karbor.api.schemas import quotas as quota_schema
|
||||
from karbor.api import validation
|
||||
from karbor import db
|
||||
from karbor import exception
|
||||
from karbor.i18n import _
|
||||
|
@ -114,6 +116,7 @@ class QuotasController(wsgi.Controller):
|
|||
resource={'id': id})
|
||||
return self._view_builder.detail_list(req, quotas, id)
|
||||
|
||||
@validation.schema(quota_schema.update)
|
||||
def update(self, req, id, body):
|
||||
context = req.environ['karbor.context']
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ metadata = {
|
|||
'type': ['object', 'null'],
|
||||
'patternProperties': {
|
||||
'^[a-zA-Z0-9-_:.# ]{1,255}$': {
|
||||
'type': ['boolean', 'string']
|
||||
'type': ['boolean', 'string', 'integer']
|
||||
}
|
||||
},
|
||||
'additionalProperties': False
|
||||
|
|
|
@ -37,7 +37,7 @@ class QuotaClassApiTest(base.TestCase):
|
|||
'/v1/quota_classes/73f74f90a1754bd7ad658afb3272323f',
|
||||
use_admin_context=True)
|
||||
self.controller.update(
|
||||
req, '73f74f90a1754bd7ad658afb3272323f', body)
|
||||
req, '73f74f90a1754bd7ad658afb3272323f', body=body)
|
||||
self.assertTrue(mock_quota_update.called)
|
||||
|
||||
@mock.patch(
|
||||
|
|
|
@ -38,7 +38,7 @@ class QuotaApiTest(base.TestCase):
|
|||
'/v1/quotas/73f74f90a1754bd7ad658afb3272323f',
|
||||
use_admin_context=True)
|
||||
self.controller.update(
|
||||
req, '73f74f90a1754bd7ad658afb3272323f', body)
|
||||
req, '73f74f90a1754bd7ad658afb3272323f', body=body)
|
||||
self.assertTrue(mock_quota_update.called)
|
||||
|
||||
def test_quota_update_invalid_project_id(self):
|
||||
|
@ -47,7 +47,7 @@ class QuotaApiTest(base.TestCase):
|
|||
req = fakes.HTTPRequest.blank(
|
||||
'/v1/quotas/111', use_admin_context=True)
|
||||
self.assertRaises(exc.HTTPBadRequest, self.controller.update,
|
||||
req, '111', body)
|
||||
req, '111', body=body)
|
||||
|
||||
@mock.patch(
|
||||
'karbor.quota.DbQuotaDriver.get_project_quotas')
|
||||
|
|
Loading…
Reference in New Issue