Merge pull request #1421 from balena-io/patch-extra-uenv-match

Patch extra uenv match
This commit is contained in:
bulldozer-balena[bot] 2020-07-31 07:18:49 +00:00 committed by GitHub
commit 0c2d9338ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 48 deletions

View File

@ -23,7 +23,10 @@ export async function remountAndWriteAtomic(
export abstract class DeviceConfigBackend {
// Does this config backend support the given device type?
public abstract matches(deviceType: string, metaRelease?: string): boolean;
public abstract async matches(
deviceType: string,
metaRelease?: string,
): Promise<boolean>;
// A function which reads and parses the configuration options from
// specific boot config

View File

@ -157,7 +157,7 @@ export class ConfigfsConfigBackend extends DeviceConfigBackend {
return this;
}
public matches(deviceType: string): boolean {
public async matches(deviceType: string): Promise<boolean> {
return ConfigfsConfigBackend.SupportedDeviceTypes.includes(deviceType);
}

View File

@ -18,6 +18,9 @@ import * as constants from '../../lib/constants';
import log from '../../lib/supervisor-console';
import { ExtLinuxEnvError, ExtLinuxParseError } from '../../lib/errors';
// The OS version when extlinux moved to READ ONLY partition
const EXTLINUX_READONLY = '2.47.0';
/**
* A backend to handle extlinux host configuration
*
@ -44,12 +47,15 @@ export class ExtlinuxConfigBackend extends DeviceConfigBackend {
'(?:' + _.escapeRegExp(ExtlinuxConfigBackend.bootConfigVarPrefix) + ')(.+)',
);
public matches(deviceType: string, metaRelease: string | undefined): boolean {
public async matches(
deviceType: string,
metaRelease: string | undefined,
): Promise<boolean> {
return (
// Only test metaRelease with Jetson devices
deviceType.startsWith('jetson-') &&
typeof metaRelease === 'string' &&
semver.lt(metaRelease, constants.extLinuxReadOnly)
semver.lt(metaRelease, EXTLINUX_READONLY)
);
}

View File

@ -1,6 +1,5 @@
import * as _ from 'lodash';
import { fs } from 'mz';
import * as semver from 'semver';
import {
ConfigOptions,
@ -61,14 +60,10 @@ export class ExtraUEnvConfigBackend extends DeviceConfigBackend {
')(.+)',
);
public matches(deviceType: string, metaRelease: string | undefined): boolean {
public async matches(deviceType: string): Promise<boolean> {
return (
deviceType === 'intel-nuc' ||
// Test metaRelease for Jetson devices
(deviceType.startsWith('jetson') &&
// Assume metaRelease is greater than or equal to EXTRA_SUPPORT if undefined
(typeof metaRelease === 'undefined' ||
semver.gte(metaRelease, constants.extLinuxReadOnly)))
(deviceType === 'intel-nuc' || deviceType.startsWith('jetson')) &&
(await fs.exists(ExtraUEnvConfigBackend.bootConfigPath))
);
}

View File

@ -50,7 +50,7 @@ export class RPiConfigBackend extends DeviceConfigBackend {
'avoid_safe_mode',
];
public matches(deviceType: string): boolean {
public async matches(deviceType: string): Promise<boolean> {
return deviceType.startsWith('raspberry') || deviceType === 'fincm3';
}

View File

@ -29,9 +29,13 @@ async function getConfigBackend(
): Promise<DeviceConfigBackend | undefined> {
// Some backends are only supported by certain release versions so pass in metaRelease
const metaRelease = await getMetaOSRelease(constants.hostOSVersionPath);
return _.find(configBackends, (backend) =>
backend.matches(deviceType, metaRelease),
);
let matched;
for (const backend of configBackends) {
if (await backend.matches(deviceType, metaRelease)) {
matched = backend;
}
}
return matched;
}
export function envToBootConfig(

View File

@ -65,8 +65,6 @@ const constants = {
// (this number is used as an upper bound when generating
// a random jitter)
maxApiJitterDelay: 60 * 1000,
// The OS version when extlinux moved to READ ONLY partition
extLinuxReadOnly: '2.47.0',
};
if (process.env.DOCKER_HOST == null) {

View File

@ -122,10 +122,12 @@ describe('Extlinux Configuration', () => {
.that.equals('3,4,5');
});
it('only matches supported devices', () => {
MATCH_TESTS.forEach(({ deviceType, metaRelease, supported }) =>
expect(backend.matches(deviceType, metaRelease)).to.equal(supported),
);
it('only matches supported devices', async () => {
for (const { deviceType, metaRelease, supported } of MATCH_TESTS) {
await expect(
backend.matches(deviceType, metaRelease),
).to.eventually.equal(supported);
}
});
it('errors when cannot find extlinux.conf', async () => {

View File

@ -66,10 +66,13 @@ describe('extra_uEnv Configuration', () => {
await expect(backend.getBootConfig()).to.eventually.deep.equal({});
});
it('only matches supported devices', () => {
MATCH_TESTS.forEach(({ deviceType, metaRelease, supported }) =>
expect(backend.matches(deviceType, metaRelease)).to.equal(supported),
);
it('only matches supported devices', async () => {
const existsStub = stub(fs, 'exists');
for (const { hasConfigFile, deviceType, supported } of MATCH_TESTS) {
existsStub.resolves(hasConfigFile);
await expect(backend.matches(deviceType)).to.eventually.equal(supported);
}
existsStub.restore();
});
it('errors when cannot find extra_uEnv.txt', async () => {
@ -235,83 +238,80 @@ const MALFORMED_CONFIGS = [
},
];
const SUPPORTED_VERSION = '2.47.0'; // or greater
const UNSUPPORTED_VERSION = '2.45.0'; // or less
const MATCH_TESTS = [
{
deviceType: 'jetson-tx1',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: true,
},
{
deviceType: 'jetson-tx2',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: true,
},
{
deviceType: 'jetson-tx2',
metaRelease: UNSUPPORTED_VERSION,
hasConfigFile: false,
supported: false,
},
{
deviceType: 'jetson-nano',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: true,
},
{
deviceType: 'jetson-nano',
metaRelease: UNSUPPORTED_VERSION,
hasConfigFile: false,
supported: false,
},
{
deviceType: 'jetson-xavier',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: true,
},
{
deviceType: 'jetson-xavier',
metaRelease: UNSUPPORTED_VERSION,
hasConfigFile: false,
supported: false,
},
{
deviceType: 'intel-nuc',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: true,
},
{
deviceType: 'intel-nuc',
metaRelease: UNSUPPORTED_VERSION,
supported: true,
},
{
deviceType: 'raspberry',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: false,
supported: false,
},
{
deviceType: 'raspberry',
metaRelease: UNSUPPORTED_VERSION,
hasConfigFile: true,
supported: false,
},
{
deviceType: 'raspberry',
hasConfigFile: false,
supported: false,
},
{
deviceType: 'fincm3',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: false,
},
{
deviceType: 'fincm3',
metaRelease: UNSUPPORTED_VERSION,
hasConfigFile: false,
supported: false,
},
{
deviceType: 'up-board',
metaRelease: SUPPORTED_VERSION,
hasConfigFile: true,
supported: false,
},
{
deviceType: 'up-board',
metaRelease: UNSUPPORTED_VERSION,
hasConfigFile: false,
supported: false,
},
];