Handle empty body in add_router_interface
when passing an empty dict body {} to add_router_interface[1], internal server error will be raised. There is argument check in the cli which checks either subnet or port id is needed, but not in the server side when the body is empty. [1]: https://developer.openstack.org/api-ref/networking/v2/?expanded=add-interface-to-router-detail Change-Id: Iad48dadb1235bc45787a1e87ff3f0d7a21df18af Closes-bug: #1674069
This commit is contained in:
parent
937e9546f3
commit
0e99b057df
|
@ -822,7 +822,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
|||
}
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
def add_router_interface(self, context, router_id, interface_info):
|
||||
def add_router_interface(self, context, router_id, interface_info=None):
|
||||
router = self._get_router(context, router_id)
|
||||
add_by_port, add_by_sub = self._validate_interface_info(interface_info)
|
||||
device_owner = self._get_device_owner(context, router_id)
|
||||
|
@ -1852,7 +1852,7 @@ class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin):
|
|||
notifier.info(context, router_event,
|
||||
{'router_interface': router_interface_info})
|
||||
|
||||
def add_router_interface(self, context, router_id, interface_info):
|
||||
def add_router_interface(self, context, router_id, interface_info=None):
|
||||
router_interface_info = super(
|
||||
L3_NAT_db_mixin, self).add_router_interface(
|
||||
context, router_id, interface_info)
|
||||
|
|
|
@ -235,7 +235,7 @@ class RouterPluginBase(object):
|
|||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def add_router_interface(self, context, router_id, interface_info):
|
||||
def add_router_interface(self, context, router_id, interface_info=None):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
|
|
|
@ -288,3 +288,11 @@ class L3_NAT_db_mixin(base.BaseTestCase):
|
|||
{'subnet_id': 'subnet-id',
|
||||
'ip_address': 'ip'}]}
|
||||
self._test_create_router(ext_gateway_info)
|
||||
|
||||
def test_add_router_interface_no_interface_info(self):
|
||||
router_db = l3_models.Router(id='123')
|
||||
with mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_get_router',
|
||||
return_value=router_db):
|
||||
self.assertRaises(
|
||||
n_exc.BadRequest,
|
||||
self.db.add_router_interface, mock.Mock(), router_db.id)
|
||||
|
|
|
@ -226,6 +226,17 @@ class L3NatExtensionTestCase(test_extensions_base.ExtensionTestCase):
|
|||
self.assertEqual(port_id, res['port_id'])
|
||||
self.assertEqual(subnet_id, res['subnet_id'])
|
||||
|
||||
def test_router_add_interface_empty_body(self):
|
||||
router_id = _uuid()
|
||||
instance = self.plugin.return_value
|
||||
|
||||
path = _get_path('routers', id=router_id,
|
||||
action="add_router_interface",
|
||||
fmt=self.fmt)
|
||||
res = self.api.put(path)
|
||||
self.assertEqual(exc.HTTPOk.code, res.status_int)
|
||||
instance.add_router_interface.assert_called_with(mock.ANY, router_id)
|
||||
|
||||
|
||||
# This base plugin class is for tests.
|
||||
class TestL3NatBasePlugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
|
Loading…
Reference in New Issue