From 8a1371588d0da485debc2dd8aba4ebad08f3c655 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Sun, 19 Feb 2017 20:49:58 -0800 Subject: [PATCH] Allow no network to be passed into subnet context Similar to change I498791614fd456ab67c453cad691f7658d107123, we can avoid an unnecessary network retrieval by making the network part of the subnet context lazily loaded by allowing None to be passed into the subnet context. If a driver does need items off of the network, the context will trigger a lookup at the time of reference. Partial-Bug: #1665967 Change-Id: Ic6651f1d44fcdbb749c99a6cc2c7300b1036388c --- neutron/plugins/ml2/driver_context.py | 7 ++++++- neutron/plugins/ml2/plugin.py | 3 +-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py index aa16a075dc8..5c374e2a606 100644 --- a/neutron/plugins/ml2/driver_context.py +++ b/neutron/plugins/ml2/driver_context.py @@ -66,7 +66,7 @@ class SubnetContext(MechanismDriverContext, api.SubnetContext): self._subnet = subnet self._original_subnet = original_subnet self._network_context = NetworkContext(plugin, plugin_context, - network) + network) if network else None @property def current(self): @@ -78,6 +78,11 @@ class SubnetContext(MechanismDriverContext, api.SubnetContext): @property def network(self): + if self._network_context is None: + 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 diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 6daf2ddb2a5..4f7bf8cda8a 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1040,9 +1040,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, self.extension_manager.process_update_subnet( context, subnet[attributes.SUBNET], updated_subnet) updated_subnet = self.get_subnet(context, id) - network = self.get_network(context, updated_subnet['network_id']) mech_context = driver_context.SubnetContext( - self, context, updated_subnet, network, + self, context, updated_subnet, network=None, original_subnet=original_subnet) self.mechanism_manager.update_subnet_precommit(mech_context)