aboutsummaryrefslogtreecommitdiff
path: root/cros_utils
diff options
context:
space:
mode:
Diffstat (limited to 'cros_utils')
-rw-r--r--cros_utils/buildbot_utils.py3
-rwxr-xr-xcros_utils/buildbot_utils_unittest.py34
2 files changed, 35 insertions, 2 deletions
diff --git a/cros_utils/buildbot_utils.py b/cros_utils/buildbot_utils.py
index 1101cbdf..35dc3ac6 100644
--- a/cros_utils/buildbot_utils.py
+++ b/cros_utils/buildbot_utils.py
@@ -2,6 +2,7 @@
# Copyright 2017 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
"""Utilities for launching and accessing ChromeOS buildbots."""
from __future__ import print_function
@@ -252,7 +253,7 @@ def GetLatestImage(chromeos_root, path):
build = '%s/R%d-%d.%d.%d' % (path, c[0], c[1], c[2], c[3])
# Blacklist "R79-12384.0.0" image released by mistake.
# TODO(crbug.com/992242): Remove the filter by 2019-09-05.
- if '.'.join(c) == '79.12384.0.0':
+ if c == [79, 12384, 0, 0]:
continue
if DoesImageExist(chromeos_root, build):
diff --git a/cros_utils/buildbot_utils_unittest.py b/cros_utils/buildbot_utils_unittest.py
index c57b2d32..bfba8d78 100755
--- a/cros_utils/buildbot_utils_unittest.py
+++ b/cros_utils/buildbot_utils_unittest.py
@@ -1,8 +1,10 @@
#!/usr/bin/env python2
-
+# -*- coding: utf-8 -*-
+#
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
"""Unittest for buildbot_utils.py."""
from __future__ import print_function
@@ -34,9 +36,19 @@ class TrybotTest(unittest.TestCase):
tryjob_out = (
'[{"buildbucket_id": "8952721143823688176", "build_config": '
'"cave-llvm-toolchain-tryjob", "url": '
+ # pylint: disable=line-too-long
'"http://cros-goldeneye/chromeos/healthmonitoring/buildDetails?buildbucketId=8952721143823688176"}]'
)
+ GSUTILS_LS = '\n'.join([
+ 'gs://chromeos-image-archive/{0}/R78-12421.0.0/',
+ 'gs://chromeos-image-archive/{0}/R78-12422.0.0/',
+ 'gs://chromeos-image-archive/{0}/R78-12423.0.0/',
+ # "R79-12384.0.0" image should be blacklisted.
+ # TODO(crbug.com/992242): Remove the filter by 2019-09-05.
+ 'gs://chromeos-image-archive/{0}/R79-12384.0.0/',
+ ])
+
buildresult_out = (
'{"8952721143823688176": {"status": "pass", "artifacts_url":'
'"gs://chromeos-image-archive/trybot-elm-release-tryjob/R67-10468.0.0-'
@@ -112,6 +124,26 @@ class TrybotTest(unittest.TestCase):
buildbucket_id = buildbot_utils.ParseTryjobBuildbucketId(self.tryjob_out)
self.assertEqual(buildbucket_id, self.buildbucket_id)
+ def testGetLatestImageValid(self):
+ with patch.object(command_executer.CommandExecuter,
+ 'ChrootRunCommandWOutput') as mocked_run:
+ with patch.object(buildbot_utils, 'DoesImageExist') as mocked_imageexist:
+ IMAGE_DIR = 'lulu-release'
+ mocked_run.return_value = (0, self.GSUTILS_LS.format(IMAGE_DIR), '')
+ mocked_imageexist.return_value = True
+ image = buildbot_utils.GetLatestImage('', IMAGE_DIR)
+ self.assertEqual(image, '{0}/R78-12423.0.0'.format(IMAGE_DIR))
+
+ def testGetLatestImageInvalid(self):
+ with patch.object(command_executer.CommandExecuter,
+ 'ChrootRunCommandWOutput') as mocked_run:
+ with patch.object(buildbot_utils, 'DoesImageExist') as mocked_imageexist:
+ IMAGE_DIR = 'kefka-release'
+ mocked_run.return_value = (0, self.GSUTILS_LS.format(IMAGE_DIR), '')
+ mocked_imageexist.return_value = False
+ image = buildbot_utils.GetLatestImage('', IMAGE_DIR)
+ self.assertIsNone(image)
+
if __name__ == '__main__':
unittest.main()