From c27e66cc7c3427dfbc1e390693c6b0a3e656c783 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 19 Jun 2015 16:28:23 +0900 Subject: [PATCH] Reject router-interface-add with a port which doesn't have any addresses Fix a regression in commit I7d4e8194815e626f1cfa267f77a3f2475fdfa3d1 . Closes-Bug: #1466750 Related-Bug: #1439824 Change-Id: Ic0c4c0adbffe14b1f08d4b2dee91e1dff41cc770 --- neutron/db/l3_db.py | 4 ++++ neutron/tests/unit/extensions/test_l3.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 8f8f70b86..295e63b89 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -513,6 +513,10 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase): port_id=port['id'], device_id=port['device_id']) + if not port['fixed_ips']: + msg = _LE('Router port must have at least one fixed IP') + raise n_exc.BadRequest(resource='router', msg=msg) + # Only allow one router port with IPv6 subnets per network id if self._port_has_ipv6_address(port): for existing_port in (rp.port for rp in router.attached_ports): diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 52503d7d8..378a79a6d 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -1292,6 +1292,18 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): expected_code=err_code, tenant_id='bad_tenant') + def test_router_add_interface_port_without_ips(self): + with self.network() as network, self.router() as r: + # Create a router port without ips + p = self._make_port(self.fmt, network['network']['id'], + device_owner=l3_constants.DEVICE_OWNER_ROUTER_INTF) + err_code = exc.HTTPBadRequest.code + self._router_interface_action('add', + r['router']['id'], + None, + p['port']['id'], + expected_code=err_code) + def test_router_add_interface_dup_subnet1_returns_400(self): with self.router() as r: with self.subnet() as s: -- 2.45.2