Compare commits

...

1 Commits

Author SHA1 Message Date
mtawata 2db3e7845a fix agnos download status output 2026-11-19 14:08:42 -08:00
9 changed files with 66 additions and 19 deletions
+9 -5
View File
@@ -211,7 +211,7 @@ def clear_partition_hash(target_slot_number: int, partition: dict) -> None:
os.sync()
def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog):
def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog, progress=None):
path = get_partition_path(target_slot_number, partition)
downloader = StreamingDecompressor(partition['url'])
@@ -227,6 +227,8 @@ def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog)
if p != last_p:
last_p = p
print(f"Installing {partition['name']}: {p}", flush=True)
if progress is not None:
progress(f"Downloading and writing AGNOS {partition['name']}", p)
if raw_hash.hexdigest().lower() != partition['hash_raw'].lower():
raise Exception(f"Raw hash mismatch '{raw_hash.hexdigest().lower()}'")
@@ -240,7 +242,7 @@ def extract_compressed_image(target_slot_number: int, partition: dict, cloudlog)
os.sync()
def flash_partition(target_slot_number: int, partition: dict, cloudlog, standalone=False):
def flash_partition(target_slot_number: int, partition: dict, cloudlog, standalone=False, progress=None):
cloudlog.info(f"Downloading and writing {partition['name']}")
if verify_partition(target_slot_number, partition):
@@ -254,7 +256,7 @@ def flash_partition(target_slot_number: int, partition: dict, cloudlog, standalo
path = get_partition_path(target_slot_number, partition)
extract_compressed_image(target_slot_number, partition, cloudlog)
extract_compressed_image(target_slot_number, partition, cloudlog, progress=progress)
# Write hash after successful flash
if not full_check:
@@ -278,7 +280,7 @@ def swap(manifest_path: str, target_slot_number: int, cloudlog) -> None:
cloudlog.error(f"Swap failed {out}")
def flash_agnos_update(manifest_path: str, target_slot_number: int, cloudlog, standalone=False) -> None:
def flash_agnos_update(manifest_path: str, target_slot_number: int, cloudlog, standalone=False, progress=None) -> None:
update = load_manifest(manifest_path)
cloudlog.info(f"Target slot {target_slot_number}")
@@ -291,7 +293,9 @@ def flash_agnos_update(manifest_path: str, target_slot_number: int, cloudlog, st
for retries in range(10):
try:
flash_partition(target_slot_number, partition, cloudlog, standalone)
if progress is not None:
progress(f"Downloading and verifying AGNOS {partition['name']}", None)
flash_partition(target_slot_number, partition, cloudlog, standalone, progress=progress)
success = True
break
@@ -181,3 +181,20 @@ def test_explicit_incompatible_manual_manifest_is_not_replaced(tmp_path, release
with patch.object(agnos, 'DEVICE_MODEL_PATH', model):
with pytest.raises(RuntimeError, match='incompatible with comma 3'):
agnos.load_manifest(str(manual))
def test_agnos_download_reports_partition_progress(tmp_path):
import hashlib
data = b'firmware'
digest = hashlib.sha256(data).hexdigest()
partition = {'name': 'system', 'url': 'https://example.invalid/system.xz', 'size': len(data), 'sparse': False, 'hash': digest, 'hash_raw': digest}
downloader = Mock(sha256=hashlib.sha256(data))
downloader.read.side_effect = [data[:4], data[4:], b'']
progress = Mock()
with patch.object(agnos, 'get_partition_path', return_value=str(tmp_path / 'partition')), \
patch.object(agnos, 'StreamingDecompressor', return_value=downloader), patch.object(agnos.os, 'sync'):
agnos.extract_compressed_image(1, partition, Mock(), progress=progress)
assert [call.args for call in progress.call_args_list] == [
('Downloading and writing AGNOS system', 50), ('Downloading and writing AGNOS system', 100)]
assert (tmp_path / 'partition').read_bytes() == data
@@ -27,7 +27,7 @@ def _fast_state(raw):
try:
value = json.loads(raw) if raw is not None else None
if not isinstance(value, dict) or value.get("version") != 1 or value.get("stage") not in (
"preparing", "fetching", "validating", "applying", "submodules", "rebooting", "complete", "error", "finalizing"):
"preparing", "fetching", "validating", "applying", "agnos", "submodules", "rebooting", "complete", "error", "finalizing"):
return None
detail = value.get("detail")
if not isinstance(detail, str) or len(detail) > 512:
@@ -814,3 +814,7 @@ let toggleSettings
SoftwarePage.methods.configureAutomaticInstalls.call({operations:{restartSchedule:'0 0 * * *',restartTimezone:'UTC'},restartTimezone:'Asia/Tokyo',
feed:{configureInstallPreferences:(...args)=>{toggleSettings=args}}},true)
assert.deepEqual(toggleSettings,[true,'0 0 * * *','UTC'],'toggle preserves the saved timezone')
assert.deepEqual(softwareProgress({...updater, state: "downloading..."},
{progress: {stage: "agnos", detail: "Downloading and writing AGNOS system", percent: 37}}),
{active: true, failed: false, percent: 37, label: "Downloading and installing AGNOS", detail: "Downloading and writing AGNOS system"})
@@ -70,7 +70,7 @@ export function softwareProgress(updater, operations = {}) {
"finalizing update...": "Preparing update", "updating...": "Updating software",
checking: "Checking for updates", downloading: "Downloading update", finalizing: "Preparing update",
preparing: "Preparing update", fetching: "Downloading update", validating: "Validating update",
applying: "Applying update", submodules: "Preparing dependencies", rebooting: "Restarting device",
agnos: "Downloading and installing AGNOS", applying: "Applying update", submodules: "Preparing dependencies", rebooting: "Restarting device",
complete: "Update complete", error: "Update failed", unavailable: "Updater status unavailable", timed_out: "Update is taking longer than expected" }
if (!active && (!stage || ["idle", "unknown"].includes(stage))) return null
const percent = Number.isFinite(progress?.percent) && progress.percent >= 0 && progress.percent <= 100 ? progress.percent : null
@@ -238,7 +238,7 @@ class TestRetainedAgnos(unittest.TestCase):
manifest.parent.mkdir(parents=True)
manifest.write_text("[]")
self.updater.handle_agnos_update()
self.flash.assert_called_once_with(str(self.root / 'openpilot/common/hardware/comma/agnos.json'), 1, self.updater.cloudlog)
self.flash.assert_called_once_with(str(self.root / 'openpilot/common/hardware/comma/agnos.json'), 1, self.updater.cloudlog, progress=None)
self.assertTrue((ROOT / 'openpilot/common/hardware/comma/agnos.json').is_file())
self.updater.set_consistent_flag.assert_called_once_with(False)
@@ -248,7 +248,7 @@ class TestRetainedAgnos(unittest.TestCase):
manifest.parent.mkdir(parents=True)
manifest.write_text("[]")
self.updater.handle_agnos_update()
self.flash.assert_called_once_with(str(manifest), 1, self.updater.cloudlog)
self.flash.assert_called_once_with(str(manifest), 1, self.updater.cloudlog, progress=None)
self.updater.set_consistent_flag.assert_called_once_with(False)
def test_invalid_policy_cannot_finalize_or_flash(self):
@@ -174,7 +174,7 @@ class TestVendoredUpdate(unittest.TestCase):
patch.object(self.updater, "normal_update") as normal:
with self.assertRaises(self.updated.FastUpdateIncompatible):
self.updater.fast_update(BRANCH, self.initial_commit)
normal.assert_not_called() # Explicit fast/rollback/version operations keep their contract.
normal.assert_not_called() # Explicit fast operations keep their contract.
@patch('openpilot.starpilot.drive_state.evidence.PhysicalSource', return_value=Mock(update_ready=Mock(return_value=True)))
def test_download_selected_version_stages_exact_commit_without_installing(self, _physical):
@@ -406,6 +406,28 @@ class TestVendoredUpdate(unittest.TestCase):
self.assertTrue(self.updater.params.values["UpdateAvailable"])
progress.assert_called_with("rebooting", "Update installed. Restarting device.")
@patch('openpilot.starpilot.drive_state.evidence.PhysicalSource', return_value=Mock(update_ready=Mock(return_value=True)))
def test_selected_version_falls_back_to_full_update_without_installing_branch_head(self, _physical):
installed = self.root / "installed"
self.git(self.root, "clone", "--no-local", str(self.merged), str(installed))
self.updated.BASEDIR = str(installed)
self.git(installed, 'remote', 'set-url', 'origin', str(self.source))
(self.source / "panda/README.md").write_text("Selected OS update")
selected = self.commit_source("Selected version")
(self.source / "panda/README.md").write_text("Newer branch head")
self.commit_source("Newer version")
self.updated.AGNOS = True
from openpilot.starpilot.software.fast_update import FastUpdateIncompatible
with patch('openpilot.starpilot.software.fast_update.fast_update', side_effect=FastUpdateIncompatible('OS update required')):
self.assertEqual(self.updater.fast_update(BRANCH, self.initial_commit, selected), 'reboot-requested')
self.assertEqual(self.git(self.finalized, 'rev-parse', 'HEAD'), selected)
self.assertEqual(self.git(installed, 'rev-parse', 'HEAD'), self.initial_commit)
self.assertTrue(self.updater.params.values['DoReboot'])
callback = self.updated.handle_agnos_update.call_args.kwargs['progress']
callback('Downloading and writing AGNOS system', 37)
self.assertEqual(self.updater.params.values['UpdaterFastState']['stage'], 'agnos')
self.assertEqual(self.updater.params.values['UpdaterFastState']['percent'], 37)
def test_normal_fallback_never_reboots_after_parked_authority_is_lost(self):
installed = self.root / "installed"
self.git(self.root, "clone", "--no-local", str(self.merged), str(installed))
+8 -8
View File
@@ -361,7 +361,7 @@ def finalize_update(progress=None) -> None:
cloudlog.info("done finalizing overlay")
def handle_agnos_update() -> None:
def handle_agnos_update(progress=None) -> None:
cur_version = HARDWARE.get_os_version()
config = run(["bash", "-c", r"unset AGNOS_VERSION AGNOS_UPDATE_POLICY; source launch_env.sh && " +
"printf '%s\\n%s\\n' \"$AGNOS_VERSION\" \"${AGNOS_UPDATE_POLICY:-auto}\""], OVERLAY_MERGED).splitlines()
@@ -386,7 +386,7 @@ def handle_agnos_update() -> None:
if not os.path.isfile(manifest_path): # releases before the openpilot/ move
manifest_path = os.path.join(OVERLAY_MERGED, "system/hardware/tici/agnos.json")
target_slot_number = get_target_slot_number()
flash_agnos_update(manifest_path, target_slot_number, cloudlog)
flash_agnos_update(manifest_path, target_slot_number, cloudlog, progress=progress)
class Updater:
@@ -746,13 +746,13 @@ class Updater:
current_os=HARDWARE.get_os_version(), invalidate=invalidate, rollback=rollback, progress=installed_progress,
selected_commit=selected_commit, versions_only=versions_only)
except FastUpdateIncompatible:
if not automatic:
if not automatic and (selected_commit is None or rollback):
raise
return self.normal_update(branch, commit, parked, progress)
return self.normal_update(branch, commit, parked, progress, selected_commit=selected_commit)
finally:
source.close()
def normal_update(self, branch: str, commit: str, parked, progress) -> str:
def normal_update(self, branch: str, commit: str, parked, progress, *, selected_commit=None) -> str:
def admitted():
if not parked() or self.get_commit_hash(BASEDIR) != commit:
raise FastUpdateError("Update source or parked state changed")
@@ -764,7 +764,7 @@ class Updater:
self.params.put("UpdaterState", "checking...", block=True)
if phone_uplink_active():
raise FastUpdateError("Software downloads are disabled while using phone internet")
if not self.fetch_update():
if not self.fetch_update(selected_commit=selected_commit, admitted=admitted):
raise FastUpdateError("Target branch is no longer available")
admitted()
self.params.put_bool("UpdateAvailable", True, block=True)
@@ -833,9 +833,9 @@ class Updater:
validate_update_revision(OVERLAY_MERGED, "HEAD", branch)
cloudlog.info("git reset success: %s", '\n'.join(r))
# TODO: show agnos download progress
if AGNOS and not legacy_return:
handle_agnos_update()
self.progress('agnos', 'Checking AGNOS operating system update...', background=background)
handle_agnos_update(progress=lambda detail, percent: self.progress('agnos', detail, background=background, percent=percent))
# Create the finalized, ready-to-swap update
self.params.put("UpdaterState", "finalizing update...", block=True)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "972ca48df861316d293c41cc3ddb3601e9e4057a542f4648aff477752d68f5d8", "schema_version": 1}
{"protected_inventory_sha256": "946e55cd9ec6abdcec53773d7343faed6b3115af978cf87a246262a5824dddb1", "schema_version": 1}