Skip to content

Commit

Permalink
fix(BA-585): Empty tag image scan error in docker registry (#3533)
Browse files Browse the repository at this point in the history
Backported-from: main
Backported-to: 23.09
Backported-of: 3533
  • Loading branch information
jopemachine committed Jan 24, 2025
1 parent 9dd8218 commit 73479c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/3513.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix empty tag image scan error in docker registry.
9 changes: 6 additions & 3 deletions src/ai/backend/manager/container_registry/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ async def _scan_image(
while tag_list_url is not None:
async with sess.get(tag_list_url, **rqst_args) as resp:
data = json.loads(await resp.read())
if "tags" in data:
# sometimes there are dangling image names in the hub.
tags.extend(data["tags"])
tags_data = data.get("tags", [])
# sometimes there are dangling image names in the hub.
if not tags_data:
break

tags.extend(tags_data)
tag_list_url = None
next_page_link = resp.links.get("next")
if next_page_link:
Expand Down
26 changes: 26 additions & 0 deletions src/ai/backend/testutils/mock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Any, Callable
from unittest import mock
from unittest.mock import AsyncMock

from aioresponses import CallbackResult


def mock_corofunc(return_value):
"""
Expand Down Expand Up @@ -155,3 +158,26 @@ async def __aenter__(self):

async def __aexit__(self, exc_type, exc_val, exc_tb):
pass


def mock_aioresponses_sequential_payloads(
mock_responses: list[Any],
) -> Callable[..., CallbackResult]:
"""
Creates a callback function for aioresponses that sequentially returns mock responses.
On each invocation, the callback function returns the next mock response from the 'mock_value' list.
If the number of calls exceeds the length of 'mock_value', it raises an Exception to indicate that no more responses are available.
"""
cb_call_counter = 0

def _callback(*args, **kwargs) -> CallbackResult:
nonlocal cb_call_counter

if cb_call_counter >= len(mock_responses):
raise Exception("No more mock responses left")

data = mock_responses[cb_call_counter]
cb_call_counter += 1
return CallbackResult(status=200, payload=data)

return _callback

0 comments on commit 73479c0

Please sign in to comment.