raise q_exc.BadRequest(resource='floatingip', msg=msg)
port_id = internal_ip = router_id = None
if 'port_id' in fip and fip['port_id']:
- port_qry = context.session.query(l3_db.FloatingIP)
+ fip_qry = context.session.query(l3_db.FloatingIP)
+ port_id, internal_ip, router_id = self.get_assoc_data(
+ context,
+ fip,
+ floatingip_db['floating_network_id'])
try:
- port_qry.filter_by(fixed_port_id=fip['port_id']).one()
+ fip_qry.filter_by(
+ fixed_port_id=fip['port_id'],
+ floating_network_id=floatingip_db['floating_network_id'],
+ fixed_ip_address=internal_ip).one()
raise l3.FloatingIPPortAlreadyAssociated(
port_id=fip['port_id'],
fip_id=floatingip_db['id'],
net_id=floatingip_db['floating_network_id'])
except sa_exc.NoResultFound:
pass
- port_id, internal_ip, router_id = self.get_assoc_data(
- context,
- fip,
- floatingip_db['floating_network_id'])
return (port_id, internal_ip, router_id)
def _update_fip_assoc(self, context, fip, floatingip_db, external_port):
import copy
import mock
+import netaddr
from oslo.config import cfg
from webob import exc
import webtest
fip['floatingip']['id'])
@contextlib.contextmanager
- def floatingip_with_assoc(self, port_id=None, fmt=None,
+ def floatingip_with_assoc(self, port_id=None, fmt=None, fixed_ip=None,
set_context=False):
with self.subnet(cidr='11.0.0.0/24') as public_sub:
self._set_net_external(public_sub['subnet']['network_id'])
- with self.port() as private_port:
+ private_port = None
+ if port_id:
+ private_port = self._show('ports', port_id)
+ with test_db_plugin.optional_ctx(private_port,
+ self.port) as private_port:
with self.router() as r:
sid = private_port['port']['fixed_ips'][0]['subnet_id']
private_sub = {'subnet': {'id': sid}}
fmt or self.fmt,
public_sub['subnet']['network_id'],
port_id=private_port['port']['id'],
+ fixed_ip=fixed_ip,
set_context=False)
yield floatingip
finally:
self.assertEqual(body['floatingip']['fixed_ip_address'],
ip_address)
+ def test_floatingip_update_different_fixed_ip_same_port(self):
+ with self.subnet() as s:
+ ip_range = list(netaddr.IPNetwork(s['subnet']['cidr']))
+ fixed_ips = [{'ip_address': str(ip_range[-3])},
+ {'ip_address': str(ip_range[-2])}]
+ with self.port(subnet=s, fixed_ips=fixed_ips) as p:
+ with self.floatingip_with_assoc(
+ port_id=p['port']['id'],
+ fixed_ip=str(ip_range[-3])) as fip:
+ body = self._show('floatingips', fip['floatingip']['id'])
+ self.assertEqual(fip['floatingip']['id'],
+ body['floatingip']['id'])
+ self.assertEqual(fip['floatingip']['port_id'],
+ body['floatingip']['port_id'])
+ self.assertEqual(str(ip_range[-3]),
+ body['floatingip']['fixed_ip_address'])
+ self.assertIsNotNone(body['floatingip']['router_id'])
+ body_2 = self._update(
+ 'floatingips', fip['floatingip']['id'],
+ {'floatingip': {'port_id': p['port']['id'],
+ 'fixed_ip_address': str(ip_range[-2])}
+ })
+ self.assertEqual(fip['floatingip']['port_id'],
+ body_2['floatingip']['port_id'])
+ self.assertEqual(str(ip_range[-2]),
+ body_2['floatingip']['fixed_ip_address'])
+
def test_floatingip_update_different_router(self):
# Create subnet with different CIDRs to account for plugins which
# do not support overlapping IPs