Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 1 | # Copyright 2017 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Module for task unittests.""" |
Xixuan Wu | 5ff0fac | 2019-01-07 10:06:35 -0800 | [diff] [blame] | 6 | # pylint: disable=g-missing-super-call |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 7 | |
| 8 | import re |
| 9 | import unittest |
| 10 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 11 | import build_lib |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 12 | import config_reader |
| 13 | import mock |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 14 | import task |
Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 15 | import task_config_reader |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 16 | import tot_manager |
| 17 | |
| 18 | |
| 19 | class FakeTotMilestoneManager(tot_manager.TotMilestoneManager): |
| 20 | """Mock class for tot_manager.TotMilestoneManager.""" |
| 21 | |
| 22 | def __init__(self, is_sanity): |
| 23 | self.is_sanity = is_sanity |
| 24 | self.storage_client = None |
| 25 | self.tot = self._tot_milestone() |
| 26 | |
| 27 | |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 28 | class FakeBuildClient(object): |
| 29 | """Mock rest_client.BuildBucketBigqueryClient.""" |
| 30 | |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 31 | def __init__(self, success=True, failed_result=None): |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 32 | self.success = success |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 33 | self.failed_result = failed_result |
| 34 | self.firmware_artifact_cros = ('gs://chromeos-image-archive/' |
| 35 | 'fake_board-release/' |
| 36 | 'R30-6182.0.0-rc2') |
| 37 | self.firmware_artifact = ('gs://chromeos-image-archive/' |
| 38 | 'firmware-fake_board-12345.67.A-firmwarebranch/' |
| 39 | 'RFoo-1.0.0-b1234567') |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 40 | |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 41 | def get_latest_passed_builds_artifact_link(self, build_config): |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 42 | if not self.success: |
Xixuan Wu | 6ec23e3 | 2019-05-23 11:56:02 -0700 | [diff] [blame] | 43 | raise ValueError('No valid builds') |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 44 | if self.failed_result: |
| 45 | return self.failed_result |
| 46 | return self.firmware_artifact_cros |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 47 | |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 48 | def get_latest_passed_builds_artifact_link_firmware(self, board): |
Xinan Lin | 318cf75 | 2019-07-19 14:50:23 -0700 | [diff] [blame] | 49 | if not self.success: |
| 50 | raise ValueError('No valid builds') |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 51 | if self.failed_result: |
| 52 | return self.failed_result |
| 53 | return self.firmware_artifact |
Xinan Lin | 318cf75 | 2019-07-19 14:50:23 -0700 | [diff] [blame] | 54 | |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 55 | |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 56 | class FakeLabConfig(object): |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 57 | """Mock class for config_reader.LabConfig.""" |
| 58 | |
| 59 | def get_cros_model_map(self): |
| 60 | return {'coral': ['robo', 'nasher', 'lava']} |
| 61 | |
| 62 | |
| 63 | class FakeMigrationConfig(object): |
| 64 | """Mock class for config_reader.MigrationConfig.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 65 | |
Xixuan Wu | 1e42c75 | 2019-03-21 13:41:49 -0700 | [diff] [blame] | 66 | def get_skylab_suites_dump(self): |
| 67 | return {} |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 68 | |
| 69 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 70 | class TaskBaseTestCase(unittest.TestCase): |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 71 | |
| 72 | BOARD = 'fake_board' |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 73 | UNIBUILD_BOARD = 'coral' |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 74 | EXCLUDE_BOARD = 'exclude_fake_board' |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 75 | NAME = 'fake_name' |
| 76 | SUITE = 'fake_suite' |
| 77 | POOL = 'fake_pool' |
| 78 | PLATFORM = '6182.0.0-rc2' |
| 79 | MILESTONE = '30' |
| 80 | NUM = 1 |
| 81 | PRIORITY = 50 |
| 82 | TIMEOUT = 600 |
| 83 | |
| 84 | def setUp(self): |
| 85 | tot_patcher = mock.patch('tot_manager.TotMilestoneManager') |
| 86 | self._mock_tot = tot_patcher.start() |
| 87 | self.addCleanup(tot_patcher.stop) |
| 88 | # Can't pass in False since storage_client is not mocked. |
| 89 | self._mock_tot.return_value = FakeTotMilestoneManager(True) |
Xixuan Wu | 51bb710 | 2019-03-18 14:51:44 -0700 | [diff] [blame] | 90 | self.task = task.Task(task_config_reader.TaskInfo( |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 91 | name=self.NAME, |
| 92 | suite=self.SUITE, |
| 93 | branch_specs=[], |
| 94 | pool=self.POOL, |
| 95 | num=self.NUM, |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 96 | boards=','.join([self.BOARD, self.UNIBUILD_BOARD]), |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 97 | exclude_boards=self.EXCLUDE_BOARD, |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 98 | priority=self.PRIORITY, |
| 99 | timeout=self.TIMEOUT)) |
| 100 | |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 101 | self._empty_configs = config_reader.Configs( |
| 102 | lab_config=config_reader.LabConfig(None), |
| 103 | migration_config=config_reader.MigrationConfig(None)) |
| 104 | self._fake_configs = config_reader.Configs( |
| 105 | lab_config=FakeLabConfig(), |
| 106 | migration_config=FakeMigrationConfig()) |
| 107 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 108 | |
| 109 | class TaskTestCase(TaskBaseTestCase): |
| 110 | |
| 111 | def setUp(self): |
| 112 | super(TaskTestCase, self).setUp() |
| 113 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 114 | mock_push = mock.patch('task.Task._push_suite') |
| 115 | self._mock_push = mock_push.start() |
| 116 | self.addCleanup(mock_push.stop) |
| 117 | |
| 118 | def testSetSpecCompareInfoEqual(self): |
| 119 | """Test compare info setting for specs that equals to a milestone.""" |
| 120 | self.task.branch_specs = re.split(r'\s*,\s*', '==tot-2') |
| 121 | self.task._set_spec_compare_info() |
| 122 | self.assertTrue(self.task._version_equal_constraint) |
| 123 | self.assertFalse(self.task._version_gte_constraint) |
| 124 | self.assertFalse(self.task._version_lte_constraint) |
| 125 | self.assertEqual(self.task._bare_branches, []) |
| 126 | |
| 127 | def testSetSpecCompareInfoLess(self): |
| 128 | """Test compare info setting for specs that is less than a milestone.""" |
| 129 | self.task.branch_specs = re.split(r'\s*,\s*', '<=tot') |
| 130 | self.task._set_spec_compare_info() |
| 131 | self.assertFalse(self.task._version_equal_constraint) |
| 132 | self.assertFalse(self.task._version_gte_constraint) |
| 133 | self.assertTrue(self.task._version_lte_constraint) |
| 134 | self.assertEqual(self.task._bare_branches, []) |
| 135 | |
| 136 | def testSetSpecCompareInfoGreater(self): |
| 137 | """Test compare info setting for specs that is greater than a milestone.""" |
| 138 | self.task.branch_specs = re.split(r'\s*,\s*', '>=tot-2') |
| 139 | self.task._set_spec_compare_info() |
| 140 | self.assertFalse(self.task._version_equal_constraint) |
| 141 | self.assertTrue(self.task._version_gte_constraint) |
| 142 | self.assertFalse(self.task._version_lte_constraint) |
| 143 | self.assertEqual(self.task._bare_branches, []) |
| 144 | |
| 145 | def testFitsSpecEqual(self): |
| 146 | """Test milestone check for specs that equals to a milestone.""" |
| 147 | self.task.branch_specs = re.split(r'\s*,\s*', '==tot-1') |
| 148 | self.task._set_spec_compare_info() |
| 149 | self.assertFalse(self.task._fits_spec('40')) |
| 150 | self.assertTrue(self.task._fits_spec('39')) |
| 151 | self.assertFalse(self.task._fits_spec('38')) |
| 152 | |
| 153 | def testFitsSpecLess(self): |
| 154 | """Test milestone check for specs that is less than a milestone.""" |
| 155 | self.task.branch_specs = re.split(r'\s*,\s*', '<=tot-1') |
| 156 | self.task._set_spec_compare_info() |
| 157 | self.assertFalse(self.task._fits_spec('40')) |
| 158 | self.assertTrue(self.task._fits_spec('39')) |
| 159 | self.assertTrue(self.task._fits_spec('38')) |
| 160 | |
| 161 | def testFitsSpecGreater(self): |
| 162 | """Test milestone check for specs that is greater than a milestone.""" |
| 163 | self.task.branch_specs = re.split(r'\s*,\s*', '>=tot-2') |
| 164 | self.task._set_spec_compare_info() |
| 165 | self.assertTrue(self.task._fits_spec('39')) |
| 166 | self.assertTrue(self.task._fits_spec('38')) |
| 167 | self.assertFalse(self.task._fits_spec('37')) |
| 168 | |
| 169 | def testGetFirmwareFromLabConfig(self): |
| 170 | """Test get firmware from lab config successfully.""" |
| 171 | with mock.patch('config_reader.LabConfig.get_firmware_ro_build_list', |
| 172 | return_value='build1,build2'): |
| 173 | firmware = self.task._get_firmware_build( |
| 174 | 'released_ro_2', self.BOARD, config_reader.LabConfig(None), None) |
| 175 | self.assertEqual(firmware, 'build2') |
| 176 | |
| 177 | def testGetFirmwareFromLabConfigOutofIndex(self): |
| 178 | """Test get firmware from lab config when firmware index is invalid.""" |
| 179 | with mock.patch('config_reader.LabConfig.get_firmware_ro_build_list', |
| 180 | return_value='build1,build2'): |
| 181 | self.assertRaises(ValueError, |
| 182 | self.task._get_latest_firmware_build_from_lab_config, |
| 183 | 'released_ro_3', |
| 184 | self.BOARD, |
| 185 | config_reader.LabConfig(None)) |
| 186 | self.assertIsNone(self.task._get_firmware_build( |
| 187 | 'released_ro_3', self.BOARD, config_reader.LabConfig(None), None)) |
| 188 | |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 189 | def testGetFirmwareFromDBSuccessfully(self): |
| 190 | """Test get firmware from BuildBucket successfully.""" |
| 191 | |
| 192 | firmware = self.task._get_firmware_build( |
| 193 | 'cros', self.BOARD, None, FakeBuildClient()) |
| 194 | self.assertEqual( |
| 195 | firmware, |
| 196 | '{0}-release/R{1}-{2}'.format(self.BOARD, |
| 197 | self.MILESTONE, |
| 198 | self.PLATFORM)) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 199 | firmware = self.task._get_firmware_build( |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 200 | 'firmware', self.BOARD, None, FakeBuildClient()) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 201 | self.assertEqual( |
| 202 | firmware, |
Xinan Lin | 39dcca8 | 2019-07-26 18:55:51 -0700 | [diff] [blame] | 203 | 'firmware-{0}-12345.67.A-firmwarebranch/' |
| 204 | 'RFoo-1.0.0-b1234567/{0}'.format(self.BOARD)) |
| 205 | |
| 206 | def testGetFirmwareFromDBFailure(self): |
| 207 | """Test get invalid firmware build from BuildBucket.""" |
| 208 | |
| 209 | # This should raise a ValueError due to the unexpected prefix. |
| 210 | foo_artifact_link = ('gs://chromeos-image-foo/' |
| 211 | 'firmware-fake_board-12345.67.A-firmwarebranch/' |
| 212 | 'RFoo-1.0.0-b1234567') |
| 213 | self.assertRaises(ValueError, self.task._get_firmware_build( |
| 214 | 'firmware', |
| 215 | self.BOARD, |
| 216 | None, |
| 217 | FakeBuildClient(failed_result=foo_artifact_link))) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 218 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 219 | def testScheduleCrosSuccessfully(self): |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 220 | """test schedule cros builds successfully.""" |
| 221 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 222 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | 1e42c75 | 2019-03-21 13:41:49 -0700 | [diff] [blame] | 223 | self._fake_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 224 | FakeBuildClient()) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 225 | self.assertEqual(self._mock_push.call_count, 1) |
| 226 | |
| 227 | def testScheduleCrosNonvalidBoard(self): |
| 228 | """Test schedule no cros builds due to non-allowed board.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 229 | branch_builds = {('%s_2' % self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 230 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 231 | self._empty_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 232 | FakeBuildClient()) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 233 | self.assertEqual(self._mock_push.call_count, 0) |
| 234 | |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 235 | def testScheduleCrosExcludeBoard(self): |
| 236 | """Test schedule no cros builds due to board is excluded.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 237 | branch_builds = {(self.EXCLUDE_BOARD, None, 'release', '56'): '0000.00.00'} |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 238 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 239 | self._empty_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 240 | FakeBuildClient()) |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 241 | self.assertEqual(self._mock_push.call_count, 0) |
| 242 | |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 243 | def testScheduleCrosSuccessfullyWithSpecifiedModel(self): |
| 244 | """Test schedule unibuild with specific model.""" |
| 245 | self.task.board = self.UNIBUILD_BOARD |
| 246 | branch_builds = {(self.UNIBUILD_BOARD, 'robo', 'release', '56'): |
| 247 | '0000.00.00', |
| 248 | (self.UNIBUILD_BOARD, 'lava', 'release', '56'): |
| 249 | '0000.00.00'} |
| 250 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 251 | self._fake_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 252 | FakeBuildClient()) |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 253 | self.assertEqual(self._mock_push.call_count, 2) |
| 254 | |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 255 | def testScheduleCrosNonValidSpec(self): |
| 256 | """Test schedule no cros builds due to non-allowed branch milestone.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 257 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 258 | # Only run tasks whose milestone = tot (R40) |
| 259 | self.task.branch_specs = re.split(r'\s*,\s*', '==tot') |
| 260 | self.task._set_spec_compare_info() |
| 261 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 262 | self._empty_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 263 | FakeBuildClient()) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 264 | self.assertEqual(self._mock_push.call_count, 0) |
| 265 | |
| 266 | def testScheduleCrosSuccessfullyWithValidFirmware(self): |
| 267 | """Test schedule cros builds successfully with valid firmware.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 268 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 269 | self.task.firmware_ro_build_spec = 'firmware' |
| 270 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | 1e42c75 | 2019-03-21 13:41:49 -0700 | [diff] [blame] | 271 | self._fake_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 272 | FakeBuildClient()) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 273 | self.assertEqual(self._mock_push.call_count, 1) |
| 274 | |
| 275 | def testScheduleCrosWithNonValidFirmware(self): |
| 276 | """Test schedule no cros builds due to non-existent firmware.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 277 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 278 | self.task.firmware_ro_build_spec = 'firmware' |
| 279 | self.task._schedule_cros_builds(branch_builds, |
Xixuan Wu | f4a4c88 | 2019-03-15 14:48:26 -0700 | [diff] [blame] | 280 | self._empty_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 281 | FakeBuildClient(success=False)) |
Xixuan Wu | 0c76d5b | 2017-08-30 16:40:17 -0700 | [diff] [blame] | 282 | self.assertEqual(self._mock_push.call_count, 0) |
| 283 | |
| 284 | def testScheduleLaunchControlWithFullBranches(self): |
| 285 | """Test schedule all launch control builds successfully.""" |
| 286 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 287 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 288 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 289 | self.task.launch_control_branches = [ |
| 290 | t.lstrip() for t in lc_branches.split(',')] |
| 291 | self.task._schedule_launch_control_builds(lc_builds) |
| 292 | self.assertEqual(self._mock_push.call_count, 2) |
| 293 | |
| 294 | def testScheduleLaunchControlWithPartlyBranches(self): |
| 295 | """Test schedule part of launch control builds due to branch check.""" |
| 296 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 297 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 298 | lc_branches = 'git_nyc-mr1-release' |
| 299 | self.task.launch_control_branches = [ |
| 300 | t.lstrip() for t in lc_branches.split(',')] |
| 301 | self.task._schedule_launch_control_builds(lc_builds) |
| 302 | self.assertEqual(self._mock_push.call_count, 1) |
| 303 | |
| 304 | def testScheduleLaunchControlWithNoBranches(self): |
| 305 | """Test schedule none of launch control builds due to branch check.""" |
| 306 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 307 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 308 | self.task.launch_control_branches = [] |
| 309 | self.task._schedule_launch_control_builds(lc_builds) |
| 310 | self.assertEqual(self._mock_push.call_count, 0) |
| 311 | |
| 312 | def testScheduleLaunchControlNonvalidBoard(self): |
| 313 | """Test schedule none of launch control builds due to board check.""" |
| 314 | lc_builds = {'%s_2' % self.BOARD: |
| 315 | ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 316 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 317 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 318 | self.task.launch_control_branches = [ |
| 319 | t.lstrip() for t in lc_branches.split(',')] |
| 320 | self.task._schedule_launch_control_builds(lc_builds) |
| 321 | self.assertEqual(self._mock_push.call_count, 0) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 322 | |
Po-Hsien Wang | 6d58973 | 2018-05-15 17:19:34 -0700 | [diff] [blame] | 323 | def testScheduleLaunchControlExcludeBoard(self): |
| 324 | """Test schedule none of launch control builds due to board check.""" |
| 325 | lc_builds = {self.EXCLUDE_BOARD: |
| 326 | ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 327 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 328 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 329 | self.task.launch_control_branches = [ |
| 330 | t.lstrip() for t in lc_branches.split(',')] |
| 331 | self.task._schedule_launch_control_builds(lc_builds) |
| 332 | self.assertEqual(self._mock_push.call_count, 0) |
| 333 | |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 334 | |
| 335 | class TaskPushTestCase(TaskBaseTestCase): |
| 336 | |
| 337 | def setUp(self): |
| 338 | super(TaskPushTestCase, self).setUp() |
| 339 | mock_push = mock.patch('task_executor.push') |
| 340 | self._mock_push = mock_push.start() |
| 341 | self.addCleanup(mock_push.stop) |
| 342 | |
| 343 | def testScheduleCrOSIsPushSuccessfully(self): |
| 344 | """Test IS_PUSHED is changed if some CrOS suites are scheduled.""" |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 345 | branch_builds = {(self.BOARD, None, 'release', '56'): '0000.00.00'} |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 346 | self.task.os_type = build_lib.OS_TYPE_CROS |
| 347 | self.assertTrue(self.task.schedule( |
Xixuan Wu | 1e42c75 | 2019-03-21 13:41:49 -0700 | [diff] [blame] | 348 | [], (branch_builds, []), self._fake_configs, |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 349 | FakeBuildClient())) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 350 | |
| 351 | def testScheduleLaunchControlIsPushSuccessfully(self): |
| 352 | """Test IS_PUSHED is changed if some launch control suites are scheduled.""" |
| 353 | lc_builds = {self.BOARD: ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 354 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 355 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 356 | self.task.launch_control_branches = [ |
| 357 | t.lstrip() for t in lc_branches.split(',')] |
| 358 | self.task.os_type = build_lib.OS_TYPES_LAUNCH_CONTROL |
| 359 | self.assertTrue(self.task.schedule( |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 360 | lc_builds, ([], []), self._empty_configs, FakeBuildClient())) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 361 | |
| 362 | def testScheduleCrosIsPushInvalidBoard(self): |
| 363 | """Test schedule no cros builds due to non-allowed board.""" |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 364 | branch_builds = ( |
Xixuan Wu | 8d2f286 | 2018-08-28 16:48:04 -0700 | [diff] [blame] | 365 | {('%s_2' % self.BOARD, None, 'release', '56'): '0000.00.00'}, {}, |
Craig Bergstrom | 58263d3 | 2018-04-26 14:11:35 -0600 | [diff] [blame] | 366 | ) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 367 | self.task.os_type = build_lib.OS_TYPE_CROS |
| 368 | self.assertFalse(self.task.schedule( |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 369 | [], branch_builds, self._empty_configs, FakeBuildClient())) |
Xixuan Wu | 5451a66 | 2017-10-17 10:57:40 -0700 | [diff] [blame] | 370 | |
| 371 | def testScheduleLaunchControlIsPushInvalidBoard(self): |
| 372 | """Test schedule none of launch control builds due to board check.""" |
| 373 | lc_builds = {'%s_2' % self.BOARD: |
| 374 | ['git_nyc-mr2-release/shamu-userdebug/3844975', |
| 375 | 'git_nyc-mr1-release/shamu-userdebug/3783920']} |
| 376 | lc_branches = 'git_nyc-mr1-release,git_nyc-mr2-release' |
| 377 | self.task.launch_control_branches = [ |
| 378 | t.lstrip() for t in lc_branches.split(',')] |
| 379 | self.task.os_type = build_lib.OS_TYPES_LAUNCH_CONTROL |
| 380 | self.task._schedule_launch_control_builds(lc_builds) |
| 381 | self.assertFalse(self.task.schedule( |
Xixuan Wu | c681901 | 2019-05-23 11:34:59 -0700 | [diff] [blame] | 382 | lc_builds, ([], []), self._empty_configs, FakeBuildClient())) |