Skip to content

Commit

Permalink
Make dvr_vmarp_table_update call conditional to dvr extension
Browse files Browse the repository at this point in the history
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
  • Loading branch information
armando-migliaccio committed Jul 29, 2014
1 parent 30556c4 commit 3eee505
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
5 changes: 4 additions & 1 deletion neutron/plugins/ml2/rpc.py
Expand Up @@ -18,6 +18,7 @@
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
Expand Down Expand Up @@ -190,7 +191,9 @@ def update_device_up(self, rpc_context, **kwargs):
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):
Expand Down
36 changes: 36 additions & 0 deletions neutron/tests/unit/ml2/test_rpcapi.py
Expand Up @@ -28,6 +28,42 @@
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):
Expand Down

0 comments on commit 3eee505

Please sign in to comment.