Skip to content

Commit

Permalink
fix(api): infer SSD type from interfaceType
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Feb 1, 2023
1 parent a36aff0 commit 6d9ddb6
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 2 deletions.
9 changes: 9 additions & 0 deletions apps/api/__TESTS__/dynamic-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TEST_CASE_13,
TEST_CASE_14,
TEST_CASE_15,
TEST_CASE_16,
TEST_CASE_2,
TEST_CASE_3,
TEST_CASE_4,
Expand Down Expand Up @@ -136,5 +137,13 @@ describe('Dynamic Info', () => {
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_15.output);
});
it('Test Case 16', () => {
CONFIG.running_in_docker = false;
const output = new DynamicStorageMapper(
true,
...toStorageInp(TEST_CASE_16)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_16.output);
});
});
});
6 changes: 6 additions & 0 deletions apps/api/__TESTS__/static-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TEST_CASE_13,
TEST_CASE_14,
TEST_CASE_15,
TEST_CASE_16,
TEST_CASE_2,
TEST_CASE_3,
TEST_CASE_4,
Expand Down Expand Up @@ -91,5 +92,10 @@ describe('Static Info', () => {
const output = mapToStorageLayout(true, ...toStorageInp(TEST_CASE_15));
expect(output).to.deep.equal(TEST_CASE_15.layout);
});
it('Test Case 16', () => {
CONFIG.running_in_docker = false;
const output = mapToStorageLayout(true, ...toStorageInp(TEST_CASE_16));
expect(output).to.deep.equal(TEST_CASE_16.layout);
});
});
});
174 changes: 174 additions & 0 deletions apps/api/__TESTS__/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5311,3 +5311,177 @@ export const TEST_CASE_15 = {
],
output: { layout: [{ load: 226189230080 }, { load: 7547945865216 }] },
} as any as TestCase;

export const TEST_CASE_16 = {
disks: [
{
device: '\\\\.\\PHYSICALDRIVE1',
type: 'SSD',
name: 'Samsung SSD 980 1TB',
vendor: 'Samsung',
size: 1000202273280,
bytesPerSector: 512,
totalCylinders: 121601,
totalHeads: 255,
totalSectors: 1953520065,
totalTracks: 31008255,
tracksPerCylinder: 255,
sectorsPerTrack: 63,
firmwareRevision: '2B4QFXO7',
serialNum: '0025_38D1_21B1_C5DF.',
interfaceType: 'NVMe',
smartStatus: 'Ok',
temperature: null,
},
{
device: '\\\\.\\PHYSICALDRIVE2',
type: 'SSD',
name: 'Samsung SSD 970 EVO Plus 500GB',
vendor: 'Samsung',
size: 500105249280,
bytesPerSector: 512,
totalCylinders: 60801,
totalHeads: 255,
totalSectors: 976768065,
totalTracks: 15504255,
tracksPerCylinder: 255,
sectorsPerTrack: 63,
firmwareRevision: '2B2QEXM7',
serialNum: '0025_3854_0140_5BFA.',
interfaceType: 'NVMe',
smartStatus: 'Ok',
temperature: null,
},
{
device: '\\\\.\\PHYSICALDRIVE0',
type: 'SSD',
name: 'Samsung SSD 860 EVO 1TB',
vendor: 'Samsung',
size: 1000202273280,
bytesPerSector: 512,
totalCylinders: 121601,
totalHeads: 255,
totalSectors: 1953520065,
totalTracks: 31008255,
tracksPerCylinder: 255,
sectorsPerTrack: 63,
firmwareRevision: 'RVT04B6Q',
serialNum: 'S4CSNJ0NB02348Z',
interfaceType: 'SATA',
smartStatus: 'Ok',
temperature: null,
},
],
sizes: [
{
fs: 'C:',
type: 'NTFS',
size: 499328741376,
used: 177384513536,
available: 321944227840,
use: 35.52,
mount: 'C:',
rw: true,
},
{
fs: 'D:',
type: 'NTFS',
size: 1000186310656,
used: 880458645504,
available: 119727665152,
use: 88.03,
mount: 'D:',
rw: true,
},
{
fs: 'E:',
type: 'NTFS',
size: 1000202039296,
used: 606456291328,
available: 393745747968,
use: 60.63,
mount: 'E:',
rw: true,
},
],
blocks: [
{
name: 'C:',
identifier: 'C:',
type: 'disk',
fsType: 'ntfs',
mount: 'C:',
size: '499328741376',
physical: 'Local',
uuid: '02887811',
label: '',
model: '',
serial: '02887811',
removable: false,
protocol: '',
group: '',
device: '\\\\.\\PHYSICALDRIVE2',
},
{
name: 'D:',
identifier: 'D:',
type: 'disk',
fsType: 'ntfs',
mount: 'D:',
size: '1000186310656',
physical: 'Local',
uuid: '2A7043B9',
label: 'Data',
model: '',
serial: '2A7043B9',
removable: false,
protocol: '',
group: '',
device: '\\\\.\\PHYSICALDRIVE0',
},
{
name: 'E:',
identifier: 'E:',
type: 'disk',
fsType: 'ntfs',
mount: 'E:',
size: '1000202039296',
physical: 'Local',
uuid: 'C8EBD118',
label: 'Data 2',
model: '',
serial: 'C8EBD118',
removable: false,
protocol: '',
group: '',
device: '\\\\.\\PHYSICALDRIVE1',
},
],
layout: [
{
brand: 'Samsung',
device: '\\\\.\\PHYSICALDRIVE2',
size: 500105249280,
type: 'NVMe',
},
{
brand: 'Samsung',
device: '\\\\.\\PHYSICALDRIVE0',
size: 1000202273280,
type: 'SSD',
},
{
brand: 'Samsung',
device: '\\\\.\\PHYSICALDRIVE1',
size: 1000202273280,
type: 'NVMe',
},
],
output: {
layout: [
{ load: 177384513536 },
{ load: 880458645504 },
{ load: 606456291328 },
],
},
} as any as TestCase;
16 changes: 14 additions & 2 deletions apps/api/src/data/storage/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ const getDiskBlocks = (blocks: Block[]) =>
!CONFIG.fs_type_filter.includes(block.fsType)
);

const getNativeDisk = (disks: Disk[], block: Block) =>
const getNativeDisk = (
disks: Disk[],
block: Block
): {
vendor: string;
size: number;
type: string;
interfaceType?: string;
} =>
disks.find(
d =>
d.device === block.device || (block.model != '' && d.name === block.model)
Expand Down Expand Up @@ -73,6 +81,10 @@ const getRaidLabel = (deviceName: string, allRaidBlocks: Block[]) => {
return undefined;
};

const getDiskType = (type: string, interfaceType?: string) => {
return type === 'SSD' && interfaceType === 'NVMe' ? 'NVMe' : type;
};

export const mapToStorageLayout = (
hostWin32: boolean,
disks: Disk[],
Expand All @@ -91,7 +103,7 @@ export const mapToStorageLayout = (
device: hostWin32 ? diskBlock.device : device,
brand: nativeDisk.vendor,
size: nativeDisk.size,
type: nativeDisk.type,
type: getDiskType(nativeDisk.type, nativeDisk.interfaceType),
};

if (raidLabel != null) {
Expand Down

0 comments on commit 6d9ddb6

Please sign in to comment.