diff options
author | Julian C. Dunn <jdunn@getchef.com> | 2014-08-14 01:28:34 -0400 |
---|---|---|
committer | Julian C. Dunn <jdunn@getchef.com> | 2014-08-14 01:28:34 -0400 |
commit | 7e129dc867bc57dffbd1920cf916a82b9eb258d3 (patch) | |
tree | f98a4f31f7b5381b19f5b6aec1bde342ab8f81f5 | |
parent | 68707017f6d8653516ac6959cf6c1e72bc0aa230 (diff) | |
download | ohai-7e129dc867bc57dffbd1920cf916a82b9eb258d3.tar.gz |
Some systems do not have a FQDN, but instead have just a bare hostname. Users expect
node['hostname'] to be properly set, but the regex for capturing this was incorrect
for this corner case.
-rw-r--r-- | lib/ohai/plugins/hostname.rb | 2 | ||||
-rw-r--r-- | spec/unit/plugins/hostname_spec.rb | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 303880ed..447b255d 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -67,7 +67,7 @@ Ohai.plugin(:Hostname) do def collect_hostname # Hostname is everything before the first dot if machinename - machinename =~ /(.+?)\./ + machinename =~ /(\w+)\.?/ hostname $1 elsif fqdn fqdn =~ /(.+?)\./ diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb index cd778aee..09c9a33e 100644 --- a/spec/unit/plugins/hostname_spec.rb +++ b/spec/unit/plugins/hostname_spec.rb @@ -72,6 +72,18 @@ describe Ohai::System, "hostname plugin" do end end + context "when a system has a bare hostname without a FQDN" do + before(:each) do + @plugin.stub(:collect_os).and_return(:default) + @plugin.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie", "")) + end + + it "should correctly set the [short] hostname" do + @plugin.run + @plugin[:hostname].should == "katie" + end + end + context "hostname --fqdn when it returns empty string" do before(:each) do @plugin.stub(:collect_os).and_return(:linux) |