Merge "NSX|V3: ensure that octavia ports receive DHCP addresses"

This commit is contained in:
Jenkins 2016-09-22 05:48:13 +00:00 committed by Gerrit Code Review
commit ffe2d556c3
3 changed files with 16 additions and 10 deletions

View File

@ -20,6 +20,7 @@ import hashlib
import eventlet
from neutron import version as n_version
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_context import context as common_context
@ -281,6 +282,12 @@ def is_ipv4_ip_address(addr):
return True
def is_port_dhcp_configurable(port):
owner = port.get('device_owner')
return (owner and
not owner.startswith(constants.DEVICE_OWNER_NETWORK_PREFIX))
def spawn_n(func, *args, **kwargs):
"""Passthrough method for eventlet.spawn_n.

View File

@ -1412,8 +1412,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
return ips
def _add_dhcp_binding(self, context, port):
if not port["device_owner"].startswith(
const.DEVICE_OWNER_COMPUTE_PREFIX):
if not utils.is_port_dhcp_configurable(port):
return
dhcp_service = nsx_db.get_nsx_service_binding(
context.session, port['network_id'], nsx_constants.SERVICE_DHCP)
@ -1503,9 +1502,11 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
# Note that Neutron allows a port with multiple IPs in the
# same subnet. But backend DHCP server may not support that.
if old_port["device_owner"] != new_port["device_owner"]:
if old_port["device_owner"].startswith(
const.DEVICE_OWNER_COMPUTE_PREFIX):
if (utils.is_port_dhcp_configurable(old_port) !=
utils.is_port_dhcp_configurable(new_port)):
# Note that the device_owner could be changed,
# but still needs DHCP binding.
if utils.is_port_dhcp_configurable(old_port):
self._delete_dhcp_binding(context, old_port)
else:
self._add_dhcp_binding(context, new_port)
@ -1549,8 +1550,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
"DHCP server %(server)s"),
{'ip': new_ip,
'server': dhcp_service['nsx_service_id']})
elif old_port["device_owner"].startswith(
const.DEVICE_OWNER_COMPUTE_PREFIX):
elif utils.is_port_dhcp_configurable(old_port):
# Update static DHCP bindings for a compute port.
bindings = nsx_db.get_nsx_dhcp_bindings(context.session,
old_port['id'])

View File

@ -39,8 +39,7 @@ def list_dhcp_bindings(resource, event, trigger, **kwargs):
"""List DHCP bindings in Neutron."""
comp_ports = [port for port in neutron_client.get_ports()
if port['device_owner'].startswith(
const.DEVICE_OWNER_COMPUTE_PREFIX)]
if nsx_utils.is_port_dhcp_configurable(port)]
LOG.info(formatters.output_formatter(constants.DHCP_BINDING, comp_ports,
['id', 'mac_address', 'fixed_ips']))
@ -77,7 +76,7 @@ def nsx_update_dhcp_bindings(resource, event, trigger, **kwargs):
for port in ports:
device_owner = port['device_owner']
if (device_owner != const.DEVICE_OWNER_DHCP and
not device_owner.startswith(const.DEVICE_OWNER_COMPUTE_PREFIX)):
not nsx_utils.is_port_dhcp_configurable(port)):
continue
for fixed_ip in port['fixed_ips']:
if netaddr.IPNetwork(fixed_ip['ip_address']).version == 6: