more robust unpublish and unstage logic

Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
Travis Glenn Hansen 2022-05-07 19:44:35 -06:00
parent 466845cbd9
commit b9e4f20863
3 changed files with 107 additions and 28 deletions

View File

@ -113,7 +113,6 @@ jobs:
SYNOLOGY_PASSWORD: ${{ secrets.SANITY_SYNOLOGY_PASSWORD }} SYNOLOGY_PASSWORD: ${{ secrets.SANITY_SYNOLOGY_PASSWORD }}
SYNOLOGY_VOLUME: ${{ secrets.SANITY_SYNOLOGY_VOLUME }} SYNOLOGY_VOLUME: ${{ secrets.SANITY_SYNOLOGY_VOLUME }}
# api-based drivers # api-based drivers
csi-sanity-truenas-scale-22_02: csi-sanity-truenas-scale-22_02:
needs: needs:
@ -312,18 +311,18 @@ jobs:
matrix: matrix:
os: [Linux, Windows] os: [Linux, Windows]
include: include:
- os: Linux - os: Linux
npmartifact: node-modules-linux-amd64 npmartifact: node-modules-linux-amd64
template: "./ci/configs/local-hostpath/basic.yaml" template: "./ci/configs/local-hostpath/basic.yaml"
run: | run: |
# run tests # run tests
ci/bin/run.sh ci/bin/run.sh
- os: Windows - os: Windows
npmartifact: node-modules-windows-amd64 npmartifact: node-modules-windows-amd64
template: ".\\ci\\configs\\local-hostpath/basic.yaml" template: ".\\ci\\configs\\local-hostpath/basic.yaml"
run: | run: |
# run tests # run tests
ci\bin\run.ps1 ci\bin\run.ps1
runs-on: runs-on:
- self-hosted - self-hosted
- ${{ matrix.os }} - ${{ matrix.os }}
@ -376,6 +375,7 @@ jobs:
- csi-sanity-truenas-core-12_0 - csi-sanity-truenas-core-12_0
- csi-sanity-truenas-core-13_0 - csi-sanity-truenas-core-13_0
- csi-sanity-zfs-generic - csi-sanity-zfs-generic
- csi-sanity-client
- csi-sanity-zfs-local - csi-sanity-zfs-local
- csi-sanity-local-hostpath - csi-sanity-local-hostpath
- csi-sanity-windows-node - csi-sanity-windows-node

View File

@ -2043,7 +2043,21 @@ class CsiBaseDriver {
result = await mount.pathIsMounted(normalized_staging_path); result = await mount.pathIsMounted(normalized_staging_path);
if (result) { if (result) {
try { try {
result = await mount.umount(normalized_staging_path, umount_args); result = await GeneralUtils.retry(
10,
0,
async () => {
return await mount.umount(normalized_staging_path, umount_args);
},
{
minExecutionTime: 1000,
retryCondition: (err) => {
if (_.get(err, "stderr", "").includes("busy")) {
return true;
}
},
}
);
} catch (err) { } catch (err) {
if (err.timeout) { if (err.timeout) {
driver.ctx.logger.warn( driver.ctx.logger.warn(
@ -2188,13 +2202,41 @@ class CsiBaseDriver {
// remove touched file // remove touched file
result = await filesystem.pathExists(block_path); result = await filesystem.pathExists(block_path);
if (result) { if (result) {
result = await filesystem.rm(block_path); result = await GeneralUtils.retry(
10,
0,
async () => {
return await filesystem.rm(block_path);
},
{
minExecutionTime: 1000,
retryCondition: (err) => {
if (_.get(err, "stderr", "").includes("busy")) {
return true;
}
},
}
);
} }
} }
result = await filesystem.pathExists(staging_target_path); result = await filesystem.pathExists(staging_target_path);
if (result) { if (result) {
result = await filesystem.rmdir(staging_target_path); result = await GeneralUtils.retry(
10,
0,
async () => {
return await filesystem.rmdir(staging_target_path);
},
{
minExecutionTime: 1000,
retryCondition: (err) => {
if (_.get(err, "stderr", "").includes("busy")) {
return true;
}
},
}
);
} }
break; break;
case NODE_OS_DRIVER_WINDOWS: { case NODE_OS_DRIVER_WINDOWS: {
@ -2777,7 +2819,21 @@ class CsiBaseDriver {
if (result) { if (result) {
try { try {
result = await mount.umount(target_path, umount_args); result = await GeneralUtils.retry(
10,
0,
async () => {
return await mount.umount(target_path, umount_args);
},
{
minExecutionTime: 1000,
retryCondition: (err) => {
if (_.get(err, "stderr", "").includes("busy")) {
return true;
}
},
}
);
} catch (err) { } catch (err) {
if (err.timeout) { if (err.timeout) {
driver.ctx.logger.warn( driver.ctx.logger.warn(
@ -2808,9 +2864,30 @@ class CsiBaseDriver {
result = await filesystem.pathExists(target_path); result = await filesystem.pathExists(target_path);
if (result) { if (result) {
if (fs.lstatSync(target_path).isDirectory()) { if (fs.lstatSync(target_path).isDirectory()) {
result = await filesystem.rmdir(target_path); result = await GeneralUtils.retry(
10,
0,
async () => {
return await filesystem.rmdir(target_path);
},
{
minExecutionTime: 1000,
retryCondition: (err) => {
if (_.get(err, "stderr", "").includes("busy")) {
return true;
}
},
}
);
} else { } else {
result = await filesystem.rm([target_path]); result = await GeneralUtils.retry(
10,
0,
async () => {
return await filesystem.rm([target_path]);
},
{ minExecutionTime: 1000 }
);
} }
} }

View File

@ -145,9 +145,7 @@ function axios_request(options, callback = function () {}) {
options.validateStatus && options.validateStatus &&
typeof options.validateStatus == "function" typeof options.validateStatus == "function"
) { ) {
if (!options.validateStatus(res.statusCode)) { senderr = true;
senderr = true;
}
} }
callback(senderr ? err : null, res, res.body); callback(senderr ? err : null, res, res.body);
} else if (err.request) { } else if (err.request) {
@ -214,12 +212,14 @@ async function retry(retries, retriesDelay, code, options = {}) {
console.log(`retry - err:`, err); console.log(`retry - err:`, err);
} }
} }
// handle minExecutionTime // handle minExecutionTime
if (options.minExecutionTime > 0) { if (options.minExecutionTime > 0) {
let minDelayTime = let executionElapsedTIme = Date.now() - executeStartTime;
options.minExecutionTime - (Date.now() - executeStartTime); let minExecutionDelayTime =
if (minDelayTime > 0) { options.minExecutionTime - executionElapsedTIme;
await sleep(minDelayTime); if (minExecutionDelayTime > 0) {
await sleep(minExecutionDelayTime);
} }
} }
@ -234,8 +234,10 @@ async function retry(retries, retriesDelay, code, options = {}) {
sleep_time = maxwait; sleep_time = maxwait;
} }
} }
console.log(`retry - waiting ${sleep_time}ms before trying again`); if (sleep_time > 0) {
await sleep(sleep_time); console.log(`retry - waiting ${sleep_time}ms before trying again`);
await sleep(sleep_time);
}
} while (true); } while (true);
} }