summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-31 13:00:30 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-31 13:00:30 -0700
commit1e23ae8f3f2b7d5228f2920b4e3aca20b4f0d158 (patch)
tree5b54a744e7beeab0434e2de124b8b3986f4adf6a
parent26424efc37c2f0528ffacc607027ffb75b3b054b (diff)
downloadchef-1e23ae8f3f2b7d5228f2920b4e3aca20b4f0d158.tar.gz
Fix cloud? helper to only report true on cloud instances
Ohai always returns the cloud key so checking for the key isn't valid for cloud. We need to make sure it's not nil instead. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--chef-utils/lib/chef-utils/dsl/cloud.rb3
-rw-r--r--chef-utils/spec/unit/dsl/cloud_spec.rb6
2 files changed, 8 insertions, 1 deletions
diff --git a/chef-utils/lib/chef-utils/dsl/cloud.rb b/chef-utils/lib/chef-utils/dsl/cloud.rb
index 734c7412aa..4b55fcdc29 100644
--- a/chef-utils/lib/chef-utils/dsl/cloud.rb
+++ b/chef-utils/lib/chef-utils/dsl/cloud.rb
@@ -30,7 +30,8 @@ module ChefUtils
# @return [Boolean]
#
def cloud?(node = __getnode)
- node.key?("cloud")
+ # cloud is always present, but nil if not on a cloud
+ !node["cloud"].nil?
end
# Return true if the current current node is in EC2.
diff --git a/chef-utils/spec/unit/dsl/cloud_spec.rb b/chef-utils/spec/unit/dsl/cloud_spec.rb
index ebf24c7818..8fc6c18528 100644
--- a/chef-utils/spec/unit/dsl/cloud_spec.rb
+++ b/chef-utils/spec/unit/dsl/cloud_spec.rb
@@ -79,4 +79,10 @@ RSpec.describe ChefUtils::DSL::Cloud do
context "on softlayer" do
cloud_reports_true_for(:cloud?, :softlayer?, node: { "softlayer" => {}, "cloud" => {} })
end
+
+ context "on virtualbox" do
+ it "does not return true for cloud?" do
+ expect(described_class.cloud?({ "virtualbox" => {}, "cloud" => nil })).to be false
+ end
+ end
end