Merge "Use ipam AllocationOnAutoAddressSubnet class"

This commit is contained in:
Jenkins 2017-03-20 07:07:37 +00:00 committed by Gerrit Code Review
commit 96367092a0
3 changed files with 14 additions and 14 deletions

View File

@ -23,7 +23,7 @@ from oslo_log import log as logging
from oslo_utils import excutils
from sqlalchemy import and_
from neutron._i18n import _, _LE, _LW
from neutron._i18n import _LE, _LW
from neutron.common import constants as n_const
from neutron.common import ipv6_utils
from neutron.db import ipam_backend_mixin
@ -254,12 +254,8 @@ class IpamPluggableBackend(ipam_backend_mixin.IpamBackendMixin):
subnet['cidr'] != n_const.PROVISIONAL_IPV6_PD_PREFIX):
if (is_auto_addr_subnet and device_owner not in
constants.ROUTER_INTERFACE_OWNERS):
msg = (_("IPv6 address %(address)s can not be directly "
"assigned to a port on subnet %(id)s since the "
"subnet is configured for automatic addresses") %
{'address': fixed['ip_address'],
'id': subnet['id']})
raise n_exc.InvalidInput(error_message=msg)
raise ipam_exc.AllocationOnAutoAddressSubnet(
ip=fixed['ip_address'], subnet_id=subnet['id'])
fixed_ip_list.append({'subnet_id': subnet['id'],
'ip_address': fixed['ip_address']})
else:

View File

@ -54,7 +54,7 @@ class InvalidSubnetRequest(exceptions.BadRequest):
"%(reason)s")
class AllocationOnAutoAddressSubnet(exceptions.NeutronException):
class AllocationOnAutoAddressSubnet(exceptions.InvalidInput):
message = _("IPv6 address %(ip)s cannot be directly "
"assigned to a port on subnet %(subnet_id)s as the "
"subnet is configured for automatic addresses")

View File

@ -1683,25 +1683,29 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
gateway_ip=constants.ATTR_NOT_SPECIFIED) as subnet:
with self.port(subnet=subnet) as port:
ips = port['port']['fixed_ips']
ip_address = '2607:f0d0:1002:51::5'
self.assertEqual(1, len(ips))
port_mac = port['port']['mac_address']
subnet_id = subnet['subnet']['id']
subnet_cidr = subnet['subnet']['cidr']
eui_addr = str(netutils.get_ipv6_addr_by_EUI64(subnet_cidr,
port_mac))
self.assertEqual(ips[0]['ip_address'], eui_addr)
self.assertEqual(ips[0]['subnet_id'], subnet['subnet']['id'])
self.assertEqual(ips[0]['subnet_id'], subnet_id)
data = {'port': {'fixed_ips': [{'subnet_id':
subnet['subnet']['id'],
'ip_address':
'2607:f0d0:1002:51::5'}]}}
data = {'port': {'fixed_ips': [{'subnet_id': subnet_id,
'ip_address': ip_address}]}}
req = self.new_update_request('ports', data,
port['port']['id'])
res = req.get_response(self.api)
err = self.deserialize(self.fmt, res)
self.assertEqual(webob.exc.HTTPClientError.code,
res.status_int)
self.assertEqual('InvalidInput', err['NeutronError']['type'])
self.assertEqual('AllocationOnAutoAddressSubnet',
err['NeutronError']['type'])
msg = str(ipam_exc.AllocationOnAutoAddressSubnet(
ip=ip_address, subnet_id=subnet_id))
self.assertEqual(err['NeutronError']['message'], msg)
def test_requested_duplicate_mac(self):
with self.port() as port: