mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 05:37:53 +00:00
Respect lockOverride when taking locks
Signed-off-by: Christina Ying Wang <christina@balena.io>
This commit is contained in:
parent
b7922e6875
commit
8ac2ce4677
@ -230,16 +230,17 @@ const executeDeviceActionWithLock = async ({
|
||||
}) => {
|
||||
try {
|
||||
if (currentService) {
|
||||
const lockOverride = await config.get('lockOverride');
|
||||
// Take lock for current service to be modified / stopped
|
||||
await executeDeviceAction(
|
||||
generateStep('takeLock', {
|
||||
appId,
|
||||
services: [currentService.serviceName],
|
||||
force,
|
||||
force: force || lockOverride,
|
||||
}),
|
||||
// FIXME: deviceState.executeStepAction only accepts force as a separate arg
|
||||
// instead of reading force from the step object, so we have to pass it twice
|
||||
force,
|
||||
force || lockOverride,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -96,6 +96,16 @@ export async function takeLock(
|
||||
});
|
||||
|
||||
const release = await takeGlobalLockRW(appId);
|
||||
|
||||
let lockOverride: boolean;
|
||||
try {
|
||||
lockOverride = await config.get('lockOverride');
|
||||
} catch (err: any) {
|
||||
throw new InternalInconsistencyError(
|
||||
`Error getting lockOverride config value: ${err?.message ?? err}`,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const actuallyLocked: string[] = [];
|
||||
const locksTaken = await getServicesLockedByAppId();
|
||||
@ -107,7 +117,7 @@ export async function takeLock(
|
||||
);
|
||||
for (const service of servicesWithoutLock) {
|
||||
await mkdirp(pathOnRoot(lockPath(appId, service)));
|
||||
await lockService(appId, service, force);
|
||||
await lockService(appId, service, force || lockOverride);
|
||||
actuallyLocked.push(service);
|
||||
}
|
||||
return actuallyLocked;
|
||||
|
@ -15,6 +15,14 @@ import { mkdirp } from '~/lib/fs-utils';
|
||||
import { takeGlobalLockRW } from '~/lib/process-lock';
|
||||
|
||||
describe('lib/update-lock', () => {
|
||||
before(async () => {
|
||||
await config.initialized();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await config.set({ lockOverride: false });
|
||||
});
|
||||
|
||||
describe('abortIfHUPInProgress', () => {
|
||||
const breadcrumbFiles = [
|
||||
'rollback-health-breadcrumb',
|
||||
@ -106,9 +114,6 @@ describe('lib/update-lock', () => {
|
||||
).to.eventually.deep.equal(exists ? supportedLockfiles : []);
|
||||
|
||||
before(async () => {
|
||||
await config.initialized();
|
||||
await config.set({ lockOverride: false });
|
||||
|
||||
// Ensure the directory is available for all tests
|
||||
await fs.mkdir(lockdir(testAppId, testServiceName), {
|
||||
recursive: true,
|
||||
|
Loading…
Reference in New Issue
Block a user