Only do deferred ip allocation on deferred ports

Only do deferred ip allocation on ports that were originally marked as
deferred IP ports on port create.

Change-Id: Ia34bc2617f99cca73f58c9e615a8ba78e667c9b3
Closes-Bug: #1617409
This commit is contained in:
Carl Baldwin 2016-09-12 16:09:50 -06:00
parent 3783dea6b2
commit ab4ee76c8b
2 changed files with 33 additions and 5 deletions

View File

@ -36,6 +36,7 @@ from neutron.db import db_base_plugin_common
from neutron.db.models import subnet_service_type as sst_model
from neutron.db import models_v2
from neutron.db import segments_db
from neutron.extensions import ip_allocation as ipa
from neutron.extensions import portbindings
from neutron.extensions import segment
from neutron.ipam import exceptions as ipam_exceptions
@ -725,9 +726,11 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
fixed_ips_requested = validators.is_attr_set(new_port.get('fixed_ips'))
old_ips = old_port.get('fixed_ips')
deferred_ip_allocation = (host and not old_host
and not old_ips
and not fixed_ips_requested)
deferred_ip_allocation = (
old_port.get('ip_allocation') == ipa.IP_ALLOCATION_DEFERRED
and host and not old_host
and not old_ips
and not fixed_ips_requested)
if not deferred_ip_allocation:
# Check that any existing IPs are valid on the new segment
new_host_requested = host and host != old_host

View File

@ -1153,14 +1153,39 @@ class TestSegmentAwareIpam(SegmentTestCase):
port = self._create_deferred_ip_port(network)
# Create the subnet and try to update the port to get an IP
with self.subnet(network=network) as subnet:
with self.subnet(network=network):
data = {'port': {portbindings.HOST_ID: 'fakehost'}}
port_id = port['port']['id']
port_req = self.new_update_request('ports', data, port_id)
response = port_req.get_response(self.api)
self.assertEqual(webob.exc.HTTPOk.code, response.status_int)
self._assert_one_ip_in_subnet(response, subnet['subnet']['cidr'])
res = self.deserialize(self.fmt, response)
self.assertEqual(0, len(res['port']['fixed_ips']))
def test_port_update_deferred_allocation_no_ipam(self):
"""Binding information is provided on update. Don't allocate."""
with self.network() as network:
with self.subnet(network=network):
pass
response = self._create_port(self.fmt,
net_id=network['network']['id'],
tenant_id=network['network']['tenant_id'],
fixed_ips=[])
port = self.deserialize(self.fmt, response)
ips = port['port']['fixed_ips']
self.assertEqual(0, len(ips))
# Create the subnet and try to update the port to get an IP
data = {'port': {portbindings.HOST_ID: 'fakehost'}}
port_id = port['port']['id']
port_req = self.new_update_request('ports', data, port_id)
response = port_req.get_response(self.api)
self.assertEqual(webob.exc.HTTPOk.code, response.status_int)
res = self.deserialize(self.fmt, response)
self.assertEqual(0, len(res['port']['fixed_ips']))
def test_port_update_deferred_allocation_no_segments_manual_alloc(self):
"""Binding information is provided, subnet created after port"""