Skip to content

Commit

Permalink
fix: allow drive mappings via uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Mar 24, 2023
1 parent c189b1e commit 44e87a8
Show file tree
Hide file tree
Showing 4 changed files with 351 additions and 1 deletion.
8 changes: 8 additions & 0 deletions apps/api/__TESTS__/dynamic-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TEST_CASE_18,
TEST_CASE_19,
TEST_CASE_2,
TEST_CASE_20,
TEST_CASE_3,
TEST_CASE_4,
TEST_CASE_5,
Expand Down Expand Up @@ -154,5 +155,12 @@ describe('Dynamic Info', () => {
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_19.output);
});
it('Test Case 20', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_20)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_20.output);
});
});
});
5 changes: 5 additions & 0 deletions apps/api/__TESTS__/static-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TEST_CASE_18,
TEST_CASE_19,
TEST_CASE_2,
TEST_CASE_20,
TEST_CASE_3,
TEST_CASE_4,
TEST_CASE_5,
Expand Down Expand Up @@ -103,5 +104,9 @@ describe('Static Info', () => {
const output = mapToStorageLayout(false, ...toStorageInp(TEST_CASE_19));
expect(output).to.deep.equal(TEST_CASE_19.layout);
});
it('Test Case 20', () => {
const output = mapToStorageLayout(false, ...toStorageInp(TEST_CASE_20));
expect(output).to.deep.equal(TEST_CASE_20.layout);
});
});
});
330 changes: 330 additions & 0 deletions apps/api/__TESTS__/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6196,3 +6196,333 @@ export const TEST_CASE_19 = {
3930067537920, 2526756556800, 3755402776576, 3789034754048,
],
} as any as TestCase;

export const TEST_CASE_20 = {
disks: [
{
device: '/dev/sda',
type: 'SSD',
name: 'OCZ-VERTEX3 ',
vendor: 'ATA',
size: 120034123776,
bytesPerSector: null,
totalCylinders: null,
totalHeads: null,
totalSectors: null,
totalTracks: null,
tracksPerCylinder: null,
sectorsPerTrack: null,
firmwareRevision: '2.25',
serialNum: '',
interfaceType: 'SATA',
smartStatus: 'unknown',
temperature: null,
},
{
device: '/dev/sdb',
type: 'HD',
name: 'WDC WD40EFRX-68W',
vendor: 'Western Digital',
size: 4000787030016,
bytesPerSector: null,
totalCylinders: null,
totalHeads: null,
totalSectors: null,
totalTracks: null,
tracksPerCylinder: null,
sectorsPerTrack: null,
firmwareRevision: '0A82',
serialNum: '',
interfaceType: 'USB',
smartStatus: 'unknown',
temperature: null,
},
{
device: '/dev/nvme0n1',
type: 'NVMe',
name: 'HJDK SSD 512GB ',
vendor: '',
size: 512110190592,
bytesPerSector: null,
totalCylinders: null,
totalHeads: null,
totalSectors: null,
totalTracks: null,
tracksPerCylinder: null,
sectorsPerTrack: null,
firmwareRevision: '',
serialNum: 'AA000000000000000003',
interfaceType: 'PCIe',
smartStatus: 'unknown',
temperature: null,
},
],
sizes: [
{
fs: 'overlay',
type: 'overlay',
size: 116012584960,
used: 16712163328,
available: 93360029696,
use: 15.18,
mount: '/',
rw: false,
},
{
fs: '/dev/sda2',
type: 'ext4',
size: 116012584960,
used: 16712163328,
available: 93360029696,
use: 15.18,
mount: '/mnt/host',
rw: true,
},
{
fs: '/dev/sda1',
type: 'vfat',
size: 535801856,
used: 155648,
available: 535646208,
use: 0.03,
mount: '/mnt/host/boot/efi',
rw: true,
},
{
fs: '/dev/sdb2',
type: 'ext4',
size: 3936483074048,
used: 1413829738496,
available: 2322614407168,
use: 37.84,
mount:
'/mnt/host/srv/dev-disk-by-uuid-c9e750f7-7ebe-4706-abd9-ce7788429acd',
rw: true,
},
],
blocks: [
{
name: 'nvme0n1',
type: 'disk',
fsType: '',
mount: '',
size: 512110190592,
physical: 'SSD',
uuid: '',
label: '',
model: 'HJDK SSD 512GB',
serial: 'AA000000000000000003',
removable: false,
protocol: 'nvme',
group: '',
device: '/dev/nvme0n1',
},
{
name: 'sda',
type: 'disk',
fsType: '',
mount: '',
size: 120034123776,
physical: 'SSD',
uuid: '',
label: '',
model: 'OCZ-VERTEX3',
serial: '',
removable: false,
protocol: 'sata',
group: '',
device: '/dev/sda',
},
{
name: 'sdb',
type: 'disk',
fsType: '',
mount: '',
size: 4000787030016,
physical: 'HDD',
uuid: '',
label: '',
model: 'WDC WD40EFRX-68W',
serial: '',
removable: false,
protocol: 'usb',
group: '',
device: '/dev/sdb',
},
{
name: 'nvme0n1p1',
type: 'part',
fsType: 'vfat',
mount: '',
size: 104857600,
physical: '',
uuid: '4878-28DA',
label: 'SYSTEM',
model: '',
serial: '',
removable: false,
protocol: 'nvme',
group: '',
device: '/dev/nvme0n1',
},
{
name: 'nvme0n1p2',
type: 'part',
fsType: '',
mount: '',
size: 16777216,
physical: '',
uuid: '',
label: '',
model: '',
serial: '',
removable: false,
protocol: 'nvme',
group: '',
device: '/dev/nvme0n1',
},
{
name: 'nvme0n1p3',
type: 'part',
fsType: 'ntfs',
mount: '',
size: 510131175424,
physical: '',
uuid: '4CCA7942CA79297A',
label: '',
model: '',
serial: '',
removable: false,
protocol: 'nvme',
group: '',
device: '/dev/nvme0n1',
},
{
name: 'nvme0n1p4',
type: 'part',
fsType: 'ntfs',
mount: '',
size: 1855979520,
physical: '',
uuid: 'C8487B45487B3174',
label: 'Recovery',
model: '',
serial: '',
removable: false,
protocol: 'nvme',
group: '',
device: '/dev/nvme0n1',
},
{
name: 'sda1',
type: 'part',
fsType: 'vfat',
mount: '/mnt/host/boot/efi',
size: 536870912,
physical: '',
uuid: '75D6-EBBF',
label: '',
model: '',
serial: '',
removable: false,
protocol: '',
group: '',
device: '/dev/sda',
},
{
name: 'sda2',
type: 'part',
fsType: 'ext4',
mount: '/mnt/host',
size: 118472310784,
physical: '',
uuid: 'b30cbbd7-bec4-4437-9d6f-a149365842dc',
label: '',
model: '',
serial: '',
removable: false,
protocol: '',
group: '',
device: '/dev/sda',
},
{
name: 'sda3',
type: 'part',
fsType: 'swap',
mount: '[SWAP]',
size: 1023410176,
physical: '',
uuid: '5a8b9c3b-618b-4c18-b201-a0e56473a781',
label: '',
model: '',
serial: '',
removable: false,
protocol: '',
group: '',
device: '/dev/sda',
},
{
name: 'sdb1',
type: 'part',
fsType: 'vfat',
mount: '',
size: 209715200,
physical: '',
uuid: '67E3-17ED',
label: 'EFI',
model: '',
serial: '',
removable: false,
protocol: '',
group: '',
device: '/dev/sdb',
},
{
name: 'sdb2',
type: 'part',
fsType: 'ext4',
mount: '/mnt/host/sftp/mataleao/Garbage',
size: 4000443056128,
physical: '',
uuid: 'c9e750f7-7ebe-4706-abd9-ce7788429acd',
label: 'Garbage',
model: '',
serial: '',
removable: false,
protocol: '',
group: '',
device: '/dev/sdb',
},
{
name: 'sdb3',
type: 'part',
fsType: 'hfsplus',
mount: '',
size: 134217728,
physical: '',
uuid: '1ee90a98-51e2-3ce5-9486-40efe12c7952',
label: 'Boot OS X',
model: '',
serial: '',
removable: false,
protocol: '',
group: '',
device: '/dev/sdb',
},
],
layout: [
{
disks: [{ brand: '', device: 'nvme0n1', type: 'NVMe' }],
size: 512110190592,
},
{
disks: [{ brand: 'ATA', device: 'sda', type: 'SSD' }],
size: 120034123776,
},
{
disks: [{ brand: 'Western Digital', device: 'sdb', type: 'HD' }],
size: 4000787030016,
},
],
output: [0, 16712318976, 1413829738496],
} as any as TestCase;
9 changes: 8 additions & 1 deletion apps/api/src/data/storage/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ export class DynamicStorageMapper {
return deviceBlocks.reduce(
(acc, curr) =>
acc +
unwrapUsed(this.validSizes.find(({ mount }) => curr.mount === mount)),
unwrapUsed(
this.validSizes.find(
({ mount }) =>
mount &&
(curr.mount === mount ||
mount.endsWith(`dev-disk-by-uuid-${curr.uuid}`))
)
),
0
);
}
Expand Down

0 comments on commit 44e87a8

Please sign in to comment.