[autotest] Pull suite sharding factor from global_config.ini
Instead of hard-coding a sharding factor in each suite control file,
put a default one in global_config.ini. Allow overrides.
BUG=chromium-os:26431
TEST=unit
TEST=use dev_harness to run control.bvt, see that it schedules 5 reimaging jobs.
STATUS=Fixed
Change-Id: Ife5a1d117701785530b040ab9b08796b06d57f76
Reviewed-on: https://gerrit.chromium.org/gerrit/15975
Tested-by: Chris Masone <cmasone@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Ready: Chris Masone <cmasone@chromium.org>
diff --git a/server/cros/dynamic_suite.py b/server/cros/dynamic_suite.py
index fbdd9a0..ecf1b7b 100644
--- a/server/cros/dynamic_suite.py
+++ b/server/cros/dynamic_suite.py
@@ -64,7 +64,7 @@
return 'SKIP_IMAGE' in g and g['SKIP_IMAGE']
- def attempt(self, build, num, board, record):
+ def attempt(self, build, board, record, num=None):
"""
Synchronously attempt to reimage some machines.
@@ -74,13 +74,16 @@
@param build: the build to install e.g.
x86-alex-release/R18-1655.0.0-a1-b1584.
- @param num: how many devices to reimage.
@param board: which kind of devices to reimage.
@param record: callable that records job status.
prototype:
record(status, subdir, name, reason)
+ @param num: how many devices to reimage.
@return True if all reimaging jobs succeed, false otherwise.
"""
+ if not num:
+ num = CONFIG.get_config_value('CROS', 'sharding_factor', type=int)
+ logging.debug("scheduling reiamging across %d machines", num)
wrapper_job_name = 'try new image'
record('START', None, wrapper_job_name)
self._ensure_version_label(VERSION_PREFIX + build)
diff --git a/server/cros/dynamic_suite_unittest.py b/server/cros/dynamic_suite_unittest.py
index 8c0a5d4..73f6d5f 100755
--- a/server/cros/dynamic_suite_unittest.py
+++ b/server/cros/dynamic_suite_unittest.py
@@ -13,7 +13,7 @@
import time
import unittest
-from autotest_lib.client.common_lib import base_job, control_data
+from autotest_lib.client.common_lib import base_job, control_data, global_config
from autotest_lib.server.cros import control_file_getter, dynamic_suite
from autotest_lib.server import frontend
@@ -38,6 +38,7 @@
_NAME = 'name'
_NUM = 4
_BOARD = 'board'
+ _CONFIG = global_config.global_config
def setUp(self):
@@ -45,6 +46,9 @@
self.afe = self.mox.CreateMock(frontend.AFE)
self.tko = self.mox.CreateMock(frontend.TKO)
self.reimager = dynamic_suite.Reimager('', afe=self.afe, tko=self.tko)
+ self._CONFIG.override_config_value('CROS',
+ 'sharding_factor',
+ "%d" % self._NUM)
def testEnsureVersionLabelAlreadyExists(self):
@@ -196,7 +200,7 @@
rjob.record('START', mox.IgnoreArg(), mox.IgnoreArg())
rjob.record('END GOOD', mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
- self.reimager.attempt(self._NAME, self._NUM, self._BOARD, rjob.record)
+ self.reimager.attempt(self._NAME, self._BOARD, rjob.record)
def testFailedReimage(self):
@@ -207,7 +211,7 @@
rjob.record('START', mox.IgnoreArg(), mox.IgnoreArg())
rjob.record('END FAIL', mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
- self.reimager.attempt(self._NAME, self._NUM, self._BOARD, rjob.record)
+ self.reimager.attempt(self._NAME, self._BOARD, rjob.record)
def testReimageThatNeverHappened(self):
@@ -219,7 +223,7 @@
rjob.record('FAIL', mox.IgnoreArg(), canary.name, mox.IgnoreArg())
rjob.record('END FAIL', mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
- self.reimager.attempt(self._NAME, self._NUM, self._BOARD, rjob.record)
+ self.reimager.attempt(self._NAME, self._BOARD, rjob.record)
class SuiteTest(mox.MoxTestBase):