When posting an 'attach interface' request to Nova with an invalid
ip for defined network, Nova returns an HTTP 500 error. In fact,
Neutron returns 'InvalidInput' error, but Neutron client is not able
to translate this error to a specific exception. So that a general
'BadRequest' exception is thrown. Neutron client and Nova need a more
specific Neutron error type, in order to address and translate the
error in to a proper Nova exception.
APIImpact
Change-Id: Id4d3108234a198c0eb75237ea8991a72bd3cc4bb
Partial-Bug:
1369871
"The number of DNS nameservers exceeds the limit %(quota)s.")
+class InvalidIpForNetwork(BadRequest):
+ message = _("IP address %(ip_address)s is not a valid IP "
+ "for any of the subnets on the specified network.")
+
+
+class InvalidIpForSubnet(BadRequest):
+ message = _("IP address %(ip_address)s is not a valid IP "
+ "for the specified subnet.")
+
+
class IpAddressInUse(InUse):
message = _("Unable to complete operation for network %(net_id)s. "
"The IP address %(ip_address)s is in use.")
IPs. Include the subnet_id in the result if only an IP address is
configured.
- :raises: InvalidInput, IpAddressInUse
+ :raises: InvalidInput, IpAddressInUse, InvalidIpForNetwork,
+ InvalidIpForSubnet
"""
fixed_ip_set = []
for fixed in fixed_ips:
subnet_id = subnet['id']
break
if not found:
- msg = _('IP address %s is not a valid IP for the defined '
- 'networks subnets') % fixed['ip_address']
- raise n_exc.InvalidInput(error_message=msg)
+ raise n_exc.InvalidIpForNetwork(
+ ip_address=fixed['ip_address'])
else:
subnet = self._get_subnet(context, fixed['subnet_id'])
if subnet['network_id'] != network_id:
if (not found and
not self._check_subnet_ip(subnet['cidr'],
fixed['ip_address'])):
- msg = _('IP address %s is not a valid IP for the defined '
- 'subnet') % fixed['ip_address']
- raise n_exc.InvalidInput(error_message=msg)
+ raise n_exc.InvalidIpForSubnet(
+ ip_address=fixed['ip_address'])
if (ipv6_utils.is_auto_address_subnet(subnet) and
device_owner not in
constants.ROUTER_INTERFACE_OWNERS):
class TestContrailPortsV2(test_plugin.TestPortsV2,
ContrailPluginTestCase):
- def setUp(self):
- super(TestContrailPortsV2, self).setUp()
+ def test_create_port_public_network_with_invalid_ip_no_subnet_id(self):
+ super(TestContrailPortsV2, self). \
+ test_create_port_public_network_with_invalid_ip_no_subnet_id(
+ expected_error='ContrailBadRequestError')
+
+ def test_create_port_public_network_with_invalid_ip_and_subnet_id(self):
+ super(TestContrailPortsV2, self). \
+ test_create_port_public_network_with_invalid_ip_and_subnet_id(
+ expected_error='ContrailBadRequestError')
def test_delete_ports_by_device_id(self):
self.skipTest("This method tests rpc API of "
self.assertIn('mac_address', port['port'])
self._delete('ports', port['port']['id'])
+ def test_create_port_public_network_with_invalid_ip_no_subnet_id(self,
+ expected_error='InvalidIpForNetwork'):
+ with self.network(shared=True) as network:
+ with self.subnet(network=network, cidr='10.0.0.0/24'):
+ ips = [{'ip_address': '1.1.1.1'}]
+ res = self._create_port(self.fmt,
+ network['network']['id'],
+ webob.exc.HTTPBadRequest.code,
+ fixed_ips=ips,
+ set_context=True)
+ data = self.deserialize(self.fmt, res)
+ msg = str(n_exc.InvalidIpForNetwork(ip_address='1.1.1.1'))
+ self.assertEqual(expected_error, data['NeutronError']['type'])
+ self.assertEqual(msg, data['NeutronError']['message'])
+
+ def test_create_port_public_network_with_invalid_ip_and_subnet_id(self,
+ expected_error='InvalidIpForSubnet'):
+ with self.network(shared=True) as network:
+ with self.subnet(network=network, cidr='10.0.0.0/24') as subnet:
+ ips = [{'subnet_id': subnet['subnet']['id'],
+ 'ip_address': '1.1.1.1'}]
+ res = self._create_port(self.fmt,
+ network['network']['id'],
+ webob.exc.HTTPBadRequest.code,
+ fixed_ips=ips,
+ set_context=True)
+ data = self.deserialize(self.fmt, res)
+ msg = str(n_exc.InvalidIpForSubnet(ip_address='1.1.1.1'))
+ self.assertEqual(expected_error, data['NeutronError']['type'])
+ self.assertEqual(msg, data['NeutronError']['message'])
+
def test_create_ports_bulk_native(self):
if self._skip_native_bulk:
self.skipTest("Plugin does not support native bulk port create")