Merge "Trigger dhcp port_update for new auto_address subnets"

This commit is contained in:
Jenkins 2016-02-05 23:55:40 +00:00 committed by Gerrit Code Review
commit 759e55929a
4 changed files with 21 additions and 6 deletions

View File

@ -578,8 +578,12 @@ 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(subnet):
self.ipam.add_auto_addrs_on_network_ports(context, subnet,
ipam_subnet)
updated_ports = self.ipam.add_auto_addrs_on_network_ports(context,
subnet, ipam_subnet)
for port_id in updated_ports:
port_info = {'port': {'id': port_id}}
self.update_port(context, port_id, port_info)
return self._make_subnet_dict(subnet, context=context)
def _get_subnetpool_id(self, context, subnet):

View File

@ -405,6 +405,7 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
and_(models_v2.Port.network_id == network_id,
~models_v2.Port.device_owner.in_(
constants.ROUTER_INTERFACE_OWNERS_SNAT)))
updated_ports = []
for port in ports:
ip_address = self._calculate_ipv6_eui64_addr(
context, subnet, port['mac_address'])
@ -419,9 +420,11 @@ class IpamNonPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
# the corresponding port has been deleted.
with context.session.begin_nested():
context.session.add(allocated)
updated_ports.append(port['id'])
except db_exc.DBReferenceError:
LOG.debug("Port %s was deleted while updating it with an "
"IPv6 auto-address. Ignoring.", port['id'])
return updated_ports
def _calculate_ipv6_eui64_addr(self, context, subnet, mac_addr):
prefix = subnet['cidr']

View File

@ -385,6 +385,7 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
and_(models_v2.Port.network_id == network_id,
~models_v2.Port.device_owner.in_(
constants.ROUTER_INTERFACE_OWNERS_SNAT)))
updated_ports = []
for port in ports:
ip_request = ipam_req.AutomaticAddressRequest(
prefix=subnet['cidr'],
@ -401,6 +402,7 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
# the corresponding port has been deleted.
with context.session.begin_nested():
context.session.add(allocated)
updated_ports.append(port['id'])
except db_exc.DBReferenceError:
LOG.debug("Port %s was deleted while updating it with an "
"IPv6 auto-address. Ignoring.", port['id'])
@ -411,6 +413,7 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
except Exception:
LOG.debug("Reverting IP allocation failed for %s",
ip_address)
return updated_ports
def allocate_subnet(self, context, network, subnet, subnetpool_id):
subnetpool = None

View File

@ -4039,10 +4039,12 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
'_get_subnet',
return_value=mock.Mock()).start()
# Add an IPv6 auto-address subnet to the network
v6_subnet = self._make_subnet(self.fmt, network, 'fe80::1',
'fe80::/64', ip_version=6,
ipv6_ra_mode=addr_mode,
ipv6_address_mode=addr_mode)
with mock.patch.object(manager.NeutronManager.get_plugin(),
'update_port') as mock_updated_port:
v6_subnet = self._make_subnet(self.fmt, network, 'fe80::1',
'fe80::/64', ip_version=6,
ipv6_ra_mode=addr_mode,
ipv6_address_mode=addr_mode)
if (insert_db_reference_error
or device_owner == constants.DEVICE_OWNER_ROUTER_SNAT
or device_owner in constants.ROUTER_INTERFACE_OWNERS):
@ -4052,6 +4054,9 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
else:
# Confirm that the port has been updated with an address
# from the new auto-address subnet
mock_updated_port.assert_called_with(mock.ANY,
port['port']['id'],
mock.ANY)
req = self.new_show_request('ports', port['port']['id'],
self.fmt)
sport = self.deserialize(self.fmt, req.get_response(self.api))