]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Validate dscp value less that 64
authorAaron Rosen <arosen@nicira.com>
Wed, 10 Jul 2013 23:55:29 +0000 (16:55 -0700)
committerAaron Rosen <arosen@nicira.com>
Wed, 10 Jul 2013 23:57:22 +0000 (16:57 -0700)
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

neutron/plugins/nicira/extensions/nvp_qos.py
neutron/tests/unit/nicira/test_nicira_plugin.py

index a9c2565147c5bb03fa55ff6dd347779d3962d034..5891be6ecf1651705244d2863b05739bdbf4018e 100644 (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},
index d51d3543b15f97f281fbffb223c8d2e404d1bf04..3be010b028dae17c080dcf70134a73d45645329d 100644 (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}}