diff options
author | Tim Smith <tsmith@chef.io> | 2020-09-02 14:05:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 14:05:25 -0700 |
commit | 9af89458b127a661a14605ca9f16bab17a748f9e (patch) | |
tree | db49aba1e1a8507dbeb4827d9df321b05070e22c | |
parent | 39d0d96a129b710f6a4fae466d72962bb16ee185 (diff) | |
parent | 147f7bf6e092e8485f184dd3796cef20c0092481 (diff) | |
download | chef-9af89458b127a661a14605ca9f16bab17a748f9e.tar.gz |
Merge pull request #10377 from chef/knife_ssh_freeze
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/chef/knife/ssh.rb | 17 | ||||
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 4 |
2 files changed, 18 insertions, 3 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 6a8e10267d..d20052b736 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -362,11 +362,21 @@ class Chef subsession ||= session command = fixup_sudo(command) command.force_encoding("binary") if command.respond_to?(:force_encoding) + begin + open_session(subsession, command) + rescue => e + open_session(subsession, command, true) + end + end + + def open_session(subsession, command, pty = false) + stderr = "" + exit_status = 0 subsession.open_channel do |chan| if config[:on_error] && exit_status != 0 chan.close else - chan.request_pty + chan.request_pty if pty chan.exec command do |ch, success| raise ArgumentError, "Cannot execute #{command}" unless success @@ -377,6 +387,11 @@ class Chef ichannel.send_data("#{get_password}\n") end end + + ch.on_extended_data do |_, _type, data| + stderr += data + end + ch.on_request "exit-status" do |ichannel, data| exit_status = [exit_status, data.read_long].max end diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index 470868d479..0ac34f10e2 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -279,10 +279,10 @@ describe Chef::Knife::Ssh do end describe "#ssh_command" do - let(:execution_channel) { double(:execution_channel, on_data: nil) } + let(:execution_channel) { double(:execution_channel, on_data: nil, on_extended_data: nil) } let(:session_channel) { double(:session_channel, request_pty: nil) } - let(:execution_channel2) { double(:execution_channel, on_data: nil) } + let(:execution_channel2) { double(:execution_channel, on_data: nil, on_extended_data: nil) } let(:session_channel2) { double(:session_channel, request_pty: nil) } let(:session) { double(:session, loop: nil) } |