Skip to content

Commit

Permalink
change method name and add docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
fregataa committed Nov 19, 2024
1 parent 8ab08cf commit 8a01dbc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
19 changes: 15 additions & 4 deletions src/ai/backend/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ async def pull_image(
"""

@abstractmethod
async def pull_image_in_background(
async def pull_image_with_stream(
self,
image_ref: ImageRef,
registry_conf: ImageRegistry,
Expand All @@ -1634,9 +1634,20 @@ async def pull_image_in_background(
timeout: Optional[float] = None,
) -> None:
"""
Pull the given image from the given registry.
Read the streaming response and report through the given ProgressReporter.
Return `None` if the pull task is successfully completed. Else, return an error message.
Pull an image with streaming output from a registry.
Stream the pull operation response and report progress through a ProgressReporter.
Args:
image_ref (ImageRef): The image name and tag to pull
registry_conf (ImageRegistry): The image registry configuration
reporter (Optional[ProgressReporter]): The progress reporter instance. If None, progress won't be reported
timeout (Optional[float]): The pull timeout
Returns:
None
Raises:
ImagePullFailure: If the pull operation fails or returns error messages
"""

@abstractmethod
Expand Down
8 changes: 6 additions & 2 deletions src/ai/backend/agent/docker/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
from ai.backend.logging.formatter import pretty

from ..agent import ACTIVE_STATUS_SET, AbstractAgent, AbstractKernelCreationContext, ComputerContext
from ..exception import ContainerCreationError, UnsupportedResource
from ..exception import ContainerCreationError, ImagePullFailure, UnsupportedResource
from ..fs import create_scratch_filesystem, destroy_scratch_filesystem
from ..kernel import AbstractKernel, KernelFeatures
from ..proxy import DomainSocketProxy, proxy_connection
Expand Down Expand Up @@ -1513,14 +1513,15 @@ async def pull_image(
async with closing_async(Docker()) as docker:
await docker.images.pull(image_ref.canonical, auth=auth_config, timeout=timeout)

async def pull_image_in_background(
async def pull_image_with_stream(
self,
image_ref: ImageRef,
registry_conf: ImageRegistry,
*,
reporter: Optional[ProgressReporter] = None,
timeout: Optional[float] = None,
) -> None:
err_msg: Optional[str] = None
auth_config = None
reg_user = registry_conf.get("username")
reg_passwd = registry_conf.get("password")
Expand Down Expand Up @@ -1708,6 +1709,7 @@ async def handle_err_response(resp: PullErrorResponse) -> None:
else:
await handle_response(_resp, layer_ids)
case dict() if resp.get("error"):
err_msg = str(resp["error"])
await handle_err_response(
PullErrorResponse(
error=resp["error"],
Expand All @@ -1718,6 +1720,8 @@ async def handle_err_response(resp: PullErrorResponse) -> None:
raise KeyError
except KeyError:
log.warning(f"Unable to deserialize pulling response. skip. (resp:{str(resp)})")
if err_msg is not None:
raise ImagePullFailure(err_msg)

async def check_image(
self, image_ref: ImageRef, image_id: str, auto_pull: AutoPullBehavior
Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/agent/dummy/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async def pull_image(
delay = self.dummy_agent_cfg["delay"]["pull-image"]
await asyncio.sleep(delay)

async def pull_image_in_background(
async def pull_image_with_stream(
self,
image_ref: ImageRef,
registry_conf: ImageRegistry,
Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/agent/kubernetes/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ async def pull_image(
# TODO: Add support for appropriate image pulling mechanism on K8s
pass

async def pull_image_in_background(
async def pull_image_with_stream(
self,
image_ref: ImageRef,
registry_conf: ImageRegistry,
Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/agent/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ async def _pull(reporter: ProgressReporter, *, img_conf: ImageConfig) -> None:
Optional[float], self.local_config["agent"]["api"]["pull-timeout"]
)
try:
await self.agent.pull_image_in_background(
await self.agent.pull_image_with_stream(
img_ref, img_conf["registry"], reporter=reporter, timeout=image_pull_timeout
)
except asyncio.TimeoutError:
Expand Down

0 comments on commit 8a01dbc

Please sign in to comment.