summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2016-05-09 16:23:55 -0700
committerTim Smith <tsmith84@gmail.com>2016-05-09 16:23:55 -0700
commitbe8c7a92395d45d1ed3ff6748d75da1c43b644e7 (patch)
tree3c1f663afca38298ce1f5576eb79eae42cb7fe2a
parent85bc7ec538dbccb2a85f9b2721dac345dd4800a5 (diff)
downloadohai-be8c7a92395d45d1ed3ff6748d75da1c43b644e7.tar.gz
Set metadata to {} not nil if it doesn't respond
This makes it easier to write recipes without being super defensive in your code
-rw-r--r--lib/ohai/plugins/openstack.rb5
-rw-r--r--spec/unit/plugins/openstack_spec.rb8
2 files changed, 6 insertions, 7 deletions
diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb
index 1654035c..2cbd048b 100644
--- a/lib/ohai/plugins/openstack.rb
+++ b/lib/ohai/plugins/openstack.rb
@@ -49,17 +49,16 @@ Ohai.plugin(:Openstack) do
# grab metadata and return a mash. if we can't connect return nil
def openstack_metadata
+ metadata = Mash.new
if can_metadata_connect?("169.254.169.254", 80)
- metadata = Mash.new
fetch_metadata.each do |k, v|
metadata[k] = v
end
Ohai::Log.debug("Plugin Openstack: Successfully fetched Openstack metadata from the metadata endpoint")
- metadata
else
Ohai::Log.debug("Plugin Openstack: Timed out connecting to Openstack metadata endpoint. Skipping metadata.")
- nil
end
+ metadata
end
collect_data do
diff --git a/spec/unit/plugins/openstack_spec.rb b/spec/unit/plugins/openstack_spec.rb
index fe1292ac..7e11e27e 100644
--- a/spec/unit/plugins/openstack_spec.rb
+++ b/spec/unit/plugins/openstack_spec.rb
@@ -49,8 +49,8 @@ describe "OpenStack Plugin" do
expect(plugin[:openstack][:provider]).to eq("openstack")
end
- it "sets the metadata attribute to nil" do
- expect(plugin[:openstack][:metadata]).to be_nil
+ it "sets the metadata attribute to {}" do
+ expect(plugin[:openstack][:metadata]).to be_empty
end
end
end
@@ -69,8 +69,8 @@ describe "OpenStack Plugin" do
expect(plugin[:openstack][:provider]).to eq("openstack")
end
- it "sets the metadata attribute to nil" do
- expect(plugin[:openstack][:metadata]).to be_nil
+ it "sets the metadata attribute to {}" do
+ expect(plugin[:openstack][:metadata]).to be_empty
end
end