mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
controller: allow unmounting the primary drive, stopping the API first
Support swapping in a backup drive: /api/disks/unmount now accepts the primary mount (previously rejected as reserved). It stops wrolpi-api so open files are released, then umounts directly since the reconciler never manages the primary mount. The /etc/fstab entry is left in place so a reboot restores the mount. Both UIs now offer Unmount for the primary mount and warn that the API service will be stopped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
5a11e23a56
commit
43f6ed2b8e
5 changed files with 209 additions and 31 deletions
|
|
@ -688,9 +688,10 @@ function SmartDetailsModal({drive, open, onClose}) {
|
|||
}
|
||||
|
||||
|
||||
// The primary mount cannot be unmounted from the UI, but its persistence
|
||||
// (an /etc/fstab entry) can be toggled. Any mount outside /media belongs to
|
||||
// the system (/, /boot/efi, /boot/firmware, …) and is entirely untouchable.
|
||||
// The primary mount can be unmounted (to swap in a backup drive), but doing
|
||||
// so stops the WROLPi API service — the unmount modal warns about this. Any
|
||||
// mount outside /media belongs to the system (/, /boot/efi, /boot/firmware, …)
|
||||
// and is entirely untouchable.
|
||||
const PRIMARY_MOUNT = '/media/wrolpi';
|
||||
|
||||
// Helper to format disk size
|
||||
|
|
@ -942,12 +943,15 @@ function DiskSection() {
|
|||
if (!unmountTarget) return;
|
||||
|
||||
try {
|
||||
await unmountDisk(unmountTarget);
|
||||
const result = await unmountDisk(unmountTarget);
|
||||
const stoppedServices = (result && result.stopped_services) || [];
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Disk Unmounted',
|
||||
description: `Unmounted ${unmountTarget}`,
|
||||
time: 3000,
|
||||
description: stoppedServices.length > 0 ?
|
||||
`Unmounted ${unmountTarget}; stopped ${stoppedServices.join(', ')}` :
|
||||
`Unmounted ${unmountTarget}`,
|
||||
time: 5000,
|
||||
});
|
||||
fetchDiskInfo();
|
||||
} catch (e) {
|
||||
|
|
@ -1077,7 +1081,7 @@ function DiskSection() {
|
|||
)}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{isMounted && (isSystemMount || isPrimary) ? (
|
||||
{isMounted && isSystemMount ? (
|
||||
<span style={{color: '#888'}}>System</span>
|
||||
) : isMounted ? (
|
||||
<Button
|
||||
|
|
@ -1168,7 +1172,18 @@ function DiskSection() {
|
|||
<Confirm
|
||||
open={unmountConfirmOpen}
|
||||
header='Unmount Disk'
|
||||
content={`Are you sure you want to unmount ${unmountTarget}?`}
|
||||
content={unmountTarget === PRIMARY_MOUNT ? (
|
||||
<div className='content'>
|
||||
<p>Are you sure you want to unmount <code>{unmountTarget}</code>?</p>
|
||||
<p>
|
||||
<Icon name='warning sign' color='yellow'/>
|
||||
This is the primary WROLPi drive. The WROLPi API service will
|
||||
be <strong>stopped</strong> before unmounting, and your media will be
|
||||
unavailable until a drive is mounted at <code>{PRIMARY_MOUNT}</code> and
|
||||
the API service is started again.
|
||||
</p>
|
||||
</div>
|
||||
) : `Are you sure you want to unmount ${unmountTarget}?`}
|
||||
onCancel={() => {
|
||||
setUnmountConfirmOpen(false);
|
||||
setUnmountTarget(null);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react';
|
||||
import {render, screen, waitFor} from '@testing-library/react';
|
||||
import {fireEvent, render, screen, waitFor} from '@testing-library/react';
|
||||
import {BrowserRouter} from 'react-router';
|
||||
import {ThemeContext, SettingsContext} from '../../contexts/contexts';
|
||||
import {ControllerPage} from './ControllerPage';
|
||||
|
|
@ -56,7 +56,13 @@ jest.mock('../../api/controller', () => ({
|
|||
getServiceLogs: jest.fn().mockResolvedValue({logs: 'Sample log output'}),
|
||||
getDisks: jest.fn().mockResolvedValue([]),
|
||||
getMounts: jest.fn().mockResolvedValue([]),
|
||||
getFstabEntries: jest.fn().mockResolvedValue([]),
|
||||
getSmartStatus: jest.fn().mockResolvedValue({}),
|
||||
mountDisk: jest.fn().mockResolvedValue({success: true}),
|
||||
unmountDisk: jest.fn().mockResolvedValue(
|
||||
{success: true, stopped_services: ['wrolpi-api']}),
|
||||
addFstabEntry: jest.fn().mockResolvedValue({success: true}),
|
||||
removeFstabEntry: jest.fn().mockResolvedValue({success: true}),
|
||||
restartServices: jest.fn().mockResolvedValue({success: true}),
|
||||
getSambaStatus: jest.fn().mockResolvedValue({enabled: false, available: true, shares: []}),
|
||||
addSambaShare: jest.fn().mockResolvedValue({success: true}),
|
||||
|
|
@ -177,6 +183,51 @@ describe('ControllerPage', () => {
|
|||
|
||||
});
|
||||
|
||||
describe('DiskSection primary unmount', () => {
|
||||
const controllerApi = require('../../api/controller');
|
||||
|
||||
beforeEach(() => {
|
||||
controllerApi.getDisks.mockResolvedValue([
|
||||
{
|
||||
name: 'sda1',
|
||||
path: '/dev/sda1',
|
||||
size: '500G',
|
||||
fstype: 'ext4',
|
||||
label: 'wrolpi',
|
||||
mountpoint: '/media/wrolpi',
|
||||
uuid: 'abc-123',
|
||||
},
|
||||
]);
|
||||
controllerApi.unmountDisk.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
controllerApi.getDisks.mockResolvedValue([]);
|
||||
});
|
||||
|
||||
test('primary mount shows Unmount button; confirming warns and unmounts', async () => {
|
||||
renderControllerPage();
|
||||
|
||||
// The primary mount is no longer labeled "System"; it gets Unmount.
|
||||
const unmountButton = await screen.findByText('Unmount');
|
||||
fireEvent.click(unmountButton);
|
||||
|
||||
// The confirm modal warns that the API service will be stopped.
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(/API service will/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Semantic's Confirm renders confirmButton='Unmount' as the last match.
|
||||
const buttons = screen.getAllByText('Unmount');
|
||||
fireEvent.click(buttons[buttons.length - 1]);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(controllerApi.unmountDisk).toHaveBeenCalledWith('/media/wrolpi');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('groupServices', () => {
|
||||
const {groupServices} = require('./ControllerPage');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue