Commit 42afe9a2 authored by Xinan Lin's avatar Xinan Lin Committed by LUCI CQ

Ensure the new patchset exists in Gerrit before we set bot-commit+1

"Publish Change Edit" is not a synchronized API call on Gerrit.
After the call, we need to explicitly check if the new patch exists
in Gerrit. Or, we may label +1 on an old patch.

BUG=1286212
TEST=train
Recipe-Nontrivial-Roll: chrome_release
Change-Id: I1443e2b4cf702f7cb4feebb43e34923f11383f35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3384422Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Xinan Lin <linxinan@chromium.org>
parent 9fa0cb72
......@@ -241,7 +241,7 @@ revision map. This doesn't overwrite the revision if it was already set.
&emsp; **@use_mirror.setter**<br>&mdash; **def [use\_mirror](/recipes/recipe_modules/gclient/api.py#116)(self, val):**
### *recipe_modules* / [gerrit](/recipes/recipe_modules/gerrit)
[DEPS](/recipes/recipe_modules/gerrit/__init__.py#3): [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/file][recipe_engine/recipe_modules/file], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
[DEPS](/recipes/recipe_modules/gerrit/__init__.py#3): [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/file][recipe_engine/recipe_modules/file], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step], [recipe\_engine/time][recipe_engine/recipe_modules/time]
PYTHON_VERSION_COMPATIBILITY: PY2+3
......@@ -1164,6 +1164,7 @@ PYTHON_VERSION_COMPATIBILITY: PY2+3
[recipe_engine/recipe_modules/resultdb]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/README.recipes.md#recipe_modules-resultdb
[recipe_engine/recipe_modules/runtime]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/README.recipes.md#recipe_modules-runtime
[recipe_engine/recipe_modules/step]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/README.recipes.md#recipe_modules-step
[recipe_engine/recipe_modules/time]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/README.recipes.md#recipe_modules-time
[recipe_engine/recipe_modules/url]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/README.recipes.md#recipe_modules-url
[recipe_engine/recipe_modules/version]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/README.recipes.md#recipe_modules-version
[recipe_engine/wkt/RecipeApi]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/ffb8f400af94e1955236df9e30c153729173fa2e/recipe_engine/recipe_api.py#883
......@@ -8,4 +8,5 @@ DEPS = [
'recipe_engine/python',
'recipe_engine/raw_io',
'recipe_engine/step',
'recipe_engine/time',
]
......@@ -394,6 +394,21 @@ class GerritApi(recipe_api.RecipeApi):
change,
])
# Make sure the new patchset is propagated to Gerrit backend.
with self.m.step.nest('verify the patchset exists on CL %d' % change):
retries = 0
max_retries = 2
while retries <= max_retries:
try:
if self.get_revision_info(host, change, 2):
break
except self.m.step.InfraFailure:
if retries == max_retries: # pragma: no cover
raise
retries += 1
with self.m.step.nest('waiting before retry'):
self.m.time.sleep((2**retries) * 10)
if submit or submit_later:
self('set Bot-Commit+1 for change %d' % change, [
'setbotcommit',
......
......@@ -279,6 +279,96 @@
"infra_step": true,
"name": "gerrit publish edit"
},
{
"cmd": [],
"name": "verify the patchset exists on CL 91827"
},
{
"cmd": [
"vpython",
"-u",
"RECIPE_REPO[depot_tools]/gerrit_client.py",
"changes",
"--host",
"https://chromium-review.googlesource.com",
"--json_file",
"/path/to/tmp/json",
"--limit",
"1",
"-p",
"change=91827",
"-o",
"ALL_REVISIONS",
"-o",
"ALL_COMMITS"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"name": "verify the patchset exists on CL 91827.gerrit changes",
"~followup_annotations": [
"@@@STEP_NEST_LEVEL@1@@@",
"@@@STEP_LOG_LINE@json.output@[]@@@",
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [],
"name": "verify the patchset exists on CL 91827.waiting before retry",
"~followup_annotations": [
"@@@STEP_NEST_LEVEL@1@@@"
]
},
{
"cmd": [
"vpython",
"-u",
"RECIPE_REPO[depot_tools]/gerrit_client.py",
"changes",
"--host",
"https://chromium-review.googlesource.com",
"--json_file",
"/path/to/tmp/json",
"--limit",
"1",
"-p",
"change=91827",
"-o",
"ALL_REVISIONS",
"-o",
"ALL_COMMITS"
],
"env": {
"PATH": "<PATH>:RECIPE_REPO[depot_tools]"
},
"infra_step": true,
"name": "verify the patchset exists on CL 91827.gerrit changes (2)",
"~followup_annotations": [
"@@@STEP_NEST_LEVEL@1@@@",
"@@@STEP_LOG_LINE@json.output@[@@@",
"@@@STEP_LOG_LINE@json.output@ {@@@",
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"91827\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"branch\": \"main\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"change_id\": \"Ideadbeef\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"created\": \"2017-01-30 13:11:20.000000000\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"has_review_started\": false, @@@",
"@@@STEP_LOG_LINE@json.output@ \"project\": \"chromium/src\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"revisions\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"184ebe53805e102605d11f6b143486d15c23a09c\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"_number\": \"2\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"commit\": {@@@",
"@@@STEP_LOG_LINE@json.output@ \"message\": \"Change commit message\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@ }, @@@",
"@@@STEP_LOG_LINE@json.output@ \"status\": \"NEW\", @@@",
"@@@STEP_LOG_LINE@json.output@ \"subject\": \"Change title\"@@@",
"@@@STEP_LOG_LINE@json.output@ }@@@",
"@@@STEP_LOG_LINE@json.output@]@@@",
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"vpython",
......
......@@ -102,6 +102,8 @@ def GenTests(api):
api.gerrit.make_gerrit_create_tag_response_data()) +
api.step_data('gerrit create change at (v8/v8 main)',
api.gerrit.update_files_response_data()) +
api.step_data('verify the patchset exists on CL 91827.gerrit changes',
api.gerrit.get_empty_changes_response_data()) +
api.step_data('gerrit submit change 91827',
api.gerrit.update_files_response_data(status='MERGED')) +
api.step_data('gerrit get_gerrit_branch (v8/v8 main)',
......
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