Time out Connect registration during startup

This commit is contained in:
firestar5683
2026-11-23 15:26:59 -06:00
parent ff9f0f0b33
commit 0ecbad2a41
4 changed files with 41 additions and 4 deletions
+20
View File
@@ -1,7 +1,10 @@
#!/usr/bin/env python3
import time
import json
import subprocess
import sys
import jwt
from contextlib import nullcontext
from typing import cast
from pathlib import Path
@@ -19,6 +22,23 @@ from openpilot.common.swaglog import cloudlog
UNREGISTERED_DONGLE_ID = "UnregisteredDevice"
STARTUP_REGISTRATION_TIMEOUT = 30
def register_at_startup() -> str | None:
params = Params()
has_identity = params.get("DongleId") or Path(Paths.persist_root(), "comma", "dongle_id").is_file()
with nullcontext() if has_identity else Spinner() as spinner:
if spinner is not None:
spinner.update(f"Registering device (up to {STARTUP_REGISTRATION_TIMEOUT} seconds)")
try:
result = subprocess.run([sys.executable, "-m", "openpilot.system.athena.registration"],
stdout=subprocess.PIPE, text=True, check=True, timeout=STARTUP_REGISTRATION_TIMEOUT)
except subprocess.TimeoutExpired:
cloudlog.warning("Connect registration timed out; starting offline")
return UNREGISTERED_DONGLE_ID
dongle_id = result.stdout.strip().rsplit("\n", 1)[-1]
return None if dongle_id == "None" else dongle_id
def is_registered_device() -> bool:
dongle = Params().get("DongleId")
@@ -1,11 +1,12 @@
import json
import subprocess
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from pathlib import Path
from openpilot.common.test import OpenpilotTestCase
from openpilot.common.params import Params
from openpilot.system.athena.registration import register, UNREGISTERED_DONGLE_ID
from openpilot.system.athena.registration import register, register_at_startup, STARTUP_REGISTRATION_TIMEOUT, UNREGISTERED_DONGLE_ID
from openpilot.system.athena.tests.helpers import MockResponse
from openpilot.common.hardware.hw import Paths
@@ -75,3 +76,19 @@ class TestRegistration(OpenpilotTestCase):
assert m.call_count == 1
assert dongle == UNREGISTERED_DONGLE_ID
assert self.params.get("DongleId") == dongle
def test_startup_timeout_leaves_registration_retryable(self, mocker):
spinner = mocker.patch("openpilot.system.athena.registration.Spinner", autospec=True)
run = mocker.patch("openpilot.system.athena.registration.subprocess.run", autospec=True)
run.side_effect = subprocess.TimeoutExpired("registration", STARTUP_REGISTRATION_TIMEOUT)
assert register_at_startup() == UNREGISTERED_DONGLE_ID
assert self.params.get("DongleId") is None
assert run.call_args.kwargs["timeout"] == STARTUP_REGISTRATION_TIMEOUT
spinner.return_value.__enter__.return_value.update.assert_called_once_with(
f"Registering device (up to {STARTUP_REGISTRATION_TIMEOUT} seconds)")
spinner.return_value.__exit__.assert_called_once()
run.side_effect = None
run.return_value = subprocess.CompletedProcess([], 0, stdout="DONGLE_ID_123\n")
assert register_at_startup() == "DONGLE_ID_123"
+2 -2
View File
@@ -17,7 +17,7 @@ from openpilot.common.hardware import HARDWARE, PC
from openpilot.system.manager.helpers import unblock_stdout, save_bootlog
from openpilot.system.manager.process import ensure_running
from openpilot.system.manager.process_config import managed_processes
from openpilot.system.athena.registration import register, UNREGISTERED_DONGLE_ID
from openpilot.system.athena.registration import register_at_startup, UNREGISTERED_DONGLE_ID
from openpilot.common.swaglog import cloudlog, add_file_handler
from openpilot.common.version import get_build_metadata
from openpilot.common.hardware.hw import Paths
@@ -104,7 +104,7 @@ def manager_init() -> None:
params.put("HardwareSerial", serial, block=True)
# set dongle id
reg_res = register(show_spinner=True)
reg_res = register_at_startup()
if reg_res:
dongle_id = reg_res
else:
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "dd17fb0e6752bbb51904bb27251c34b9cdd4e0199ef30366f19f26ed44a7efbf", "schema_version": 1}
{"protected_inventory_sha256": "4b479a73b1d8213206d165ff0c84721a21c59af8f2e890a1b4fb15696a5bf8c0", "schema_version": 1}