mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-20 02:18:59 +00:00
Support containerd snapshotter progress reporting
This commit is contained in:
@@ -341,23 +341,40 @@ class DockerInterface(JobGroup, ABC):
|
||||
]
|
||||
|
||||
# First set the total bytes to be downloaded/extracted on the main job
|
||||
# Note: With containerd snapshotter, total may be None (time-based progress instead of byte-based)
|
||||
if not install_job.extra:
|
||||
total = 0
|
||||
has_byte_progress = True
|
||||
for job in layer_jobs:
|
||||
if not job.extra:
|
||||
return
|
||||
# If any layer has None for total, we can't do byte-weighted aggregation
|
||||
if job.extra["total"] is None:
|
||||
has_byte_progress = False
|
||||
break
|
||||
total += job.extra["total"]
|
||||
install_job.extra = {"total": total}
|
||||
|
||||
# Store whether we have byte-based progress for later use
|
||||
install_job.extra = {"total": total if has_byte_progress else None}
|
||||
else:
|
||||
total = install_job.extra["total"]
|
||||
has_byte_progress = total is not None
|
||||
|
||||
# Then determine total progress based on progress of each sub-job, factoring in size of each compared to total
|
||||
# Then determine total progress based on progress of each sub-job
|
||||
# If we have byte counts, weight by size. Otherwise, simple average.
|
||||
progress = 0.0
|
||||
stage = PullImageLayerStage.PULL_COMPLETE
|
||||
for job in layer_jobs:
|
||||
if not job.extra:
|
||||
return
|
||||
progress += job.progress * (job.extra["total"] / total)
|
||||
|
||||
if has_byte_progress:
|
||||
# Byte-weighted progress (classic Docker behavior)
|
||||
progress += job.progress * (job.extra["total"] / total)
|
||||
else:
|
||||
# Simple average progress (containerd snapshotter with time-based progress)
|
||||
progress += job.progress / len(layer_jobs)
|
||||
|
||||
job_stage = PullImageLayerStage.from_status(cast(str, job.stage))
|
||||
|
||||
if job_stage < PullImageLayerStage.EXTRACTING:
|
||||
|
||||
@@ -647,3 +647,94 @@ async def test_install_progress_handles_layers_skipping_download(
|
||||
assert job.done is True
|
||||
assert job.progress == 100
|
||||
capture_exception.assert_not_called()
|
||||
|
||||
|
||||
async def test_install_progress_handles_containerd_snapshotter(
|
||||
coresys: CoreSys,
|
||||
test_docker_interface: DockerInterface,
|
||||
capture_exception: Mock,
|
||||
):
|
||||
"""Test install handles containerd snapshotter time-based progress (total=None)."""
|
||||
coresys.core.set_state(CoreState.RUNNING)
|
||||
# Containerd snapshotter reports extraction progress as time elapsed (e.g., "7 s")
|
||||
# with current=7, total=None instead of byte-based progress
|
||||
coresys.docker.docker.api.pull.return_value = [
|
||||
{"status": "Pulling from test/image", "id": "latest"},
|
||||
{"status": "Pulling fs layer", "progressDetail": {}, "id": "layer1"},
|
||||
{
|
||||
"status": "Downloading",
|
||||
"progressDetail": {"current": 100, "total": 1000},
|
||||
"progress": "[=====> ] 100B/1000B",
|
||||
"id": "layer1",
|
||||
},
|
||||
{
|
||||
"status": "Downloading",
|
||||
"progressDetail": {"current": 1000, "total": 1000},
|
||||
"progress": "[==================================================>] 1000B/1000B",
|
||||
"id": "layer1",
|
||||
},
|
||||
{"status": "Download complete", "progressDetail": {}, "id": "layer1"},
|
||||
{
|
||||
"status": "Extracting",
|
||||
"progressDetail": {"current": 1000, "total": 1000},
|
||||
"progress": "[==================================================>] 1000B/1000B",
|
||||
"id": "layer1",
|
||||
},
|
||||
{"status": "Pull complete", "progressDetail": {}, "id": "layer1"},
|
||||
# Layer 2: Containerd snapshotter with time-based extraction
|
||||
{"status": "Pulling fs layer", "progressDetail": {}, "id": "layer2"},
|
||||
{
|
||||
"status": "Downloading",
|
||||
"progressDetail": {"current": 50, "total": 500},
|
||||
"progress": "[=====> ] 50B/500B",
|
||||
"id": "layer2",
|
||||
},
|
||||
{
|
||||
"status": "Downloading",
|
||||
"progressDetail": {"current": 500, "total": 500},
|
||||
"progress": "[==================================================>] 500B/500B",
|
||||
"id": "layer2",
|
||||
},
|
||||
{"status": "Download complete", "progressDetail": {}, "id": "layer2"},
|
||||
# Time-based extraction progress (containerd snapshotter)
|
||||
{
|
||||
"status": "Extracting",
|
||||
"progressDetail": {"current": 3, "total": None},
|
||||
"progress": "3 s",
|
||||
"id": "layer2",
|
||||
},
|
||||
{
|
||||
"status": "Extracting",
|
||||
"progressDetail": {"current": 7, "total": None},
|
||||
"progress": "7 s",
|
||||
"id": "layer2",
|
||||
},
|
||||
{"status": "Pull complete", "progressDetail": {}, "id": "layer2"},
|
||||
{"status": "Digest: sha256:test"},
|
||||
{"status": "Status: Downloaded newer image for test/image:latest"},
|
||||
]
|
||||
|
||||
with patch.object(
|
||||
type(coresys.supervisor), "arch", PropertyMock(return_value="amd64")
|
||||
):
|
||||
event = asyncio.Event()
|
||||
job, install_task = coresys.jobs.schedule_job(
|
||||
test_docker_interface.install,
|
||||
JobSchedulerOptions(),
|
||||
AwesomeVersion("1.2.3"),
|
||||
"test",
|
||||
)
|
||||
|
||||
async def listen_for_job_end(reference: SupervisorJob):
|
||||
if reference.uuid != job.uuid:
|
||||
return
|
||||
event.set()
|
||||
|
||||
coresys.bus.register_event(BusEvent.SUPERVISOR_JOB_END, listen_for_job_end)
|
||||
await install_task
|
||||
await event.wait()
|
||||
|
||||
# The key assertion: Job should complete without crashing on None total
|
||||
assert job.done is True
|
||||
assert job.progress == 100
|
||||
capture_exception.assert_not_called()
|
||||
|
||||
Reference in New Issue
Block a user