-
Notifications
You must be signed in to change notification settings - Fork 22
feat(api): expose internal boot devices in array GraphQL #1894
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
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a5af026
feat(array): expose internal boot disks as BOOT
Ajit-Mehrotra 937460f
feat(array): expose boot devices collection
Ajit-Mehrotra fb3b50a
fix(api): build shared before type checks
Ajit-Mehrotra 5baaeab
refactor(array): keep boot field as active disk
Ajit-Mehrotra f394c68
docs(array): clarify boot metadata docs
Ajit-Mehrotra bce81a6
Revert "fix(api): build shared before type checks"
Ajit-Mehrotra 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -166,6 +166,7 @@ enum ArrayDiskStatus { | |
| } | ||
|
|
||
| enum ArrayDiskType { | ||
| BOOT | ||
| DATA | ||
| PARITY | ||
| FLASH | ||
|
|
||
140 changes: 140 additions & 0 deletions
140
api/src/__test__/core/modules/array/get-array-data.test.ts
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,140 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { getArrayData } from '@app/core/modules/array/get-array-data.js'; | ||
| import { getParityCheckStatus, ParityCheckStatus } from '@app/core/modules/array/parity-check-status.js'; | ||
| import { store } from '@app/store/index.js'; | ||
| import { FileLoadStatus } from '@app/store/types.js'; | ||
| import { | ||
| ArrayDisk, | ||
| ArrayDiskStatus, | ||
| ArrayDiskType, | ||
| ArrayState, | ||
| } from '@app/unraid-api/graph/resolvers/array/array.model.js'; | ||
|
|
||
| vi.mock('@app/core/modules/array/parity-check-status.js', () => ({ | ||
| ParityCheckStatus: { | ||
| NEVER_RUN: 'never_run', | ||
| }, | ||
| getParityCheckStatus: vi.fn(), | ||
| })); | ||
|
|
||
| const buildDisk = (overrides: Partial<ArrayDisk> = {}): ArrayDisk => ({ | ||
| id: 'disk-id', | ||
| idx: 1, | ||
| type: ArrayDiskType.DATA, | ||
| device: 'sda', | ||
| comment: null, | ||
| fsFree: 0, | ||
| fsSize: 0, | ||
| fsUsed: 0, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| const buildGetState = (disks: ArrayDisk[]) => () => | ||
| ({ | ||
| emhttp: { | ||
| status: FileLoadStatus.LOADED, | ||
| var: { | ||
| mdState: ArrayState.STOPPED, | ||
| maxArraysz: 28, | ||
| }, | ||
| disks, | ||
| }, | ||
| }) as unknown as ReturnType<typeof store.getState>; | ||
|
|
||
| describe('getArrayData', () => { | ||
| beforeEach(() => { | ||
| vi.mocked(getParityCheckStatus).mockReturnValue({ | ||
| status: ParityCheckStatus.NEVER_RUN, | ||
| speed: '0', | ||
| date: undefined, | ||
| duration: 0, | ||
| progress: 0, | ||
| }); | ||
| }); | ||
|
|
||
| it('prefers Boot slots from disks.ini over flash disks', () => { | ||
| const result = getArrayData( | ||
| buildGetState([ | ||
| buildDisk({ | ||
| id: 'flash-disk', | ||
| idx: 32, | ||
| device: 'sdb', | ||
| type: ArrayDiskType.FLASH, | ||
| }), | ||
| buildDisk({ | ||
| id: 'boot-disk', | ||
| idx: 54, | ||
| device: 'nvme0n1', | ||
| type: ArrayDiskType.BOOT, | ||
| status: ArrayDiskStatus.DISK_OK, | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(result.boot?.id).toBe('boot-disk'); | ||
| }); | ||
|
|
||
| it('matches webgui and picks the first present Boot disk with a device', () => { | ||
| const result = getArrayData( | ||
| buildGetState([ | ||
| buildDisk({ | ||
| id: 'boot-disk-missing', | ||
| idx: 54, | ||
| device: '', | ||
| type: ArrayDiskType.BOOT, | ||
| status: ArrayDiskStatus.DISK_NP, | ||
| }), | ||
| buildDisk({ | ||
| id: 'boot-disk-online', | ||
| idx: 55, | ||
| device: 'nvme0n1', | ||
| type: ArrayDiskType.BOOT, | ||
| status: ArrayDiskStatus.DISK_OK, | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(result.boot?.id).toBe('boot-disk-online'); | ||
| }); | ||
|
|
||
| it('falls back to a mounted Boot disk when no present Boot disk has a device', () => { | ||
| const result = getArrayData( | ||
| buildGetState([ | ||
| buildDisk({ | ||
| id: 'boot-disk-mounted', | ||
| idx: 54, | ||
| device: '', | ||
| type: ArrayDiskType.BOOT, | ||
| status: ArrayDiskStatus.DISK_NP, | ||
| fsStatus: 'Mounted', | ||
| }), | ||
| buildDisk({ | ||
| id: 'boot-disk-unmounted', | ||
| idx: 55, | ||
| device: '', | ||
| type: ArrayDiskType.BOOT, | ||
| status: ArrayDiskStatus.DISK_NP_DSBL, | ||
| fsStatus: 'Unmounted', | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(result.boot?.id).toBe('boot-disk-mounted'); | ||
| }); | ||
|
|
||
| it('falls back to flash when disks.ini has no Boot slots', () => { | ||
| const result = getArrayData( | ||
| buildGetState([ | ||
| buildDisk({ | ||
| id: 'flash-disk', | ||
| idx: 32, | ||
| device: 'sdb', | ||
| type: ArrayDiskType.FLASH, | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(result.boot?.id).toBe('flash-disk'); | ||
| }); | ||
| }); |
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
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
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
Oops, something went wrong.
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.