Improve error handling when mounts fail #4872
Merged
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.
Proposed change
When we fail to mount a media or share type mount it is supposed to mount a read-only file in that spot. This ensures that attempts to write to that folder will fail and report rather then essentially silently fail by writing locally (and then creating other issues later). This logic did not work because it relied on user permissions and all docker containers in the Home Assistant ecosystem run as
root
. This changes the bind mount itself to use the read-only option which causes write failures even forroot
.Since there was a feature request to create mounts of type media and share as read-only this was extended into a feature. Users can now make read-only mounts of type media and share.
As for backup type mounts, we expected that if the user tried to make a backup on a downed mount they would get a timeout. It appears that instead it writes the file locally instead. This causes impossible to fix errors next startup as we cannot mount over a non-empty folder and users can't see these folders without going into the supervisor container.
So if the user tries to make a backup in a mount we first check that the folder is in fact a mountpoint using Path.is_mount. In testing this only returns true if the folder is a mountpoint and if that connection is active. If this returns false we raise an error immediately and exit.
Type of change
Additional information
Checklist
black --fast supervisor tests
)If API endpoints of add-on configuration are added/changed: