diff options
author | Tim Smith <tsmith84@gmail.com> | 2021-02-08 12:36:52 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2021-04-21 19:26:37 -0700 |
commit | 229ec68b6ebe7c8b4d5302c7a2821c260accb221 (patch) | |
tree | e08b37184b7fd7cccde77d13a8531723e8a99d67 | |
parent | 0f311cb9dffd63929ec99c254f682272236d98e2 (diff) | |
download | chef-old_policyfiles.tar.gz |
Remove legacy Policyfiles compatibility mode for Server < 12.1old_policyfiles
Require Chef Infra Server 12.1+ to use Policyfiles. As Lamont put it this was prototype support code that was most likely unused and is useless to continue to cart around.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | chef-config/lib/chef-config/config.rb | 20 | ||||
-rw-r--r-- | lib/chef/policy_builder/dynamic.rb | 8 | ||||
-rw-r--r-- | lib/chef/policy_builder/policyfile.rb | 33 | ||||
-rw-r--r-- | spec/unit/policy_builder/dynamic_spec.rb | 13 | ||||
-rw-r--r-- | spec/unit/policy_builder/policyfile_spec.rb | 161 |
5 files changed, 22 insertions, 213 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index 2f261b45a7..df0d946028 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -612,26 +612,6 @@ module ChefConfig default :named_run_list, nil - # Policyfiles can be used in a native mode (default) or compatibility mode. - # Native mode requires Chef Server 12.1 (it can be enabled via feature flag - # on some prior versions). In native mode, policies and associated - # cookbooks are accessed via feature-specific APIs. In compat mode, - # policies are stored as data bags and cookbooks are stored at the - # cookbooks/ endpoint. Compatibility mode can be dangerous on existing Chef - # Servers; it's recommended to upgrade your Chef Server rather than use - # compatibility mode. Compatibility mode remains available so you can use - # policyfiles with servers that don't yet support the native endpoints. - default :policy_document_native_api, true - - # When policyfiles are used in compatibility mode, `policy_name` and - # `policy_group` are instead specified using a combined configuration - # setting, `deployment_group`. For example, if policy_name should be - # "webserver" and policy_group should be "staging", then `deployment_group` - # should be set to "webserver-staging", which is the name of the data bag - # item that the policy will be stored as. NOTE: this setting only has an - # effect if `policy_document_native_api` is set to `false`. - default :deployment_group, nil - # Set these to enable SSL authentication / mutual-authentication # with the server diff --git a/lib/chef/policy_builder/dynamic.rb b/lib/chef/policy_builder/dynamic.rb index 3d9d4c0b7d..cc6465ea28 100644 --- a/lib/chef/policy_builder/dynamic.rb +++ b/lib/chef/policy_builder/dynamic.rb @@ -153,8 +153,7 @@ class Chef def select_implementation(node) if policyfile_set_in_config? || policyfile_attribs_in_node_json? || - node_has_policyfile_attrs?(node) || - policyfile_compat_mode_config? + node_has_policyfile_attrs?(node) @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) @@ -178,11 +177,6 @@ class Chef def policyfile_set_in_config? 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/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb index 35282bf915..0f4a2b5070 100644 --- a/lib/chef/policy_builder/policyfile.rb +++ b/lib/chef/policy_builder/policyfile.rb @@ -320,12 +320,8 @@ class Chef # @api private def policyfile_location - if Chef::Config[:policy_document_native_api] - validate_policy_config! - "policy_groups/#{policy_group}/policies/#{policy_name}" - else - "data/policyfiles/#{deployment_group}" - end + validate_policy_config! + "policy_groups/#{policy_group}/policies/#{policy_name}" end # Do some minimal validation of the policyfile we fetched from the @@ -366,11 +362,6 @@ class Chef class ConfigurationError < StandardError; end # @api private - def deployment_group - Chef::Config[:deployment_group] || raise(ConfigurationError, "Setting `deployment_group` is not configured.") - end - - # @api private def validate_policy_config! raise ConfigurationError, "Setting `policy_group` is not configured." unless policy_group @@ -477,15 +468,8 @@ class Chef # @api private # Fetches the CookbookVersion object for the given name and identifier # specified in the lock_data. - # TODO: This only implements Chef 11 compatibility mode, which means that - # cookbooks are fetched by the "dotted_decimal_identifier": a - # representation of a SHA1 in the traditional x.y.z version format. def manifest_for(cookbook_name, lock_data) - if Chef::Config[:policy_document_native_api] - artifact_manifest_for(cookbook_name, lock_data) - else - compat_mode_manifest_for(cookbook_name, lock_data) - end + artifact_manifest_for(cookbook_name, lock_data) end # @api private @@ -541,17 +525,6 @@ class Chef Chef::Config[:named_run_list] end - def compat_mode_manifest_for(cookbook_name, lock_data) - xyz_version = lock_data["dotted_decimal_identifier"] - rel_url = "cookbooks/#{cookbook_name}/#{xyz_version}" - inflate_cbv_object(api_service.get(rel_url)) - rescue Exception => e - message = "Error loading cookbook #{cookbook_name} at version #{xyz_version} from #{rel_url}: #{e.class} - #{e.message}" - err = Chef::Exceptions::CookbookNotFound.new(message) - err.set_backtrace(e.backtrace) - raise err - end - def artifact_manifest_for(cookbook_name, lock_data) identifier = lock_data["identifier"] rel_url = "cookbook_artifacts/#{cookbook_name}/#{identifier}" diff --git a/spec/unit/policy_builder/dynamic_spec.rb b/spec/unit/policy_builder/dynamic_spec.rb index d61dec4bc8..12d650e587 100644 --- a/spec/unit/policy_builder/dynamic_spec.rb +++ b/spec/unit/policy_builder/dynamic_spec.rb @@ -144,19 +144,6 @@ 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" } } diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index 6be0da8f4d..161519d306 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -206,103 +206,9 @@ describe Chef::PolicyBuilder::Policyfile do end before do - Chef::Config[:policy_document_native_api] = false - Chef::Config[:deployment_group] = "example-policy-stage" allow(policy_builder).to receive(:api_service).and_return(api_service) end - describe "when using compatibility mode (policy_document_native_api == false)" do - - before do - Chef::Config[:deployment_group] = "example-policy-stage" - end - - context "when the deployment group cannot be loaded" do - let(:error404) { Net::HTTPClientException.new("404 message", :body) } - - before do - expect(api_service).to receive(:get) - .with("data/policyfiles/example-policy-stage") - .and_raise(error404) - end - - it "raises an error" do - expect { policy_builder.finish_load_node(node) }.to raise_error(err_namespace::ConfigurationError) - end - - end - - context "when the deployment_group is not configured" do - before do - Chef::Config[:deployment_group] = nil - end - - it "errors while loading the node" do - expect { policy_builder.finish_load_node(node) }.to raise_error(err_namespace::ConfigurationError) - end - - end - - context "when deployment_group is correctly configured" do - - let(:policy_relative_url) { "data/policyfiles/example-policy-stage" } - - before do - expect(api_service).to receive(:get).with(policy_relative_url).and_return(parsed_policyfile_json) - end - - it "fetches the policy file from a data bag item" do - expect(policy_builder.policy).to eq(parsed_policyfile_json) - end - - it "extracts the run_list from the policyfile" do - expect(policy_builder.run_list).to eq(policyfile_run_list) - end - - end - end - - context "and policy_document_native_api is configured" do - - before do - Chef::Config[:policy_document_native_api] = true - Chef::Config[:policy_group] = "policy-stage" - Chef::Config[:policy_name] = "example" - end - - context "and policy_name or policy_group are not configured" do - - it "raises a Configuration error for policy_group" do - Chef::Config[:policy_group] = nil - expect { policy_builder.policy }.to raise_error(err_namespace::ConfigurationError) - end - - it "raises a Configuration error for policy_name" do - Chef::Config[:policy_name] = nil - expect { policy_builder.policy }.to raise_error(err_namespace::ConfigurationError) - end - - end - - context "and policy_name and policy_group are configured" do - - let(:policy_relative_url) { "policy_groups/policy-stage/policies/example" } - - before do - expect(api_service).to receive(:get).with(policy_relative_url).and_return(parsed_policyfile_json) - end - - it "fetches the policy file from a data bag item" do - expect(policy_builder.policy).to eq(parsed_policyfile_json) - end - - it "extracts the run_list from the policyfile" do - expect(policy_builder.run_list).to eq(policyfile_run_list) - end - end - - end - describe "building policy from the policyfile" do before do @@ -803,64 +709,33 @@ describe Chef::PolicyBuilder::Policyfile do end end # shared_examples_for "fetching cookbooks" - context "when using compatibility mode (policy_document_native_api == false)" do - let(:cookbook1_url) { "cookbooks/example1/#{example1_xyz_version}" } - let(:cookbook2_url) { "cookbooks/example2/#{example2_xyz_version}" } - - context "when the cookbooks don't exist on the server" do - include_examples "fetching cookbooks when they don't exist" - end - - context "when the cookbooks exist on the server" do - - before do - expect(api_service).to receive(:get).with(cookbook1_url) - .and_return(example1_cookbook_data) - expect(api_service).to receive(:get).with(cookbook2_url) - .and_return(example2_cookbook_data) + before do + Chef::Config[:policy_name] = "example" + Chef::Config[:policy_group] = "policy-stage" + end - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data) - .and_return(example1_cookbook_object) - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data) - .and_return(example2_cookbook_object) - end + let(:cookbook1_url) { "cookbook_artifacts/example1/#{example1_identifier}" } + let(:cookbook2_url) { "cookbook_artifacts/example2/#{example2_identifier}" } - include_examples "fetching cookbooks when they exist" - end + context "when the cookbooks don't exist on the server" do + include_examples "fetching cookbooks when they don't exist" end - context "when using native API mode (policy_document_native_api == true)" do + context "when the cookbooks exist on the server" do before do - Chef::Config[:policy_document_native_api] = true - Chef::Config[:policy_group] = "policy-stage" - Chef::Config[:policy_name] = "example" - end + expect(api_service).to receive(:get).with(cookbook1_url) + .and_return(example1_cookbook_data) + expect(api_service).to receive(:get).with(cookbook2_url) + .and_return(example2_cookbook_data) - let(:cookbook1_url) { "cookbook_artifacts/example1/#{example1_identifier}" } - let(:cookbook2_url) { "cookbook_artifacts/example2/#{example2_identifier}" } - - context "when the cookbooks don't exist on the server" do - include_examples "fetching cookbooks when they don't exist" + expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data) + .and_return(example1_cookbook_object) + expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data) + .and_return(example2_cookbook_object) end - context "when the cookbooks exist on the server" do - - before do - expect(api_service).to receive(:get).with(cookbook1_url) - .and_return(example1_cookbook_data) - expect(api_service).to receive(:get).with(cookbook2_url) - .and_return(example2_cookbook_data) - - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example1_cookbook_data) - .and_return(example1_cookbook_object) - expect(Chef::CookbookVersion).to receive(:from_cb_artifact_data).with(example2_cookbook_data) - .and_return(example2_cookbook_object) - end - - include_examples "fetching cookbooks when they exist" - - end + include_examples "fetching cookbooks when they exist" end |