]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Better message on allowed address pairs error
authorKevin Benton <blak111@gmail.com>
Fri, 28 Aug 2015 05:12:48 +0000 (22:12 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Wed, 2 Sep 2015 22:43:33 +0000 (22:43 +0000)
Neutron was throwing a 500 error when a non-iterable was passed
into allowed address pairs. This patch just catches that and
converts it into a regular badrequest message.

Closes-Bug: #1477829
Change-Id: I3c6f55df4912c7a9480fa097988f910b254572fd
Signed-off-by: Kevin Benton <blak111@gmail.com>
neutron/extensions/allowedaddresspairs.py
neutron/tests/unit/db/test_allowedaddresspairs_db.py

index 5189e4f330505a6f08533fa3fe5e48c0172a0789..9b73a1542abe8e728dfd7222bd183446c6c0f5a8 100644 (file)
@@ -49,9 +49,13 @@ class AllowedAddressPairExhausted(nexception.BadRequest):
 
 def _validate_allowed_address_pairs(address_pairs, valid_values=None):
     unique_check = {}
-    if len(address_pairs) > cfg.CONF.max_allowed_address_pair:
-        raise AllowedAddressPairExhausted(
-            quota=cfg.CONF.max_allowed_address_pair)
+    try:
+        if len(address_pairs) > cfg.CONF.max_allowed_address_pair:
+            raise AllowedAddressPairExhausted(
+                quota=cfg.CONF.max_allowed_address_pair)
+    except TypeError:
+        raise webob.exc.HTTPBadRequest(
+            _("Allowed address pairs must be a list."))
 
     for address_pair in address_pairs:
         # mac_address is optional, if not set we use the mac on the port
index 2d3788a5b6ed042d73af3950a76cbd3cc580bb0a..af0ec336dc9263740e6c7e573a9102ef56f454fd 100644 (file)
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+from oslo_config import cfg
+from webob import exc as web_exc
 
 from neutron.api.v2 import attributes as attr
 from neutron.db import allowedaddresspairs_db as addr_pair_db
@@ -23,7 +25,6 @@ from neutron.extensions import portsecurity as psec
 from neutron.extensions import securitygroup as secgroup
 from neutron import manager
 from neutron.tests.unit.db import test_db_base_plugin_v2
-from oslo_config import cfg
 
 
 DB_PLUGIN_KLASS = ('neutron.tests.unit.db.test_allowedaddresspairs_db.'
@@ -97,6 +98,16 @@ class AllowedAddressPairDBTestCase(AllowedAddressPairTestCase):
 
 class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
 
+    def test_create_port_allowed_address_pairs_bad_format(self):
+        with self.network() as net:
+            bad_values = [False, True, None, 1.1, 1]
+            for value in bad_values:
+                self._create_port(
+                    self.fmt, net['network']['id'],
+                    expected_res_status=web_exc.HTTPBadRequest.code,
+                    arg_list=(addr_pair.ADDRESS_PAIRS,),
+                    allowed_address_pairs=value)
+
     def test_create_port_allowed_address_pairs(self):
         with self.network() as net:
             address_pairs = [{'mac_address': '00:00:00:00:00:01',