From 2e70bd59a84cf4697552f7d0d20c756ace2d2fe6 Mon Sep 17 00:00:00 2001 From: Joao Mario Lago Date: Wed, 13 Mar 2024 12:46:57 -0300 Subject: [PATCH] core: kraken: Add check for space prior to install * Add free space check in kraken prior to install extension --- core/services/kraken/kraken.py | 8 ++++++++ core/services/kraken/main.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/core/services/kraken/kraken.py b/core/services/kraken/kraken.py index 01a6eb63b6..3220175966 100644 --- a/core/services/kraken/kraken.py +++ b/core/services/kraken/kraken.py @@ -346,5 +346,13 @@ async def load_stats(self) -> Dict[str, Any]: } return result + async def has_enough_disk_space(self, path: str = "/", required: int = 1073741824) -> bool: + try: + free_space = psutil.disk_usage(path).free + # Right now only check if there is 1GB of free space as a hardcoded value + return free_space > required + except FileNotFoundError: + return False + async def stop(self) -> None: self.should_run = False diff --git a/core/services/kraken/main.py b/core/services/kraken/main.py index 958400cce6..8850363dfa 100755 --- a/core/services/kraken/main.py +++ b/core/services/kraken/main.py @@ -78,6 +78,11 @@ async def install_extension(extension: Extension) -> Any: status_code=status.HTTP_400_BAD_REQUEST, detail="Invalid extension description", ) + if not kraken.has_enough_disk_space(): + raise HTTPException( + status_code=status.HTTP_507_INSUFFICIENT_STORAGE, + detail="Not enough disk space to install the extension", + ) return StreamingResponse(kraken.install_extension(extension))