From 3ab402367804ac05480bae2d5ee7f74aa2a041b5 Mon Sep 17 00:00:00 2001 From: Travis Glenn Hansen Date: Mon, 29 Nov 2021 00:56:19 -0700 Subject: [PATCH] minor targetCli fix to work-around Ubuntu 18:04 bug Signed-off-by: Travis Glenn Hansen --- src/driver/controller-zfs-generic/index.js | 16 +++++++++++++++- src/utils/ssh.js | 21 ++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/driver/controller-zfs-generic/index.js b/src/driver/controller-zfs-generic/index.js index 70a464f..075e20b 100644 --- a/src/driver/controller-zfs-generic/index.js +++ b/src/driver/controller-zfs-generic/index.js @@ -353,7 +353,21 @@ delete ${iscsiName} driver.ctx.logger.verbose("TargetCLI command: " + logCommand); - let response = await sshClient.exec(sshClient.buildCommand(command, args)); + // https://github.com/democratic-csi/democratic-csi/issues/127 + // https://bugs.launchpad.net/ubuntu/+source/python-configshell-fb/+bug/1776761 + // can apply the linked patch with some modifications to overcome the + // KeyErrors or we can simply start a fake tty which does not seem to have + // a detrimental effect, only affects Ubuntu 18.04 and older + let options = { + pty: true, + }; + let response = await sshClient.exec( + sshClient.buildCommand(command, args), + options + ); + if (response.code != 0) { + throw new Error(response.stderr); + } driver.ctx.logger.verbose( "TargetCLI response: " + JSON.stringify(response) ); diff --git a/src/utils/ssh.js b/src/utils/ssh.js index f0148cb..d008090 100644 --- a/src/utils/ssh.js +++ b/src/utils/ssh.js @@ -33,25 +33,28 @@ class SshClient { var conn = new Client(); if (client.options.connection.debug == true) { - client.options.connection.debug = function(msg) { + client.options.connection.debug = function (msg) { client.debug(msg); }; } - conn - .on("error", function(err) { + .on("error", function (err) { client.debug("Client :: error"); reject(err); }) - .on("ready", function() { + .on("ready", function () { client.debug("Client :: ready"); - conn.exec(command, options, function(err, stream) { + //options.pty = true; + //options.env = { + // TERM: "", + //}; + conn.exec(command, options, function (err, stream) { if (err) reject(err); let stderr; let stdout; stream - .on("close", function(code, signal) { + .on("close", function (code, signal) { client.debug( "Stream :: close :: code: " + code + ", signal: " + signal ); @@ -61,7 +64,7 @@ class SshClient { resolve({ stderr, stdout, code, signal }); conn.end(); }) - .on("data", function(data) { + .on("data", function (data) { client.debug("STDOUT: " + data); if (stream_proxy) { stream_proxy.stdout.emit("data", ...arguments); @@ -71,7 +74,7 @@ class SshClient { } stdout = stdout.concat(data); }) - .stderr.on("data", function(data) { + .stderr.on("data", function (data) { client.debug("STDERR: " + data); if (stream_proxy) { stream_proxy.stderr.emit("data", ...arguments); @@ -86,7 +89,7 @@ class SshClient { .connect(client.options.connection); if (stream_proxy) { - stream_proxy.on("kill", signal => { + stream_proxy.on("kill", (signal) => { conn.end(); }); }