summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2013-12-04 14:37:26 -0800
committerBryan McLellan <btm@opscode.com>2013-12-04 14:37:26 -0800
commite5434f52f7ba9a91491ccedec8165e494de2aa4f (patch)
treef741c7b2e40bda3ea131130e07ae05cc5ddea7c3
parent9ff75eb3acc1c19e73e5cca6cfa962dafd7398e5 (diff)
downloadohai-e5434f52f7ba9a91491ccedec8165e494de2aa4f.tar.gz
OHAI-537: Require the os plugin in the hostname plugin
The hostname plugin uses the os plugin, so it needs to be loaded first. In a normal run it happens to be loaded but if you're only running the hostname plugin it will fail without the os plugin.
-rw-r--r--lib/ohai/plugins/hostname.rb3
-rw-r--r--spec/unit/plugins/hostname_spec.rb12
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb
index 119e3c29..34c9a155 100644
--- a/lib/ohai/plugins/hostname.rb
+++ b/lib/ohai/plugins/hostname.rb
@@ -18,10 +18,11 @@
provides "fqdn", "domain"
+require_plugin "os"
require_plugin "#{os}::hostname"
# Domain is everything after the first dot
if fqdn
fqdn =~ /.+?\.(.*)/
domain $1
-end \ No newline at end of file
+end
diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb
index 1ac8dc53..fb427535 100644
--- a/spec/unit/plugins/hostname_spec.rb
+++ b/spec/unit/plugins/hostname_spec.rb
@@ -35,5 +35,15 @@ describe Ohai::System, "hostname plugin" do
@ohai._require_plugin("hostname")
@ohai.domain.should == nil
end
-
+
+ it "should require the os plugin" do
+ @ohai.should_receive(:require_plugin).with("os").and_return(true)
+ @ohai._require_plugin("hostname")
+ end
+
+ it "should load a platform specific hostname plugin" do
+ @ohai[:os] = "linux"
+ @ohai.should_receive(:require_plugin).with("linux::hostname").and_return(true)
+ @ohai._require_plugin("hostname")
+ end
end