Merge "Check for existence instead of fetching the whole net object" into stable/ussuri

This commit is contained in:
Zuul 2021-04-25 14:32:27 +00:00 committed by Gerrit Code Review
commit 667f5b5d10
2 changed files with 8 additions and 2 deletions

View File

@ -264,6 +264,11 @@ class DbBasePluginCommon(object):
raise exceptions.SubnetNotFound(subnet_id=id)
return subnet
def _network_exists(self, context, network_id):
query = model_query.query_with_hooks(
context, models_v2.Network, field='id')
return query.filter(models_v2.Network.id == network_id).first()
def _get_subnet_object(self, context, id):
subnet = subnet_obj.Subnet.get_object(context, id=id)
if not subnet:

View File

@ -1309,7 +1309,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
if not validators.is_attr_set(network_id):
msg = _("network_id must be specified.")
raise exc.InvalidInput(error_message=msg)
if not network_obj.Network.objects_exist(context, id=network_id):
if not self._network_exists(context, network_id):
raise exc.NetworkNotFound(net_id=network_id)
subnetpool = subnetpool_obj.SubnetPool.get_object(context,
@ -1419,7 +1419,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
port_data['mac_address'] = p.get('mac_address')
with db_api.CONTEXT_WRITER.using(context):
# Ensure that the network exists.
self._get_network(context, network_id)
if not self._network_exists(context, network_id):
raise exc.NetworkNotFound(net_id=network_id)
# Create the port
db_port = self._create_db_port_obj(context, port_data)