]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Make dvr_vmarp_table_update call conditional to dvr extension
authorarmando-migliaccio <armamig@gmail.com>
Tue, 29 Jul 2014 03:09:04 +0000 (20:09 -0700)
committerarmando-migliaccio <armamig@gmail.com>
Tue, 29 Jul 2014 03:31:58 +0000 (20:31 -0700)
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

neutron/plugins/ml2/rpc.py
neutron/tests/unit/ml2/test_rpcapi.py

index 18ab181db04812ef605610926a1d13182ce37159..ae447fa8e431d08d7cd03654652d8d5d34313961 100644 (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):
index 9eed323bfca05a9731ea7f48ffd5b6a5654f4a36..8277b2594bf3b0aebf2ac9bf95a2981f600ce435 100644 (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):