make target delete more robust during in use scenarios

Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
Travis Glenn Hansen 2022-03-12 21:07:56 -07:00
parent e0657190ed
commit 196e2f6744
3 changed files with 26 additions and 0 deletions

View File

@ -4,6 +4,10 @@ set -e
set -x
export PATH="/usr/local/lib/nodejs/bin:${PATH}"
node --version
npm --version
# install deps
npm i

View File

@ -1,3 +1,4 @@
const _ = require("lodash");
const { GrpcError, grpc } = require("../../utils/grpc");
const { CsiBaseDriver } = require("../index");
const HttpClient = require("./http").Client;
@ -1539,7 +1540,25 @@ class FreeNASApiDriver extends CsiBaseDriver {
}
if (deleteAsset) {
let retries = 0;
let maxRetries = 5;
let retryWait = 1000;
response = await httpClient.delete(endpoint);
// sometimes after an initiator has detached it takes a moment for TrueNAS to settle
// code: 422 body: {\"message\":\"Target csi-ci-55877e95sanity-node-expand-volume-e54f81fa-cd38e798 is in use.\",\"errno\":14}
while (
response.statusCode == 422 &&
retries < maxRetries &&
_.get(response, "body.message").includes("Target") &&
_.get(response, "body.message").includes("is in use") &&
_.get(response, "body.errno") == 14
) {
retries++;
await sleep(retryWait);
response = await httpClient.delete(endpoint);
}
if (![200, 204, 404].includes(response.statusCode)) {
throw new GrpcError(
grpc.status.UNKNOWN,

View File

@ -103,7 +103,10 @@ class ISCSI {
"-o",
"new",
]);
// create DB entry
await iscsi.exec(options.paths.iscsiadm, args);
// update attributes 1 by 1
for (let attribute in attributes) {
let args = [];
args = args.concat([