summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-03-31 13:48:38 -0700
committerGitHub <noreply@github.com>2020-03-31 13:48:38 -0700
commit5313c69f330e52362ba8a8e8e6313936b0d09521 (patch)
tree5b54a744e7beeab0434e2de124b8b3986f4adf6a
parent26424efc37c2f0528ffacc607027ffb75b3b054b (diff)
parent1e23ae8f3f2b7d5228f2920b4e3aca20b4f0d158 (diff)
downloadchef-5313c69f330e52362ba8a8e8e6313936b0d09521.tar.gz
Merge pull request #9553 from chef/fix_cloud
Fix cloud? helper to only report true on cloud instances
-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