Merge "Recycle IPs used by 'gateway' ports"

This commit is contained in:
Jenkins 2013-05-22 14:46:00 +00:00 committed by Gerrit Code Review
commit f700f26da5
2 changed files with 34 additions and 7 deletions

View File

@ -26,7 +26,6 @@ from webob import exc as web_exc
from quantum.api.v2 import attributes
from quantum.api.v2 import base
from quantum.common import exceptions
from quantum.db import db_base_plugin_v2
from quantum.db import model_base
from quantum.db import models_v2
from quantum.openstack.common import log as logging
@ -267,7 +266,7 @@ class NetworkGatewayMixin(nvp_networkgw.NetworkGatewayPluginBase):
network_mapping_info):
raise GatewayConnectionInUse(mapping=network_mapping_info,
gateway_id=network_gateway_id)
# TODO(salvatore-orlando): This will give the port a fixed_ip,
# TODO(salvatore-orlando): Creating a port will give it an IP,
# but we actually do not need any. Instead of wasting an IP we
# should have a way to say a port shall not be associated with
# any subnet
@ -313,12 +312,11 @@ class NetworkGatewayMixin(nvp_networkgw.NetworkGatewayPluginBase):
gw_db.network_connections.append(
NetworkConnection(**network_mapping_info))
port_id = port['id']
# now deallocate the ip from the port
# now deallocate and recycle ip from the port
for fixed_ip in port.get('fixed_ips', []):
db_base_plugin_v2.QuantumDbPluginV2._delete_ip_allocation(
context, network_id,
fixed_ip['subnet_id'],
fixed_ip['ip_address'])
self._recycle_ip(context, network_id,
fixed_ip['subnet_id'],
fixed_ip['ip_address'])
LOG.debug(_("Ensured no Ip addresses are configured on port %s"),
port_id)
return {'connection_info':

View File

@ -462,6 +462,35 @@ class NetworkGatewayDbTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
'vlan', 555,
expected_status=exc.HTTPBadRequest.code)
def test_connect_network_does_not_waste_ips(self):
# Ensure address is immediately recycled
cfg.CONF.set_override('dhcp_lease_duration', -1)
with self._network_gateway() as gw:
with self.network() as net:
with self.subnet(network=net) as sub:
with self.port(subnet=sub) as port_1:
expected_ips = port_1['port']['fixed_ips']
# port_1 has now been deleted
body = self._gateway_action('connect',
gw[self.resource]['id'],
net['network']['id'],
'flat')
gw_port_id = body['connection_info']['port_id']
gw_port_body = self._show('ports', gw_port_id)
self.assertEqual(gw[self.resource]['id'],
gw_port_body['port']['device_id'])
self.assertEqual([], gw_port_body['port']['fixed_ips'])
# Verify a new port gets same address as port_1
# This will confirm the gateway port did not waste an ip
with self.port(subnet=sub) as port_2:
self.assertEqual(expected_ips,
port_2['port']['fixed_ips'])
# Clean up - otherwise delete will fail
self._gateway_action('disconnect',
gw[self.resource]['id'],
net['network']['id'],
'flat')
def test_disconnect_network_ambiguous_returns_409(self):
with self._network_gateway() as gw:
with self.network() as net_1: