-
Notifications
You must be signed in to change notification settings - Fork 151
[1.4] Make host file helpers report failure instead of silently patching #4242
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
Merged
patrickelectric
merged 6 commits into
bluerobotics:1.4-dev
from
joaoantoniocardoso:fix/1.4-host-file-helpers-report-failure
Aug 26, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dd8f182
core: libs: commonwealth: Raise when host file helpers fail
joaoantoniocardoso 0f5c387
core: tools: blueos_startup_update: Skip boot patches when files are …
joaoantoniocardoso 4c74389
core: libs: commonwealth: Fall back to Other when host OS cannot be read
joaoantoniocardoso 3978b45
core: libs: commonwealth: Pin locate_file when find exits 1 with a match
joaoantoniocardoso 10bbac4
core: tools: blueos_startup_update: Keep restart requests when a late…
joaoantoniocardoso eaa5ca5
core: services: ardupilot_manager: Default Navigator serials to Bulls…
joaoantoniocardoso 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
62 changes: 62 additions & 0 deletions
62
core/libs/commonwealth/commonwealth/utils/tests/test_commands.py
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,62 @@ | ||
| import subprocess | ||
| from unittest.mock import mock_open, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from .. import commands | ||
|
|
||
|
|
||
| def _result(returncode: int, stdout: str = "", stderr: str = "") -> subprocess.CompletedProcess[str]: | ||
| return subprocess.CompletedProcess(args=[], returncode=returncode, stdout=stdout, stderr=stderr) | ||
|
|
||
|
|
||
| def test_load_file_returns_contents_when_cat_succeeds(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(commands, "run_command", lambda *_args, **_kwargs: _result(0, stdout="dtoverlay=spi0-led\n")) | ||
| assert commands.load_file("/boot/config.txt") == "dtoverlay=spi0-led\n" | ||
|
|
||
|
|
||
| def test_load_file_returns_empty_string_for_empty_file(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(commands, "run_command", lambda *_args, **_kwargs: _result(0, stdout="")) | ||
| assert commands.load_file("/boot/config.txt") == "" | ||
|
|
||
|
|
||
| def test_load_file_raises_when_cat_fails(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr( | ||
| commands, "run_command", lambda *_args, **_kwargs: _result(1, stdout="", stderr="cat: No such file") | ||
| ) | ||
| with pytest.raises(commands.HostFileError, match="Failed to read /boot/config.txt"): | ||
| commands.load_file("/boot/config.txt") | ||
|
|
||
|
|
||
| def test_locate_file_returns_first_match(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr( | ||
| commands, "run_command", lambda *_args, **_kwargs: _result(0, stdout="/boot/firmware/config.txt\n") | ||
| ) | ||
| assert commands.locate_file(["/boot/firmware/config.txt", "/boot/config.txt"]) == "/boot/firmware/config.txt" | ||
|
|
||
|
|
||
| def test_locate_file_returns_none_when_find_prints_nothing(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(commands, "run_command", lambda *_args, **_kwargs: _result(1, stdout="", stderr="No such file")) | ||
| assert commands.locate_file(["/missing/a", "/missing/b"]) is None | ||
|
|
||
|
|
||
| def test_save_file_raises_when_upload_fails(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(commands, "run_command", lambda *_args, **_kwargs: _result(0)) | ||
| monkeypatch.setattr(commands, "upload_file", lambda *_args, **_kwargs: _result(1, stderr="Permission denied")) | ||
| with pytest.raises(commands.HostFileError, match="Failed to save /boot/config.txt"): | ||
| commands.save_file("/boot/config.txt", "[pi4]\n", "before_test") | ||
|
|
||
|
|
||
| def test_save_file_succeeds_when_upload_succeeds(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(commands, "run_command", lambda *_args, **_kwargs: _result(0)) | ||
| monkeypatch.setattr(commands, "upload_file", lambda *_args, **_kwargs: _result(0)) | ||
| commands.save_file("/boot/config.txt", "[pi4]\n", "before_test") | ||
|
|
||
|
|
||
| def test_upload_file_returns_mv_failure(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(commands, "upload_file_with_ssh_key", lambda *_args, **_kwargs: _result(0)) | ||
| monkeypatch.setattr(commands, "run_command", lambda *_args, **_kwargs: _result(1, stderr="Read-only file system")) | ||
| with patch("builtins.open", mock_open()): | ||
| result = commands.upload_file("[pi4]\n", "/boot/config.txt", False) | ||
| assert result.returncode == 1 | ||
| assert "Read-only file system" in result.stderr |
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.