Skip to content

Commit a5e3fef

Browse files
olethanhnesitor
authored andcommitted
Fix reserved space calculation
1 parent c10d8f4 commit a5e3fef

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/aleph/vm/pool.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def teardown(self) -> None:
102102
# upon supervisor restart or upgrade.
103103
pass
104104

105-
def calculate_available_disk(self):
105+
def calculate_available_disk(self) -> int:
106106
"""Disk available for the creation of new VM.
107107
108-
This take into account the disk request (but not used) for Volume of executions in the pool
108+
This takes into account the disk request (but not used) for Volume of executions in the pool
109109
Result in bytes."""
110110
free_space = shutil.disk_usage(str(settings.PERSISTENT_VOLUMES_DIR)).free
111-
# Free disk space reported by system
111+
# Free disk space reported by the system
112112

113113
# Calculate the reservation
114114
total_delta = 0
@@ -118,12 +118,15 @@ def calculate_available_disk(self):
118118
delta = execution.resources.get_disk_usage_delta()
119119
logger.debug("Disk usage delta: %d for %s", delta, execution.vm_hash)
120120
total_delta += delta
121-
available_space = free_space - total_delta
121+
available_space = free_space + total_delta
122+
122123
logger.info(
123124
"Disk: freespace : %.f Mb, available space (non reserved) %.f Mb",
124125
free_space / 1024**2,
125126
available_space / 1024**2,
126127
)
128+
available_space = max(available_space, 0)
129+
# floor value to zero to avoid negative values
127130
return available_space
128131

129132
async def create_a_vm(

0 commit comments

Comments
 (0)