Ensure database sessions are always cleaned up

TL; DR; This makes it safe to basically just always get a new session.

Database sessions were created each time someone called
db.get_[mw_]session().  This meant that the caller was responsible for
closing the session and making sure resources were cleaned up in all
cases.  We used to do this with a try ... finally ... approach but this
is accident prone.  In the case of celery it's possible that the finally
block is never reached; for example if a worker is hard-killed by the
main celery process.  So, the solution is to move to a scoped_session
which means that as long as we are on the same thread,
db.get_[mw_]session() will always return the same session.  We have
removed the session.close() calls from all over the code.  Indeed, going
forward, one should be very careful when closing sessions manually as
this may have unintended consequences.  Instead of relying on ourselves
to close the scoped session, this is now happening *always* in the
different scenarios we have:

* Flask - session is cleaned up on app.teardown_request
* Celery - session is cleaned up on tasks signaling that they're ending
* Scripts - sessions are still cleaned up manually

Also, rolling back sessions needs to happen whenever an exception is
caught and not re-raised.  For this purpose, get_[mw_]session calls will
always check to see if the session is active and roll it back if it's
not.

TODO: do the same connection opening tests for mediawiki db engines

Bug: 68833
Change-Id: I764940fbd67b057d964743e982f7863268a250c9