summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-09-07 22:05:52 -0700
committerTim Smith <tsmith@chef.io>2017-09-07 22:05:52 -0700
commit78af77bfa160b623f63717d555c07bc8afa2b6da (patch)
tree42b538a77c434fdb1ba7cc1ae72e38c91fbd9022
parent00bfd9fd3a2623464cfc899eb57cb618c087cb8e (diff)
downloadohai-78af77bfa160b623f63717d555c07bc8afa2b6da.tar.gz
Return nils on error instead of an empty hash
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/mixin/azure_metadata.rb4
-rw-r--r--lib/ohai/plugins/azure.rb1
-rw-r--r--spec/unit/mixin/azure_metadata_spec.rb4
3 files changed, 5 insertions, 4 deletions
diff --git a/lib/ohai/mixin/azure_metadata.rb b/lib/ohai/mixin/azure_metadata.rb
index 8c62bb49..9a3765a9 100644
--- a/lib/ohai/mixin/azure_metadata.rb
+++ b/lib/ohai/mixin/azure_metadata.rb
@@ -41,11 +41,11 @@ module Ohai
parser.parse(data)
rescue FFI_Yajl::ParseError
Ohai::Log.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
- {}
+ nil
end
else
Ohai::Log.warn("Mixin AzureMetadata: Received resonse code #{response.code} requesting metadata")
- {}
+ nil
end
end
end
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index 671b4428..908ea575 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -92,6 +92,7 @@ Ohai.plugin(:Azure) do
return nil unless can_socket_connect?(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80)
endpoint_data = fetch_metadata
+ return nil if endpoint_data.nil?
metadata = initialize_metadata_mash
# blindly add everything in compute to our data structure
diff --git a/spec/unit/mixin/azure_metadata_spec.rb b/spec/unit/mixin/azure_metadata_spec.rb
index 96c7ecfb..e7414120 100644
--- a/spec/unit/mixin/azure_metadata_spec.rb
+++ b/spec/unit/mixin/azure_metadata_spec.rb
@@ -43,7 +43,7 @@ describe Ohai::Mixin::AzureMetadata do
expect(Ohai::Log).to receive(:warn)
vals = mixin.fetch_metadata
- expect(vals).to eq({})
+ expect(vals).to eq(nil)
end
it "returns an empty hash given invalid JSON response" do
@@ -52,7 +52,7 @@ describe Ohai::Mixin::AzureMetadata do
expect(Ohai::Log).to receive(:warn)
vals = mixin.fetch_metadata
- expect(vals).to eq({})
+ expect(vals).to eq(nil)
end
it "returns a populated hash given valid JSON response" do