From 1865255246e78d827c81bb9413a248b4365b1713 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Tue, 13 Apr 2021 18:56:57 +0300 Subject: [PATCH] Pass existing DB obj to save DB requests On port and network update ML2 plugin gets a db object and can pass it to db_base_plugin_v2 when doing super call. Change-Id: I1213f59fe643807f303e3ad7f24925fa333a5512 (cherry picked from commit 02f4eca1ae43b89775171f4f70be54075b95c9dd) --- neutron/db/db_base_plugin_v2.py | 12 ++++++++---- neutron/plugins/ml2/plugin.py | 8 ++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 8a67a20a30b..42867382a1d 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -418,10 +418,12 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, return network @db_api.retry_if_session_inactive() - def update_network(self, context, id, network): + def update_network(self, context, id, network, db_network=None): n = network['network'] + # we dont't use DB objects not belonging to the current active session + db_network = db_network if context.session.is_active else None with db_api.CONTEXT_WRITER.using(context): - network = self._get_network(context, id) + network = db_network or self._get_network(context, id) # validate 'shared' parameter if 'shared' in n: entry = None @@ -1459,11 +1461,13 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, new_mac, current_owner) @db_api.retry_if_session_inactive() - def update_port(self, context, id, port): + def update_port(self, context, id, port, db_port=None): + # we dont't use DB objects not belonging to the current active session + db_port = db_port if context.session.is_active else None new_port = port['port'] with db_api.CONTEXT_WRITER.using(context): - db_port = self._get_port(context, id) + db_port = db_port or self._get_port(context, id) new_mac = new_port.get('mac_address') self._validate_port_for_update(context, db_port, new_port, new_mac) # Note: _make_port_dict is called here to load extension data diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index e8863d232c7..35d435e031c 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1089,9 +1089,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, self._update_provider_network_attributes( context, original_network, net_data) - updated_network = super(Ml2Plugin, self).update_network(context, - id, - network) + updated_network = super(Ml2Plugin, self).update_network( + context, id, network, db_network=db_network) self.extension_manager.process_update_network(context, net_data, updated_network) self._process_l3_update(context, updated_network, net_data) @@ -1651,7 +1650,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, need_port_update_notify |= mac_address_updated original_port = self._make_port_dict(port_db) updated_port = super(Ml2Plugin, self).update_port(context, id, - port) + port, + db_port=port_db) self.extension_manager.process_update_port(context, attrs, updated_port) self._portsec_ext_port_update_processing(updated_port, context,