diff options
author | Bryan McLellan <btm@chef.io> | 2015-03-23 15:21:57 -0400 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-03-23 15:24:06 -0400 |
commit | efc8b5d5d4be88f1e21b113bca64dd8bcb38c6a8 (patch) | |
tree | 7c6cf4e5c5b687194b66f84ceb61cd0a582eee45 | |
parent | be2d46f113d314e142315248d98e65a73d7ed467 (diff) | |
download | ohai-btm/revert-265-solaris.tar.gz |
Revert the Solaris portion of #265 to fix #420 temporarilybtm/revert-265-solaris
Fixes #420, for now.
-rw-r--r-- | lib/ohai/plugins/hostname.rb | 16 | ||||
-rw-r--r-- | spec/unit/plugins/solaris2/hostname_spec.rb | 6 |
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 447b255d..72e42144 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -138,9 +138,23 @@ Ohai.plugin(:Hostname) do end collect_data(:solaris2) do + require 'socket' + machinename from_cmd("hostname") hostname from_cmd("hostname") - fqdn resolve_fqdn + fqdn_lookup = Socket.getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first[2] + if fqdn_lookup.split('.').length > 1 + # we recieved an fqdn + fqdn fqdn_lookup + else + # default to assembling one + so = shell_out("hostname") + h = so.stdout.split($/)[0] + so = shell_out("domainname") + d = so.stdout.split($/)[0] + + fqdn("#{h}.#{d}") + end domain collect_domain end diff --git a/spec/unit/plugins/solaris2/hostname_spec.rb b/spec/unit/plugins/solaris2/hostname_spec.rb index 00c2936c..183aa1b5 100644 --- a/spec/unit/plugins/solaris2/hostname_spec.rb +++ b/spec/unit/plugins/solaris2/hostname_spec.rb @@ -22,14 +22,14 @@ describe Ohai::System, "Solaris2.X hostname plugin" do before(:each) do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:solaris2) - allow(@plugin).to receive(:resolve_fqdn).and_return("kitteh.inurfridge.eatinurfoodz") allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "kitteh\n", "")) -# Socket.stub(:getaddrinfo).and_return( [["AF_INET", 0, "kitteh.inurfridge.eatinurfoodz", "10.1.2.3", 2, 0, 0]] ); + allow(Socket).to receive(:getaddrinfo).and_return( [["AF_INET", 0, "kitteh.inurfridge.eatinurfoodz", "10.1.2.3", 2, 0, 0]] ); end it_should_check_from("solaris2::hostname", "hostname", "hostname", "kitteh") - it "should get the fqdn value from #resolve_fqdn" do + it "should get the fqdn value from socket getaddrinfo" do + expect(Socket).to receive(:getaddrinfo) @plugin.run expect(@plugin["fqdn"]).to eq("kitteh.inurfridge.eatinurfoodz") end |