Fix L2pop to not send updates for unrelated networks

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
This commit is contained in:
Sylvain Afchain 2013-10-16 23:28:44 +02:00
parent 1cb773f175
commit 42d5f28073
2 changed files with 55 additions and 22 deletions

View File

@ -60,6 +60,7 @@ class L2populationDbMixin(base_db.CommonDbMixin):
query = query.join(agents_db.Agent, query = query.join(agents_db.Agent,
agents_db.Agent.host == agents_db.Agent.host ==
ml2_models.PortBinding.host) ml2_models.PortBinding.host)
query = query.join(models_v2.Port)
query = query.filter(models_v2.Port.network_id == network_id, query = query.filter(models_v2.Port.network_id == network_id,
models_v2.Port.admin_state_up == True, models_v2.Port.admin_state_up == True,
agents_db.Agent.agent_type.in_( agents_db.Agent.agent_type.in_(

View File

@ -265,39 +265,71 @@ class TestL2PopulationRpcTestCase(test_plugin.NeutronDbPluginV2TestCase):
self._register_ml2_agents() self._register_ml2_agents()
with self.subnet(network=self._network) as subnet: 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, with self.port(subnet=subnet,
arg_list=(portbindings.HOST_ID,), arg_list=(portbindings.HOST_ID,),
**host_arg) as port1: **host_arg) as port1:
with self.subnet(cidr='10.1.0.0/24') as subnet2: with self.subnet(cidr='10.1.0.0/24') as subnet2:
host_arg = {portbindings.HOST_ID: HOST + '_2'}
with self.port(subnet=subnet2, with self.port(subnet=subnet2,
arg_list=(portbindings.HOST_ID,), arg_list=(portbindings.HOST_ID,),
**host_arg): **host_arg):
p1 = port1['port'] 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' + p1['id'] device = 'tap' + p3['id']
self.mock_fanout.reset_mock() self.mock_cast.reset_mock()
self.callbacks.update_device_up(self.adminContext, self.mock_fanout.reset_mock()
agent_id=HOST, self.callbacks.update_device_up(
device=device) self.adminContext, agent_id=HOST,
device=device)
p1_ips = [p['ip_address'] for p in p1['fixed_ips']] p1_ips = [p['ip_address']
expected = {'args': for p in p1['fixed_ips']]
{'fdb_entries': expected1 = {'args':
{p1['network_id']: {'fdb_entries':
{'ports': {p1['network_id']:
{'20.0.0.1': [constants.FLOODING_ENTRY, {'ports':
[p1['mac_address'], {'20.0.0.2':
p1_ips[0]]]}, [constants.FLOODING_ENTRY,
'network_type': 'vxlan', [p1['mac_address'],
'segment_id': 1}}}, p1_ips[0]]]},
'namespace': None, 'network_type': 'vxlan',
'method': 'add_fdb_entries'} 'segment_id': 1}}},
'namespace': None,
'method': 'add_fdb_entries'}
self.mock_fanout.assert_called_with( topic = topics.get_topic_name(topics.AGENT,
mock.ANY, expected, topic=self.fanout_topic) 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): def test_fdb_remove_called_from_rpc(self):
self._register_ml2_agents() self._register_ml2_agents()