]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
do not raise exception on ip address recycle operation
authorJiajun Liu <jiajun@unitedstack.com>
Wed, 17 Jul 2013 03:00:23 +0000 (03:00 +0000)
committerJiajun Liu <jiajun@unitedstack.com>
Thu, 25 Jul 2013 02:06:32 +0000 (10:06 +0800)
Currenty a exception will raise on ip address recycle operation if the ip
address doesn't belong to any allocation pool which will make user unable
to update port, even worse it will make user unable to create new port.
So do not raise exception if the ip address to be recycled doesn't belong
to any allocation, just delete it from the ip allocation table.

fixes bug 1201692

Change-Id: Icfbded5158f1f4043f69bb1463fd4c830c9714a9

neutron/db/db_base_plugin_v2.py
neutron/tests/unit/test_db_plugin.py

index cdb71632fdd64ae122d9c2c558bed99f84938065..cfb4af8016ffe7588b33214ffee92ca5b194b961 100644 (file)
@@ -362,9 +362,9 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
                 pool_id = allocation_pool['id']
                 break
         if not pool_id:
-            error_message = _("No allocation pool found for "
-                              "ip address:%s") % ip_address
-            raise q_exc.InvalidInput(error_message=error_message)
+            NeutronDbPluginV2._delete_ip_allocation(
+                context, network_id, subnet_id, ip_address)
+            return
         # Two requests will be done on the database. The first will be to
         # search if an entry starts with ip_address + 1 (r1). The second
         # will be to see if an entry ends with ip_address -1 (r2).
index 458019cbdab589199f0cdb61c9daf5f4af88f4e0..8a702a5671d5d082cf121cdd56fb9a3e390d8bb3 100644 (file)
@@ -1707,6 +1707,28 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s
 
                 self.assertEqual(q.count(), 1)
 
+    def test_recycle_ip_address_without_allocation_pool(self):
+        plugin = NeutronManager.get_plugin()
+        allocation_pools = [{"start": '10.0.0.10',
+                             "end": '10.0.0.50'}]
+        with self.subnet(cidr='10.0.0.0/24',
+                         allocation_pools=allocation_pools) as subnet:
+            network_id = subnet['subnet']['network_id']
+            subnet_id = subnet['subnet']['id']
+            fixed_ips = [{"subnet_id": subnet_id,
+                          "ip_address": '10.0.0.100'}]
+            with self.port(subnet=subnet, fixed_ips=fixed_ips) as port:
+                update_context = context.Context('', port['port']['tenant_id'])
+                ip_address = port['port']['fixed_ips'][0]['ip_address']
+                plugin._recycle_ip(update_context,
+                                   network_id,
+                                   subnet_id,
+                                   ip_address)
+
+                q = update_context.session.query(models_v2.IPAllocation)
+                q = q.filter_by(subnet_id=subnet_id)
+                self.assertEqual(q.count(), 0)
+
     def test_recycle_held_ip_address(self):
         plugin = NeutronManager.get_plugin()
         with self.subnet() as subnet: