Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BA-585): Empty tag image scan error in docker registry (#3533) #3543

Open
wants to merge 1 commit into
base: 23.09
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading