]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Validate expected parameters in add/remove router interfaces
authorEdgar Magana <emagana@gmail.com>
Thu, 5 Jun 2014 23:33:16 +0000 (16:33 -0700)
committerEdgar Magana <emagana@gmail.com>
Fri, 11 Jul 2014 21:28:59 +0000 (14:28 -0700)
The add and remove router interface methods check that interface_info
is not empty but don't check if it contains any of expected parameters:
port_id and subnet_id
This patch adds a helper method to validate that interface_info contains
at least one of the expected parameters
Include a unit test for the empty port_id and subnet_id case

Closes-Bug: #1325982

Change-Id: Ia370565235a33a847704b972c875d8f1573306c0

neutron/db/l3_db.py
neutron/tests/unit/test_l3_plugin.py

index 8575abf66c45a984005e31eeeb8cbb025b29aafe..eb4600a2d7ba4296801b72fb456311fe51b96b98 100644 (file)
@@ -403,11 +403,11 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
         return DEVICE_OWNER_ROUTER_INTF
 
     def _validate_interface_info(self, interface_info):
-        if not interface_info:
+        port_id_specified = interface_info and 'port_id' in interface_info
+        subnet_id_specified = interface_info and 'subnet_id' in interface_info
+        if not (port_id_specified or subnet_id_specified):
             msg = _("Either subnet_id or port_id must be specified")
             raise n_exc.BadRequest(resource='router', msg=msg)
-        port_id_specified = 'port_id' in interface_info
-        subnet_id_specified = 'subnet_id' in interface_info
         if port_id_specified and subnet_id_specified:
             msg = _("Cannot specify both subnet-id and port-id")
             raise n_exc.BadRequest(resource='router', msg=msg)
index b02ba15f8743af61e11b84e3ab840ac7580be840..7e4f885d8d9e2c82b16b02c8eea42c34eee1646d 100644 (file)
@@ -786,6 +786,13 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
                                               None,
                                               p['port']['id'])
 
+    def test_router_add_interface_empty_port_and_subnet_ids(self):
+        with self.router() as r:
+            self._router_interface_action('add', r['router']['id'],
+                                          None, None,
+                                          expected_code=exc.
+                                          HTTPBadRequest.code)
+
     def test_router_add_interface_port_bad_tenant_returns_404(self):
         with mock.patch('neutron.context.Context.to_dict') as tdict:
             admin_context = {'roles': ['admin']}