diff options
author | Thom May <thom@clearairturbulence.org> | 2015-04-08 10:51:30 +0100 |
---|---|---|
committer | Thom May <thom@clearairturbulence.org> | 2015-04-08 10:51:30 +0100 |
commit | 648c9f91d4a0ccbcf661a5ee4d3ec67d8538a5f3 (patch) | |
tree | d024e7acbc8a90e35565009f5de7dc7b51c5d125 | |
parent | 361ba778a36b9da6e29ece85c124babcbfaabdd8 (diff) | |
parent | 32f787fe9aa273c6705f49dfd591bcb09891c277 (diff) | |
download | chef-648c9f91d4a0ccbcf661a5ee4d3ec67d8538a5f3.tar.gz |
Merge pull request #3131 from evertrue/evertrue/eherot/add_empty_check_for_ssh_hostname
For knife ssh: Do not try to use item[:cloud][:public_hostname] for the hostname if it is empty
-rw-r--r-- | lib/chef/knife/ssh.rb | 4 | ||||
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index 50fedd0e49..656baf5e8f 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -175,7 +175,9 @@ class Chef if config[:attribute_from_cli] Chef::Log.debug("Using node attribute '#{config[:attribute_from_cli]}' from the command line as the ssh target") host = extract_nested_value(item, config[:attribute_from_cli]) - elsif item[:cloud] && item[:cloud][:public_hostname] + elsif item[:cloud] && + item[:cloud][:public_hostname] && + !item[:cloud][:public_hostname].empty? Chef::Log.debug("Using node attribute 'cloud[:public_hostname]' automatically as the ssh target") host = item[:cloud][:public_hostname] else diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index 501b02c933..a838a21edc 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -96,6 +96,24 @@ describe Chef::Knife::Ssh do should_return_specified_attributes end + context "when cloud hostnames are available but empty" do + before do + @node_foo.automatic_attrs[:cloud][:public_hostname] = '' + @node_bar.automatic_attrs[:cloud][:public_hostname] = '' + end + + it "returns an array of fqdns" do + configure_query([@node_foo, @node_bar]) + expect(@knife).to receive(:session_from_list).with([ + ['foo.example.org', nil], + ['bar.example.org', nil] + ]) + @knife.configure_session + end + + should_return_specified_attributes + end + it "should raise an error if no host are found" do configure_query([ ]) expect(@knife.ui).to receive(:fatal) |