From 7502c26d385072c0e30a1849a579c44b37bbaf31 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Wed, 15 Feb 2017 21:40:07 -0800 Subject: [PATCH] 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. Conflicts: neutron/plugins/ml2/plugin.py Partial-Bug: #1665215 Change-Id: I498791614fd456ab67c453cad691f7658d107123 (cherry picked from commit 60edb4c9519543a04d5ccc73c8b5371123fefcd8) --- neutron/plugins/ml2/driver_context.py | 7 ++++++- neutron/plugins/ml2/plugin.py | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py index afc73911615..43df5d3d808 100644 --- a/neutron/plugins/ml2/driver_context.py +++ b/neutron/plugins/ml2/driver_context.py @@ -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 diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index b337af27771..8fefeff7aae 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1732,8 +1732,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(session, port.id, port.port_binding.host) mech_context = driver_context.PortContext(