Skip to content

Commit

Permalink
Recycle IPs used by 'gateway' ports
Browse files Browse the repository at this point in the history
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
  • Loading branch information
salv-orlando committed May 21, 2013
1 parent 08c4905 commit 8b3445e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
12 changes: 5 additions & 7 deletions quantum/plugins/nicira/nicira_networkgw_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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
Expand Down Expand Up @@ -267,7 +266,7 @@ def connect_network(self, context, network_gateway_id,
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
Expand Down Expand Up @@ -313,12 +312,11 @@ def connect_network(self, context, network_gateway_id,
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':
Expand Down
29 changes: 29 additions & 0 deletions quantum/tests/unit/nicira/test_networkgw.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,35 @@ def test_connect_unspecified_network_returns_400(self):
'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:
Expand Down

0 comments on commit 8b3445e

Please sign in to comment.