]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fixed floating IP logic in PLUMgrid plugin
authorFawad Khaliq <fawad@plumgrid.com>
Tue, 8 Apr 2014 22:49:35 +0000 (15:49 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:54 +0000 (23:06 +0800)
  * Fixed associate and disassociate
    floating IP logic
  * Added unit tests

Change-Id: I310f5550bca1c9015cbda3e0338eb90a36dc96f1
Closes-Bug: 1298495
(cherry picked from commit 9f8cb33557ecc7c0a832610e913a56a8b8e6c524)

neutron/plugins/plumgrid/drivers/fake_plumlib.py
neutron/plugins/plumgrid/drivers/plumlib.py
neutron/plugins/plumgrid/plumgrid_plugin/plumgrid_plugin.py
neutron/tests/unit/plumgrid/test_plumgrid_plugin.py

index a0a01023d68b4ad3b84ae2c780d006b921e0d477..bf0cb9f9aae3781c92f3ac74549e7fdb15a2c8bd 100644 (file)
@@ -55,7 +55,7 @@ class Plumlib():
     def create_subnet(self, sub_db, net_db, ipnet):
         pass
 
-    def update_subnet(self, org_sub_db, new_sub_db, ipnet):
+    def update_subnet(self, orig_sub_db, new_sub_db, ipnet):
         pass
 
     def delete_subnet(self, tenant_id, net_db, net_id):
@@ -85,11 +85,15 @@ class Plumlib():
     def remove_router_interface(self, tenant_id, net_id, router_id):
         pass
 
-    def create_floatingip(self, net_db, floating_ip):
+    def create_floatingip(self, floating_ip):
         pass
 
-    def update_floatingip(self, net_db, floating_ip, id):
+    def update_floatingip(self, floating_ip_orig, floating_ip, id):
         pass
 
-    def delete_floatingip(self, net_db, floating_ip_org, id):
+    def delete_floatingip(self, floating_ip_orig, id):
         pass
+
+    def disassociate_floatingips(self, fip, port_id):
+        return dict((key, fip[key]) for key in ("id", "floating_network_id",
+                                                "floating_ip_address"))
index 7a6c98c1907f0a14d49c0b97f0d6cd435571dfe3..8e2607e857bfb62fb25c029bca2b79d6bf5b1669 100644 (file)
@@ -57,8 +57,8 @@ class Plumlib(object):
     def create_subnet(self, sub_db, net_db, ipnet):
         self.plumlib.create_subnet(sub_db, net_db, ipnet)
 
-    def update_subnet(self, org_sub_db, new_sub_db, ipnet):
-        self.plumlib.update_subnet(org_sub_db, new_sub_db, ipnet)
+    def update_subnet(self, orig_sub_db, new_sub_db, ipnet):
+        self.plumlib.update_subnet(orig_sub_db, new_sub_db, ipnet)
 
     def delete_subnet(self, tenant_id, net_db, net_id):
         self.plumlib.delete_subnet(tenant_id, net_db, net_id)
@@ -87,11 +87,14 @@ class Plumlib(object):
     def remove_router_interface(self, tenant_id, net_id, router_id):
         self.plumlib.remove_router_interface(tenant_id, net_id, router_id)
 
-    def create_floatingip(self, net_db, floating_ip):
-        self.plumlib.create_floatingip(net_db, floating_ip)
+    def create_floatingip(self, floating_ip):
+        self.plumlib.create_floatingip(floating_ip)
 
-    def update_floatingip(self, net_db, floating_ip, id):
-        self.plumlib.update_floatingip(net_db, floating_ip, id)
+    def update_floatingip(self, floating_ip_orig, floating_ip, id):
+        self.plumlib.update_floatingip(floating_ip_orig, floating_ip, id)
 
-    def delete_floatingip(self, net_db, floating_ip_org, id):
-        self.plumlib.delete_floatingip(net_db, floating_ip_org, id)
+    def delete_floatingip(self, floating_ip_orig, id):
+        self.plumlib.delete_floatingip(floating_ip_orig, id)
+
+    def disassociate_floatingips(self, floating_ip, port_id):
+        self.plumlib.disassociate_floatingips(floating_ip, port_id)
index 2e41aadae19ae38c786bcced938b7ea8b5d96684..17b20f001381b127143d85681d1dfcdf94d8a5c8 100644 (file)
@@ -23,6 +23,7 @@ to the PLUMgrid Network Management System called Director
 
 import netaddr
 from oslo.config import cfg
+from sqlalchemy.orm import exc as sa_exc
 
 from neutron.api.v2 import attributes
 from neutron.common import constants
@@ -335,7 +336,7 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2,
 
         LOG.debug(_("update_subnet() called"))
         # Collecting subnet info
-        org_sub_db = self._get_subnet(context, subnet_id)
+        orig_sub_db = self._get_subnet(context, subnet_id)
 
         with context.session.begin(subtransactions=True):
             # Plugin DB - Subnet Update
@@ -346,7 +347,7 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2,
             try:
                 # PLUMgrid Server does not support updating resources yet
                 LOG.debug(_("PLUMgrid Library: update_network() called"))
-                self._plumlib.update_subnet(org_sub_db, new_sub_db, ipnet)
+                self._plumlib.update_subnet(orig_sub_db, new_sub_db, ipnet)
 
             except Exception as err_message:
                 raise plum_excep.PLUMgridException(err_msg=err_message)
@@ -482,14 +483,9 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2,
 
             floating_ip = super(NeutronPluginPLUMgridV2,
                                 self).create_floatingip(context, floatingip)
-
-            net_id = floating_ip['floating_network_id']
-            net_db = super(NeutronPluginPLUMgridV2,
-                           self).get_network(context, net_id)
-
             try:
                 LOG.debug(_("PLUMgrid Library: create_floatingip() called"))
-                self._plumlib.create_floatingip(net_db, floating_ip)
+                self._plumlib.create_floatingip(floating_ip)
 
             except Exception as err_message:
                 raise plum_excep.PLUMgridException(err_msg=err_message)
@@ -500,18 +496,15 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2,
         LOG.debug(_("Neutron PLUMgrid Director: update_floatingip() called"))
 
         with context.session.begin(subtransactions=True):
-
+            floating_ip_orig = super(NeutronPluginPLUMgridV2,
+                                     self).get_floatingip(context, id)
             floating_ip = super(NeutronPluginPLUMgridV2,
                                 self).update_floatingip(context, id,
                                                         floatingip)
-
-            net_id = floating_ip['floating_network_id']
-            net_db = super(NeutronPluginPLUMgridV2,
-                           self).get_network(context, net_id)
-
             try:
                 LOG.debug(_("PLUMgrid Library: update_floatingip() called"))
-                self._plumlib.update_floatingip(net_db, floating_ip, id)
+                self._plumlib.update_floatingip(floating_ip_orig, floating_ip,
+                                                id)
 
             except Exception as err_message:
                 raise plum_excep.PLUMgridException(err_msg=err_message)
@@ -523,21 +516,39 @@ class NeutronPluginPLUMgridV2(db_base_plugin_v2.NeutronDbPluginV2,
 
         with context.session.begin(subtransactions=True):
 
-            floating_ip_org = super(NeutronPluginPLUMgridV2,
-                                    self).get_floatingip(context, id)
+            floating_ip_orig = super(NeutronPluginPLUMgridV2,
+                                     self).get_floatingip(context, id)
 
-            net_id = floating_ip_org['floating_network_id']
-            net_db = super(NeutronPluginPLUMgridV2,
-                           self).get_network(context, net_id)
             super(NeutronPluginPLUMgridV2, self).delete_floatingip(context, id)
 
             try:
                 LOG.debug(_("PLUMgrid Library: delete_floatingip() called"))
-                self._plumlib.delete_floatingip(net_db, floating_ip_org, id)
+                self._plumlib.delete_floatingip(floating_ip_orig, id)
 
             except Exception as err_message:
                 raise plum_excep.PLUMgridException(err_msg=err_message)
 
+    def disassociate_floatingips(self, context, port_id):
+        LOG.debug(_("Neutron PLUMgrid Director: disassociate_floatingips() "
+                    "called"))
+
+        try:
+            fip_qry = context.session.query(l3_db.FloatingIP)
+            floating_ip = fip_qry.filter_by(fixed_port_id=port_id).one()
+
+            LOG.debug(_("PLUMgrid Library: disassociate_floatingips()"
+                        " called"))
+            self._plumlib.disassociate_floatingips(floating_ip, port_id)
+
+        except sa_exc.NoResultFound:
+            pass
+
+        except Exception as err_message:
+            raise plum_excep.PLUMgridException(err_msg=err_message)
+
+        super(NeutronPluginPLUMgridV2,
+              self).disassociate_floatingips(context, port_id)
+
     """
     Internal PLUMgrid Fuctions
     """
index 6cc39ce793e3312ca2bf7f96919db8c7c4a2ba0c..8cf1868ec830b0eb503c1ab8ccbf7b9c494b42f4 100644 (file)
@@ -148,3 +148,25 @@ class TestPlumgridProvidernet(PLUMgridPluginV2TestCase):
         self.assertEqual(net['network'][provider.NETWORK_TYPE], 'vlan')
         self.assertEqual(net['network'][provider.SEGMENTATION_ID], 3333)
         self.assertEqual(net['network'][provider.PHYSICAL_NETWORK], 'phy3333')
+
+
+class TestDisassociateFloatingIP(PLUMgridPluginV2TestCase):
+
+    def test_disassociate_floating_ip(self):
+        port_id = "abcdefgh"
+        tenant_id = "94eb42de4e331"
+        fip_net_id = "b843d18245678"
+        fip_addr = "10.0.3.44"
+        fip_id = "e623679734051"
+        fip = {"router_id": "94eb42de4e331",
+               "tenant_id": tenant_id,
+               "floating_network_id": fip_net_id,
+               "fixed_ip_address": "192.168.8.2",
+               "floating_ip_address": fip_addr,
+               "port_id": port_id,
+               "id": fip_id}
+        plumlib = importutils.import_object(PLUM_DRIVER)
+        fip_res = plumlib.disassociate_floatingips(fip, port_id)
+        self.assertEqual(fip_res["id"], fip_id)
+        self.assertEqual(fip_res["floating_ip_address"], fip_addr)
+        self.assertEqual(fip_res["floating_network_id"], fip_net_id)