diff options
author | Tim Smith <tsmith@chef.io> | 2021-03-09 11:27:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 11:27:19 -0800 |
commit | 05932221d4a8b4be6be4c3e7abc0c4f5ea9e5d9b (patch) | |
tree | 5db58ab4c6acb852282fb1e9f45e7cc6cd59ec81 | |
parent | d17e4f2ffbb9d152d8f4d30c2abd2d1356dcac56 (diff) | |
parent | a27fd8e69117c95adbd742c0c8c17ad19f1f6ebf (diff) | |
download | chef-05932221d4a8b4be6be4c3e7abc0c4f5ea9e5d9b.tar.gz |
Merge pull request #11150 from chef/effortless
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | chef-utils/lib/chef-utils/dsl/introspection.rb | 11 | ||||
-rw-r--r-- | chef-utils/spec/unit/dsl/introspection_spec.rb | 12 |
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 |