mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-24 21:37:10 +00:00
Merge pull request #2132 from balena-os/lower-case-cpu-id
Always lower case the cpu id to avoid bouncing between casing when reporting
This commit is contained in:
commit
1b210d4fa6
@ -73,6 +73,7 @@ export async function getCpuTemp(): Promise<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getSystemId(): Promise<string | undefined> {
|
export async function getSystemId(): Promise<string | undefined> {
|
||||||
|
let systemId: undefined | string;
|
||||||
try {
|
try {
|
||||||
// This will work on arm devices
|
// This will work on arm devices
|
||||||
const buffer = await Promise.any([
|
const buffer = await Promise.any([
|
||||||
@ -81,14 +82,20 @@ export async function getSystemId(): Promise<string | undefined> {
|
|||||||
fs.readFile('/sys/devices/soc0/serial_number'),
|
fs.readFile('/sys/devices/soc0/serial_number'),
|
||||||
]);
|
]);
|
||||||
// Remove the null/newline bytes at the end
|
// Remove the null/newline bytes at the end
|
||||||
return buffer.toString('utf-8').replace(/\0/g, '').trim();
|
systemId = buffer.toString('utf-8').replace(/\0/g, '').trim();
|
||||||
} catch {
|
} catch {
|
||||||
// Otherwise use dmidecode
|
// Otherwise use dmidecode
|
||||||
const [baseBoardInfo] = (
|
const [baseBoardInfo] = (
|
||||||
await dmidecode('baseboard').catch(() => [] as DmiDecodeInfo[])
|
await dmidecode('baseboard').catch(() => [] as DmiDecodeInfo[])
|
||||||
).filter((entry) => entry.type === 'Base Board Information');
|
).filter((entry) => entry.type === 'Base Board Information');
|
||||||
return baseBoardInfo?.values?.['Serial Number'] || undefined;
|
systemId = baseBoardInfo?.values?.['Serial Number'] || undefined;
|
||||||
}
|
}
|
||||||
|
if (systemId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Always lower case so as not to jump between casing when jumping between eg /proc/device-tree/serial-number and /sys/devices/soc0/serial_number which can return different casing
|
||||||
|
// Lower case was chosen because that is what `/proc/device-tree/serial-number` usually returns and seems to be the more consistently available version
|
||||||
|
return systemId.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSystemModel(): Promise<string | undefined> {
|
export async function getSystemModel(): Promise<string | undefined> {
|
||||||
|
@ -129,7 +129,7 @@ describe('System information', () => {
|
|||||||
stdout: mockCPU.dmidecode,
|
stdout: mockCPU.dmidecode,
|
||||||
});
|
});
|
||||||
const cpuId = await sysInfo.getSystemId();
|
const cpuId = await sysInfo.getSystemId();
|
||||||
expect(cpuId).to.equal('GEBN94600PWW');
|
expect(cpuId).to.equal('gebn94600pww');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gets system model', async () => {
|
it('gets system model', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user