From b51738b3102e4954fce7c470145e430609ac2e31 Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Wed, 10 Jul 2013 16:55:29 -0700 Subject: [PATCH] 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 --- neutron/plugins/nicira/extensions/nvp_qos.py | 12 ++++++++++-- neutron/tests/unit/nicira/test_nicira_plugin.py | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/neutron/plugins/nicira/extensions/nvp_qos.py b/neutron/plugins/nicira/extensions/nvp_qos.py index a9c256514..5891be6ec 100644 --- a/neutron/plugins/nicira/extensions/nvp_qos.py +++ b/neutron/plugins/nicira/extensions/nvp_qos.py @@ -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}, diff --git a/neutron/tests/unit/nicira/test_nicira_plugin.py b/neutron/tests/unit/nicira/test_nicira_plugin.py index d51d3543b..3be010b02 100644 --- a/neutron/tests/unit/nicira/test_nicira_plugin.py +++ b/neutron/tests/unit/nicira/test_nicira_plugin.py @@ -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}} -- 2.45.2