Skip to content

Commit

Permalink
Detect Dreamhost DreamCompute
Browse files Browse the repository at this point in the history
  • Loading branch information
tas50 committed May 9, 2016
1 parent be8c7a9 commit 4ce91ca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 12 additions & 1 deletion lib/ohai/plugins/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

provides "openstack"
depends "dmi"
depends "etc"

# do we have the openstack dmi data
def openstack_dmi?
Expand All @@ -47,6 +48,16 @@ def openstack_hint?
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
Expand All @@ -65,7 +76,7 @@ def openstack_metadata
# 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")
Expand Down
17 changes: 13 additions & 4 deletions spec/unit/plugins/openstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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

Expand All @@ -55,6 +55,18 @@
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
Expand Down Expand Up @@ -248,9 +260,6 @@ def allow_get_response(url, response_body)
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

0 comments on commit 4ce91ca

Please sign in to comment.