Pass context in l3 flavor notifications

There are some notifications pass context in l3 flavor
notifications, and add context for consistency.

Change-Id: I01ced41201b61c624e675375b7bcd9589b2553e0
Closes-bug: #1785539
(cherry picked from commit ae81d403f7)
This commit is contained in:
Wenran Xiao 2018-08-03 11:40:20 +08:00 committed by LIU Yulong
parent 27c53ebc97
commit a47b7c065f
3 changed files with 66 additions and 2 deletions

View File

@ -193,7 +193,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
self._core_plugin.delete_port( self._core_plugin.delete_port(
context, port_id, l3_port_check=False) context, port_id, l3_port_check=False)
registry.notify(resources.FLOATING_IP, events.AFTER_DELETE, registry.notify(resources.FLOATING_IP, events.AFTER_DELETE,
self, **fips[0]) self, context=context, **fips[0])
def _get_dead_floating_port_candidates(self, context): def _get_dead_floating_port_candidates(self, context):
filters = {'device_id': ['PENDING'], filters = {'device_id': ['PENDING'],
@ -512,6 +512,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
registry.notify(resources.ROUTER_GATEWAY, registry.notify(resources.ROUTER_GATEWAY,
events.AFTER_CREATE, events.AFTER_CREATE,
self._create_gw_port, self._create_gw_port,
context=context,
gw_ips=ext_ips, gw_ips=ext_ips,
network_id=new_network_id, network_id=new_network_id,
router_id=router_id) router_id=router_id)
@ -1496,7 +1497,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
floatingip.floating_port_id, floatingip.floating_port_id,
l3_port_check=False) l3_port_check=False)
registry.notify(resources.FLOATING_IP, events.AFTER_DELETE, registry.notify(resources.FLOATING_IP, events.AFTER_DELETE,
self, **floatingip_dict) self, context=context, **floatingip_dict)
return floatingip_dict return floatingip_dict
@db_api.retry_if_session_inactive() @db_api.retry_if_session_inactive()

View File

@ -1919,6 +1919,22 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
network_id=n['network']['id'], network_id=n['network']['id'],
subnets=[]) subnets=[])
def test_router_add_gateway_notifications(self):
call_count_total = 3
with self.router() as r:
with self.network() as n:
self._set_net_external(n['network']['id'])
with mock.patch.object(registry, 'notify') as notify:
self._add_external_gateway_to_router(
r['router']['id'], n['network']['id'])
self.assertEqual(call_count_total, notify.call_count)
expected = [mock.call(
resources.ROUTER_GATEWAY,
events.AFTER_CREATE, mock.ANY,
context=mock.ANY, gw_ips=mock.ANY,
network_id=mock.ANY, router_id=mock.ANY)]
notify.assert_has_calls(expected)
def test_router_remove_interface_inuse_returns_409(self): def test_router_remove_interface_inuse_returns_409(self):
with self.router() as r: with self.router() as r:
with self.subnet() as s: with self.subnet() as s:
@ -3730,6 +3746,36 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
registry.unsubscribe(fake_method, resources.FLOATING_IP, registry.unsubscribe(fake_method, resources.FLOATING_IP,
events.PRECOMMIT_CREATE) events.PRECOMMIT_CREATE)
def test_floatingip_delete_after_event(self):
fake_method = mock.Mock()
try:
registry.subscribe(fake_method, resources.FLOATING_IP,
events.AFTER_DELETE)
with self.subnet(cidr='11.0.0.0/24') as public_sub:
self._set_net_external(public_sub['subnet']['network_id'])
f = self._make_floatingip(self.fmt,
public_sub['subnet']['network_id'],
port_id=None,
fixed_ip=None,
set_context=True)
self._delete('floatingips', f['floatingip']['id'])
fake_method.assert_called_once_with(
resources.FLOATING_IP, events.AFTER_DELETE, mock.ANY,
context=mock.ANY, description=mock.ANY,
dns_domain=mock.ANY, dns_name=mock.ANY,
fixed_ip_address=f['floatingip']['fixed_ip_address'],
floating_ip_address=f['floatingip']['floating_ip_address'],
floating_network_id=f['floatingip']['floating_network_id'],
id=f['floatingip']['id'],
port_id=f['floatingip']['port_id'],
project_id=f['floatingip']['project_id'],
router_id=f['floatingip']['router_id'],
status=f['floatingip']['status'],
tenant_id=f['floatingip']['tenant_id'])
finally:
registry.unsubscribe(fake_method, resources.FLOATING_IP,
events.AFTER_DELETE)
def test_router_create_precommit_event(self): def test_router_create_precommit_event(self):
nset = lambda *a, **k: setattr(k['router_db'], 'name', 'hello') nset = lambda *a, **k: setattr(k['router_db'], 'name', 'hello')
registry.subscribe(nset, resources.ROUTER, events.PRECOMMIT_CREATE) registry.subscribe(nset, resources.ROUTER, events.PRECOMMIT_CREATE)

View File

@ -1760,6 +1760,23 @@ class TestMl2DvrPortsV2(TestMl2PortsV2):
def test_delete_port_with_floatingip_notifies_l3_plugin(self): def test_delete_port_with_floatingip_notifies_l3_plugin(self):
self.test_delete_port_notifies_l3_plugin(floating_ip=True) self.test_delete_port_notifies_l3_plugin(floating_ip=True)
def test_delete_port_with_floatingip_create_precommit_event(self):
fake_method = mock.Mock()
with self.port(device_owner='network:floatingip') as port:
try:
registry.subscribe(fake_method, resources.FLOATING_IP,
events.PRECOMMIT_DELETE)
port_id = port['port']['id']
self.plugin.delete_port(self.context, port_id)
fake_method.assert_called_once_with(
resources.FLOATING_IP, events.PRECOMMIT_DELETE, mock.ANY,
bind=mock.ANY, bindings=mock.ANY, context=mock.ANY,
id=mock.ANY, levels=mock.ANY, network=mock.ANY,
port=mock.ANY, port_db=mock.ANY)
finally:
registry.unsubscribe(fake_method, resources.FLOATING_IP,
events.PRECOMMIT_DELETE)
def test_concurrent_csnat_port_delete(self): def test_concurrent_csnat_port_delete(self):
plugin = directory.get_plugin(plugin_constants.L3) plugin = directory.get_plugin(plugin_constants.L3)
r = plugin.create_router( r = plugin.create_router(