From a27fd8e69117c95adbd742c0c8c17ad19f1f6ebf Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Sat, 6 Mar 2021 19:44:51 -0800 Subject: Add effortless? helper to chef-utils This uses our new effortless detection in Ohai Signed-off-by: Tim Smith --- chef-utils/lib/chef-utils/dsl/introspection.rb | 11 +++++++++++ chef-utils/spec/unit/dsl/introspection_spec.rb | 12 ++++++++++++ 2 files changed, 23 insertions(+) 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 -- cgit v1.2.1