[autotest] add a directAFE class which bypasses rpc calls
This CL adds a directAFE object which inherits from frontend.AFE, but
which replaces the underlying RpcClient.run function (responsible for
turning AFE calls into RPC calls) into a function that just makese
direct calls to rpc_interface and site_rpc_interface, bypassing RPC
process. This is desirable in places like test_that, which use an
in-memory process-local sqlite database to back a local afe.
BUG=chromium:236471
TEST=unit tests
Change-Id: Ib89a28be9ebc6f5c4e6ff93a08721ac63ab8b377
Reviewed-on: https://gerrit.chromium.org/gerrit/50383
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
diff --git a/frontend/afe/direct_afe_unittest.py b/frontend/afe/direct_afe_unittest.py
new file mode 100755
index 0000000..3371597
--- /dev/null
+++ b/frontend/afe/direct_afe_unittest.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+#pylint: disable-msg=C0111
+import unittest
+import common
+#pylint: disable-msg=W0611
+from autotest_lib.frontend import setup_django_lite_environment
+from autotest_lib.frontend.afe import direct_afe
+
+
+class DirectAFETest(unittest.TestCase):
+ def testEntryCreation(self):
+ afe = direct_afe.directAFE()
+
+ jobs = afe.get_jobs()
+ self.assertEquals(len(jobs), 0)
+
+ hosts = afe.get_hosts()
+ self.assertEquals(len(hosts), 0)
+
+ afe.create_host('a_host')
+ hosts = afe.get_hosts()
+ self.assertEquals(len(hosts), 1)
+
+ afe.create_job('job_name', hosts=['a_host'])
+ jobs = afe.get_jobs()
+ self.assertEquals(len(jobs), 1)
+
+if __name__ == '__main__':
+ unittest.main()