From: Salvatore Orlando Date: Tue, 21 May 2013 18:05:00 +0000 (+0200) Subject: Recycle IPs used by 'gateway' ports X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8b3445eaa5008d3f8c9932ab95a03d0115b6ea32;p=openstack-build%2Fneutron-build.git Recycle IPs used by 'gateway' ports Bug 1182602 Previous code simply removed IP allocation for these ports which should never have an IP. This patch triggers IP recycling so the IP addresses can be reused by other ports. Change-Id: I594e02d5bbc78b219eab07e595cde713d6450ffe --- diff --git a/quantum/plugins/nicira/nicira_networkgw_db.py b/quantum/plugins/nicira/nicira_networkgw_db.py index cc9d51b31..f50a0759d 100644 --- a/quantum/plugins/nicira/nicira_networkgw_db.py +++ b/quantum/plugins/nicira/nicira_networkgw_db.py @@ -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': diff --git a/quantum/tests/unit/nicira/test_networkgw.py b/quantum/tests/unit/nicira/test_networkgw.py index 6a59f7a82..c1fd33c92 100644 --- a/quantum/tests/unit/nicira/test_networkgw.py +++ b/quantum/tests/unit/nicira/test_networkgw.py @@ -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: