Comment 7 for bug 1731668

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/523192
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=31751a7149a3bb4b51087aecdc3b14c061c60d9b
Submitter: Zuul
Branch: master

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.

    Closes-bug: #1731668
    [1]: https://github.com/openstack/oslo.db/blob/stable/pike/oslo_db/sqlalchemy/exc_filters.py#L95-L153

    Change-Id: Ic5860cbef4d47e847bb5f190526b5a8ea3c33298