lib/chef_metal/transport/ssh.rb in chef-metal-0.8.1 vs lib/chef_metal/transport/ssh.rb in chef-metal-0.8.2
- old
+ new
@@ -1,8 +1,9 @@
require 'chef_metal/transport'
require 'uri'
require 'socket'
+require 'timeout'
module ChefMetal
class Transport
class SSH < ChefMetal::Transport
def initialize(host, username, ssh_options, options)
@@ -30,11 +31,10 @@
channel.request_pty do |chan, success|
raise "could not get pty" if !success && options[:ssh_pty_enable]
end
end
-
channel.exec("#{options[:prefix]}#{command}") do |ch, success|
raise "could not execute command: #{command.inspect}" unless success
channel.on_data do |ch2, data|
stdout << data
@@ -50,14 +50,16 @@
exitstatus = data.read_long
end
end
end
- channel.wait
+ with_execute_timeout(execute_options) do
+ channel.wait
+ end
Chef::Log.info("Completed #{command} on #{username}@#{host}: exit status #{exitstatus}")
- Chef::Log.debug("Stdout was:\n#{stdout}") if stdout != '' && !options[:stream] && !options[:stream_stdout]
- Chef::Log.info("Stderr was:\n#{stderr}") if stderr != '' && !options[:stream] && !options[:stream_stderr]
+ Chef::Log.debug("Stdout was:\n#{stdout}") if stdout != '' && !options[:stream] && !options[:stream_stdout] && Chef::Config.log_level != :debug
+ Chef::Log.info("Stderr was:\n#{stderr}") if stderr != '' && !options[:stream] && !options[:stream_stderr] && Chef::Config.log_level != :debug
SSHResult.new(command, execute_options, stdout, stderr, exitstatus)
end
def read_file(path)
Chef::Log.debug("Reading file #{path} from #{username}@#{host}")