Allow no network to be passed into PortContext

This allows a PortContext to be constructed without a network
passed in for cases like update_port_status that don't examine
bindings, segments, or any other network properties.

In the event that a mechanism driver is loaded that does reference
the 'network' property for these occasions, the context will look
up the network then in a late binding fashion.

This will improve the performance of the update_port_status call
from the provisioning blocks callback, which doesn't provide a
cached network to update_port_status.

Partial-Bug: #1665215
Change-Id: I498791614fd456ab67c453cad691f7658d107123
This commit is contained in:
Kevin Benton 2017-02-15 21:40:07 -08:00
parent 2c01ad9c56
commit 60edb4c951
2 changed files with 6 additions and 3 deletions

View File

@ -89,7 +89,7 @@ class PortContext(MechanismDriverContext, api.PortContext):
self._port = port
self._original_port = original_port
self._network_context = NetworkContext(plugin, plugin_context,
network)
network) if network else None
self._binding = binding
self._binding_levels = binding_levels
self._segments_to_bind = None
@ -151,6 +151,11 @@ class PortContext(MechanismDriverContext, api.PortContext):
@property
def network(self):
if not self._network_context:
network = self._plugin.get_network(
self._plugin_context, self.current['network_id'])
self._network_context = NetworkContext(
self._plugin, self._plugin_context, network)
return self._network_context
@property

View File

@ -1747,8 +1747,6 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
# listening for db events can modify the port if necessary
context.session.flush()
updated_port = self._make_port_dict(port)
network = network or self.get_network(
context, original_port['network_id'])
levels = db.get_binding_levels(context, port.id,
port.port_binding.host)
mech_context = driver_context.PortContext(