From f52280287f956f67c7b9c5c53ad945d96dd69103 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Thu, 15 Apr 2021 15:45:16 +0300 Subject: [PATCH] Improve Subnet create performance - pass network dict from ml2 plugin to _create_subnet_postcommit - skip ipam subnet fetch for non ipv6 auto-address subnets - don't count subnets (DB request) if subnet has no segment Change-Id: Iaecfda2700c5316cb25a93496d24ece366e40a4a --- neutron/db/db_base_plugin_v2.py | 10 +++++++--- neutron/plugins/ml2/plugin.py | 3 ++- neutron/services/segments/plugin.py | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 41f9b83e203..ade587e4a17 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -16,6 +16,7 @@ import functools import netaddr +from neutron_lib.api.definitions import external_net as extnet_def from neutron_lib.api.definitions import ip_allocation as ipalloc_apidef from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import portbindings as portbindings_def @@ -739,11 +740,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, @db_api.retry_if_session_inactive() def _create_subnet_postcommit(self, context, result, network=None, ipam_subnet=None): - if not network: + # need to get db net obj with full subnet info either if no network + # is passed or if passed network is an external net dict from + # ml2 plugin (with only IDs in 'subnets') + if not network or network.get(extnet_def.EXTERNAL): network = self._get_network(context, result['network_id']) - if not ipam_subnet: - ipam_subnet = self.ipam.get_subnet(context, result['id']) if hasattr(network, 'external') and network.external: self._update_router_gw_ports(context, @@ -752,6 +754,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, # If this subnet supports auto-addressing, then update any # internal ports on the network with addresses for this subnet. if ipv6_utils.is_auto_address_subnet(result): + if not ipam_subnet: + ipam_subnet = self.ipam.get_subnet(context, result['id']) updated_ports = self.ipam.add_auto_addrs_on_network_ports( context, result, ipam_subnet) for port_id in updated_ports: diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 76e29072269..862f6bebbcd 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1292,7 +1292,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, def _after_create_subnet(self, context, result, mech_context): # db base plugin post commit ops - self._create_subnet_postcommit(context, result) + self._create_subnet_postcommit(context, result, + network=mech_context.network.current) # add network to subnet dict to save a DB call on dhcp notification result['network'] = mech_context.network.current diff --git a/neutron/services/segments/plugin.py b/neutron/services/segments/plugin.py index 7071230de66..be00c92c7a3 100644 --- a/neutron/services/segments/plugin.py +++ b/neutron/services/segments/plugin.py @@ -658,8 +658,8 @@ class SegmentHostRoutes(object): # If there are other subnets on the network and subnet has segment_id # ensure host routes for all subnets are updated. - if (self._count_subnets(context, subnet['network_id']) > 1 and - subnet.get('segment_id')): + if (subnet.get('segment_id') and + self._count_subnets(context, subnet['network_id']) > 1): self._update_routed_network_host_routes(context, subnet['network_id'])