]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Force service provider relationships to load
authorBrandon Logan <brandon.logan@rackspace.com>
Wed, 9 Dec 2015 00:24:28 +0000 (18:24 -0600)
committerBrandon Logan <brandon.logan@rackspace.com>
Thu, 10 Dec 2015 07:26:51 +0000 (01:26 -0600)
A race condition was exposed in the LBaaS V2 db layer that was caused by a
hack to get around this issue.  The real issue is that since the
ProviderResourceAssociation is inserted independently, any models that were
created before this insert will not have their relationship with the
ProviderResourceAssocation loaded.  Using the session.expire_all method will
force the session to retrieve all new data and load this relationship for any
resource that uses this relationship.

Change-Id: I940b541f4ef9c489126cd2d215b1d857f0624de0
Closes-Bug: #1504465

neutron/db/servicetype_db.py

index 825f3cff2dfa9f670f52be69ae9f4d7ec04dc5bd..61f2de56f897ab9e60d14cdd090e2fc154e41080 100644 (file)
@@ -93,6 +93,14 @@ class ServiceTypeManager(object):
             assoc = ProviderResourceAssociation(provider_name=provider_name,
                                                 resource_id=resource_id)
             context.session.add(assoc)
+        # NOTE(blogan): the ProviderResourceAssociation relationship will not
+        # be populated if a resource was created before this.  The expire_all
+        # will force the session to go retrieve the new data when that
+        # resource will be read again.  It has been suggested that we can
+        # crawl through everything in the mapper to find the resource with
+        # the ID that matches resource_id and expire that one, but we can
+        # just start with this.
+        context.session.expire_all()
 
     def del_resource_associations(self, context, resource_ids):
         if not resource_ids: