def _allocate_fixed_ips(self, context, fixed_ips, mac_address):
"""Allocate IP addresses according to the configured fixed_ips."""
ips = []
+
+ # we need to start with entries that asked for a specific IP in case
+ # those IPs happen to be next in the line for allocation for ones that
+ # didn't ask for a specific IP
+ fixed_ips.sort(key=lambda x: 'ip_address' not in x)
for fixed in fixed_ips:
subnet = self._get_subnet(context, fixed['subnet_id'])
is_auto_addr = ipv6_utils.is_auto_address_subnet(subnet)
self.assertIn('mac_address', port['port'])
self._delete('ports', port['port']['id'])
+ def test_create_port_anticipating_allocation(self):
+ with self.network(shared=True) as network:
+ with self.subnet(network=network, cidr='10.0.0.0/24') as subnet:
+ fixed_ips = [{'subnet_id': subnet['subnet']['id']},
+ {'subnet_id': subnet['subnet']['id'],
+ 'ip_address': '10.0.0.2'}]
+ self._create_port(self.fmt, network['network']['id'],
+ webob.exc.HTTPCreated.code,
+ fixed_ips=fixed_ips)
+
def test_create_port_public_network_with_invalid_ip_no_subnet_id(self,
expected_error='InvalidIpForNetwork'):
with self.network(shared=True) as network: