Merge "segments: fix scheduling duplicate segments"
This commit is contained in:
commit
26ce2e28de
@ -500,8 +500,13 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
|
||||
subnets = subnet_obj.Subnet.get_objects(
|
||||
payload.context, segment_id=segment_ids)
|
||||
network_ids = {s.network_id for s in subnets}
|
||||
|
||||
# pre-compute net-id per segments.
|
||||
netsegs = {}
|
||||
[netsegs.setdefault(s['network_id'], []).append(s)
|
||||
for s in segments if 'network_id' in s]
|
||||
for network_id in network_ids:
|
||||
for segment in segments:
|
||||
for segment in netsegs.get(network_id, []):
|
||||
self._schedule_network(
|
||||
payload.context, network_id, dhcp_notifier,
|
||||
candidate_hosts=segment['hosts'])
|
||||
|
@ -1595,10 +1595,16 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn,
|
||||
payload = events.DBEventPayload(
|
||||
ctx,
|
||||
metadata={'host': 'HOST A',
|
||||
'current_segment_ids': set(['segment-1'])})
|
||||
'current_segment_ids': set([
|
||||
'segment-1', 'segment-2', 'segment-3'])})
|
||||
segments_plugin = mock.Mock()
|
||||
segments_plugin.get_segments.return_value = [
|
||||
{'id': 'segment-1', 'hosts': ['HOST A']}]
|
||||
{'id': 'segment-1', 'hosts': ['HOST A'],
|
||||
'network_id': 'net-1'},
|
||||
{'id': 'segment-2', 'hosts': ['HOST A', 'HOST B'],
|
||||
'network_id': 'net-1'},
|
||||
{'id': 'segment-3', 'hosts': ['HOST A', 'HOST C'],
|
||||
'network_id': 'net-2'}]
|
||||
dhcp_notifier = mock.Mock()
|
||||
dhcp_mixin = agentschedulers_db.DhcpAgentSchedulerDbMixin()
|
||||
with mock.patch(
|
||||
@ -1618,9 +1624,14 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn,
|
||||
resources.SEGMENT_HOST_MAPPING, events.AFTER_CREATE,
|
||||
ctx, payload)
|
||||
if subnet_on_segment:
|
||||
schedule_network.assert_called_once_with(
|
||||
ctx, subnet_on_segment.network_id,
|
||||
dhcp_notifier, candidate_hosts=['HOST A'])
|
||||
self.assertEqual(schedule_network.mock_calls, [
|
||||
mock.call(
|
||||
ctx, subnet_on_segment.network_id,
|
||||
dhcp_notifier, candidate_hosts=['HOST A']),
|
||||
mock.call(
|
||||
ctx, subnet_on_segment.network_id,
|
||||
dhcp_notifier, candidate_hosts=['HOST A', 'HOST B'])
|
||||
])
|
||||
else:
|
||||
schedule_network.assert_not_called()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user