Skip to content

Commit

Permalink
return empty values rather than raising NotImplementedError
Browse files Browse the repository at this point in the history
  • Loading branch information
fregataa committed Feb 18, 2025
1 parent 77a6385 commit eb95be4
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions src/ai/backend/storage/volumes/noop/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Sequence
from datetime import datetime
from pathlib import Path, PurePosixPath
from typing import Any, AsyncIterator, Optional

Expand All @@ -10,18 +11,26 @@
from ...types import (
CapacityUsage,
DirEntry,
DirEntryType,
FSPerfMetric,
QuotaConfig,
QuotaUsage,
Stat,
TreeUsage,
VFolderID,
)
from ..abc import AbstractFSOpModel, AbstractQuotaModel, AbstractVolume


async def _return_empty_dir_entry() -> AsyncIterator[DirEntry]:
yield DirEntry(
"", Path(), DirEntryType.FILE, Stat(0, "", 0, datetime.now(), datetime.now()), ""
)


class NoopQuotaModel(AbstractQuotaModel):
def __init__(self) -> None:
return
pass

def mangle_qspath(self, ref: VFolderID | QuotaScopeID | str | None) -> Path:
return Path()
Expand All @@ -32,32 +41,32 @@ async def create_quota_scope(
options: Optional[QuotaConfig] = None,
extra_args: Optional[dict[str, Any]] = None,
) -> None:
raise NotImplementedError
pass

async def describe_quota_scope(
self,
quota_scope_id: QuotaScopeID,
) -> Optional[QuotaUsage]:
raise NotImplementedError
pass

async def update_quota_scope(
self,
quota_scope_id: QuotaScopeID,
config: QuotaConfig,
) -> None:
raise NotImplementedError
pass

async def unset_quota(
self,
quota_scope_id: QuotaScopeID,
) -> None:
raise NotImplementedError
pass

async def delete_quota_scope(
self,
quota_scope_id: QuotaScopeID,
) -> None:
raise NotImplementedError
pass


class NoopFSOpModel(AbstractFSOpModel):
Expand All @@ -69,40 +78,40 @@ async def copy_tree(
src_path: Path,
dst_path: Path,
) -> None:
raise NotImplementedError
pass

async def move_tree(
self,
src_path: Path,
dst_path: Path,
) -> None:
raise NotImplementedError
pass

async def delete_tree(
self,
path: Path,
) -> None:
raise NotImplementedError
pass

def scan_tree(
self,
path: Path,
*,
recursive: bool = True,
) -> AsyncIterator[DirEntry]:
raise NotImplementedError
return _return_empty_dir_entry()

async def scan_tree_usage(
self,
path: Path,
) -> TreeUsage:
raise NotImplementedError
return TreeUsage(0, 0)

async def scan_tree_size(
self,
path: Path,
) -> BinarySize:
raise NotImplementedError
return BinarySize(0)


class NoopVolume(AbstractVolume):
Expand Down Expand Up @@ -148,13 +157,13 @@ async def get_vfolder_mount(self, vfid: VFolderID, subpath: str) -> Path:
return Path()

async def put_metadata(self, vfid: VFolderID, payload: bytes) -> None:
raise NotImplementedError
pass

async def get_metadata(self, vfid: VFolderID) -> bytes:
raise NotImplementedError
return b""

async def get_performance_metric(self) -> FSPerfMetric:
raise NotImplementedError
return FSPerfMetric(0, 0, 0, 0, 0.0, 0.0)

async def get_fs_usage(self) -> CapacityUsage:
return CapacityUsage(0, 0)
Expand All @@ -178,7 +187,7 @@ def scandir(
*,
recursive: bool = True,
) -> AsyncIterator[DirEntry]:
raise NotImplementedError
return _return_empty_dir_entry()

async def mkdir(
self,
Expand All @@ -188,7 +197,7 @@ async def mkdir(
parents: bool = False,
exist_ok: bool = False,
) -> None:
raise NotImplementedError
pass

async def rmdir(
self,
Expand All @@ -197,42 +206,42 @@ async def rmdir(
*,
recursive: bool = False,
) -> None:
raise NotImplementedError
pass

async def move_file(
self,
vfid: VFolderID,
src: PurePosixPath,
dst: PurePosixPath,
) -> None:
raise NotImplementedError
pass

async def move_tree(
self,
vfid: VFolderID,
src: PurePosixPath,
dst: PurePosixPath,
) -> None:
raise NotImplementedError
pass

async def copy_file(
self,
vfid: VFolderID,
src: PurePosixPath,
dst: PurePosixPath,
) -> None:
raise NotImplementedError
pass

async def prepare_upload(self, vfid: VFolderID) -> str:
raise NotImplementedError
return ""

async def add_file(
self,
vfid: VFolderID,
relpath: PurePosixPath,
payload: AsyncIterator[bytes],
) -> None:
raise NotImplementedError
pass

def read_file(
self,
Expand All @@ -241,7 +250,10 @@ def read_file(
*,
chunk_size: int = 0,
) -> AsyncIterator[bytes]:
raise NotImplementedError
async def _noop() -> AsyncIterator[bytes]:
yield b""

return _noop()

async def delete_files(
self,
Expand All @@ -250,7 +262,7 @@ async def delete_files(
*,
recursive: bool = False,
) -> None:
raise NotImplementedError
pass


def init_noop_volume(
Expand Down

0 comments on commit eb95be4

Please sign in to comment.