From: armando-migliaccio Date: Tue, 29 Jul 2014 03:09:04 +0000 (-0700) Subject: Make dvr_vmarp_table_update call conditional to dvr extension X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3eee50510fed29a7a8d97d4193a1c3c0a209a712;p=openstack-build%2Fneutron-build.git Make dvr_vmarp_table_update call conditional to dvr extension Without making this call conditional, every l3plugin that integrates with the ML2 plugin will need to implement this method and this must not be necessary. Closes-bug: #1349638 Change-Id: Ie9ba3bad4152810f5bfa530be54be70139cebc0c --- diff --git a/neutron/plugins/ml2/rpc.py b/neutron/plugins/ml2/rpc.py index 18ab181db..ae447fa8e 100644 --- a/neutron/plugins/ml2/rpc.py +++ b/neutron/plugins/ml2/rpc.py @@ -18,6 +18,7 @@ from neutron.api.rpc.handlers import dvr_rpc from neutron.common import constants as q_const from neutron.common import rpc as n_rpc from neutron.common import topics +from neutron.common import utils from neutron.db import dhcp_rpc_base from neutron.db import securitygroups_rpc_base as sg_db_rpc from neutron.extensions import portbindings @@ -190,7 +191,9 @@ class RpcCallbacks(n_rpc.RpcCallback, host) l3plugin = manager.NeutronManager.get_service_plugins().get( service_constants.L3_ROUTER_NAT) - if l3plugin: + if (l3plugin and + utils.is_extension_supported(l3plugin, + q_const.L3_DISTRIBUTED_EXT_ALIAS)): l3plugin.dvr_vmarp_table_update(rpc_context, port_id, "add") def get_dvr_mac_address_by_host(self, rpc_context, **kwargs): diff --git a/neutron/tests/unit/ml2/test_rpcapi.py b/neutron/tests/unit/ml2/test_rpcapi.py index 9eed323bf..8277b2594 100644 --- a/neutron/tests/unit/ml2/test_rpcapi.py +++ b/neutron/tests/unit/ml2/test_rpcapi.py @@ -28,6 +28,42 @@ from neutron.plugins.ml2 import rpc as plugin_rpc from neutron.tests import base +class RpcCallbacks(base.BaseTestCase): + + def setUp(self): + super(RpcCallbacks, self).setUp() + self.callbacks = plugin_rpc.RpcCallbacks(mock.Mock(), mock.Mock()) + + def _test_update_device_up(self, extensions, kwargs): + with mock.patch.object(plugin_rpc.manager, 'NeutronManager') as mgr: + with mock.patch.object(self.callbacks, '_device_to_port_id'): + mock_l3plugin = mock.Mock() + mgr.get_service_plugins.return_value = { + 'L3_ROUTER_NAT': mock_l3plugin + } + type(mock_l3plugin).supported_extension_aliases = ( + mock.PropertyMock(return_value=extensions)) + self.callbacks.update_device_up(mock.ANY, **kwargs) + return mock_l3plugin + + def test_update_device_up_without_dvr(self): + kwargs = { + 'agent_id': 'foo_agent', + 'device': 'foo_device' + } + l3plugin = self._test_update_device_up(['router'], kwargs) + self.assertFalse(l3plugin.dvr_vmarp_table_update.call_count) + + def test_update_device_up_with_dvr(self): + kwargs = { + 'agent_id': 'foo_agent', + 'device': 'foo_device' + } + l3plugin = self._test_update_device_up(['router', 'dvr'], kwargs) + l3plugin.dvr_vmarp_table_update.assert_called_once_with( + mock.ANY, mock.ANY, 'add') + + class RpcApiTestCase(base.BaseTestCase): def _test_rpc_api(self, rpcapi, topic, method, rpc_method, **kwargs):