Only update SegmentHostMapping for the given host

Now, when an agent removes a physical network from its configuration,
not only the segments with that physical network will be unbinded
from the host of upated agent. All the segments with that physical
network will be unbinded from all hosts. This is incorrect, the
segments should only be unbinded from the host of updated agent.

Change-Id: Iccca843d1682ac54ec87c3b003a33a0fc5c62205
Closes-bug: #1592463
This commit is contained in:
Hong Hui Xiao 2016-06-14 15:35:40 +00:00
parent 93a7bef28b
commit b20188d265
2 changed files with 38 additions and 1 deletions
neutron
services/segments
tests/unit/extensions

@ -173,7 +173,7 @@ def update_segment_host_mapping(context, host, current_segment_ids):
host=host))
stale_segment_ids = previous_segment_ids - current_segment_ids
if stale_segment_ids:
context.session.query(SegmentHostMapping).filter(
segments_host_query.filter(
SegmentHostMapping.segment_id.in_(
stale_segment_ids)).delete(synchronize_session=False)

@ -392,6 +392,43 @@ class TestMl2HostSegmentMappingOVS(HostSegmentMappingTestCase):
segments_host_db[segment['id']]['segment_id'])
self.assertEqual(host2, segments_host_db[segment['id']]['host'])
def test_update_agent_only_change_agent_host_mapping(self):
host1 = 'host1'
host2 = 'host2'
physical_network = 'phys_net1'
with self.network() as network:
network = network['network']
segment1 = self._test_create_segment(
network_id=network['id'],
physical_network=physical_network,
segmentation_id=200,
network_type=p_constants.TYPE_VLAN)['segment']
self._register_agent(host1, mappings={physical_network: 'br-eth-1'},
plugin=self.plugin)
self._register_agent(host2, mappings={physical_network: 'br-eth-1'},
plugin=self.plugin)
# Update agent at host2 should only change mapping with host2.
other_phys_net = 'phys_net2'
segment2 = self._test_create_segment(
network_id=network['id'],
physical_network=other_phys_net,
segmentation_id=201,
network_type=p_constants.TYPE_VLAN)['segment']
self._register_agent(host2, mappings={other_phys_net: 'br-eth-2'},
plugin=self.plugin)
# We should have segment1 map to host1 and segment2 map to host2 now
segments_host_db1 = self._get_segments_for_host(host1)
self.assertEqual(1, len(segments_host_db1))
self.assertEqual(segment1['id'],
segments_host_db1[segment1['id']]['segment_id'])
self.assertEqual(host1, segments_host_db1[segment1['id']]['host'])
segments_host_db2 = self._get_segments_for_host(host2)
self.assertEqual(1, len(segments_host_db2))
self.assertEqual(segment2['id'],
segments_host_db2[segment2['id']]['segment_id'])
self.assertEqual(host2, segments_host_db2[segment2['id']]['host'])
def test_new_segment_after_host_reg(self):
host1 = 'host1'
physical_network = 'phys_net1'