| # Copyright 2016 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import datetime |
| |
| PYTHON_VERSION_COMPATIBILITY = 'PY2+3' |
| |
| DEPS = [ |
| 'recipe_autoroller', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/json', |
| 'recipe_engine/properties', |
| 'recipe_engine/proto', |
| 'recipe_engine/time', |
| ] |
| |
| from recipe_engine import recipe_api |
| from recipe_engine.post_process import MustRun |
| |
| from PB.recipe_engine.recipes_cfg import RepoSpec, DepRepoSpecs |
| from PB.recipe_engine.recipes_cfg import AutorollRecipeOptions |
| |
| PROPERTIES = { |
| 'projects': |
| recipe_api.Property(), |
| } |
| |
| |
| def RunSteps(api, projects): |
| api.recipe_autoroller.roll_projects(projects) |
| |
| |
| def GenTests(api): |
| # For conciseness. |
| repo_spec = api.recipe_autoroller.repo_spec |
| |
| def test(name, *test_data, status='SUCCESS'): |
| return api.test( |
| name, |
| api.buildbucket.generic_build( |
| project='infra', bucket='cron', builder='recipe-autoroller'), |
| api.properties(projects=[ |
| ('build', 'https://example.com/build.git'), |
| ]), |
| *test_data, |
| status=status) |
| |
| yield test( |
| 'basic', |
| api.recipe_autoroller.roll_data('build'), |
| ) |
| |
| yield test( |
| 'basic with recipes_path', |
| api.recipe_autoroller.roll_data('build', repo_spec( |
| trivial_commit=False, recipes_path='some/path')), |
| ) |
| |
| yield test( |
| 'multiple_commits', |
| api.recipe_autoroller.roll_data('build', num_commits=3), |
| ) |
| |
| yield test( |
| 'nontrivial', |
| api.recipe_autoroller.roll_data('build', trivial=False), |
| ) |
| |
| yield test( |
| 'empty', |
| api.recipe_autoroller.roll_data('build', empty=True), |
| ) |
| |
| yield test( |
| 'failure', |
| api.recipe_autoroller.roll_data('build', success=False), |
| status='FAILURE', |
| ) |
| |
| yield test( |
| 'failed_upload', |
| api.recipe_autoroller.roll_data('build'), |
| api.override_step_data( |
| 'build.git cl issue', |
| api.json.output({ |
| 'issue': None, |
| 'issue_url': None |
| })), |
| status='FAILURE', |
| ) |
| |
| yield test( |
| 'multiple_failures', |
| api.properties(projects=[ |
| ('build', 'https://example.com/build.git'), |
| ('depot_tools', 'https://example.com/depot_tools.git'), |
| ]), |
| api.recipe_autoroller.roll_data('build'), |
| api.recipe_autoroller.roll_data('depot_tools'), |
| api.override_step_data( |
| 'build.git cl issue', |
| api.json.output({ |
| 'issue': None, |
| 'issue_url': None |
| })), |
| api.override_step_data( |
| 'depot_tools.git cl issue', |
| api.json.output({ |
| 'issue': None, |
| 'issue_url': None |
| })), |
| status='FAILURE', |
| ) |
| |
| yield test( |
| 'repo_data_trivial_cq', |
| api.recipe_autoroller.recipe_cfg('build'), |
| api.recipe_autoroller.repo_data( |
| 'build', |
| trivial=True, |
| status='commit', |
| timestamp=datetime.datetime(2016, 2, 1, 1, 23, 45)), |
| api.time.seed(1451606400), |
| ) |
| |
| yield test( |
| 'repo_data_trivial_cq_stale', |
| api.recipe_autoroller.recipe_cfg('build'), |
| api.recipe_autoroller.repo_data( |
| 'build', |
| trivial=True, |
| status='commit', |
| timestamp=datetime.datetime(2016, 2, 1, 1, 23, 45)), |
| api.time.seed(1454371200), |
| status='FAILURE', |
| ) |
| |
| yield test( |
| 'repo_data_trivial_open', |
| api.recipe_autoroller.repo_data( |
| 'build', trivial=True, status='open', |
| timestamp=datetime.datetime(2016, 2, 1, 1, 23, 45)), |
| api.recipe_autoroller.roll_data('build'), |
| api.time.seed(1451606400), |
| api.post_process(MustRun, 'build.git cl set-close'), |
| ) |
| |
| yield test( |
| 'repo_data_trivial_closed', |
| api.recipe_autoroller.repo_data( |
| 'build', |
| trivial=True, |
| status='closed', |
| timestamp=datetime.datetime(2016, 2, 1, 1, 23, 45)), |
| api.recipe_autoroller.roll_data('build'), |
| api.time.seed(1451606400), |
| ) |
| |
| yield test( |
| 'repo_data_nontrivial_open', |
| api.recipe_autoroller.recipe_cfg('build'), |
| api.recipe_autoroller.repo_data( |
| 'build', |
| trivial=False, |
| status='waiting', |
| timestamp=datetime.datetime(2016, 2, 1, 1, 23, 45)), |
| api.time.seed(1451606400), |
| ) |
| |
| yield test( |
| 'repo_data_nontrivial_open_stale', |
| api.recipe_autoroller.recipe_cfg('build'), |
| api.recipe_autoroller.repo_data( |
| 'build', |
| trivial=False, |
| status='waiting', |
| timestamp=datetime.datetime(2016, 2, 1, 1, 23, 45)), |
| api.time.seed(1454371200), |
| status='FAILURE', |
| ) |
| |
| yield test( |
| 'trivial_custom_tbr_no_dryrun', |
| api.recipe_autoroller.roll_data('build', repo_spec(trivial_commit=False)), |
| ) |
| |
| yield test( |
| 'trivial_custom_tbr_dryrun', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(trivial_commit=False, trivial_dryrun=True)), |
| ) |
| |
| opts = AutorollRecipeOptions.TrivialOptions |
| yield test( |
| 'trivial_code_review_1', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(self_approve_method=opts.CODE_REVIEW_1_APPROVE)), |
| ) |
| |
| yield test( |
| 'trivial_code_review_2', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(self_approve_method=opts.CODE_REVIEW_2_APPROVE)), |
| ) |
| |
| yield test( |
| 'trivial_no_labels_approval', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(self_approve_method=opts.NO_LABELS_APPROVE)), |
| ) |
| |
| yield test( |
| 'trivial_code_review_led', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(self_approve_method=opts.CODE_REVIEW_2_APPROVE)), |
| api.properties(**{'$recipe_engine/led': {'shadowed_bucket': 'roll'}}), |
| ) |
| |
| yield test( |
| 'repo_disabled', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(disable_reason='I am a water buffalo.')), |
| ) |
| |
| # The recipe shouldn't crash if the autoroller options are not specified. |
| yield test( |
| 'trivial_no_autoroll_options', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(include_autoroll_options=False), trivial=True), |
| ) |
| |
| yield test( |
| 'nontrivial_no_autoroll_options', |
| api.recipe_autoroller.roll_data( |
| 'build', repo_spec(include_autoroll_options=False), trivial=False), |
| ) |
| |
| no_cc_authors_spec = RepoSpec() |
| no_cc_authors_spec.autoroll_recipe_options.no_cc_authors = True |
| |
| yield test( |
| 'no_cc_authors', |
| api.recipe_autoroller.roll_data('build'), |
| api.override_step_data( |
| 'build.get deps', |
| api.proto.output_stream( |
| DepRepoSpecs(repo_specs={'recipe_engine': no_cc_authors_spec}))), |
| ) |
| |
| # TODO(fxbug.dev/54380): delete this testcase after crrev.com/c/2252547 has |
| # rolled into all downstream repos that are rolled by an autoroller. |
| yield test( |
| 'failed_get_deps', |
| api.recipe_autoroller.roll_data('build'), |
| api.override_step_data('build.get deps', retcode=1), |
| ) |