diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index 5d797c08999..102f54e053f 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