mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-22 06:57:49 +00:00
Merge pull request #1957 from balena-os/avoid-config-appId-for-host-config-patch
Don't use config.get for appId when checking locks in host config PATCH
This commit is contained in:
commit
ddc00d196f
@ -5,6 +5,7 @@ import { promises as fs } from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
import * as config from './config';
|
import * as config from './config';
|
||||||
|
import * as applicationManager from './compose/application-manager';
|
||||||
import * as constants from './lib/constants';
|
import * as constants from './lib/constants';
|
||||||
import * as dbus from './lib/dbus';
|
import * as dbus from './lib/dbus';
|
||||||
import { ENOENT, InternalInconsistencyError } from './lib/errors';
|
import { ENOENT, InternalInconsistencyError } from './lib/errors';
|
||||||
@ -217,12 +218,13 @@ export function get(): Bluebird<HostConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function patch(conf: HostConfig, force: boolean): Promise<void> {
|
export async function patch(conf: HostConfig, force: boolean): Promise<void> {
|
||||||
const appId = await config.get('applicationId');
|
const apps = await applicationManager.getCurrentApps();
|
||||||
if (!appId) {
|
const appIds = Object.keys(apps).map((strId) => parseInt(strId, 10));
|
||||||
|
if (!appIds.length) {
|
||||||
throw new InternalInconsistencyError('Could not find an appId');
|
throw new InternalInconsistencyError('Could not find an appId');
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateLock.lock(appId, { force }, () => {
|
return updateLock.lock(appIds, { force }, () => {
|
||||||
const promises: Array<Promise<void>> = [];
|
const promises: Array<Promise<void>> = [];
|
||||||
if (conf != null && conf.network != null) {
|
if (conf != null && conf.network != null) {
|
||||||
if (conf.network.proxy != null) {
|
if (conf.network.proxy != null) {
|
||||||
|
@ -31,10 +31,11 @@ import * as targetStateCache from '../src/device-state/target-state-cache';
|
|||||||
import blink = require('../src/lib/blink');
|
import blink = require('../src/lib/blink');
|
||||||
import constants = require('../src/lib/constants');
|
import constants = require('../src/lib/constants');
|
||||||
import * as deviceAPI from '../src/device-api/common';
|
import * as deviceAPI from '../src/device-api/common';
|
||||||
|
|
||||||
import { UpdatesLockedError } from '../src/lib/errors';
|
import { UpdatesLockedError } from '../src/lib/errors';
|
||||||
import { SchemaTypeKey } from '../src/config/schema-type';
|
import { SchemaTypeKey } from '../src/config/schema-type';
|
||||||
import log from '../src/lib/supervisor-console';
|
import log from '../src/lib/supervisor-console';
|
||||||
|
import * as applicationManager from '../src/compose/application-manager';
|
||||||
|
import App from '../src/compose/app';
|
||||||
|
|
||||||
describe('SupervisorAPI [V1 Endpoints]', () => {
|
describe('SupervisorAPI [V1 Endpoints]', () => {
|
||||||
let api: SupervisorAPI;
|
let api: SupervisorAPI;
|
||||||
@ -937,11 +938,23 @@ describe('SupervisorAPI [V1 Endpoints]', () => {
|
|||||||
before(() => {
|
before(() => {
|
||||||
configSetStub = stub(config, 'set').callsFake(configSetFakeFn);
|
configSetStub = stub(config, 'set').callsFake(configSetFakeFn);
|
||||||
logWarnStub = stub(log, 'warn');
|
logWarnStub = stub(log, 'warn');
|
||||||
|
stub(applicationManager, 'getCurrentApps').resolves({
|
||||||
|
'1234567': new App(
|
||||||
|
{
|
||||||
|
appId: 1234567,
|
||||||
|
services: [],
|
||||||
|
volumes: {},
|
||||||
|
networks: {},
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
after(() => {
|
||||||
configSetStub.restore();
|
configSetStub.restore();
|
||||||
logWarnStub.restore();
|
logWarnStub.restore();
|
||||||
|
(applicationManager.getCurrentApps as SinonStub).restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user