blob: fb3355b83f3a794a20d4233f91e143deef149692 [file]
# Copyright 2020 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# Copied from
# https://chromium.googlesource.com/chromiumos/infra/recipes/+/HEAD/recipe_modules/repo/
# pylint: disable=missing-module-docstring
from __future__ import annotations
from collections.abc import Iterator
from recipe_engine import recipe_api, recipe_test_api
DEPS = [
'pigweed/repo',
'recipe_engine/path',
]
def RunSteps(api: recipe_api.RecipeScriptApi):
api.repo.ensure_synced_checkout(
api.path.cleanup_dir / 'ensure', 'http://manifest_url'
)
def attempt_retry_repo(api, attempt): # pylint: disable=invalid-name
"""Step data for retries."""
if attempt == 1:
step_text = 'ensure synced checkout.repo init'
retcode = 128
elif attempt == 2:
step_text = 'ensure synced checkout.clean up root path and retry'
retcode = 0
else:
step_text = 'ensure synced checkout.repo sync'
retcode = 128
return api.step_data(step_text, retcode=retcode)
def GenTests(api) -> Iterator[recipe_test_api.TestData]:
yield (
api.test('repo_retry_failure', status='INFRA_FAILURE')
+ attempt_retry_repo(api, 1)
+ attempt_retry_repo(api, 2)
+ attempt_retry_repo(api, 3)
)