]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix for floating ip association and deletion
authorSayaji <sayaji15@gmail.com>
Wed, 30 Jul 2014 18:06:59 +0000 (11:06 -0700)
committerSayaji <sayaji15@gmail.com>
Wed, 10 Sep 2014 22:45:21 +0000 (15:45 -0700)
Added code to associate fip to a vm in VSD, if
the fip was already associated with the vm port
in Neutron. Also added code in fip deletion,
to get the correct router id based on the check
if the fip is associated to a Neutron port or
not.
Closes-Bug: #1350469
Change-Id: I1aa24f420f656043086a4f501b15722216b843e9

neutron/plugins/nuage/plugin.py
neutron/tests/unit/nuage/test_nuage_plugin.py

index f0041e18ee9c2795a20731e6b419c0da0d522376..e29e60e9554b99a26846218ac5cfa5ab7d525f23 100644 (file)
@@ -41,6 +41,7 @@ from neutron.extensions import securitygroup as ext_sg
 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
@@ -51,6 +52,8 @@ from neutron.plugins.nuage import nuagedb
 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,
@@ -279,7 +282,8 @@ class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2,
                     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,
@@ -1232,13 +1236,13 @@ class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2,
 
         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
@@ -1248,25 +1252,35 @@ class NuagePlugin(db_base_plugin_v2.NeutronDbPluginV2,
                         '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]}
index 16c049a703a6328c541583d1a3e9e38c519eeda2..2bad4dadc4e7ed14ea2bf344c82aba22c98630fc 100644 (file)
@@ -373,6 +373,34 @@ class TestNuagePluginPortBinding(NuagePluginV2TestCase,
 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()