diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-05-09 16:49:26 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-05-09 17:20:57 -0700 |
commit | b18d70fc9011eb4efe83da1ccea4cd1e300df3a3 (patch) | |
tree | 09ec4ea33d90aaa58b2f9d46cf78947d479da06d | |
parent | be8c7a92395d45d1ed3ff6748d75da1c43b644e7 (diff) | |
download | ohai-b18d70fc9011eb4efe83da1ccea4cd1e300df3a3.tar.gz |
Detect Dreamhost DreamCompute
-rw-r--r-- | lib/ohai/plugins/openstack.rb | 13 | ||||
-rw-r--r-- | spec/unit/plugins/openstack_spec.rb | 17 |
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb index 2cbd048b..06563700 100644 --- a/lib/ohai/plugins/openstack.rb +++ b/lib/ohai/plugins/openstack.rb @@ -23,6 +23,7 @@ Ohai.plugin(:Openstack) do provides "openstack" depends "dmi" + depends "etc" # do we have the openstack dmi data def openstack_dmi? @@ -47,6 +48,16 @@ Ohai.plugin(:Openstack) do end end + # dreamhost systems hae the dhc-user on them + def openstack_provider + begin + return "dreamhost" if etc["passwd"]["dhc-user"] + rescue NoMethodError + # handle etc not existing on non-linux systems + end + return "openstack" + end + # grab metadata and return a mash. if we can't connect return nil def openstack_metadata metadata = Mash.new @@ -65,7 +76,7 @@ Ohai.plugin(:Openstack) do # fetch data if we look like openstack if openstack_hint? || openstack_dmi? openstack Mash.new - openstack[:provider] = "openstack" # for now this is our only provider + openstack[:provider] = openstack_provider openstack[:metadata] = openstack_metadata # fetch metadata or set this to nil else Ohai::Log.debug("Plugin Openstack: Node does not appear to be an Openstack node") diff --git a/spec/unit/plugins/openstack_spec.rb b/spec/unit/plugins/openstack_spec.rb index 7e11e27e..9b8397fb 100644 --- a/spec/unit/plugins/openstack_spec.rb +++ b/spec/unit/plugins/openstack_spec.rb @@ -45,7 +45,7 @@ describe "OpenStack Plugin" do plugin.run end - it "sets openstack provider attribute if the hint is provided" do + it "sets openstack attribute" do expect(plugin[:openstack][:provider]).to eq("openstack") end @@ -55,6 +55,18 @@ describe "OpenStack Plugin" do end end + context "when running on dreamhost" do + it "sets openstack provider attribute to dreamhost" do + plugin["etc"] = { "passwd" => { "dhc-user" => {} } } + allow(plugin).to receive(:can_metadata_connect?). + with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80). + and_return(false) + plugin[:dmi] = { :system => { :all_records => [ { :Manufacturer => "OpenStack Foundation" } ] } } + plugin.run + expect(plugin[:openstack][:provider]).to eq("dreamhost") + end + end + context "when the hint is present" do context "and the metadata service is not available" do before do @@ -248,9 +260,6 @@ EOM it "sets the provider to openstack" do expect(plugin["openstack"]["provider"]).to eq("openstack") end - it "sets the provider to openstack" do - expect(plugin["openstack"]["provider"]).to eq("openstack") - end end end end |