Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions tests/functional/ctst/steps/azureArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,26 @@ function getAzureCreds(
* @returns {string} name of the tar blob
*/
async function isObjectRehydrated(zenko: Zenko, objectName: string) {
let found = false;
const {
tarName,
} = await findObjectPackAndManifest(
const { tarName } = await findObjectPackAndManifest(
zenko,
zenko.getSaved<string>('bucketName'),
objectName || zenko.getSaved<string>('objectName'),
);
const start = new Date();
assert(tarName);
while (!found) {
found = await AzureHelper.blobExists(
const start = Date.now();
//wait for 1 minute max
while (Date.now() - start <= 60000) {
const found = await AzureHelper.blobExists(
zenko.parameters.AzureArchiveContainer,
`rehydrate/${tarName}`,
getAzureCreds(zenko),
);
await Utils.sleep(1000);

//wait for 1 minute max
if (new Date().getTime() - start.getTime() > 60000) {
return undefined;
if (found) {
return tarName;
}
await Utils.sleep(1000);
}
return tarName;
return undefined;
}

/**
Expand Down
23 changes: 9 additions & 14 deletions tests/functional/ctst/steps/utils/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ export async function waitForZenkoToStabilize(
// So, this function will first wait till we detect a reconciliation
// (deploymentInProgress = true), and then wait for the status to be available
const startTime = Date.now();
let status = false;
let deploymentFailure: ZenkoStatusValue = {
lastTransitionTime: '',
message: '',
Expand All @@ -287,7 +286,7 @@ export async function waitForZenkoToStabilize(
world.logger.debug('Waiting for Zenko to stabilize');
const zenkoClient = createKubeCustomObjectClient(world);

while (!status && Date.now() - startTime < timeout) {
while (Date.now() - startTime < timeout) {
const zenkoCR = await zenkoClient.getNamespacedCustomObject({
group: 'zenko.io',
version: 'v1alpha2',
Expand Down Expand Up @@ -342,19 +341,16 @@ export async function waitForZenkoToStabilize(
deploymentInProgress.status === 'False' &&
available.status === 'True'
) {
status = true;
return;
}

await Utils.sleep(1000);
}

if (!status) {
throw new Error('Zenko did not stabilize');
}
throw new Error('Zenko did not stabilize');
}

export async function waitForDataServicesToStabilize(world: Zenko, timeout = 15 * 60 * 1000, namespace = 'default') {
let allRunning = false;
const startTime = Date.now();
const annotationKey = 'operator.zenko.io/dependencies';
const dataServices = ['connector-cloudserver-config', 'backbeat-config'];
Expand All @@ -379,8 +375,8 @@ export async function waitForDataServicesToStabilize(world: Zenko, timeout = 15
deployments: deployments.map(deployment => deployment.metadata?.name),
});

while (!allRunning && Date.now() - startTime < timeout) {
allRunning = true;
while (Date.now() - startTime < timeout) {
let allRunning = true;

// get the deployments in the array, and check in loop if they are ready
for (const deployment of deployments) {
Expand Down Expand Up @@ -414,14 +410,13 @@ export async function waitForDataServicesToStabilize(world: Zenko, timeout = 15
}
}

if (allRunning) {
return true;
}
await Utils.sleep(1000);
}

if (!allRunning) {
throw new Error('Data services did not stabilize');
}

return allRunning;
throw new Error('Data services did not stabilize');
}

export async function displayCRStatus(world: Zenko, namespace = 'default') {
Expand Down
34 changes: 15 additions & 19 deletions tests/functional/ctst/steps/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,24 +484,16 @@ async function verifyObjectLocation(this: Zenko, objectName: string,
if (versionId) {
this.addCommandParameter({ versionId });
}
let conditionOk = false;

const startTime = Date.now();
const timeoutMs = 5 * 60 * 1000;
while (!conditionOk) {
if (Date.now() - startTime > timeoutMs) {
throw new Error(
`verifyObjectLocation timed out after ${timeoutMs / 1000}s ` +
`waiting for object "${objName}" to reach status "${objectTransitionStatus}" ` +
`with storage class "${storageClass}"`
);
}
while (Date.now() - startTime <= timeoutMs) {
const res = await S3.headObject(this.getCommandParameters());
if (res.err?.includes('NotFound')) {
await Utils.sleep(1000);
continue;
} else if (res.err) {
break;
}
if (res.err) {
throw new Error(`verifyObjectLocation: headObject failed for "${objName}": ${res.err}`);
}
assert(res.stdout);
const parsed = safeJsonParse<{
Expand All @@ -510,19 +502,23 @@ async function verifyObjectLocation(this: Zenko, objectName: string,
}>(res.stdout);
assert(parsed.ok);
const expectedClass = storageClass !== '' ? storageClass : undefined;
if (parsed.result?.StorageClass === expectedClass) {
conditionOk = true;
}
let ok = parsed.result?.StorageClass === expectedClass;
if (objectTransitionStatus == 'restored') {
const isRestored = !!parsed.result?.Restore &&
ok = ok && !!parsed.result?.Restore &&
parsed.result.Restore.includes('ongoing-request="false", expiry-date=');
conditionOk = conditionOk && isRestored;
} else if (objectTransitionStatus == 'cold') {
conditionOk = conditionOk && !parsed.result?.Restore;
ok = ok && !parsed.result?.Restore;
}
if (ok) {
return;
}
await Utils.sleep(1000);
}
assert(conditionOk);
throw new Error(
`verifyObjectLocation timed out after ${timeoutMs / 1000}s ` +
`waiting for object "${objName}" to reach status "${objectTransitionStatus}" ` +
`with storage class "${storageClass}"`
);
}

async function restoreObject(this: Zenko, objectName: string, days: number) {
Expand Down
Loading