from neutron.openstack.common import excutils
from neutron.openstack.common import importutils
from neutron.openstack.common import lockutils
+from neutron.openstack.common import log as logging
from neutron.openstack.common import loopingcall
from neutron.plugins.nuage.common import config
from neutron.plugins.nuage.common import constants
from neutron.plugins.nuage import syncmanager
from neutron import policy
+LOG = logging.getLogger(__name__)
+
class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2,
external_net_db.External_net_db_mixin,
net_partition = nuagedb.get_net_partition_by_id(
session, subnet_mapping['net_partition_id'])
self._create_update_port(context, port,
- net_partition['np_name'])
+ net_partition['name'])
+ self._check_floatingip_update(context, port)
updated_port = self._make_port_dict(port)
sg_port = self._extend_port_dict_security_group(
updated_port,
return neutron_fip
- def delete_floatingip(self, context, id):
- fip = self._get_floatingip(context, id)
+ def delete_floatingip(self, context, fip_id):
+ fip = self._get_floatingip(context, fip_id)
port_id = fip['fixed_port_id']
with context.session.begin(subtransactions=True):
if port_id:
params = {
- 'neutron_port_id': id,
+ 'neutron_port_id': port_id,
}
nuage_port = self.nuageclient.get_nuage_port_by_id(params)
if (nuage_port and
'nuage_fip_id': None
}
self.nuageclient.update_nuage_vm_vport(params)
- rtr_id = fip['last_known_router_id']
- if rtr_id:
+ LOG.debug("Floating-ip %(fip)s is disassociated from "
+ "vport %(vport)s",
+ {'fip': fip_id,
+ 'vport': nuage_port['nuage_vport_id']})
+
+ router_id = fip['router_id']
+ else:
+ router_id = fip['last_known_router_id']
+
+ if router_id:
ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid(
context.session,
- rtr_id)
+ router_id)
if not ent_rtr_mapping:
msg = _('router %s is not associated with '
- 'any net-partition') % rtr_id
+ 'any net-partition') % router_id
raise n_exc.BadRequest(resource='floatingip',
msg=msg)
params = {
'router_id': ent_rtr_mapping['nuage_router_id'],
- 'fip_id': id
+ 'fip_id': fip_id
}
fip = self.nuageclient.get_nuage_fip_by_id(params)
if fip:
self.nuageclient.delete_nuage_floatingip(
fip['nuage_fip_id'])
- super(NuagePlugin, self).delete_floatingip(context, id)
+ LOG.debug('Floating-ip %s deleted from VSD', fip_id)
+
+ super(NuagePlugin, self).delete_floatingip(context, fip_id)
def delete_security_group(self, context, id):
filters = {'security_group_id': [id]}
class TestNuageL3NatTestCase(NuagePluginV2TestCase,
test_l3_plugin.L3NatDBIntTestCase):
+ def test_update_port_with_assoc_floatingip(self):
+ with self.subnet(cidr='200.0.0.0/24') as public_sub:
+ self._set_net_external(public_sub['subnet']['network_id'])
+ with self.port() as port:
+ p_id = port['port']['id']
+ with self.floatingip_with_assoc(port_id=p_id):
+ # Update the port with dummy vm info
+ port_dict = {
+ 'device_id': uuidutils.generate_uuid(),
+ 'device_owner': 'compute:Nova'
+ }
+ port = self._update('ports', port['port']['id'],
+ {'port': port_dict})
+ self.assertEqual(port_dict['device_id'],
+ port['port']['device_id'])
+
+ def test_disassociated_floatingip_delete(self):
+ with self.subnet(cidr='200.0.0.0/24') as public_sub:
+ self._set_net_external(public_sub['subnet']['network_id'])
+ with self.port() as port:
+ p_id = port['port']['id']
+ with self.floatingip_with_assoc(port_id=p_id) as fip:
+
+ # Disassociate fip from the port
+ fip = self._update('floatingips', fip['floatingip']['id'],
+ {'floatingip': {'port_id': None}})
+ self.assertIsNone(fip['floatingip']['router_id'])
+
def test_network_update_external_failure(self):
self._test_network_update_external_failure()