]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix port creation issue appeared with postgresql backend
authorEugene Nikanorov <enikanorov@mirantis.com>
Thu, 22 Aug 2013 15:08:34 +0000 (19:08 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Fri, 23 Aug 2013 10:14:46 +0000 (14:14 +0400)
IPAllocationPool has relation to IPAvailabilityRange which is setup to
load eagerly. Eager loading is implemented with left outer join which is
incompatible with with_lockmode('update') on postgresql.
The fix redefines eager loading with options(joinedload) making it use
inner join.

fixes bug 1215350

Change-Id: I148d37f2a1c2a340327d36c240eb8173aee9219a

neutron/db/db_base_plugin_v2.py

index b9ae77d14647c52fe241b8f0f639f08ec497fef9..1db6464de9c4ace80955fdb44c7f8277dc6dbec7 100644 (file)
@@ -312,9 +312,11 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
         subnet.
         """
         # Grab all allocation pools for the subnet
-        pool_qry = context.session.query(
-            models_v2.IPAllocationPool).with_lockmode('update')
-        allocation_pools = pool_qry.filter_by(subnet_id=subnet_id)
+        allocation_pools = (context.session.query(
+            models_v2.IPAllocationPool).filter_by(subnet_id=subnet_id).
+            options(orm.joinedload('available_ranges', innerjoin=True)).
+            with_lockmode('update'))
+
         # Find the allocation pool for the IP to recycle
         pool_id = None
         for allocation_pool in allocation_pools: