always use ip for nvme transport address

Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
Travis Glenn Hansen 2022-12-29 00:14:28 -07:00
parent d05e29a148
commit 6738ca4a7e
3 changed files with 35 additions and 8 deletions

View File

@ -459,6 +459,7 @@ jobs:
- csi-sanity-synology-dsm6 - csi-sanity-synology-dsm6
- csi-sanity-synology-dsm7 - csi-sanity-synology-dsm7
- csi-sanity-truenas-scale-22_02 - csi-sanity-truenas-scale-22_02
- csi-sanity-truenas-scale-22_12
- 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
@ -498,6 +499,7 @@ jobs:
- csi-sanity-synology-dsm6 - csi-sanity-synology-dsm6
- csi-sanity-synology-dsm7 - csi-sanity-synology-dsm7
- csi-sanity-truenas-scale-22_02 - csi-sanity-truenas-scale-22_02
- csi-sanity-truenas-scale-22_12
- 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

View File

@ -1,6 +1,7 @@
const _ = require("lodash"); const _ = require("lodash");
const axios = require("axios"); const axios = require("axios");
const crypto = require("crypto"); const crypto = require("crypto");
const dns = require("dns");
function sleep(ms) { function sleep(ms) {
return new Promise((resolve) => { return new Promise((resolve) => {
@ -261,6 +262,18 @@ async function retry(retries, retriesDelay, code, options = {}) {
} while (true); } while (true);
} }
async function hostname_lookup(hostname) {
return new Promise((resolve, reject) => {
dns.lookup(hostname, function (err, result) {
if (err) {
return reject(err);
}
return resolve(result);
});
});
}
module.exports.sleep = sleep; module.exports.sleep = sleep;
module.exports.md5 = md5; module.exports.md5 = md5;
module.exports.crc32 = crc32; module.exports.crc32 = crc32;
@ -277,3 +290,4 @@ module.exports.default_supported_file_filesystems =
default_supported_file_filesystems; default_supported_file_filesystems;
module.exports.retry = retry; module.exports.retry = retry;
module.exports.trimchar = trimchar; module.exports.trimchar = trimchar;
module.exports.hostname_lookup = hostname_lookup;

View File

@ -1,7 +1,6 @@
const cp = require("child_process"); const cp = require("child_process");
const { trimchar } = require("./general"); const { hostname_lookup, trimchar } = require("./general");
const URI = require("uri-js"); const URI = require("uri-js");
const { deleteItems } = require("@kubernetes/client-node");
const DEFAULT_TIMEOUT = process.env.NVMEOF_DEFAULT_TIMEOUT || 30000; const DEFAULT_TIMEOUT = process.env.NVMEOF_DEFAULT_TIMEOUT || 30000;
@ -65,7 +64,7 @@ class NVMEoF {
*/ */
async discover(transport, args = []) { async discover(transport, args = []) {
const nvmeof = this; const nvmeof = this;
transport = nvmeof.parseTransport(transport); transport = await nvmeof.parseTransport(transport);
let transport_args = []; let transport_args = [];
if (transport.type) { if (transport.type) {
@ -90,7 +89,7 @@ class NVMEoF {
*/ */
async connectByNQNTransport(nqn, transport, args = []) { async connectByNQNTransport(nqn, transport, args = []) {
const nvmeof = this; const nvmeof = this;
transport = nvmeof.parseTransport(transport); transport = await nvmeof.parseTransport(transport);
let transport_args = []; let transport_args = [];
if (transport.type) { if (transport.type) {
@ -150,7 +149,7 @@ class NVMEoF {
await nvmeof.exec(nvmeof.options.paths.nvme, args); await nvmeof.exec(nvmeof.options.paths.nvme, args);
} }
parseTransport(transport) { async parseTransport(transport) {
if (typeof transport === "object") { if (typeof transport === "object") {
return transport; return transport;
} }
@ -176,6 +175,18 @@ class NVMEoF {
address = trimchar(address, "["); address = trimchar(address, "[");
address = trimchar(address, "]"); address = trimchar(address, "]");
break; break;
case "tcp":
/**
* kernel stores value as ip, so if address passed as hostname then
* translate to ip address
*
* TODO: this could be brittle
*/
let lookup = await hostname_lookup(address);
if (lookup) {
address = lookup;
}
break;
} }
switch (type) { switch (type) {
@ -206,7 +217,7 @@ class NVMEoF {
async namespaceDevicePathByTransportNQNNamespace(transport, nqn, namespace) { async namespaceDevicePathByTransportNQNNamespace(transport, nqn, namespace) {
const nvmeof = this; const nvmeof = this;
transport = nvmeof.parseTransport(transport); transport = await nvmeof.parseTransport(transport);
let nativeMultipathEnabled = await nvmeof.nativeMultipathEnabled(); let nativeMultipathEnabled = await nvmeof.nativeMultipathEnabled();
if (nativeMultipathEnabled) { if (nativeMultipathEnabled) {
let subsystem = await nvmeof.getSubsystemByNQN(nqn); let subsystem = await nvmeof.getSubsystemByNQN(nqn);
@ -235,7 +246,7 @@ class NVMEoF {
async controllerDevicePathByTransportNQN(transport, nqn) { async controllerDevicePathByTransportNQN(transport, nqn) {
const nvmeof = this; const nvmeof = this;
transport = nvmeof.parseTransport(transport); transport = await nvmeof.parseTransport(transport);
let controller = await nvmeof.getControllerByTransportNQN(transport, nqn); let controller = await nvmeof.getControllerByTransportNQN(transport, nqn);
if (controller) { if (controller) {
return `/dev/${controller.Controller}`; return `/dev/${controller.Controller}`;
@ -258,7 +269,7 @@ class NVMEoF {
async getControllerByTransportNQN(transport, nqn) { async getControllerByTransportNQN(transport, nqn) {
const nvmeof = this; const nvmeof = this;
transport = nvmeof.parseTransport(transport); transport = await nvmeof.parseTransport(transport);
let subsystem = await nvmeof.getSubsystemByNQN(nqn); let subsystem = await nvmeof.getSubsystemByNQN(nqn);
if (subsystem) { if (subsystem) {
for (let controller of subsystem.Controllers) { for (let controller of subsystem.Controllers) {