[autotest] Use global database for tko models in django v3.

This adds the global database to django.
A django database router is added to determine to which database
should be used for which models. All tko models are always taken or
written from or into the global database while all other objects
remain unchanged.

BUG=chromium:422637
TEST=Ran suites, syncdb, restart apache, ran a suite.
Confirm global database connection is closed after each attempt to get
test view: https://x20web.corp.google.com/~beeps/log/db_routers.html

Change-Id: Idf6933d1d112bbc5a2896fa61afd03f6604dafb5
Reviewed-on: https://chromium-review.googlesource.com/223501
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Prashanth B <beeps@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/frontend/setup_django_environment.py b/frontend/setup_django_environment.py
index 055e9e9..cd390a3 100644
--- a/frontend/setup_django_environment.py
+++ b/frontend/setup_django_environment.py
@@ -4,7 +4,20 @@
 
 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'autotest_lib.frontend.settings')
 
+def _enable_autocommit_by_name(name):
+    """Enable autocommit for the connection with matching name.
+
+    @param name: Name of the connection.
+    """
+    from django.db import connections
+    # ensure a connection is open
+    connections[name].cursor()
+    connections[name].connection.autocommit(True)
+
+
 def enable_autocommit():
-    from django.db import connection
-    connection.cursor() # ensure a connection is open
-    connection.connection.autocommit(True)
+    """Enable autocommit for default and global connection.
+    """
+    _enable_autocommit_by_name('default')
+    _enable_autocommit_by_name('global')
+