Merge pull request #2263 from balena-os/bugfix-1-for-update-lock-state-apply

Update lock state apply: patch DockerName & respect lockOverride
This commit is contained in:
flowzone-app[bot] 2024-04-06 08:21:00 +00:00 committed by GitHub
commit 4319d0aa56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 7 deletions

View File

@ -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,
);
}

View File

@ -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;

View File

@ -96,7 +96,7 @@ const CONFIG_VAR_NAME_REGEX = /^[a-zA-Z_][a-zA-Z0-9_:]*$/;
const shortStringWithRegex = (name: string, regex: RegExp, message: string) =>
new t.Type<string, string>(
name,
(s: unknown): s is string => ShortString.is(s) && VAR_NAME_REGEX.test(s),
(s: unknown): s is string => ShortString.is(s) && regex.test(s),
(i, c) =>
pipe(
ShortString.validate(i, c),

View File

@ -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,