summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-07-13 02:20:23 +0000
committerGerrit Code Review <review@openstack.org>2018-07-13 02:20:23 +0000
commit8f27c2a165e3da1bacac7653da6d53a4fb2121f1 (patch)
tree5caf6ff486e825d132607c3f14fa937201e1b709
parent13631ff187b6c2c6eec4f356a917288560dc5886 (diff)
parentf5f682c63a043d59388731d78fae98481685019e (diff)
Merge "Modify logic of l3-agent to be notified"
-rw-r--r--neutron/db/l3_dvrscheduler_db.py9
-rw-r--r--neutron/tests/unit/scheduler/test_l3_agent_scheduler.py37
2 files changed, 40 insertions, 6 deletions
diff --git a/neutron/db/l3_dvrscheduler_db.py b/neutron/db/l3_dvrscheduler_db.py
index 866c3be..e50f507 100644
--- a/neutron/db/l3_dvrscheduler_db.py
+++ b/neutron/db/l3_dvrscheduler_db.py
@@ -453,8 +453,13 @@ def _notify_l3_agent_port_update(resource, event, trigger, **kwargs):
453 fips = l3plugin._get_floatingips_by_port_id( 453 fips = l3plugin._get_floatingips_by_port_id(
454 context, port_id=original_port['id']) 454 context, port_id=original_port['id'])
455 fip = fips[0] if fips else None 455 fip = fips[0] if fips else None
456 if fip and not (removed_routers and 456 removed_router_ids = [
457 fip['router_id'] in removed_routers): 457 info['router_id'] for info in removed_routers
458 ]
459 if (fip and
460 l3plugin.is_distributed_router(fip['router_id']) and
461 not (removed_routers and
462 fip['router_id'] in removed_router_ids)):
458 l3plugin.l3_rpc_notifier.routers_updated_on_host( 463 l3plugin.l3_rpc_notifier.routers_updated_on_host(
459 context, [fip['router_id']], 464 context, [fip['router_id']],
460 original_port[portbindings.HOST_ID]) 465 original_port[portbindings.HOST_ID])
diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
index b2745f7..97a041e 100644
--- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
+++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
@@ -1036,9 +1036,34 @@ class L3DvrSchedulerTestCase(L3SchedulerBaseMixin,
1036 fip = {'router_id': 'router_id'} 1036 fip = {'router_id': 'router_id'}
1037 self._test__notify_l3_agent_port_binding_change(None, fip) 1037 self._test__notify_l3_agent_port_binding_change(None, fip)
1038 1038
1039 def test__notify_l3_agent_port_binding_change_fip_dvr(self):
1040 fip = {'router_id': 'router_id'}
1041 is_distributed = True
1042 self._test__notify_l3_agent_port_binding_change(None,
1043 fip, is_distributed)
1044
1045 def test__notify_l3_agent_port_binding_change_fip_dvr_rmrt(self):
1046 fip = {'router_id': 'router_id'}
1047 router_to_remove = [{'agent_id': 'foo_agent',
1048 'router_id': 'foo_id',
1049 'host': 'vm-host1'}]
1050 is_distributed = True
1051 self._test__notify_l3_agent_port_binding_change(router_to_remove,
1052 fip, is_distributed)
1053
1054 def test__notify_l3_agent_port_binding_change_fip_dvr_on_rmrt(self):
1055 fip = {'router_id': 'foo_id'}
1056 router_to_remove = [{'agent_id': 'foo_agent',
1057 'router_id': 'foo_id',
1058 'host': 'vm-host1'}]
1059 is_distributed = True
1060 self._test__notify_l3_agent_port_binding_change(router_to_remove,
1061 fip, is_distributed)
1062
1039 def _test__notify_l3_agent_port_binding_change(self, 1063 def _test__notify_l3_agent_port_binding_change(self,
1040 routers_to_remove=None, 1064 routers_to_remove=None,
1041 fip=None): 1065 fip=None,
1066 is_distributed=False):
1042 source_host = 'vm-host1' 1067 source_host = 'vm-host1'
1043 kwargs = { 1068 kwargs = {
1044 'context': self.adminContext, 1069 'context': self.adminContext,
@@ -1055,9 +1080,12 @@ class L3DvrSchedulerTestCase(L3SchedulerBaseMixin,
1055 l3plugin = mock.Mock() 1080 l3plugin = mock.Mock()
1056 directory.add_plugin(plugin_constants.L3, l3plugin) 1081 directory.add_plugin(plugin_constants.L3, l3plugin)
1057 with mock.patch.object(l3plugin, 'get_dvr_routers_to_remove', 1082 with mock.patch.object(l3plugin, 'get_dvr_routers_to_remove',
1058 return_value=routers_to_remove),\ 1083 return_value=routers_to_remove
1084 if routers_to_remove else []),\
1059 mock.patch.object(l3plugin, '_get_floatingips_by_port_id', 1085 mock.patch.object(l3plugin, '_get_floatingips_by_port_id',
1060 return_value=[fip] if fip else []): 1086 return_value=[fip] if fip else []),\
1087 mock.patch.object(l3plugin, 'is_distributed_router',
1088 return_value=is_distributed):
1061 l3_dvrscheduler_db._notify_l3_agent_port_update( 1089 l3_dvrscheduler_db._notify_l3_agent_port_update(
1062 'port', 'after_update', mock.ANY, **kwargs) 1090 'port', 'after_update', mock.ANY, **kwargs)
1063 if routers_to_remove: 1091 if routers_to_remove:
@@ -1066,7 +1094,8 @@ class L3DvrSchedulerTestCase(L3SchedulerBaseMixin,
1066 self.assertEqual( 1094 self.assertEqual(
1067 1, 1095 1,
1068 l3plugin.delete_arp_entry_for_dvr_service_port.call_count) 1096 l3plugin.delete_arp_entry_for_dvr_service_port.call_count)
1069 if fip and not routers_to_remove: 1097 if fip and is_distributed and not (routers_to_remove and
1098 fip['router_id'] is routers_to_remove[0]['router_id']):
1070 (l3plugin.l3_rpc_notifier.routers_updated_on_host. 1099 (l3plugin.l3_rpc_notifier.routers_updated_on_host.
1071 assert_called_once_with(mock.ANY, ['router_id'], source_host)) 1100 assert_called_once_with(mock.ANY, ['router_id'], source_host))
1072 self.assertEqual( 1101 self.assertEqual(