Skip to content
Closed
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
61 changes: 61 additions & 0 deletions devenv/checks/colimaDiskSpace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from __future__ import annotations

from devenv.lib import colima
from devenv.lib import proc
from devenv.lib_check.types import checker
from devenv.lib_check.types import fixer

tags: set[str] = {"builtin"}
name = "colima VM has sufficient disk space"


@checker
def check() -> tuple[bool, str]:
status = colima.check()
if status != colima.ColimaStatus.UP:
Copy link

@runningcode runningcode Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the Colima status was when this happened. I assume this exits early if colima reports that it is up?

return True, ""

try:
output = proc.run(
("colima", "exec", "--", "df", "--output=pcent", "/"), stdout=True
)
except RuntimeError:
return True, ""

lines = output.strip().split("\n")
if len(lines) >= 2:
percent_str = lines[1].strip().rstrip("%")
try:
used_percent = int(percent_str)
if used_percent > 90:
return (
False,
f"Colima VM disk is {used_percent}% full (less than 10% free space).\n"
"Consider resizing the disk or cleaning up unused Docker images/containers.",
)
except ValueError:
pass

return True, ""


@fixer
def fix() -> tuple[bool, str]:
return (
False,
"""
First you should try to cleanup unused Docker resources:
docker system prune -a

Failing that, you can resize the Colima VM's disk:

1. Stop colima:
colima stop

2. Install qemu:
brew install qemu

2. Restart colima, resizing to a larger disk (e.g., 200GB):
colima start --disk 200
""",
)
4 changes: 4 additions & 0 deletions devenv/lib/colima.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def start(restart: bool = False) -> ColimaStatus:
"colima",
"start",
"--verbose",
# default 60GiB disk is generally not enough over time
# since devs work with a lot of images
"--disk",
"128",
# this effectively makes the vm's resolvectl status use:
# DNS Servers: 8.8.8.8 1.1.1.1 192.168.5.2
# https://lima-vm.io/docs/config/network/user/
Expand Down
78 changes: 78 additions & 0 deletions tests/checks/test_colimaDiskSpace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from __future__ import annotations

from unittest import mock

from devenv.checks import colimaDiskSpace
from devenv.lib import colima


def test_check_skipped_when_colima_down() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.DOWN
):
assert colimaDiskSpace.check() == (True, "")


def test_check_skipped_when_colima_unhealthy() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.UNHEALTHY
):
assert colimaDiskSpace.check() == (True, "")


def test_check_passes_when_disk_has_space() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.UP
), mock.patch(
"devenv.checks.colimaDiskSpace.proc.run", return_value="Use%\n 50%"
):
assert colimaDiskSpace.check() == (True, "")


def test_check_passes_at_90_percent() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.UP
), mock.patch(
"devenv.checks.colimaDiskSpace.proc.run", return_value="Use%\n 90%"
):
assert colimaDiskSpace.check() == (True, "")


def test_check_fails_when_disk_full() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.UP
), mock.patch(
"devenv.checks.colimaDiskSpace.proc.run", return_value="Use%\n 95%"
):
ok, msg = colimaDiskSpace.check()
assert ok is False
assert "95% full" in msg
assert "less than 10% free" in msg


def test_check_fails_at_91_percent() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.UP
), mock.patch(
"devenv.checks.colimaDiskSpace.proc.run", return_value="Use%\n 91%"
):
ok, msg = colimaDiskSpace.check()
assert ok is False


def test_check_skipped_on_df_error() -> None:
with mock.patch.object(
colima, "check", return_value=colima.ColimaStatus.UP
), mock.patch(
"devenv.checks.colimaDiskSpace.proc.run",
side_effect=RuntimeError("command failed"),
):
assert colimaDiskSpace.check() == (True, "")


def test_fix_returns_instructions() -> None:
ok, msg = colimaDiskSpace.fix()
assert ok is False
assert "colima stop" in msg
assert "colima start --disk 200" in msg
assert "docker system prune" in msg