[autotest] Move rpc_utils import in site_rpc_interface.py
In order to allow for unit tests of site_rpc_interface.py, we
need to avoid importing autotest_lib.frontend.afe.rpc_utils, as
it pulls in and tries to set up django. The current mechanism
seems to be a bit flaky, so simplify the logic and simply
put the import behind a layer of indirection that can be
mocked out during tests.
BUG=chromium-os:27074
TEST=unit
TEST=./cli/atest suite create -b x86-mario -i x86-mario-release/R19-1932.0.0-a1-b1751 dummy
Change-Id: I0b331128a317fcf64269964325e051c45aeef023
Reviewed-on: https://gerrit.chromium.org/gerrit/17843
Reviewed-by: Scott Zawalski <scottz@chromium.org>
Commit-Ready: Chris Masone <cmasone@chromium.org>
Tested-by: Chris Masone <cmasone@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index 4e25714..3fb8937 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -9,10 +9,6 @@
import sys
from autotest_lib.client.common_lib import global_config
from autotest_lib.client.common_lib.cros import dev_server
-# rpc_utils initializes django, which we can't do in unit tests.
-if 'unittest' not in sys.modules.keys():
- # So, only load that module if we're not running unit tests.
- from autotest_lib.frontend.afe import rpc_utils
from autotest_lib.server.cros import control_file_getter, dynamic_suite
@@ -27,7 +23,15 @@
def _rpc_utils():
- """Returns the rpc_utils module. MUST be mocked for unit tests."""
+ """Returns the rpc_utils module. MUST be mocked for unit tests.
+
+ rpc_utils initializes django, which we can't do in unit tests.
+ This layer of indirection allows us to only load that module if we're
+ not running unit tests.
+
+ @return: autotest_lib.frontend.afe.rpc_utils
+ """
+ from autotest_lib.frontend.afe import rpc_utils
return rpc_utils