diff --git a/ec2api/api/network_interface.py b/ec2api/api/network_interface.py index 9db839d8..3d31d1e5 100644 --- a/ec2api/api/network_interface.py +++ b/ec2api/api/network_interface.py @@ -118,8 +118,7 @@ def create_network_interface(context, subnet_id, os_port = neutron.create_port(os_port_body)['port'] except (neutron_exception.IpAddressGenerationFailureClient, neutron_exception.OverQuotaClient): - raise exception.NetworkInterfaceLimitExceeded( - subnet_id=subnet_id) + raise exception.InsufficientFreeAddressesInSubnet() except (neutron_exception.IpAddressInUseClient, neutron_exception.BadRequest) as ex: # NOTE(ft): AWS returns InvalidIPAddress.InUse for a primary IP @@ -279,8 +278,7 @@ def assign_private_ip_addresses(context, network_interface_id, neutron.update_port(os_port['id'], {'port': {'fixed_ips': fixed_ips}}) except neutron_exception.IpAddressGenerationFailureClient: - raise exception.NetworkInterfaceLimitExceeded( - subnet_id=subnet['id']) + raise exception.InsufficientFreeAddressesInSubnet() except neutron_exception.IpAddressInUseClient: msg = _('Some of %(addresses)s is assigned, but move is not ' 'allowed.') % {'addresses': private_ip_address} diff --git a/ec2api/exception.py b/ec2api/exception.py index 6271881e..a14e8e27 100644 --- a/ec2api/exception.py +++ b/ec2api/exception.py @@ -462,9 +462,9 @@ class SubnetLimitExceeded(EC2OverlimitException): 'can create') -class NetworkInterfaceLimitExceeded(EC2OverlimitException): - msg_fmt = _('You have reached the limit of network interfaces for subnet' - '%(subnet_id)s.') +class InsufficientFreeAddressesInSubnet(EC2OverlimitException): + msg_fmt = _('The specified subnet does not have enough free addresses to ' + 'satisfy the request.') class AddressLimitExceeded(EC2OverlimitException): diff --git a/ec2api/tests/functional/api/test_network_interfaces.py b/ec2api/tests/functional/api/test_network_interfaces.py index 4fffe063..1e95fbbb 100644 --- a/ec2api/tests/functional/api/test_network_interfaces.py +++ b/ec2api/tests/functional/api/test_network_interfaces.py @@ -142,7 +142,8 @@ class NetworkInterfaceTest(base.EC2TestCase): SubnetId=self.subnet_id) except botocore.exceptions.ClientError as e: error_code = e.response['Error']['Code'] - self.assertEqual('NetworkInterfaceLimitExceeded', error_code) + self.assertEqual('InsufficientFreeAddressesInSubnet', + error_code, e.message) break ni_id = data['NetworkInterface']['NetworkInterfaceId'] res_clean = self.addResourceCleanUp( diff --git a/ec2api/tests/unit/test_network_interface.py b/ec2api/tests/unit/test_network_interface.py index 70a4a335..ef5dd7c9 100644 --- a/ec2api/tests/unit/test_network_interface.py +++ b/ec2api/tests/unit/test_network_interface.py @@ -239,7 +239,7 @@ class NetworkInterfaceTestCase(base.ApiTestCase): self.neutron.create_port.side_effect = cls() do_check({'SubnetId': fakes.ID_EC2_SUBNET_1, 'PrivateIpAddress': fakes.IP_NETWORK_INTERFACE_1}, - 'NetworkInterfaceLimitExceeded') + 'InsufficientFreeAddressesInSubnet') for cls in [neutron_exception.IpAddressInUseClient, neutron_exception.BadRequest]: @@ -656,7 +656,7 @@ class NetworkInterfaceTestCase(base.ApiTestCase): self.neutron.update_port.side_effect = ( neutron_exception.IpAddressGenerationFailureClient()) - do_check('NetworkInterfaceLimitExceeded') + do_check('InsufficientFreeAddressesInSubnet') self.neutron.update_port.side_effect = ( neutron_exception.IpAddressInUseClient())