Validate dscp value less that 64

Previously neutron would raise a 500 error if the dscp value was greater
than 63. This patch adds validation to neutron so that a clear error
message is returned if the value is greater than 63.

Fixes bug 1200026

Change-Id: I41a93661952669d112463608be907eede1901490
This commit is contained in:
Aaron Rosen 2013-07-10 16:55:29 -07:00
parent 58424dd616
commit b51738b310
2 changed files with 16 additions and 2 deletions

View File

@ -43,7 +43,8 @@ class DefaultQueueAlreadyExists(qexception.InUse):
class QueueInvalidDscp(qexception.InvalidInput):
message = _("Invalid value for dscp %(data)s must be integer.")
message = _("Invalid value for dscp %(data)s must be integer value"
"between 0 and 63.")
class QueueMinGreaterMax(qexception.InvalidInput):
@ -83,6 +84,13 @@ def convert_to_unsigned_int_or_none(val):
raise qexception.InvalidInput(error_message=msg)
return val
def convert_to_unsigned_int_or_none_max_63(val):
val = convert_to_unsigned_int_or_none(val)
if val > 63:
raise QueueInvalidDscp(data=val)
return val
# Attribute Map
RESOURCE_ATTRIBUTE_MAP = {
'qos_queues': {
@ -105,7 +113,7 @@ RESOURCE_ATTRIBUTE_MAP = {
'default': 'untrusted', 'is_visible': True},
'dscp': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': '0',
'convert_to': convert_to_unsigned_int_or_none},
'convert_to': convert_to_unsigned_int_or_none_max_63},
'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True,
'validate': {'type:string': None},

View File

@ -777,6 +777,12 @@ class TestNiciraQoSQueue(NiciraPluginV2TestCase):
port = self.deserialize('json', res)
self.assertEqual(ext_qos.QUEUE not in port['port'], True)
def test_dscp_value_out_of_range(self):
body = {'qos_queue': {'tenant_id': 'admin', 'dscp': '64',
'name': 'foo', 'min': 20, 'max': 20}}
res = self._create_qos_queue('json', body)
self.assertEqual(res.status_int, 400)
def test_non_admin_cannot_create_queue(self):
body = {'qos_queue': {'tenant_id': 'not_admin',
'name': 'foo', 'min': 20, 'max': 20}}