Merge "Fix delete_port case in handle_port_metadata_access"

This commit is contained in:
Jenkins 2015-12-17 06:55:48 +00:00 committed by Gerrit Code Review
commit bcb424ac8d

View File

@ -48,14 +48,22 @@ def handle_port_dhcp_access(plugin, context, port_data, action):
def handle_port_metadata_access(plugin, context, port, is_delete=False): def handle_port_metadata_access(plugin, context, port, is_delete=False):
# For instances supporting DHCP option 121 and created in a
# DHCP-enabled but isolated network. This method is useful
# only when no network namespace support.
if (cfg.CONF.NSX.metadata_mode == config.MetadataModes.INDIRECT and if (cfg.CONF.NSX.metadata_mode == config.MetadataModes.INDIRECT and
port.get('device_owner') == const.DEVICE_OWNER_DHCP): port.get('device_owner') == const.DEVICE_OWNER_DHCP):
if port.get('fixed_ips', []) or is_delete: if not port.get('fixed_ips'):
# If port does not have an IP, the associated subnet is in
# deleting state.
LOG.info(_LI('Port %s has no IP due to subnet in deleting state'),
port['id'])
return
fixed_ip = port['fixed_ips'][0] fixed_ip = port['fixed_ips'][0]
query = context.session.query(models_v2.Subnet) query = context.session.query(models_v2.Subnet)
subnet = query.filter( subnet = query.filter(
models_v2.Subnet.id == fixed_ip['subnet_id']).one() models_v2.Subnet.id == fixed_ip['subnet_id']).one()
# If subnet does not have a gateway do not create metadata # If subnet does not have a gateway, do not create metadata
# route. This is done via the enable_isolated_metadata # route. This is done via the enable_isolated_metadata
# option if desired. # option if desired.
if not subnet.get('gateway_ip'): if not subnet.get('gateway_ip'):
@ -83,6 +91,8 @@ def handle_port_metadata_access(plugin, context, port, is_delete=False):
def handle_router_metadata_access(plugin, context, router_id, interface=None): def handle_router_metadata_access(plugin, context, router_id, interface=None):
# For instances created in a DHCP-disabled network but connected to
# a router.
if cfg.CONF.NSX.metadata_mode != config.MetadataModes.DIRECT: if cfg.CONF.NSX.metadata_mode != config.MetadataModes.DIRECT:
LOG.debug("Metadata access network is disabled") LOG.debug("Metadata access network is disabled")
return return