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
This commit is contained in:
armando-migliaccio 2014-07-28 20:09:04 -07:00
parent 30556c4a23
commit 3eee50510f
2 changed files with 40 additions and 1 deletions

View File

@ -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):

View File

@ -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):