Merge "DVR: Rename dvr_update_router_addvm function" into stable/liberty

This commit is contained in:
Jenkins 2016-06-08 23:54:50 +00:00 committed by Gerrit Code Review
commit c3b005b3bc
2 changed files with 25 additions and 14 deletions

View File

@ -99,7 +99,13 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
the state of the router and the Compute Nodes.
"""
def dvr_update_router_addvm(self, context, port):
def dvr_handle_new_service_port(self, context, port):
"""Handle new dvr service port creation.
When a new dvr service port is created, this function will
schedule a dvr router to new compute node if needed and notify
l3 agent on that node.
"""
port_host = port[portbindings.HOST_ID]
l3_agent_on_host = (self.get_l3_agents(
context, filters={'host': [port_host]}) or [None])[0]
@ -113,7 +119,7 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
context, router_id, l3_agent_on_host['id']):
self.schedule_router(
context, router_id, candidates=[l3_agent_on_host])
LOG.debug('DVR: dvr_update_router_addvm %s ', router_id)
LOG.debug('DVR: Handle new service_port on router: %s', router_id)
self.l3_rpc_notifier.routers_updated_on_host(
context, router_ids, port_host)
@ -152,7 +158,7 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
def check_ports_on_host_and_subnet(self, context, host,
port_id, subnet_id):
"""Check if there is any dvr serviceable port on the subnet_id."""
"""Check if there are any dvr service ports on the subnet_id."""
filter_sub = {'fixed_ips': {'subnet_id': [subnet_id]}}
ports = self._core_plugin.get_ports(context, filters=filter_sub)
for port in ports:
@ -474,7 +480,7 @@ def _notify_l3_agent_new_port(resource, event, trigger, **kwargs):
l3plugin = manager.NeutronManager.get_service_plugins().get(
service_constants.L3_ROUTER_NAT)
context = kwargs['context']
l3plugin.dvr_update_router_addvm(context, port)
l3plugin.dvr_handle_new_service_port(context, port)
l3plugin.dvr_vmarp_table_update(context, port, "add")
@ -534,7 +540,7 @@ def _notify_l3_agent_port_update(resource, event, trigger, **kwargs):
new_port[portbindings.HOST_ID]))
if (is_new_port_binding_changed and
n_utils.is_dvr_serviced(new_device_owner)):
l3plugin.dvr_update_router_addvm(context, new_port)
l3plugin.dvr_handle_new_service_port(context, new_port)
l3plugin.dvr_vmarp_table_update(context, new_port, "add")
elif kwargs.get('mac_address_updated') or is_fixed_ips_changed:
l3plugin.dvr_vmarp_table_update(context, new_port, "add")

View File

@ -905,7 +905,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
l3_dvrscheduler_db._notify_l3_agent_port_update(
'port', 'after_update', plugin, **kwargs)
self.assertFalse(l3plugin.dvr_vmarp_table_update.called)
self.assertFalse(l3plugin.dvr_update_router_addvm.called)
self.assertFalse(
l3plugin.dvr_handle_new_service_port.called)
self.assertFalse(l3plugin.remove_router_from_l3_agent.called)
self.assertFalse(l3plugin.dvr_deletens_if_no_port.called)
@ -925,7 +926,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
'port', 'after_create', mock.ANY, **kwargs)
l3plugin.dvr_vmarp_table_update.assert_called_once_with(
self.adminContext, kwargs.get('port'), 'add')
l3plugin.dvr_update_router_addvm.assert_called_once_with(
l3plugin.dvr_handle_new_service_port.assert_called_once_with(
self.adminContext, kwargs.get('port'))
def test__notify_l3_agent_new_port_no_action(self):
@ -943,7 +944,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
l3_dvrscheduler_db._notify_l3_agent_new_port(
'port', 'after_create', mock.ANY, **kwargs)
self.assertFalse(l3plugin.dvr_vmarp_table_update.called)
self.assertFalse(l3plugin.dvr_update_router_addvm.called)
self.assertFalse(
l3plugin.dvr_handle_new_service_port.called)
def test__notify_l3_agent_update_port_no_action(self):
kwargs = {
@ -965,7 +967,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
'port', 'after_update', mock.ANY, **kwargs)
self.assertFalse(l3plugin.dvr_vmarp_table_update.called)
self.assertFalse(l3plugin.dvr_update_router_addvm.called)
self.assertFalse(
l3plugin.dvr_handle_new_service_port.called)
self.assertFalse(l3plugin.remove_router_from_l3_agent.called)
self.assertFalse(l3plugin.dvr_deletens_if_no_port.called)
@ -991,7 +994,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
l3plugin.dvr_vmarp_table_update.assert_called_once_with(
self.adminContext, kwargs.get('port'), 'add')
self.assertFalse(l3plugin.dvr_update_router_addvm.called)
self.assertFalse(l3plugin.dvr_handle_new_service_port.called)
def test__notify_l3_agent_update_port_with_port_binding_change(self):
kwargs = {
@ -1018,7 +1021,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
l3plugin.remove_router_from_l3_agent.assert_called_once_with(
mock.ANY, 'foo_agent', 'foo_id')
self.assertEqual(2, l3plugin.dvr_vmarp_table_update.call_count)
l3plugin.dvr_update_router_addvm.assert_called_once_with(
l3plugin.dvr_handle_new_service_port.assert_called_once_with(
self.adminContext, kwargs.get('port'))
def test__notify_l3_agent_update_port_removing_routers(self):
@ -1059,7 +1062,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
l3plugin.dvr_vmarp_table_update.assert_called_once_with(
self.adminContext, mock.ANY, 'del')
self.assertFalse(l3plugin.dvr_update_router_addvm.called)
self.assertFalse(
l3plugin.dvr_handle_new_service_port.called)
l3plugin.remove_router_from_l3_agent.assert_called_once_with(
mock.ANY, 'foo_agent', 'foo_id')
@ -1087,7 +1091,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
l3plugin.remove_router_from_l3_agent.assert_called_once_with(
mock.ANY, 'foo_agent', 'foo_id')
def test_dvr_update_router_addvm(self):
def test_dvr_handle_new_service_port(self):
port = {
'id': 'port1',
'device_id': 'abcd',
@ -1134,7 +1138,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
mock.patch.object(
self.dut, 'get_l3_agents',
return_value=[agent_on_host]) as get_l3_agents:
self.dut.dvr_update_router_addvm(self.adminContext, port)
self.dut.dvr_handle_new_service_port(
self.adminContext, port)
get_l3_agents.assert_called_once_with(
self.adminContext, filters={'host': [port['binding:host_id']]})