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
This commit is contained in:
Kevin Benton 2017-02-19 20:49:58 -08:00
parent f9e5c2a726
commit 8a1371588d
2 changed files with 7 additions and 3 deletions

View File

@ -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

View File

@ -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)