From ad4ed0856eb63338cc026e9eb0f94b6d2e7c5e06 Mon Sep 17 00:00:00 2001 From: williamlardier Date: Mon, 2 Dec 2024 14:46:33 +0100 Subject: [PATCH] Update how zenko-ctst account is created It seems that we are not robust against parallel account creations in Vault/Pensieve, leading in some cases to two accounts in the __account collection, but also in the pensieve overlay. However, when the overlay is updated (adding a new location, or a bucket configuration), ZKOP will thus fail the overlay validation and the reconciliations will all fail. It was affecting the bucket tests, but may affect more tests later. Issue: ZENKO-4941 --- tests/ctst/world/Zenko.ts | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/tests/ctst/world/Zenko.ts b/tests/ctst/world/Zenko.ts index 4421348cd..383d74328 100644 --- a/tests/ctst/world/Zenko.ts +++ b/tests/ctst/world/Zenko.ts @@ -4,6 +4,7 @@ import { AccessKey } from '@aws-sdk/client-iam'; import { Credentials } from '@aws-sdk/client-sts'; import { aws4Interceptor } from 'aws4-axios'; import qs from 'qs'; +import lockFile from 'proper-lockfile'; import Werelogs from 'werelogs'; import { CacheHelper, @@ -632,22 +633,29 @@ export default class Zenko extends World { Identity.useIdentity(IdentityEnum.ADMIN, site.adminIdentityName); let account = null; - CacheHelper.logger.debug('Creating account', { - accountName, - adminIdentityName: site.adminIdentityName, - credentials: Identity.getCurrentCredentials(), - }); - // Create the account if already exist will not throw any error + let releaseLock: (() => Promise) | null = null; try { - await SuperAdmin.createAccount({ accountName }); - /* eslint-disable */ - } catch (err: any) { - CacheHelper.logger.debug('Error while creating account', { - accountName, - err, + releaseLock = await lockFile.lock('/tmp/account-init.lock', { + stale: Constants.DEFAULT_TIMEOUT / 2, + retries: { + retries: 5, + factor: 3, + minTimeout: 1000, + maxTimeout: 5000, + } }); - if (!err.EntityAlreadyExists && err.code !== 'EntityAlreadyExists') { - throw err; + + try { + await SuperAdmin.createAccount({ accountName }); + /* eslint-disable */ + } catch (err: any) { + if (!err.EntityAlreadyExists && err.code !== 'EntityAlreadyExists') { + throw err; + } + } + } finally { + if (releaseLock) { + await releaseLock(); } } /* eslint-enable */