diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 76867cb7af7..c3b06e8c86b 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 817d32f9687..36c5f9a47d7 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'])