summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2021-03-06 19:44:51 -0800
committerTim Smith <tsmith84@gmail.com>2021-03-07 09:58:52 -0800
commita27fd8e69117c95adbd742c0c8c17ad19f1f6ebf (patch)
tree5db58ab4c6acb852282fb1e9f45e7cc6cd59ec81
parentd17e4f2ffbb9d152d8f4d30c2abd2d1356dcac56 (diff)
downloadchef-effortless.tar.gz
Add effortless? helper to chef-utilseffortless
This uses our new effortless detection in Ohai Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--chef-utils/lib/chef-utils/dsl/introspection.rb11
-rw-r--r--chef-utils/spec/unit/dsl/introspection_spec.rb12
2 files changed, 23 insertions, 0 deletions
diff --git a/chef-utils/lib/chef-utils/dsl/introspection.rb b/chef-utils/lib/chef-utils/dsl/introspection.rb
index 4edfb8d139..eff75727a9 100644
--- a/chef-utils/lib/chef-utils/dsl/introspection.rb
+++ b/chef-utils/lib/chef-utils/dsl/introspection.rb
@@ -29,6 +29,17 @@ module ChefUtils
module Introspection
include TrainHelpers
+ # Determine if the node is using the Chef Effortless pattern in which the Chef Infra Client is packaged using Chef Habitat
+ #
+ # @param [Chef::Node] node the node to check
+ # @since 17.0
+ #
+ # @return [Boolean]
+ #
+ def effortless?(node = __getnode)
+ !!(node && node.read("chef_packages", "chef", "chef_effortless"))
+ end
+
# Determine if the node is a docker container.
#
# @param [Chef::Node] node the node to check
diff --git a/chef-utils/spec/unit/dsl/introspection_spec.rb b/chef-utils/spec/unit/dsl/introspection_spec.rb
index 2a841dee68..bcbe573ce1 100644
--- a/chef-utils/spec/unit/dsl/introspection_spec.rb
+++ b/chef-utils/spec/unit/dsl/introspection_spec.rb
@@ -32,6 +32,18 @@ RSpec.describe ChefUtils::DSL::Introspection do
let(:test_instance) { IntrospectionTestClass.new(node) }
+ context "#effortless?" do
+ # FIXME: use a real VividMash for these tests instead of stubbing
+ it "is false by default" do
+ expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(nil)
+ expect(ChefUtils.effortless?(node)).to be false
+ end
+ it "is true when ohai reports a effortless" do
+ expect(node).to receive(:read).with("chef_packages", "chef", "chef_effortless").and_return(true)
+ expect(ChefUtils.effortless?(node)).to be true
+ end
+ end
+
context "#docker?" do
# FIXME: use a real VividMash for these tests instead of stubbing
it "is false by default" do