diff options
-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 |