summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/openstack/compute/contrib/quotas.py43
-rw-r--r--nova/api/openstack/wsgi.py3
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_quotas.py11
3 files changed, 40 insertions, 17 deletions
diff --git a/nova/api/openstack/compute/contrib/quotas.py b/nova/api/openstack/compute/contrib/quotas.py
index ddfe5bf08..c7fe87a1f 100644
--- a/nova/api/openstack/compute/contrib/quotas.py
+++ b/nova/api/openstack/compute/contrib/quotas.py
@@ -88,23 +88,34 @@ class QuotaSetsController(object):
context = req.environ['nova.context']
authorize_update(context)
project_id = id
+
+ bad_keys = []
+ for key in body['quota_set'].keys():
+ if (key not in QUOTAS and
+ key != 'tenant_id' and
+ key != 'id'):
+ bad_keys.append(key)
+
+ if len(bad_keys) > 0:
+ msg = _("Bad key(s) %s in quota_set") % ",".join(bad_keys)
+ raise webob.exc.HTTPBadRequest(explanation=msg)
+
for key in body['quota_set'].keys():
- if key in QUOTAS:
- try:
- value = int(body['quota_set'][key])
- except (ValueError, TypeError):
- LOG.warn(_("Quota for %s should be integer.") % key)
- # NOTE(hzzhoushaoyu): Do not prevent valid value to be
- # updated. If raise BadRequest, some may be updated and
- # others may be not.
- continue
- self._validate_quota_limit(value)
- try:
- db.quota_update(context, project_id, key, value)
- except exception.ProjectQuotaNotFound:
- db.quota_create(context, project_id, key, value)
- except exception.AdminRequired:
- raise webob.exc.HTTPForbidden()
+ try:
+ value = int(body['quota_set'][key])
+ except (ValueError, TypeError):
+ LOG.warn(_("Quota for %s should be integer.") % key)
+ # NOTE(hzzhoushaoyu): Do not prevent valid value to be
+ # updated. If raise BadRequest, some may be updated and
+ # others may be not.
+ continue
+ self._validate_quota_limit(value)
+ try:
+ db.quota_update(context, project_id, key, value)
+ except exception.ProjectQuotaNotFound:
+ db.quota_create(context, project_id, key, value)
+ except exception.AdminRequired:
+ raise webob.exc.HTTPForbidden()
return {'quota_set': self._get_quotas(context, id)}
@wsgi.serializers(xml=QuotaTemplate)
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py
index 88b203a33..f7e8d0c6a 100644
--- a/nova/api/openstack/wsgi.py
+++ b/nova/api/openstack/wsgi.py
@@ -232,7 +232,8 @@ class XMLDeserializer(TextDeserializer):
else:
result = dict()
for attr in node.attributes.keys():
- result[attr] = node.attributes[attr].nodeValue
+ if not attr.startswith("xmlns"):
+ result[attr] = node.attributes[attr].nodeValue
for child in node.childNodes:
if child.nodeType != node.TEXT_NODE:
result[child.nodeName] = self._from_xml_node(child,
diff --git a/nova/tests/api/openstack/compute/contrib/test_quotas.py b/nova/tests/api/openstack/compute/contrib/test_quotas.py
index 0616c4628..f9eab2b94 100644
--- a/nova/tests/api/openstack/compute/contrib/test_quotas.py
+++ b/nova/tests/api/openstack/compute/contrib/test_quotas.py
@@ -132,6 +132,17 @@ class QuotaSetsTest(test.TestCase):
self.assertRaises(webob.exc.HTTPForbidden, self.controller.update,
req, 'update_me', body)
+ def test_quotas_update_invalid_key(self):
+ body = {'quota_set': {'instances2': -2, 'cores': -2,
+ 'ram': -2, 'floating_ips': -2,
+ 'metadata_items': -2, 'injected_files': -2,
+ 'injected_file_content_bytes': -2}}
+
+ req = fakes.HTTPRequest.blank('/v2/fake4/os-quota-sets/update_me',
+ use_admin_context=True)
+ self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
+ req, 'update_me', body)
+
def test_quotas_update_invalid_limit(self):
body = {'quota_set': {'instances': -2, 'cores': -2,
'ram': -2, 'floating_ips': -2,