Retry transient dependency downloads during source qualification
Device Core qualification / qualify (push) Successful in 6m3s
Device Core qualification / qualify (push) Successful in 6m3s
This commit is contained in:
@@ -34,6 +34,13 @@ Installed Platform runner013 adds redacted per-field evidence before automatic
|
|||||||
rollback. It does not relax runtime acceptance or prove the cause fixed. The next
|
rollback. It does not relax runtime acceptance or prove the cause fixed. The next
|
||||||
application release will use this instrumentation; the source qualification pins
|
application release will use this instrumentation; the source qualification pins
|
||||||
the same published Platform commit.
|
the same published Platform commit.
|
||||||
|
Run10 (`893cb6490c1d37df1f9bca19d5c058c304091b87`) then failed before producing
|
||||||
|
an artifact: npm reported `ECONNRESET` during dependency installation. No release
|
||||||
|
was installed. Dependency installation now makes at most three frozen `npm ci`
|
||||||
|
attempts for explicit ECONNRESET, ETIMEDOUT or EAI_AGAIN errors, with 5/10second
|
||||||
|
pauses. Integrity, authentication, lockfile, unclassified and mixed errors fail
|
||||||
|
immediately. Build/test failures are never retried by this rule, and an exhausted
|
||||||
|
install failure cannot produce a qualification report.
|
||||||
The complete evidence and remaining gates are recorded in the Platform
|
The complete evidence and remaining gates are recorded in the Platform
|
||||||
repository at `infra/device-core-deploy/ACCEPTANCE_20260929.md` and in Ops.
|
repository at `infra/device-core-deploy/ACCEPTANCE_20260929.md` and in Ops.
|
||||||
|
|
||||||
|
|||||||
+28
-2
@@ -9,6 +9,7 @@ from pathlib import Path
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
SHA = re.compile(r"[0-9a-f]{40}")
|
SHA = re.compile(r"[0-9a-f]{40}")
|
||||||
@@ -19,15 +20,37 @@ DEPENDENCIES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def run(args, cwd, capture=False):
|
def run(args, cwd, capture=False, capture_errors=False):
|
||||||
return subprocess.run(
|
return subprocess.run(
|
||||||
args, cwd=cwd, check=True, text=True,
|
args, cwd=cwd, check=True, text=True,
|
||||||
stdout=subprocess.PIPE if capture else None,
|
stdout=subprocess.PIPE if capture else None,
|
||||||
|
stderr=subprocess.STDOUT if capture_errors else None,
|
||||||
env={**os.environ, "GIT_TERMINAL_PROMPT": "0", "CI": "true",
|
env={**os.environ, "GIT_TERMINAL_PROMPT": "0", "CI": "true",
|
||||||
"NODEDC_LAUNCHER_REPO": str(Path(__file__).resolve().parents[3] / "NODEDC_LAUNCHER")},
|
"NODEDC_LAUNCHER_REPO": str(Path(__file__).resolve().parents[3] / "NODEDC_LAUNCHER")},
|
||||||
).stdout
|
).stdout
|
||||||
|
|
||||||
|
|
||||||
|
def install_dependencies(cwd):
|
||||||
|
"""Retry only explicit transport failures in a disposable npm ci checkout."""
|
||||||
|
command = ["npm", "ci", "--ignore-scripts", "--no-audit", "--no-fund"]
|
||||||
|
transient = {"ECONNRESET", "ETIMEDOUT", "EAI_AGAIN"}
|
||||||
|
for attempt in range(1, 4):
|
||||||
|
try:
|
||||||
|
output = run(command, cwd, capture=True, capture_errors=True)
|
||||||
|
except subprocess.CalledProcessError as error:
|
||||||
|
output = error.output or ""
|
||||||
|
print(output, end="", flush=True)
|
||||||
|
codes = set(re.findall(r"^npm (?:error|ERR!) code ([A-Z][A-Z0-9_]*)\s*$",
|
||||||
|
output, re.MULTILINE))
|
||||||
|
if attempt == 3 or not codes or not codes.issubset(transient):
|
||||||
|
raise
|
||||||
|
print("ci_dependency_retry=" + str(attempt) + ";codes=" + ",".join(sorted(codes)), flush=True)
|
||||||
|
time.sleep(5 * attempt)
|
||||||
|
else:
|
||||||
|
print(output or "", end="", flush=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def read_lock(root):
|
def read_lock(root):
|
||||||
lock = json.loads((root / "infra/ci/sources.lock.json").read_text())
|
lock = json.loads((root / "infra/ci/sources.lock.json").read_text())
|
||||||
if lock.get("schema") != "nodedc.device-core.ci-sources.v1":
|
if lock.get("schema") != "nodedc.device-core.ci-sources.v1":
|
||||||
@@ -126,7 +149,10 @@ def qualify(root, commit, lock, report):
|
|||||||
completed = []
|
completed = []
|
||||||
for name, cwd, command in steps:
|
for name, cwd, command in steps:
|
||||||
print("ci_step=" + name, flush=True)
|
print("ci_step=" + name, flush=True)
|
||||||
run(command, cwd)
|
if name in ("design-install", "device-install"):
|
||||||
|
install_dependencies(cwd)
|
||||||
|
else:
|
||||||
|
run(command, cwd)
|
||||||
completed.append(name)
|
completed.append(name)
|
||||||
verify_sources(root, commit, lock)
|
verify_sources(root, commit, lock)
|
||||||
result = {
|
result = {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import importlib.util
|
import importlib.util
|
||||||
|
import io
|
||||||
import json
|
import json
|
||||||
|
from contextlib import redirect_stdout
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -107,6 +109,52 @@ class QualificationTests(unittest.TestCase):
|
|||||||
CI.qualify(self.root, self.commit, {}, report)
|
CI.qualify(self.root, self.commit, {}, report)
|
||||||
self.assertEqual(json.loads(report.read_text())["sourceCommit"], "old")
|
self.assertEqual(json.loads(report.read_text())["sourceCommit"], "old")
|
||||||
|
|
||||||
|
def test_network_install_error_recovers_using_the_same_frozen_command(self):
|
||||||
|
failure = subprocess.CalledProcessError(152, "npm", output="npm error code ECONNRESET\n")
|
||||||
|
with mock.patch.object(CI, "run", side_effect=[failure, "installed\n"]) as execute, \
|
||||||
|
mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||||
|
CI.install_dependencies(self.root)
|
||||||
|
self.assertEqual(execute.call_count, 2)
|
||||||
|
self.assertEqual(execute.call_args_list[0], execute.call_args_list[1])
|
||||||
|
self.assertEqual(execute.call_args.args[0], ["npm", "ci", "--ignore-scripts", "--no-audit", "--no-fund"])
|
||||||
|
pause.assert_called_once_with(5)
|
||||||
|
|
||||||
|
def test_permanent_mixed_and_unclassified_install_failures_never_retry(self):
|
||||||
|
for output in ("npm error code EINTEGRITY\n", "npm error code E401\n",
|
||||||
|
"npm error code EUSAGE\n", "download ECONNRESET in explanatory text\n",
|
||||||
|
"npm error code ECONNRESET\nnpm error code E403\n", ""):
|
||||||
|
with self.subTest(output=output), mock.patch.object(
|
||||||
|
CI, "run", side_effect=subprocess.CalledProcessError(1, "npm", output=output)
|
||||||
|
) as execute, mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||||
|
with self.assertRaises(subprocess.CalledProcessError):
|
||||||
|
CI.install_dependencies(self.root)
|
||||||
|
execute.assert_called_once()
|
||||||
|
pause.assert_not_called()
|
||||||
|
|
||||||
|
def test_install_retries_are_bounded_and_do_not_publish_a_report(self):
|
||||||
|
report = self.root.parent / "result.json"
|
||||||
|
failure = subprocess.CalledProcessError(1, "npm", output="npm error code ETIMEDOUT\n")
|
||||||
|
with mock.patch.object(CI, "verify_sources"), mock.patch.object(
|
||||||
|
CI, "run", side_effect=["v22.21.0\n", "10.9.4\n", failure, failure, failure]
|
||||||
|
) as execute, mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||||
|
with self.assertRaises(subprocess.CalledProcessError):
|
||||||
|
CI.qualify(self.root, self.commit, {"node": "v22.21.0", "npm": "10.9.4"}, report)
|
||||||
|
self.assertEqual(execute.call_count, 5)
|
||||||
|
self.assertEqual(pause.call_args_list, [mock.call(5), mock.call(10)])
|
||||||
|
self.assertFalse(report.exists())
|
||||||
|
|
||||||
|
def test_build_failure_is_not_retried_as_an_install(self):
|
||||||
|
report = self.root.parent / "result.json"
|
||||||
|
failure = subprocess.CalledProcessError(1, "npm", output="npm error code ECONNRESET\n")
|
||||||
|
with mock.patch.object(CI, "verify_sources"), mock.patch.object(
|
||||||
|
CI, "run", side_effect=["v22.21.0\n", "10.9.4\n", "installed\n", failure]
|
||||||
|
) as execute, mock.patch.object(CI.time, "sleep") as pause, redirect_stdout(io.StringIO()):
|
||||||
|
with self.assertRaises(subprocess.CalledProcessError):
|
||||||
|
CI.qualify(self.root, self.commit, {"node": "v22.21.0", "npm": "10.9.4"}, report)
|
||||||
|
self.assertEqual(execute.call_count, 4)
|
||||||
|
pause.assert_not_called()
|
||||||
|
self.assertFalse(report.exists())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user