-
Notifications
You must be signed in to change notification settings - Fork 4
Add colima VM diskspace check #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| 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 | ||
|
|
||
sentry[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
| """, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?