commit 31751a7149a3bb4b51087aecdc3b14c061c60d9b
Author: Jay Pipes <email address hidden>
Date: Mon Nov 27 13:50:00 2017 -0500
Use oslo_db Session in resource_provider.py
In a number of places in resource_provider.py, we're checking for
DBDuplicateError after running conn.execute(). And "conn" is an
SQLAlchemy Connection object. The issue is that DBDuplicateError is not
an SQLAlchemy exception. Instead, it is an oslo_db-specific exception
that is used to mask differences between DB drivers that variably return
an OperationalError or an IntegrityError when a duplicate key is found
[1].
In practice, what this means is that all calling locations that use the
straight "conn.execute()" calling sequence cannot rely on catching
DBDuplicateError (because SQLAlchemy's Connection.execute() method will
never raise it). Instead, all of those calling locations needed to be
updated to use context.session.execute() instead. This allows
DBDuplicateError to be caught properly.
In addition, all the manual construction of transactions in
resource_provider.py that did:
with conn.begin()
needed to have those manual begin() calls removed. The reason is that
oslo_db's Session object (which is what is injected by the enginefacade
into the nova.context.RequestContext) automatically handles creation,
commit and rollback of transactions based on whether the source
entrypoint is a writer or reader context.
Reviewed: https:/ /review. openstack. org/523192 /git.openstack. org/cgit/ openstack/ nova/commit/ ?id=31751a7149a 3bb4b51087aecdc 3b14c061c60d9b
Committed: https:/
Submitter: Zuul
Branch: master
commit 31751a7149a3bb4 b51087aecdc3b14 c061c60d9b
Author: Jay Pipes <email address hidden>
Date: Mon Nov 27 13:50:00 2017 -0500
Use oslo_db Session in resource_ provider. py
In a number of places in resource_ provider. py, we're checking for Error after running conn.execute(). And "conn" is an
DBDuplicate
SQLAlchemy Connection object. The issue is that DBDuplicateError is not
an SQLAlchemy exception. Instead, it is an oslo_db-specific exception
that is used to mask differences between DB drivers that variably return
an OperationalError or an IntegrityError when a duplicate key is found
[1].
In practice, what this means is that all calling locations that use the Error (because SQLAlchemy's Connection. execute( ) method will session. execute( ) instead. This allows Error to be caught properly.
straight "conn.execute()" calling sequence cannot rely on catching
DBDuplicate
never raise it). Instead, all of those calling locations needed to be
updated to use context.
DBDuplicate
In addition, all the manual construction of transactions in provider. py that did:
resource_
with conn.begin()
needed to have those manual begin() calls removed. The reason is that RequestContext) automatically handles creation,
oslo_db's Session object (which is what is injected by the enginefacade
into the nova.context.
commit and rollback of transactions based on whether the source
entrypoint is a writer or reader context.
Closes-bug: #1731668 /github. com/openstack/ oslo.db/ blob/stable/ pike/oslo_ db/sqlalchemy/ exc_filters. py#L95- L153
[1]: https:/
Change-Id: Ic5860cbef4d47e 847bb5f190526b5 a8ea3c33298