diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 29fea8ae529..e9ff59d6360 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -518,6 +518,12 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase): 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) + for key in ('port_id', 'subnet_id'): + if key not in interface_info: + continue + err = attributes._validate_uuid(interface_info[key]) + if err: + raise n_exc.BadRequest(resource='router', msg=err) if not for_removal: if port_id_specified and subnet_id_specified: msg = _("Cannot specify both subnet-id and port-id") diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index e9e339744d8..f1ecae6c30d 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -379,9 +379,9 @@ class L3NatTestCaseMixin(object): tenant_id=None, msg=None): interface_data = {} - if subnet_id: + if subnet_id is not None: interface_data.update({'subnet_id': subnet_id}) - if port_id: + if port_id is not None: interface_data.update({'port_id': port_id}) req = self.new_action_request('routers', interface_data, router_id, @@ -960,6 +960,20 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): # nsx metadata access case self.assertIn(payload['tenant_id'], [stid, ''], msg) + def test_router_add_interface_bad_values(self): + with self.router() as r: + exp_code = exc.HTTPBadRequest.code + self._router_interface_action('add', + r['router']['id'], + False, + None, + expected_code=exp_code) + self._router_interface_action('add', + r['router']['id'], + None, + False, + expected_code=exp_code) + def test_router_add_interface_subnet(self): fake_notifier.reset() with self.router() as r: