Add disconnect modification support to exception handling

This patch backports an additional feature from the
SQLAlchemy 0.9.7 handle_error() event, the ability to alter the
"is disconnect" status of an exception.  In this case, the
supported case is only to take an exception that's not a disconnect,
and to graduate it to a disconnect.  Going in the other direction
isn't possible with the approach here because the connection invalidation
would already have taken place, as we are wrapping the _handle_dbapi_error()
method.

We may want to be able to promote an exception to "is disconnect" in
cases where special database configurations or backends such as that of
Percona have complex detection scenarios not covered by SQLAlchemy's
provided backends.

partially implement bp: use-events-for-error-wrapping

Change-Id: I23a4da2dc39af015a01d6d587c57c5e1c4b95f31
Integrate the ping listener into the filter system.

Replace the use of the connection pool "checkout" event
for "pinging" a connection with the use of the Connection.begin()
event.  This event corresponds to the start of a transaction, so
will "ping" the connection for every transaction rather than just
on checkout, and by running at the level of Connection rather
than the pool, we have access to the whole range of services we
need, including that we can emit a core "select([1])" that will
work on all backends, we get the use of the handle_error() event,
and we get the built in checking for "is disconnect" as well
as the engine/pool being invalidated or disposed as is appropriate
for the SQLAlchemy version in use.  The begin() event is a safe
place to recycle the connection from an invalid state back to
a ready state.

partially implement bp: use-events-for-error-wrapping

Change-Id: Ic29e12f1288f084a5e727101686dd71b12a5787b
Port _is_db_connection_error check to exception filters

The last part where we are handling DB exceptions is the
_is_db_connection_error() function, which is called within a retry
loop inside of session.create_engine() to perform an initial
connection test.  SQLAlchemy currently does not run "connect"
errors through the exception handling system.  In order to have
these exceptions participate in the filtering system, add
a new function handle_connect_error(engine) which runs
engine.connect() and feeds the exception into the
handler(context) system directly, producing a compatible context
that the filters can use.   Refactor the looping mechanism within
session.create_engine() into a separate function _test_connection()
so that the logic is encapsulated and can be tested.

partially implement bp: use-events-for-error-wrapping

Change-Id: Iad1bac9d0f9202b21e4c9c170aa84494b770728d
Updated from global requirements

Change-Id: I4eed49a24f716b51093dbf52a3706cd0409ca6d9
Use SQLAlchemy cursor execute events for tracing

This change provides a consistent
system of intercepting statement executions, gaining information
about the current stack trace, and then injecting that information
either into the statement and/or logging it.   The system
works for any backend without the need to code to DBAPI
details or monkeypatching of the cursor.

Change-Id: If80db9a0a898d2cb94837ff059fc054590050506
Merge "Add disconnect modification support to exception handling"
Merge "Updated from global requirements"
Merge "Integrate the ping listener into the filter system."
Merge "Port _is_db_connection_error check to exception filters"
Merge "Use SQLAlchemy cursor execute events for tracing"