From e07b6d81080be49e49ca143ed16316eeede7d5e5 Mon Sep 17 00:00:00 2001 From: zhengyong Date: Tue, 28 Apr 2020 14:05:23 +0800 Subject: [PATCH] Revising log with wrong network_id when create port failed Log network_id passed from api rather than subnet['network_id'] Change-Id: I8151253be1ca42bbf4b49f904751565783723769 Closes-Bug: #1844607 --- neutron/db/ipam_backend_mixin.py | 9 +++++---- neutron/db/ipam_pluggable_backend.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index 78955f87f1f..63c5c73d2ee 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -383,7 +383,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): if segment.is_dynamic: raise segment_exc.SubnetCantAssociateToDynamicSegment() - def _get_subnet_for_fixed_ip(self, context, fixed, subnets): + def _get_subnet_for_fixed_ip(self, context, fixed, subnets, network_id): # Subnets are all the subnets belonging to the same network. if not subnets: msg = _('IP allocation requires subnets for network') @@ -396,12 +396,13 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): return subnet subnet = get_matching_subnet() if not subnet: - subnet_obj = self._get_subnet_object(context, - fixed['subnet_id']) + # Call this method to keep original status code + # in case subnet is not found + self._get_subnet_object(context, fixed['subnet_id']) msg = (_("Failed to create port on network %(network_id)s" ", because fixed_ips included invalid subnet " "%(subnet_id)s") % - {'network_id': subnet_obj.network_id, + {'network_id': network_id, 'subnet_id': fixed['subnet_id']}) raise exc.InvalidInput(error_message=msg) # Ensure that the IP is valid on the subnet diff --git a/neutron/db/ipam_pluggable_backend.py b/neutron/db/ipam_pluggable_backend.py index 30807839f7c..b9cfcca2434 100644 --- a/neutron/db/ipam_pluggable_backend.py +++ b/neutron/db/ipam_pluggable_backend.py @@ -291,7 +291,8 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin): fixed_ip_list = [] for fixed in fixed_ips: fixed['device_owner'] = device_owner - subnet = self._get_subnet_for_fixed_ip(context, fixed, subnets) + subnet = self._get_subnet_for_fixed_ip(context, fixed, + subnets, network_id) is_auto_addr_subnet = ipv6_utils.is_auto_address_subnet(subnet) if ('ip_address' in fixed and