l3: Send notify on router_create when ext gw is specified
A router that got created with an external gateway specified now
triggers a notfiy_router_updated event. This triggers scheduling
of the router and creation of the network namespace on the target
node.
Change-Id: I7f6ff5edf6a9c5ffa6d8978c1f3de0e106b6a8bb
Closes-Bug: #1535707
(cherry picked from commit da00d1a186
)
This commit is contained in:
parent
41be555edd
commit
ef6ea62d5d
|
@ -1575,6 +1575,13 @@ class L3RpcNotifierMixin(object):
|
||||||
class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin):
|
class L3_NAT_db_mixin(L3_NAT_dbonly_mixin, L3RpcNotifierMixin):
|
||||||
"""Mixin class to add rpc notifier methods to db_base_plugin_v2."""
|
"""Mixin class to add rpc notifier methods to db_base_plugin_v2."""
|
||||||
|
|
||||||
|
def create_router(self, context, router):
|
||||||
|
router_dict = super(L3_NAT_db_mixin, self).create_router(context,
|
||||||
|
router)
|
||||||
|
if router_dict.get('external_gateway_info'):
|
||||||
|
self.notify_router_updated(context, router_dict['id'], None)
|
||||||
|
return router_dict
|
||||||
|
|
||||||
def update_router(self, context, id, router):
|
def update_router(self, context, id, router):
|
||||||
router_dict = super(L3_NAT_db_mixin, self).update_router(context,
|
router_dict = super(L3_NAT_db_mixin, self).update_router(context,
|
||||||
id, router)
|
id, router)
|
||||||
|
|
|
@ -207,3 +207,45 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase):
|
||||||
events.AFTER_UPDATE, mock.ANY,
|
events.AFTER_UPDATE, mock.ANY,
|
||||||
context=mock.ANY,
|
context=mock.ANY,
|
||||||
subnetpool_id='fake_id')
|
subnetpool_id='fake_id')
|
||||||
|
|
||||||
|
|
||||||
|
class L3_NAT_db_mixin(base.BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(L3_NAT_db_mixin, self).setUp()
|
||||||
|
self.db = l3_db.L3_NAT_db_mixin()
|
||||||
|
|
||||||
|
def _test_create_router(self, external_gateway_info=None):
|
||||||
|
router_db = l3_db.Router(id='123')
|
||||||
|
router_dict = {'id': '123', 'tenant_id': '456',
|
||||||
|
'external_gateway_info': external_gateway_info}
|
||||||
|
# Need to use a copy here as the create_router method pops the gateway
|
||||||
|
# information
|
||||||
|
router_input = {'router': router_dict.copy()}
|
||||||
|
|
||||||
|
with mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_create_router_db',
|
||||||
|
return_value=router_db) as crd,\
|
||||||
|
mock.patch.object(l3_db.L3_NAT_dbonly_mixin, '_make_router_dict',
|
||||||
|
return_value=router_dict),\
|
||||||
|
mock.patch.object(l3_db.L3_NAT_dbonly_mixin,
|
||||||
|
'_update_router_gw_info') as urgi,\
|
||||||
|
mock.patch.object(l3_db.L3_NAT_db_mixin, 'notify_router_updated')\
|
||||||
|
as nru:
|
||||||
|
|
||||||
|
self.db.create_router(mock.ANY, router_input)
|
||||||
|
self.assertTrue(crd.called)
|
||||||
|
if external_gateway_info:
|
||||||
|
self.assertTrue(urgi.called)
|
||||||
|
self.assertTrue(nru.called)
|
||||||
|
else:
|
||||||
|
self.assertFalse(urgi.called)
|
||||||
|
self.assertFalse(nru.called)
|
||||||
|
|
||||||
|
def test_create_router_no_gateway(self):
|
||||||
|
self._test_create_router()
|
||||||
|
|
||||||
|
def test_create_router_gateway(self):
|
||||||
|
ext_gateway_info = {'network_id': 'net-id', 'enable_snat': True,
|
||||||
|
'external_fixed_ips': [
|
||||||
|
{'subnet_id': 'subnet-id',
|
||||||
|
'ip_address': 'ip'}]}
|
||||||
|
self._test_create_router(ext_gateway_info)
|
||||||
|
|
Loading…
Reference in New Issue