summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalim Alam <salam@chef.io>2016-03-29 16:27:33 -0700
committerSalim Alam <salam@chef.io>2016-03-29 16:27:33 -0700
commite82138ddf51e6f45fc3d215866ccc48845b6e0c3 (patch)
treea188628cba1654663d5fc2558e8b43e0eb186158
parentfb2c03d2c5509b7781f32278a872f39fd7f426b1 (diff)
downloadchef-e82138ddf51e6f45fc3d215866ccc48845b6e0c3.tar.gz
Add option to set ssh timeoutsalam/timeout
-rw-r--r--lib/chef/knife/ssh.rb9
-rw-r--r--spec/unit/knife/ssh_spec.rb17
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index 4ccc300036..a3ed8eb3d0 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -80,6 +80,12 @@ class Chef
:description => "The ssh port",
:proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key.strip }
+ option :ssh_timeout,
+ :short => "-t SECONDS",
+ :long => "--ssh-timeout SECONDS",
+ :description => "The ssh connection timeout",
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_timeout] = key.strip }
+
option :ssh_gateway,
:short => "-G GATEWAY",
:long => "--ssh-gateway GATEWAY",
@@ -258,6 +264,9 @@ class Chef
# Handle port overrides for the main connection.
session_opts[:port] = Chef::Config[:knife][:ssh_port] if Chef::Config[:knife][:ssh_port]
session_opts[:port] = config[:ssh_port] if config[:ssh_port]
+ # Handle connection timeout
+ session_opts[:timeout] = Chef::Config[:knife][:ssh_timeout] if Chef::Config[:knife][:ssh_timeout]
+ session_opts[:timeout] = config[:ssh_timeout] if config[:ssh_timeout]
# Create the hostspec.
hostspec = session_opts[:user] ? "#{session_opts.delete(:user)}@#{host}" : host
# Connect a new session on the multi.
diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb
index 3a8728515d..65cc5a97b4 100644
--- a/spec/unit/knife/ssh_spec.rb
+++ b/spec/unit/knife/ssh_spec.rb
@@ -203,6 +203,23 @@ describe Chef::Knife::Ssh do
expect(@knife.session.servers[0].port).to eq(123)
end
+ it "uses the timeout from Chef Config" do
+ Chef::Config[:knife][:ssh_timeout] = 5
+ @knife.session_from_list([["the.b.org", nil]])
+ expect(@knife.session.servers[0].options[:timeout]).to eq(5)
+ end
+
+ it "uses the timeout from knife config" do
+ @knife.config[:ssh_timeout] = 6
+ @knife.session_from_list([["the.b.org", nil]])
+ expect(@knife.session.servers[0].options[:timeout]).to eq(6)
+ end
+
+ it "defaults to no timeout" do
+ @knife.session_from_list([["the.b.org", nil]])
+ expect(@knife.session.servers[0].options[:timeout]).to eq(nil)
+ end
+
it "uses the user from an ssh config file" do
@knife.session_from_list([["the.b.org", 123]])
expect(@knife.session.servers[0].user).to eq("locutus")