diff options
author | danielsdeleo <dan@chef.io> | 2015-09-15 11:23:06 -0700 |
---|---|---|
committer | danielsdeleo <dan@chef.io> | 2015-09-17 14:29:50 -0700 |
commit | 90075c9d83c2df2916fd1a2d441401e1c7cf5362 (patch) | |
tree | 686f2d1ee887bc3e50e00ea279fa1cd7b4a16ec3 | |
parent | 460a7ec5347891d6615b7f88944cbd76998769b1 (diff) | |
download | chef-90075c9d83c2df2916fd1a2d441401e1c7cf5362.tar.gz |
Detect when user wants policyfile compat mode
-rw-r--r-- | lib/chef/policy_builder/dynamic.rb | 9 | ||||
-rw-r--r-- | spec/unit/policy_builder/dynamic_spec.rb | 13 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lib/chef/policy_builder/dynamic.rb b/lib/chef/policy_builder/dynamic.rb index d2849dd4f1..0f266a25fb 100644 --- a/lib/chef/policy_builder/dynamic.rb +++ b/lib/chef/policy_builder/dynamic.rb @@ -112,7 +112,10 @@ class Chef end def select_implementation(node) - if policyfile_set_in_config? || policyfile_attribs_in_node_json? || node_has_policyfile_attrs?(node) + if policyfile_set_in_config? || + policyfile_attribs_in_node_json? || + node_has_policyfile_attrs?(node) || + policyfile_compat_mode_config? @implementation = Policyfile.new(node_name, ohai_data, json_attribs, override_runlist, events) else @implementation = ExpandNodeObject.new(node_name, ohai_data, json_attribs, override_runlist, events) @@ -137,6 +140,10 @@ class Chef config[:use_policyfile] || config[:policy_name] || config[:policy_group] end + def policyfile_compat_mode_config? + config[:deployment_group] && !config[:policy_document_native_api] + end + end end end diff --git a/spec/unit/policy_builder/dynamic_spec.rb b/spec/unit/policy_builder/dynamic_spec.rb index 105a34390e..aff19f4d11 100644 --- a/spec/unit/policy_builder/dynamic_spec.rb +++ b/spec/unit/policy_builder/dynamic_spec.rb @@ -156,6 +156,19 @@ describe Chef::PolicyBuilder::Dynamic do end + context "and deployment_group and policy_document_native_api are set on Chef::Config" do + + before do + Chef::Config[:deployment_group] = "example-policy-staging" + Chef::Config[:policy_document_native_api] = false + end + + it "uses the Policyfile implementation" do + expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile) + end + + end + context "and policyfile attributes are present in json_attribs" do let(:json_attribs) { {"policy_name" => "example-policy", "policy_group" => "testing"} } |