]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix L2pop to not send updates for unrelated networks
authorSylvain Afchain <sylvain.afchain@enovance.com>
Wed, 16 Oct 2013 21:28:44 +0000 (23:28 +0200)
committerSylvain Afchain <sylvain.afchain@enovance.com>
Thu, 17 Oct 2013 06:47:15 +0000 (08:47 +0200)
With this patch L2 population mechanism driver
sends updates only with ports related to the
network id of the port which is being updated.

Fixes bug: 1240744
Change-Id: If7d51ce26bf0d0837a00da07fe85f48d55e681c6

neutron/plugins/ml2/drivers/l2pop/db.py
neutron/tests/unit/ml2/drivers/test_l2population.py

index b176a396b7d8773cbf9027ef10a4ed9457070de9..e7bf92d3b9d196478f12752f7a2a7b54566b7016 100644 (file)
@@ -60,6 +60,7 @@ class L2populationDbMixin(base_db.CommonDbMixin):
             query = query.join(agents_db.Agent,
                                agents_db.Agent.host ==
                                ml2_models.PortBinding.host)
+            query = query.join(models_v2.Port)
             query = query.filter(models_v2.Port.network_id == network_id,
                                  models_v2.Port.admin_state_up == True,
                                  agents_db.Agent.agent_type.in_(
index 57a0a2bbe20abd6093c5a88a2bd264813d17173c..f32402d65eb1d3e9520dc35afde7efe260879cd6 100644 (file)
@@ -265,39 +265,71 @@ class TestL2PopulationRpcTestCase(test_plugin.NeutronDbPluginV2TestCase):
         self._register_ml2_agents()
 
         with self.subnet(network=self._network) as subnet:
-            host_arg = {portbindings.HOST_ID: HOST}
+            host_arg = {portbindings.HOST_ID: HOST + '_2'}
             with self.port(subnet=subnet,
                            arg_list=(portbindings.HOST_ID,),
                            **host_arg) as port1:
                 with self.subnet(cidr='10.1.0.0/24') as subnet2:
-                    host_arg = {portbindings.HOST_ID: HOST + '_2'}
                     with self.port(subnet=subnet2,
                                    arg_list=(portbindings.HOST_ID,),
                                    **host_arg):
-                        p1 = port1['port']
-
-                        device = 'tap' + p1['id']
-
-                        self.mock_fanout.reset_mock()
-                        self.callbacks.update_device_up(self.adminContext,
-                                                        agent_id=HOST,
-                                                        device=device)
-
-                        p1_ips = [p['ip_address'] for p in p1['fixed_ips']]
-                        expected = {'args':
-                                    {'fdb_entries':
-                                     {p1['network_id']:
-                                      {'ports':
-                                       {'20.0.0.1': [constants.FLOODING_ENTRY,
-                                                     [p1['mac_address'],
-                                                      p1_ips[0]]]},
-                                       'network_type': 'vxlan',
-                                       'segment_id': 1}}},
-                                    'namespace': None,
-                                    'method': 'add_fdb_entries'}
-
-                        self.mock_fanout.assert_called_with(
-                            mock.ANY, expected, topic=self.fanout_topic)
+                        host_arg = {portbindings.HOST_ID: HOST}
+                        with self.port(subnet=subnet,
+                                       arg_list=(portbindings.HOST_ID,),
+                                       **host_arg) as port3:
+                            p1 = port1['port']
+                            p3 = port3['port']
+
+                            device = 'tap' + p3['id']
+
+                            self.mock_cast.reset_mock()
+                            self.mock_fanout.reset_mock()
+                            self.callbacks.update_device_up(
+                                self.adminContext, agent_id=HOST,
+                                device=device)
+
+                            p1_ips = [p['ip_address']
+                                      for p in p1['fixed_ips']]
+                            expected1 = {'args':
+                                         {'fdb_entries':
+                                          {p1['network_id']:
+                                           {'ports':
+                                            {'20.0.0.2':
+                                             [constants.FLOODING_ENTRY,
+                                              [p1['mac_address'],
+                                               p1_ips[0]]]},
+                                            'network_type': 'vxlan',
+                                            'segment_id': 1}}},
+                                         'namespace': None,
+                                         'method': 'add_fdb_entries'}
+
+                            topic = topics.get_topic_name(topics.AGENT,
+                                                          topics.L2POPULATION,
+                                                          topics.UPDATE,
+                                                          HOST)
+
+                            self.mock_cast.assert_called_with(mock.ANY,
+                                                              expected1,
+                                                              topic=topic)
+
+                            p3_ips = [p['ip_address']
+                                      for p in p3['fixed_ips']]
+                            expected2 = {'args':
+                                         {'fdb_entries':
+                                          {p1['network_id']:
+                                           {'ports':
+                                            {'20.0.0.1':
+                                             [constants.FLOODING_ENTRY,
+                                              [p3['mac_address'],
+                                               p3_ips[0]]]},
+                                            'network_type': 'vxlan',
+                                            'segment_id': 1}}},
+                                         'namespace': None,
+                                         'method': 'add_fdb_entries'}
+
+                            self.mock_fanout.assert_called_with(
+                                mock.ANY, expected2,
+                                topic=self.fanout_topic)
 
     def test_fdb_remove_called_from_rpc(self):
         self._register_ml2_agents()