diff options
author | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-05-29 18:41:18 +0000 |
---|---|---|
committer | showard <showard@592f7852-d20e-0410-864c-8624ca9c26a4> | 2009-05-29 18:41:18 +0000 |
commit | 96c13fcf9c9b2de0e3a89a794e2ea26a0226a24c (patch) | |
tree | 67d099c4d0b94b7b2cf3cea6f66b1d16e5d1b467 | |
parent | db160d1478cded4807556f6b42a2f6dae4c3e42a (diff) |
make the readonly connection fallback to the regular Django connection when running in the scheduer. this is really important, because otherwise the readonly connection is not autocommit and bad, bad things could happen, though i'm not sure exactly what existing problems there might have been. we used to do this only for testing, but since we do it in another context here, i renamed the method to be more generic and appropriate.
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@3183 592f7852-d20e-0410-864c-8624ca9c26a4
-rw-r--r-- | frontend/afe/readonly_connection.py | 14 | ||||
-rw-r--r-- | frontend/setup_test_environment.py | 4 | ||||
-rwxr-xr-x | scheduler/monitor_db.py | 4 |
3 files changed, 16 insertions, 6 deletions
diff --git a/frontend/afe/readonly_connection.py b/frontend/afe/readonly_connection.py index d4e51bbe..31af595a 100644 --- a/frontend/afe/readonly_connection.py +++ b/frontend/afe/readonly_connection.py @@ -21,8 +21,12 @@ class ReadOnlyConnection(object): @classmethod - def set_testing_mode(cls, enabled): - if enabled: + def set_globally_disabled(cls, disabled): + """ + When globally disabled, the ReadOnlyConnection will simply pass through + to the global Django connection. + """ + if disabled: cls._the_instance = DummyReadOnlyConnection() else: cls._the_instance = None @@ -92,11 +96,15 @@ class ReadOnlyConnection(object): class DummyReadOnlyConnection(object): - 'A dummy version for testing which does nothing.' + """ + A dummy version which passes queries straight to the global Django + connection. + """ def __init__(self): self._is_set = False + def set_django_connection(self): assert not self._is_set self._is_set = True diff --git a/frontend/setup_test_environment.py b/frontend/setup_test_environment.py index 84df0244..77b59623 100644 --- a/frontend/setup_test_environment.py +++ b/frontend/setup_test_environment.py @@ -54,9 +54,9 @@ def destroy_test_database(): def set_up(): run_syncdb() - readonly_connection.ReadOnlyConnection.set_testing_mode(True) + readonly_connection.ReadOnlyConnection.set_globally_disabled(True) def tear_down(): - readonly_connection.ReadOnlyConnection.set_testing_mode(False) + readonly_connection.ReadOnlyConnection.set_globally_disabled(False) destroy_test_database() diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py index 64dcdc5e..3c9948ef 100755 --- a/scheduler/monitor_db.py +++ b/scheduler/monitor_db.py @@ -14,7 +14,7 @@ from autotest_lib.frontend import setup_django_environment from autotest_lib.client.common_lib import global_config from autotest_lib.client.common_lib import host_protections, utils from autotest_lib.database import database_connection -from autotest_lib.frontend.afe import models, rpc_utils +from autotest_lib.frontend.afe import models, rpc_utils, readonly_connection from autotest_lib.scheduler import drone_manager, drones, email_manager from autotest_lib.scheduler import monitor_db_cleanup from autotest_lib.scheduler import status_server, scheduler_config @@ -196,6 +196,8 @@ def init(logfile): # ensure Django connection is in autocommit setup_django_environment.enable_autocommit() + # bypass the readonly connection + readonly_connection.ReadOnlyConnection.set_globally_disabled(True) logging.info("Setting signal handler") signal.signal(signal.SIGINT, handle_sigint) |