Browse Source

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
changes/34/588434/7
Wenran Xiao 3 years ago
parent
commit
ae81d403f7
  1. 5
      neutron/db/l3_db.py
  2. 46
      neutron/tests/unit/extensions/test_l3.py
  3. 17
      neutron/tests/unit/plugins/ml2/test_plugin.py

5
neutron/db/l3_db.py

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

46
neutron/tests/unit/extensions/test_l3.py

@ -1914,6 +1914,22 @@ class L3NatTestCaseBase(L3NatTestCaseMixin):
network_id=n['network']['id'],
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):
with self.router() as r:
with self.subnet() as s:
@ -3725,6 +3741,36 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
registry.unsubscribe(fake_method, resources.FLOATING_IP,
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):
nset = lambda *a, **k: setattr(k['router_db'], 'name', 'hello')
registry.subscribe(nset, resources.ROUTER, events.PRECOMMIT_CREATE)

17
neutron/tests/unit/plugins/ml2/test_plugin.py

@ -1719,6 +1719,23 @@ class TestMl2DvrPortsV2(TestMl2PortsV2):
def test_delete_port_with_floatingip_notifies_l3_plugin(self):
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):
plugin = directory.get_plugin(plugin_constants.L3)
r = plugin.create_router(

Loading…
Cancel
Save