]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
fix connection context manager in rc cache
authorJay Pipes <jaypipes@gmail.com>
Thu, 3 Nov 2016 15:31:49 +0000 (11:31 -0400)
committerJay Pipes <jaypipes@gmail.com>
Thu, 3 Nov 2016 15:48:52 +0000 (11:48 -0400)
This patch changes the context manager call in the _refresh_from_db()
method from this:

with ctx.session.connection() as conn:

to this:

with db_api.api_context_manager.reader.connection.using(ctx):

This is necessary to prevent errors about using a closed connection that
surfaced when writing a functional test case that tested that deleting a
custom resource class when inventory is associated with that custom
resource class.

Change-Id: I844d00028281ccbbfa527cd77469592fe1d7c151

nova/db/sqlalchemy/resource_class_cache.py

index 9188958c8abc3b2aa73303d919315699062942f3..97304311fea90e95de14c6cafa81ede799ea7c1b 100644 (file)
@@ -44,7 +44,7 @@ def _refresh_from_db(ctx, cache):
 
     :param cache: ResourceClassCache object to refresh.
     """
-    with ctx.session.connection() as conn:
+    with db_api.api_context_manager.reader.connection.using(ctx) as conn:
         sel = sa.select([_RC_TBL.c.id, _RC_TBL.c.name])
         res = conn.execute(sel).fetchall()
         cache.id_cache = {r[1]: r[0] for r in res}