mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Disks: allow persisting the primary mount from the UI; clean NTFS before mounting.
The Disks page treated /media/wrolpi as fully protected, so a manually-mounted primary drive could not be persisted from the UI — and the Persist toggle would have been wrong anyway: it wrote fstab.yaml, which the wrolpi-mounts reconciler refuses to apply for the primary mount (RESERVED_MOUNT_POINTS). Route Persist for the primary mount to the host's /etc/fstab (as onboarding does), report its entry in the fstab list endpoint, and enable the toggle in both UIs while keeping Unmount blocked. Mounts outside /media (e.g. /boot/efi, which showed an Unmount button) are now entirely untouchable System mounts. Also: - Run `ntfsfix -d` before mounting ntfs/ntfs3 volumes so the Windows dirty flag (Fast Startup, unclean unplug) cannot block mounting; non-fatal and a no-op on clean volumes. - Add uid/gid fstab options for ntfs/ntfs3, matching mount_drive(). - Log reconcile diagnostics (desired/already-mounted/skipped with reasons) so an idle wrolpi-mounts run explains itself in the journal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
85bd5619fa
commit
c25902b92a
11 changed files with 251 additions and 18 deletions
|
|
@ -345,6 +345,89 @@ class TestFstabMutateEndpoints:
|
|||
assert response.status_code == 404
|
||||
|
||||
|
||||
# --- Primary mount persistence (/etc/fstab, not fstab.yaml) ----------------
|
||||
|
||||
class TestPrimaryMountPersist:
|
||||
"""The primary mount (/media/wrolpi) persists via the host's /etc/fstab,
|
||||
not fstab.yaml: the wrolpi-mounts reconciler refuses to manage it
|
||||
(RESERVED_MOUNT_POINTS), so a fstab.yaml entry would never be applied."""
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def primary_media_dir(self, monkeypatch):
|
||||
"""conftest isolates MEDIA_DIRECTORY to a tmp dir; these tests need the
|
||||
real primary mount point so the endpoints route to /etc/fstab."""
|
||||
monkeypatch.setenv("MEDIA_DIRECTORY", "/media/wrolpi")
|
||||
|
||||
def test_post_primary_routes_to_etc_fstab(self, test_client, disks_env):
|
||||
with mock.patch(
|
||||
"controller.api.disks.add_etc_fstab_entry",
|
||||
return_value={"success": True, "device": "UUID=abc-123",
|
||||
"mount_point": "/media/wrolpi"},
|
||||
) as add_etc:
|
||||
response = test_client.post(
|
||||
"/api/disks/fstab",
|
||||
json={"device": "/dev/sdb2",
|
||||
"mount_point": "/media/wrolpi",
|
||||
"fstype": "ntfs"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["device"] == "UUID=abc-123"
|
||||
add_etc.assert_called_once()
|
||||
# fstab.yaml must NOT contain the primary mount.
|
||||
assert fstab_yaml.load(disks_env["fstab_path"]).mount_points() == set()
|
||||
|
||||
def test_post_primary_reports_etc_fstab_failure(self, test_client, disks_env):
|
||||
with mock.patch(
|
||||
"controller.api.disks.add_etc_fstab_entry",
|
||||
return_value={"success": False, "error": "WROL Mode is enabled"},
|
||||
):
|
||||
response = test_client.post(
|
||||
"/api/disks/fstab",
|
||||
json={"device": "/dev/sdb2",
|
||||
"mount_point": "/media/wrolpi",
|
||||
"fstype": "ntfs"},
|
||||
)
|
||||
assert response.status_code == 500
|
||||
assert "WROL Mode" in response.json()["detail"]
|
||||
|
||||
def test_delete_primary_routes_to_etc_fstab(self, test_client, disks_env):
|
||||
with mock.patch(
|
||||
"controller.api.disks.remove_etc_fstab_entry",
|
||||
return_value={"success": True, "mount_point": "/media/wrolpi"},
|
||||
) as remove_etc:
|
||||
response = test_client.delete("/api/disks/fstab/media/wrolpi")
|
||||
assert response.status_code == 200
|
||||
remove_etc.assert_called_once_with("/media/wrolpi")
|
||||
|
||||
def test_delete_primary_missing_returns_404(self, test_client, disks_env):
|
||||
with mock.patch(
|
||||
"controller.api.disks.remove_etc_fstab_entry",
|
||||
return_value={"success": False,
|
||||
"error": "No entry found for /media/wrolpi"},
|
||||
):
|
||||
response = test_client.delete("/api/disks/fstab/media/wrolpi")
|
||||
assert response.status_code == 404
|
||||
|
||||
def test_list_includes_primary_from_etc_fstab(self, test_client, disks_env):
|
||||
etc_entries = [
|
||||
{"type": "comment", "line": "# /etc/fstab\n"},
|
||||
{"type": "mount", "device": "UUID=root", "mount_point": "/",
|
||||
"fstype": "ext4", "options": "defaults", "dump": "0", "pass": "1"},
|
||||
{"type": "mount", "device": "UUID=abc-123",
|
||||
"mount_point": "/media/wrolpi", "fstype": "ntfs",
|
||||
"options": "defaults,nofail", "dump": "0", "pass": "2"},
|
||||
]
|
||||
with mock.patch("controller.api.disks.parse_etc_fstab",
|
||||
return_value=etc_entries):
|
||||
response = test_client.get("/api/disks/fstab")
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
mount_points = [e["mount_point"] for e in body]
|
||||
# The primary appears; unrelated system mounts (e.g. /) do not.
|
||||
assert mount_points == ["/media/wrolpi"]
|
||||
assert body[0]["device"] == "UUID=abc-123"
|
||||
|
||||
|
||||
# --- SMART ----------------------------------------------------------------
|
||||
|
||||
class TestSmartEndpoints:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue