Avoid segment DB lookup in _expand_segment on port

The port context already has a network attached to it that contains
all of the segments for that network. In all cases the segments the
port wants to lookup should be present here so we can just iterate
over them without a separate DB query.

Partial-Bug: #1665215
Change-Id: I9014c4e401134f4db908ed989e0095d0ca95b7c9
(cherry picked from commit 2c01ad9c56)
This commit is contained in:
Kevin Benton 2017-02-15 21:36:12 -08:00 committed by Ihar Hrachyshka
parent 2ea107f2c8
commit 1960f384aa
1 changed files with 6 additions and 0 deletions

View File

@ -192,6 +192,12 @@ class PortContext(MechanismDriverContext, api.PortContext):
self._original_binding_levels[-1].segment_id)
def _expand_segment(self, segment_id):
for s in self.network.network_segments:
if s['id'] == segment_id:
return s
# TODO(kevinbenton): eliminate the query below. The above should
# always return since the port is bound to a network segment. Leaving
# in for now for minimally invasive change for back-port.
segment = segments_db.get_segment_by_id(self._plugin_context,
segment_id)
if not segment: