13 Commits

Author SHA1 Message Date
rossella
1b7c295d52 Retry query if db deadlock error is received
Add a decorator retry_on_deadlock(). All db.api functions marked
with this decorator will be retried if a DBDeadlock exception is
received.

Change-Id: I3488bfec67ec1c563292f1b61a7a9697f118809c
Closes-bug: 1348588
2015-01-14 09:56:02 +00:00
Jenkins
67c6f02bb9 Merge "Ensure DBConnectionError is raised on failed revalidate" 2015-01-13 15:13:04 +00:00
Mike Bayer
b1fc55c7ce Restore the check_foreign_keys() method.
This method was prematurely removed from oslo.db without
a deprecation phase, when Alembic added support for
foreign key autodetection.   oslo.db continues to use
alembic for this purpose, however the
ModelsMigrationsSync.check_foreign_keys() method is restored
directly for those projects which were calling into it
explicitly.

Change-Id: Id892567bd60d6b4b88765bbfe3cd5c5e75910b25
2015-01-12 17:26:23 -05:00
Mike Bayer
046e576467 Ensure DBConnectionError is raised on failed revalidate
The second call to connection.scalar() inside of _connect_ping_listener()
is not subject to the exc_filters system under SQLAlchemy 0.9 and earlier,
in the case that the attempt to revalidate within fails.  This causes
the exception to be propagated outwards as the original
OperationalError (assuming that's what the DBAPI raised, as is typical),
rather than it being wrapped again in DBConnectionError.

SQLAlchemy 1.0 has altered this behavior such that the handle_error()
listener is invoked correctly for revalidiation attempts (it was being
invoked before, but without the correct state), as well as
for initial connect attempts, as part of
https://bitbucket.org/zzzeek/sqlalchemy/issue/3266/.  For 0.9 and earlier,
we here backport this system into oslo/db/sqlalchemy/compat.py,
including that we redefine the connection pool's handler to re-throw
the original dbapi.Error instance directly, then move the handling
of this error in terms of SQLAlchemy wrapping and events into
the Engine and Connection.   The approach here works back to
SQLAlchemy 0.8, and is conditional based on whether or not
SQLAlchemy 1.0 is detected.

Change-Id: I455e957b043318a8500909c66cadde53228b52d6
2015-01-12 16:02:01 -05:00
Jenkins
b84d921ac8 Merge "Make sure sort_key_attr is QueryableAttribute when query" 2015-01-12 17:17:24 +00:00
Eli Qiao
bce8ed3042 Make sure sort_key_attr is QueryableAttribute when query
When doing query.order_by, sort_key_attr is get from model class,
we need to make sure sort_key_attr is really a QueryableAttribute
type instance before we do the query or it will cause errors.
This will prevent if there IS a function which name is same as sort_key.

Closes-Bug: 1405069
Change-Id: I8a3eb08ab3469ec08e05bfce754b664943d65c83
2015-01-09 06:12:06 +08:00
Mike Bayer
cfbe5c5634 Ensure mysql_sql_mode is set for MySQLOpportunisticTests
The default setting for oslo.db is TRADITIONAL for mysql_sql_mode;
this is set up in oslo_db/options.py as well as
in EngineFacade; however, the provisioning system currently does not
use these options or EngineFacade, and the default for
mysql_sql_mode in the base session.create_engine() is None.
For a MySQL/MariaDB database where this is not established in my.cnf,
tests will run without TRADITIONAL SQL mode and some tests will fail,
including some Nova migration tests that rely upon this.

This patch resolves that as well as the warning we see
in tests regarding the empty SQL mode.

Change-Id: I3acdc0fb30327f56a76ee299cc6bade7c5a7e312
2015-01-08 11:59:47 +02:00
Jenkins
98b434db7d Merge "Ensure PostgreSQL connection errors are wrapped" 2015-01-06 02:07:43 +00:00
Jenkins
d0c13d2a13 Merge "Fix PatchStacktraceTest test" 2015-01-05 13:05:26 +00:00
Victor Sergeyev
91b0199a4f Fix PatchStacktraceTest test
After we moved out from the namespaces, tests were moved to
oslo_db/tests. The code in oslo_db.sqlalchemy.session filters out
lines from modules under oslo_db, so the test filename does not
appear in the context for the error message.
Use patched traceback module in tests to fix it.

Closes-Bug: #1405376

Change-Id: Id6022c065dfe13351fca5e54baa343d6c96b0270
2015-01-05 09:31:48 +00:00
Roman Podoliaka
30433383c7 Ensure PostgreSQL connection errors are wrapped
Currently PostgreSQL connection errors are not wrapped with our
custom DBConnectionError and engine.connect() will raise
OperationalError instead.

Change-Id: Iefdb9a99ca0cbe982bf12cb7e1ac47996fc5a025
2015-01-05 11:28:54 +02:00
Ann Kamyshnikova
75b402be3b Remove check_foreign_keys from ModelsMigrationsSync
Alembic 0.7.1 contains checks of foreign keys so method
check_foreign_keys is not needed anymore.

Change-Id: I77a2bba2de08125b5a601de03c1d2d5c73fa33ee
2014-12-31 11:56:59 +03:00
Doug Hellmann
7063585c60 Move files out of the namespace package
Move the public API out of oslo.db to oslo_db. Retain the ability to
import from the old namespace package for backwards compatibility for
this release cycle.

Blueprint: drop-namespace-packages

Change-Id: Ie96b482b9fbcb1d85203ad35bb65c1f43e912a44
2014-12-24 13:28:48 +02:00