From 8ac2ce4677d98bc3eb875fa20f329723c08d8023 Mon Sep 17 00:00:00 2001 From: Christina Ying Wang Date: Sat, 6 Apr 2024 00:31:55 -0700 Subject: [PATCH] Respect lockOverride when taking locks Signed-off-by: Christina Ying Wang --- src/device-api/actions.ts | 5 +++-- src/lib/update-lock.ts | 12 +++++++++++- test/integration/lib/update-lock.spec.ts | 11 ++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/device-api/actions.ts b/src/device-api/actions.ts index 30218f20..982f6f54 100644 --- a/src/device-api/actions.ts +++ b/src/device-api/actions.ts @@ -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, ); } diff --git a/src/lib/update-lock.ts b/src/lib/update-lock.ts index 9e72dbf8..f6fc62e8 100644 --- a/src/lib/update-lock.ts +++ b/src/lib/update-lock.ts @@ -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; diff --git a/test/integration/lib/update-lock.spec.ts b/test/integration/lib/update-lock.spec.ts index 67a92584..a82d609f 100644 --- a/test/integration/lib/update-lock.spec.ts +++ b/test/integration/lib/update-lock.spec.ts @@ -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,