summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsawanoboly <sawanoboriyu@higanworks.com>2017-04-23 13:22:55 +0900
committerBryan McLellan <btm@loftninjas.org>2017-07-25 14:30:55 -0400
commit93fe1aca2beff64b30910daa2aac615bc623d259 (patch)
tree5aa01c98e777bcb6b91d4ada7be8543c83c3002c
parent06da66921afc15816b72491311de2bf2ff2bf9d1 (diff)
downloadchef-93fe1aca2beff64b30910daa2aac615bc623d259.tar.gz
use ServerAliveInterval option if exists in ssh_config.
Signed-off-by: SAWANOBORI Yukihiko <sawanoboriyu@higanworks.com> use keepalive settings if exists in ssh_config. write spec to check whether it has been keepalive option was loaded from ssh_config.
-rw-r--r--lib/chef/knife/ssh.rb4
-rw-r--r--spec/unit/knife/ssh_spec.rb8
2 files changed, 11 insertions, 1 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb
index 380a60fdd6..ae14ce9954 100644
--- a/lib/chef/knife/ssh.rb
+++ b/lib/chef/knife/ssh.rb
@@ -273,6 +273,10 @@ class Chef
opts[:paranoid] = false
opts[:user_known_hosts_file] = "/dev/null"
end
+ if ssh_config[:keepalive]
+ opts[:keepalive] = true
+ opts[:keepalive_interval] = ssh_config[:keepalive_interval]
+ end
end
end
diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb
index 6141a8a6df..e15ca8a7f0 100644
--- a/spec/unit/knife/ssh_spec.rb
+++ b/spec/unit/knife/ssh_spec.rb
@@ -187,7 +187,7 @@ describe Chef::Knife::Ssh do
describe "#session_from_list" do
before :each do
@knife.instance_variable_set(:@longest, 0)
- ssh_config = { :timeout => 50, :user => "locutus", :port => 23 }
+ ssh_config = { :timeout => 50, :user => "locutus", :port => 23, :keepalive => true, :keepalive_interval => 60 }
allow(Net::SSH).to receive(:configuration_for).with("the.b.org", true).and_return(ssh_config)
end
@@ -223,6 +223,12 @@ describe Chef::Knife::Ssh do
@knife.session_from_list([["the.b.org", 123]])
expect(@knife.session.servers[0].user).to eq("locutus")
end
+
+ it "uses keepalive settings from an ssh config file" do
+ @knife.session_from_list([["the.b.org", 123]])
+ expect(@knife.session.servers[0].options[:keepalive]).to be true
+ expect(@knife.session.servers[0].options[:keepalive_interval]).to eq 60
+ end
end
describe "#ssh_command" do