[autotest] Inject a dictionary of vars into suite control files
Currently we inject a bunch of variables into suite control files that are
passed to dynamic_suites. This makes changing dynamic_suites interface hard
as we need to push to both the lab and moblab. Switch to inject the dictionary
directly in suite control files. After the change, the dictionary and the
bunch of variables will coexist.
BUG=chromium:480684
TEST=Test with unittest and moblab
Change-Id: I6d1491f8502c0409039b687f0ff77775e1036693
Reviewed-on: https://chromium-review.googlesource.com/269224
Tested-by: Shuqian Zhao <shuqianz@chromium.org>
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Shuqian Zhao <shuqianz@chromium.org>
diff --git a/server/cros/dynamic_suite/tools.py b/server/cros/dynamic_suite/tools.py
index a09be3b..e3d8b54 100644
--- a/server/cros/dynamic_suite/tools.py
+++ b/server/cros/dynamic_suite/tools.py
@@ -148,7 +148,9 @@
control_file += "%s=%s\n" % (key, repr(value))
else:
control_file += "%s=%r\n" % (key, value)
- return control_file + control_file_in
+
+ args_dict_str = "%s=%s\n" % ('args_dict', repr(vars))
+ return control_file + args_dict_str + control_file_in
def is_usable(host):
diff --git a/server/cros/dynamic_suite/tools_unittest.py b/server/cros/dynamic_suite/tools_unittest.py
index 2febfa6..89d29c6 100644
--- a/server/cros/dynamic_suite/tools_unittest.py
+++ b/server/cros/dynamic_suite/tools_unittest.py
@@ -7,7 +7,9 @@
"""Unit tests for server/cros/dynamic_suite/tools.py."""
import mox
+import unittest
+import common
from autotest_lib.server.cros.dynamic_suite.fakes import FakeHost
from autotest_lib.server.cros.dynamic_suite.host_spec import HostSpec
from autotest_lib.server.cros.dynamic_suite import host_spec
@@ -39,7 +41,8 @@
def testInjectVars(self):
"""Should inject dict of varibles into provided strings."""
def find_all_in(d, s):
- """Returns true if all key-value pairs in |d| are printed in |s|."""
+ """Returns true if all key-value pairs in |d| are printed in |s|
+ and the dictionary representation is also in |s|."""
for k, v in d.iteritems():
if isinstance(v, str):
if "%s='%s'\n" % (k, v) not in s:
@@ -47,6 +50,9 @@
else:
if "%s=%r\n" % (k, v) not in s:
return False
+ args_dict_str = "%s=%s\n" % ('args_dict', repr(d))
+ if args_dict_str not in s:
+ return False
return True
v = {'v1': 'one', 'v2': 'two', 'v3': None, 'v4': False, 'v5': 5}
@@ -68,3 +74,7 @@
self.mox.ReplayAll()
host = FakeHost(locked=True, locked_by=infra_user)
self.assertFalse(tools.incorrectly_locked(host))
+
+
+if __name__ == "__main__":
+ unittest.main()