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
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
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
This commit fixes the output from pretty_tox.sh so that the testr
slowest output is gobbled up by the pipe into subunit-trace.
Change-Id: I4e23cb3c3773e58a297416c1f51996fef059330a
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
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
This ports Nova/Neutron's'(and others) "pretty tox" script into tools/
and establishes it within tox.ini. This causes a vanilla test run
to output the full package names of all tests, the index of the
subprocess it's being run within, as well as the total run time
and status of each test. It also captures stdout/stderr and reports on that
as well; revealing that oslo.db's tests have a lot of deprecation
warnings in fact.
The display of this runner shows a lot more information than the
default testr/subunit thing which is somewhat useless, and for
those who are actually watching the test output, this is what
we'd most like to see.
Pretty Tox. Pretty please, can we have?
Change-Id: I50d1c6e998425964dd9a5497c2bc1e9145be3120
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
Currently PostgreSQL connection errors are not wrapped with our
custom DBConnectionError and engine.connect() will raise
OperationalError instead.
Change-Id: Iefdb9a99ca0cbe982bf12cb7e1ac47996fc5a025
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
Update the README to fix the link to the bug reporting site and to
provide a slightly more detailed description of the library.
Change-Id: I8896297bd8d7a64c72e17c0d9a985cb35991e41d
The two regexp-based filters in exc_filters.py->_is_db_connection_error()
were both incorrectly formed. The tests for these filters would pass
because the fixture also set the is_disconnect flag to True, which
normally would be set by SQLAlchemy, and therefore the
_raise_operational_errors_directly_filter() or possibly
the _raise_for_remaining_DBAPIError() filters would catch this,
view the is_disconnect flag as True, and promote to a DBConnectionError.
However, the _is_db_connection_error() filters are intended to
work independently of whether this flag is set; so two new tests
are added which unset the flag, and ensure that the exception messages
as given are caught here.
Change-Id: I37ddd669b89669730ae1ff07c7bc7a6ba5705f67
In python3.x the 'uee' variable will be removed from the
scope after the except block exits (if it ever is entered)
so we need to use a different variable name to ensure that
it will not be deleted so we can use it later.
Change-Id: Ia86a2bd1a46e57eaf47704eadc991fd0c9b08661
Tests in TestConnectionUtils class depends on database and DB connector,
so the simplest way to run them with python 3.X is to use same database
and connector for the both python versions. PostgreSQL and psycopg2 are
looks good for this.
Replaced ``mysql`` to ``postgresql`` in TestConnectionUtils.
Change-Id: Icb1d6324b58feed515e4eb885715cbf2195768cf
This patch applies upgrades to the sqlalchemy/exc_filters.py and
sqlalchemy/compat/handle_error.py compatibility layers to accommodate
new changes in SQLAlchemy 1.0. SQLA 1.0 will now route errors that
occur upon connect through the handle_error() event, just like any other,
so that when 1.0 is present we no longer need to use
exc_filters.handle_connect_error; the method becomes a passthrough
as far as running the event handler. Additionally, SQLAlchemy 1.0
has added the "engine" parameter to ExceptionContext, specifically
to suit the case when the initial connect has failed and there is
no Connection object; the compatibility layer here now emulates
this behavior for SQLAlchemy versions prior to 1.0.
Change-Id: I61714f3c32625a621eaba501d20346519b8b12c7
Replace URLs for workflow documentation to appropriate parts of the
OpenStack Project Infrastructure Manual.
Change-Id: I318dea15e0d2f7ef22427fe22d8d57173e60e784
Add a check that models.ModelBase is iterable.
Remove checking on next() method since models.modelBase
isn't actually iterator.
Remove unnecessary checks from TimestampMixinTest
Change-Id: Ibbde0e49bec25e1acddaf64f03083cf46481a581
The tests in tests/sqlalchemy/test_migrations.py which expect
to see changes in unique constraints fail due to the
assumption that the "include_object" feature of Alembic only
deals with the 'table' and 'column' constructs. As Alembic
0.7.0 has added include_object support for 'index' and
'unique_constraint', this method should not be limiting
itself to not include objects that it's testing for.
Tests won't pass on Alembic 0.7.0 without this patch.
Change-Id: Ia71446bb8c0b248c6310534deb290524e3946987