From e462e286b41dafb2506d0a403a72cb455e1e6b18 Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Fri, 6 Jan 2023 13:51:35 +0100 Subject: [PATCH] fix(api): removed host size from unassigned sizes Some users may have encountered wrong size readings, when no mounts were present on the partitions - this may have been caused by douplicating host sizes into the unassigned pool. fixes #514 --- apps/api/__TESTS__/dynamic-info.test.ts | 14 +- apps/api/__TESTS__/static-info.test.ts | 5 + apps/api/__TESTS__/test-cases.ts | 339 +++++++++++++++++++++++- apps/api/src/data/storage/dynamic.ts | 4 +- 4 files changed, 355 insertions(+), 7 deletions(-) diff --git a/apps/api/__TESTS__/dynamic-info.test.ts b/apps/api/__TESTS__/dynamic-info.test.ts index bef7b5f4e..264b427db 100644 --- a/apps/api/__TESTS__/dynamic-info.test.ts +++ b/apps/api/__TESTS__/dynamic-info.test.ts @@ -8,6 +8,7 @@ import { TEST_CASE_11, TEST_CASE_12, TEST_CASE_13, + TEST_CASE_14, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, @@ -21,11 +22,10 @@ import { const toStorageInp = (inp: TestCase) => [inp.layout, inp.blocks, inp.sizes] as const; -beforeEach(() => { - CONFIG.running_in_docker = true; -}); - describe('Dynamic Info', () => { + beforeEach(() => { + CONFIG.running_in_docker = true; + }); describe('Storage', () => { it('Test Case 1', () => { const output = new DynamicStorageMapper( @@ -106,5 +106,11 @@ describe('Dynamic Info', () => { ).getMappedLayout(); expect(output).to.deep.equal(TEST_CASE_13.output); }); + it('Test Case 14', () => { + const output = new DynamicStorageMapper( + ...toStorageInp(TEST_CASE_14) + ).getMappedLayout(); + expect(output).to.deep.equal(TEST_CASE_14.output); + }); }); }); diff --git a/apps/api/__TESTS__/static-info.test.ts b/apps/api/__TESTS__/static-info.test.ts index 66953927e..64210f2ab 100644 --- a/apps/api/__TESTS__/static-info.test.ts +++ b/apps/api/__TESTS__/static-info.test.ts @@ -8,6 +8,7 @@ import { TEST_CASE_11, TEST_CASE_12, TEST_CASE_13, + TEST_CASE_14, TEST_CASE_2, TEST_CASE_3, TEST_CASE_4, @@ -80,5 +81,9 @@ describe('Static Info', () => { const output = mapToStorageLayout(...toStorageInp(TEST_CASE_13)); expect(output).to.deep.equal(TEST_CASE_13.layout); }); + it('Test Case 14', () => { + const output = mapToStorageLayout(...toStorageInp(TEST_CASE_14)); + expect(output).to.deep.equal(TEST_CASE_14.layout); + }); }); }); diff --git a/apps/api/__TESTS__/test-cases.ts b/apps/api/__TESTS__/test-cases.ts index 72676037b..215bd778e 100644 --- a/apps/api/__TESTS__/test-cases.ts +++ b/apps/api/__TESTS__/test-cases.ts @@ -2329,7 +2329,7 @@ export const TEST_CASE_7 = { type: 'SSD', }, ], - output: { layout: [{ load: 104365518848 }] }, + output: { layout: [{ load: 104307191808 }] }, } as any as TestCase; // https://github.com/MauriceNino/dashdot/issues/196 @@ -2980,7 +2980,7 @@ export const TEST_CASE_9 = { type: 'HD', }, ], - output: { layout: [{ load: 1040577499136 }, { load: 0 }] }, + output: { layout: [{ load: 1039808245760 }, { load: 0 }] }, } as any as TestCase; // https://github.com/MauriceNino/dashdot/issues/182 @@ -4816,3 +4816,338 @@ export const TEST_CASE_13 = { ], }, } as any as TestCase; + +// https://github.com/MauriceNino/dashdot/issues/514 +export const TEST_CASE_14 = { + disks: [ + { + device: '/dev/nvme0n1', + type: 'NVMe', + name: 'SAMSUNG MZVL2512HCJQ-00B00 ', + vendor: 'Samsung', + size: 512110190592, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: '', + serialNum: 'S675NX0T349018', + interfaceType: 'PCIe', + smartStatus: 'unknown', + temperature: null, + }, + { + device: '/dev/nvme1n1', + type: 'NVMe', + name: 'SAMSUNG MZVL2512HCJQ-00B00 ', + vendor: 'Samsung', + size: 512110190592, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: '', + serialNum: 'S675NX0T551801', + interfaceType: 'PCIe', + smartStatus: 'unknown', + temperature: null, + }, + ], + sizes: [ + { + fs: 'overlay', + type: 'overlay', + size: 467645579264, + used: 322657038336, + available: 121158221824, + use: 72.7, + mount: '/', + rw: false, + }, + { + fs: '/dev/md3', + type: 'ext4', + size: 467645579264, + used: 322657038336, + available: 121158221824, + use: 72.7, + mount: '/mnt/host', + rw: true, + }, + { + fs: '/dev/md2', + type: 'ext3', + size: 1036726272, + used: 126164992, + available: 856981504, + use: 12.83, + mount: '/mnt/host/boot', + rw: true, + }, + { + fs: '/dev/md0', + type: 'vfat', + size: 268087296, + used: 176128, + available: 267911168, + use: 0.07, + mount: '/mnt/host/boot/efi', + rw: true, + }, + { + fs: 'db-ita-crypt:/', + type: 'fuse.rclone', + size: 1845410008137728, + used: 1374804697473024, + available: 470605310664704, + use: 74.5, + mount: '/mnt/host/media', + rw: false, + }, + ], + blocks: [ + { + name: 'nvme0n1', + type: 'disk', + fsType: '', + mount: '', + size: 512110190592, + physical: 'SSD', + uuid: '', + label: '', + model: 'SAMSUNG MZVL2512HCJQ-00B00', + serial: 'S675NX0T349018 ', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme1n1', + type: 'disk', + fsType: '', + mount: '', + size: 512110190592, + physical: 'SSD', + uuid: '', + label: '', + model: 'SAMSUNG MZVL2512HCJQ-00B00', + serial: 'S675NX0T551801 ', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme1n1', + }, + { + name: 'nvme0n1p1', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 268435456, + physical: '', + uuid: '8df5997d-5c07-5336-7809-e1c1d275f2fe', + label: 'archlinux-latest-64-minimal:0', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme0n1p2', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 34359738368, + physical: '', + uuid: '0a811c0a-841f-c9d2-8a5c-4f39e3c91f82', + label: 'archlinux-latest-64-minimal:1', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme0n1p3', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 1073741824, + physical: '', + uuid: 'cf2c6311-172d-a71c-0b49-2b2deb8a7be5', + label: 'archlinux-latest-64-minimal:2', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme0n1p4', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 476406160896, + physical: '', + uuid: '7b8fc46e-10f1-612a-84a6-e6411f4dcaca', + label: 'archlinux-latest-64-minimal:3', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme1n1p1', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 268435456, + physical: '', + uuid: '8df5997d-5c07-5336-7809-e1c1d275f2fe', + label: 'archlinux-latest-64-minimal:0', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme1n1', + }, + { + name: 'nvme1n1p2', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 34359738368, + physical: '', + uuid: '0a811c0a-841f-c9d2-8a5c-4f39e3c91f82', + label: 'archlinux-latest-64-minimal:1', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme1n1', + }, + { + name: 'nvme1n1p3', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 1073741824, + physical: '', + uuid: 'cf2c6311-172d-a71c-0b49-2b2deb8a7be5', + label: 'archlinux-latest-64-minimal:2', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme1n1', + }, + { + name: 'nvme1n1p4', + type: 'part', + fsType: 'linux_raid_member', + mount: '', + size: 476406160896, + physical: '', + uuid: '7b8fc46e-10f1-612a-84a6-e6411f4dcaca', + label: 'archlinux-latest-64-minimal:3', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme1n1', + }, + { + name: 'md0', + type: 'raid1', + fsType: 'vfat', + mount: '/mnt/host/boot/efi', + size: 268369920, + physical: '', + uuid: 'F539-5EE9', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'md1', + type: 'raid1', + fsType: 'swap', + mount: '[SWAP]', + size: 34325135360, + physical: '', + uuid: '3cd6a192-5778-48af-bfb1-8e30da09122e', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'md2', + type: 'raid1', + fsType: 'ext3', + mount: '/mnt/host/boot', + size: 1071644672, + physical: '', + uuid: '53300eed-6ccb-4ad7-878f-9359a47fddac', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'md3', + type: 'raid1', + fsType: 'ext4', + mount: '/mnt/host', + size: 476270886912, + physical: '', + uuid: '826abd28-f0af-4b95-8e27-34ce300b1304', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + ], + layout: [ + { + brand: 'Samsung', + device: 'nvme0n1', + raidGroup: 'archlinux-latest-64-minimal:0', + size: 512110190592, + type: 'NVMe', + }, + { + brand: 'Samsung', + device: 'nvme1n1', + raidGroup: 'archlinux-latest-64-minimal:0', + size: 512110190592, + type: 'NVMe', + }, + ], + output: { layout: [{ load: 322783203328 }, { load: 0 }] }, +} as any as TestCase; diff --git a/apps/api/src/data/storage/dynamic.ts b/apps/api/src/data/storage/dynamic.ts index 4389f7f25..88f154efd 100644 --- a/apps/api/src/data/storage/dynamic.ts +++ b/apps/api/src/data/storage/dynamic.ts @@ -74,7 +74,9 @@ export class DynamicStorageMapper { ); const unclaimedSpace = this.validSizes .filter( - ({ mount }) => !this.validBlocks.some(part => part.mount === mount) + ({ mount }) => + !this.isRootMount(mount) && + !this.validBlocks.some(part => part.mount === mount) ) .reduce((acc, { used }) => acc + used, 0);