Commit c8bdb695 authored by Yuke Liao's avatar Yuke Liao Committed by Commit Bot

[lacros] Allow different behaviors when building and testing on bots

A temporary solution to allow different downloading behaviors when
building and testing on bots until version is pinned to chromium/src.

Bug: 1104318
Change-Id: I945a8be7f39a3762107791f70ff48cd09410b8d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315424Reviewed-by: default avatarSven Zheng <svenzheng@chromium.org>
Commit-Queue: Yuke Liao <liaoyuke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791537}
parent 4bc661a2
...@@ -113,13 +113,22 @@ def _remove_unused_ash_chrome_versions(version_to_skip): ...@@ -113,13 +113,22 @@ def _remove_unused_ash_chrome_versions(version_to_skip):
'past %d days', p, days) 'past %d days', p, days)
shutil.rmtree(p) shutil.rmtree(p)
def _DownloadAshChromeIfNecessary(version):
def _DownloadAshChromeIfNecessary(version, is_download_for_bots=False):
"""Download a given version of ash-chrome if not already exists. """Download a given version of ash-chrome if not already exists.
Currently, a special constant version value is support: "for_bots", the reason Currently, a special constant version value is support: "for_bots", the reason
is that version number is still not pinned to chromium/src, so a constant is that version number is still not pinned to chromium/src, so a constant
value is needed to make sure that after the builder who downloads and isolates value is needed to make sure that after the builder who downloads and isolates
ash-chrome, the tester knows where to look for the binary to use. ash-chrome, the tester knows where to look for the binary to use.
Additionally, a is_download_for_bots boolean argument is introduced to
indicate whether this function is downloading for bots specifically or
downloading while running tests, and it is needed because when version is
"for_bots", the expected behavior is different in the 2 scenarios: when
downloading for bots to isolate, we always want to update for_bots/ to reflect
the latest version; however, when downloading while running tests, we want to
skip updating to latest because swarming testers aren't supposed to have
external network access.
TODO(crbug.com/1107010): remove the support once ash-chrome version is pinned TODO(crbug.com/1107010): remove the support once ash-chrome version is pinned
to chromium/src. to chromium/src.
...@@ -140,7 +149,7 @@ def _DownloadAshChromeIfNecessary(version): ...@@ -140,7 +149,7 @@ def _DownloadAshChromeIfNecessary(version):
os.path.join(ash_chrome_dir, 'chrome')) os.path.join(ash_chrome_dir, 'chrome'))
ash_chrome_dir = _GetAshChromeDirPath(version) ash_chrome_dir = _GetAshChromeDirPath(version)
if version != 'for_bots' and IsAshChromeDirValid(ash_chrome_dir): if not is_download_for_bots and IsAshChromeDirValid(ash_chrome_dir):
return return
shutil.rmtree(ash_chrome_dir, ignore_errors=True) shutil.rmtree(ash_chrome_dir, ignore_errors=True)
...@@ -150,7 +159,7 @@ def _DownloadAshChromeIfNecessary(version): ...@@ -150,7 +159,7 @@ def _DownloadAshChromeIfNecessary(version):
gsutil = download_from_google_storage.Gsutil( gsutil = download_from_google_storage.Gsutil(
download_from_google_storage.GSUTIL_DEFAULT_PATH) download_from_google_storage.GSUTIL_DEFAULT_PATH)
gs_version = (_GetLatestVersionOfAshChrome() gs_version = (_GetLatestVersionOfAshChrome()
if version == 'for_bots' else version) if is_download_for_bots else version)
logging.info('Ash-chrome version: %s', gs_version) logging.info('Ash-chrome version: %s', gs_version)
gs_path = _GS_URL_BASE + '/' + gs_version + '/' + _GS_ASH_CHROME_PATH gs_path = _GS_URL_BASE + '/' + gs_version + '/' + _GS_ASH_CHROME_PATH
exit_code = gsutil.call('cp', gs_path, tmp.name) exit_code = gsutil.call('cp', gs_path, tmp.name)
...@@ -317,7 +326,7 @@ def Main(): ...@@ -317,7 +326,7 @@ def Main():
help='Download prebuilt ash-chrome for bots so that tests are hermetic ' help='Download prebuilt ash-chrome for bots so that tests are hermetic '
'during execution') 'during execution')
download_parser.set_defaults( download_parser.set_defaults(
func=lambda *_: _DownloadAshChromeIfNecessary('for_bots')) func=lambda *_: _DownloadAshChromeIfNecessary('for_bots', True))
test_parser = subparsers.add_parser('test', help='Run tests') test_parser = subparsers.add_parser('test', help='Run tests')
test_parser.set_defaults(func=_RunTest) test_parser.set_defaults(func=_RunTest)
......
...@@ -33,7 +33,7 @@ class TestRunnerTest(unittest.TestCase): ...@@ -33,7 +33,7 @@ class TestRunnerTest(unittest.TestCase):
args = ['script_name', 'download_for_bots'] args = ['script_name', 'download_for_bots']
with mock.patch.object(sys, 'argv', args): with mock.patch.object(sys, 'argv', args):
test_runner.Main() test_runner.Main()
mock_download.assert_called_with('for_bots') mock_download.assert_called_with('for_bots', True)
@parameterized.expand([ @parameterized.expand([
'url_unittests', 'url_unittests',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment