mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Ensure that we always have the pi4 overlay assigned
Change-type: patch Closes: #1171 Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
7811ab4f22
commit
426d8cd10a
@ -337,18 +337,14 @@ export class DeviceConfig {
|
||||
target: Dictionary<string>,
|
||||
deviceType: string,
|
||||
): boolean {
|
||||
let targetBootConfig = configUtils.envToBootConfig(configBackend, target);
|
||||
const targetBootConfig = configUtils.envToBootConfig(configBackend, target);
|
||||
const currentBootConfig = configUtils.envToBootConfig(
|
||||
configBackend,
|
||||
current,
|
||||
);
|
||||
|
||||
if (deviceType === 'fincm3') {
|
||||
// current will always have the balena-fin dtoverlay, but the target does
|
||||
// not have to as this is one that we enforce. If there is no balena-fin in the
|
||||
// target state, add it
|
||||
targetBootConfig = DeviceConfig.ensureFinOverlay(targetBootConfig);
|
||||
}
|
||||
// Some devices require specific overlays, here we apply them
|
||||
DeviceConfig.ensureRequiredOverlay(deviceType, targetBootConfig);
|
||||
|
||||
if (!_.isEqual(currentBootConfig, targetBootConfig)) {
|
||||
_.each(targetBootConfig, (value, key) => {
|
||||
@ -539,17 +535,18 @@ export class DeviceConfig {
|
||||
return false;
|
||||
}
|
||||
|
||||
let conf = configUtils.envToBootConfig(backend, target);
|
||||
const conf = configUtils.envToBootConfig(backend, target);
|
||||
this.logger.logSystemMessage(
|
||||
`Applying boot config: ${JSON.stringify(conf)}`,
|
||||
{},
|
||||
'Apply boot config in progress',
|
||||
);
|
||||
|
||||
// Ensure that the fin always has it's dtoverlay
|
||||
if ((await this.config.get('deviceType')) === 'fincm3') {
|
||||
conf = DeviceConfig.ensureFinOverlay(conf);
|
||||
}
|
||||
// Ensure devices already have required overlays
|
||||
DeviceConfig.ensureRequiredOverlay(
|
||||
await this.config.get('deviceType'),
|
||||
conf,
|
||||
);
|
||||
|
||||
try {
|
||||
await backend.setBootConfig(conf);
|
||||
@ -613,19 +610,34 @@ export class DeviceConfig {
|
||||
}
|
||||
|
||||
// Modifies conf
|
||||
private static ensureFinOverlay(conf: ConfigOptions) {
|
||||
if (conf.dtoverlay != null) {
|
||||
if (_.isArray(conf.dtoverlay)) {
|
||||
if (!_.includes(conf.dtoverlay, 'balena-fin')) {
|
||||
conf.dtoverlay.push('balena-fin');
|
||||
}
|
||||
} else if (conf.dtoverlay !== 'balena-fin') {
|
||||
conf.dtoverlay = [conf.dtoverlay, 'balena-fin'];
|
||||
}
|
||||
} else {
|
||||
conf.dtoverlay = ['balena-fin'];
|
||||
private static ensureRequiredOverlay(
|
||||
deviceType: string,
|
||||
conf: ConfigOptions,
|
||||
) {
|
||||
switch (deviceType) {
|
||||
case 'fincm3':
|
||||
this.ensureDtoverlay(conf, 'balena-fin');
|
||||
break;
|
||||
case 'raspberrypi4-64':
|
||||
this.ensureDtoverlay(conf, 'vc4-fkms-v3d');
|
||||
break;
|
||||
}
|
||||
conf.dtoverlay = (conf.dtoverlay as string[]).filter(s => !_.isEmpty(s));
|
||||
|
||||
return conf;
|
||||
}
|
||||
|
||||
// Modifies conf
|
||||
private static ensureDtoverlay(conf: ConfigOptions, field: string) {
|
||||
if (conf.dtoverlay == null) {
|
||||
conf.dtoverlay = [];
|
||||
} else if (_.isString(conf.dtoverlay)) {
|
||||
conf.dtoverlay = [conf.dtoverlay];
|
||||
}
|
||||
if (!_.includes(conf.dtoverlay, field)) {
|
||||
conf.dtoverlay.push(field);
|
||||
}
|
||||
conf.dtoverlay = conf.dtoverlay.filter(s => !_.isEmpty(s));
|
||||
|
||||
return conf;
|
||||
}
|
||||
}
|
||||
|
@ -218,11 +218,11 @@ describe 'DeviceConfig', ->
|
||||
|
||||
describe 'Balena fin', ->
|
||||
it 'should always add the balena-fin dtoverlay', ->
|
||||
expect(DeviceConfig.ensureFinOverlay({})).to.deep.equal({ dtoverlay: ['balena-fin'] })
|
||||
expect(DeviceConfig.ensureFinOverlay({ test: '123', test2: ['123'], test3: ['123', '234'] })).to
|
||||
expect(DeviceConfig.ensureRequiredOverlay('fincm3', {})).to.deep.equal({ dtoverlay: ['balena-fin'] })
|
||||
expect(DeviceConfig.ensureRequiredOverlay('fincm3', { test: '123', test2: ['123'], test3: ['123', '234'] })).to
|
||||
.deep.equal({ test: '123', test2: ['123'], test3: ['123', '234'], dtoverlay: ['balena-fin'] })
|
||||
expect(DeviceConfig.ensureFinOverlay({ dtoverlay: 'test' })).to.deep.equal({ dtoverlay: ['test', 'balena-fin'] })
|
||||
expect(DeviceConfig.ensureFinOverlay({ dtoverlay: ['test'] })).to.deep.equal({ dtoverlay: ['test', 'balena-fin'] })
|
||||
expect(DeviceConfig.ensureRequiredOverlay('fincm3', { dtoverlay: 'test' })).to.deep.equal({ dtoverlay: ['test', 'balena-fin'] })
|
||||
expect(DeviceConfig.ensureRequiredOverlay('fincm3', { dtoverlay: ['test'] })).to.deep.equal({ dtoverlay: ['test', 'balena-fin'] })
|
||||
|
||||
it 'should not cause a config change when the cloud does not specify the balena-fin overlay', ->
|
||||
expect(@deviceConfig.bootConfigChangeRequired(
|
||||
@ -246,5 +246,35 @@ describe 'DeviceConfig', ->
|
||||
'fincm3'
|
||||
)).to.equal(false)
|
||||
|
||||
describe 'Raspberry pi4', ->
|
||||
it 'should always add the vc4-fkms-v3d dtoverlay', ->
|
||||
expect(DeviceConfig.ensureRequiredOverlay('raspberrypi4-64', {})).to.deep.equal({ dtoverlay: ['vc4-fkms-v3d'] })
|
||||
expect(DeviceConfig.ensureRequiredOverlay('raspberrypi4-64', { test: '123', test2: ['123'], test3: ['123', '234'] })).to
|
||||
.deep.equal({ test: '123', test2: ['123'], test3: ['123', '234'], dtoverlay: ['vc4-fkms-v3d'] })
|
||||
expect(DeviceConfig.ensureRequiredOverlay('raspberrypi4-64', { dtoverlay: 'test' })).to.deep.equal({ dtoverlay: ['test', 'vc4-fkms-v3d'] })
|
||||
expect(DeviceConfig.ensureRequiredOverlay('raspberrypi4-64', { dtoverlay: ['test'] })).to.deep.equal({ dtoverlay: ['test', 'vc4-fkms-v3d'] })
|
||||
|
||||
it 'should not cause a config change when the cloud does not specify the pi4 overlay', ->
|
||||
expect(@deviceConfig.bootConfigChangeRequired(
|
||||
rpiConfigBackend,
|
||||
{ HOST_CONFIG_dtoverlay: '"test","vc4-fkms-v3d"' },
|
||||
{ HOST_CONFIG_dtoverlay: '"test"' },
|
||||
'raspberrypi4-64'
|
||||
)).to.equal(false)
|
||||
|
||||
expect(@deviceConfig.bootConfigChangeRequired(
|
||||
rpiConfigBackend,
|
||||
{ HOST_CONFIG_dtoverlay: '"test","vc4-fkms-v3d"' },
|
||||
{ HOST_CONFIG_dtoverlay: 'test' },
|
||||
'raspberrypi4-64'
|
||||
)).to.equal(false)
|
||||
|
||||
expect(@deviceConfig.bootConfigChangeRequired(
|
||||
rpiConfigBackend,
|
||||
{ HOST_CONFIG_dtoverlay: '"test","test2","vc4-fkms-v3d"' },
|
||||
{ HOST_CONFIG_dtoverlay: '"test","test2"' },
|
||||
'raspberrypi4-64'
|
||||
)).to.equal(false)
|
||||
|
||||
# This will require stubbing device.reboot, gosuper.post, config.get/set
|
||||
it 'applies the target state'
|
||||
|
Loading…
Reference in New Issue
Block a user