chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +21 -25
- data/Gemfile +46 -0
- data/README.md +4 -4
- data/Rakefile +4 -110
- data/bin/chef-service-manager +3 -1
- data/distro/common/html/knife_cookbook_site.html +18 -18
- data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
- data/lib/chef.rb +1 -1
- data/lib/chef/application.rb +1 -1
- data/lib/chef/application/apply.rb +19 -1
- data/lib/chef/application/client.rb +11 -5
- data/lib/chef/application/knife.rb +2 -2
- data/lib/chef/application/solo.rb +1 -1
- data/lib/chef/application/windows_service_manager.rb +19 -12
- data/lib/chef/chef_class.rb +46 -0
- data/lib/chef/chef_fs/config.rb +22 -24
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
- data/lib/chef/chef_fs/file_pattern.rb +4 -15
- data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
- data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
- data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
- data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
- data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
- data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
- data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
- data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
- data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
- data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
- data/lib/chef/chef_fs/knife.rb +35 -7
- data/lib/chef/chef_fs/path_utils.rb +65 -34
- data/lib/chef/client.rb +2 -3
- data/lib/chef/config.rb +34 -2
- data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
- data/lib/chef/cookbook/metadata.rb +25 -3
- data/lib/chef/cookbook/synchronizer.rb +1 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
- data/lib/chef/cookbook_version.rb +3 -3
- data/lib/chef/delayed_evaluator.rb +21 -0
- data/lib/chef/deprecation/mixin/template.rb +1 -2
- data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
- data/lib/chef/deprecation/provider/file.rb +1 -1
- data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
- data/lib/chef/deprecation/provider/remote_file.rb +1 -2
- data/lib/chef/deprecation/provider/template.rb +1 -1
- data/lib/chef/deprecation/warnings.rb +3 -4
- data/lib/chef/dsl/reboot_pending.rb +3 -2
- data/lib/chef/dsl/recipe.rb +26 -7
- data/lib/chef/dsl/resources.rb +2 -2
- data/lib/chef/event_dispatch/base.rb +51 -22
- data/lib/chef/event_dispatch/dispatcher.rb +21 -6
- data/lib/chef/event_dispatch/dsl.rb +64 -0
- data/lib/chef/exceptions.rb +28 -1
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/base.rb +3 -0
- data/lib/chef/formatters/doc.rb +56 -6
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
- data/lib/chef/formatters/minimal.rb +2 -2
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
- data/lib/chef/http/http_request.rb +1 -1
- data/lib/chef/knife.rb +35 -55
- data/lib/chef/knife/bootstrap.rb +41 -0
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
- data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
- data/lib/chef/knife/bootstrap/templates/README.md +3 -4
- data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
- data/lib/chef/knife/cookbook_create.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +6 -6
- data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
- data/lib/chef/knife/core/bootstrap_context.rb +12 -4
- data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
- data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
- data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
- data/lib/chef/knife/core/node_presenter.rb +24 -1
- data/lib/chef/knife/core/object_loader.rb +1 -0
- data/lib/chef/knife/core/subcommand_loader.rb +131 -146
- data/lib/chef/knife/node_run_list_remove.rb +12 -1
- data/lib/chef/knife/null.rb +10 -0
- data/lib/chef/knife/rehash.rb +62 -0
- data/lib/chef/knife/search.rb +3 -3
- data/lib/chef/knife/ssh.rb +52 -30
- data/lib/chef/knife/ssl_check.rb +3 -2
- data/lib/chef/knife/user_edit.rb +1 -2
- data/lib/chef/local_mode.rb +5 -0
- data/lib/chef/log.rb +5 -1
- data/lib/chef/mixin/deprecation.rb +8 -8
- data/lib/chef/mixin/params_validate.rb +362 -135
- data/lib/chef/mixin/template.rb +48 -0
- data/lib/chef/mixin/which.rb +1 -1
- data/lib/chef/mixin/wide_string.rb +72 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
- data/lib/chef/mixin/windows_env_helper.rb +4 -1
- data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
- data/lib/chef/monkey_patches/win32/registry.rb +72 -0
- data/lib/chef/node.rb +116 -3
- data/lib/chef/node_map.rb +2 -2
- data/lib/chef/platform/handler_map.rb +0 -5
- data/lib/chef/platform/provider_mapping.rb +5 -6
- data/lib/chef/platform/query_helpers.rb +46 -4
- data/lib/chef/platform/rebooter.rb +1 -1
- data/lib/chef/platform/service_helpers.rb +30 -32
- data/lib/chef/policy_builder.rb +1 -8
- data/lib/chef/policy_builder/dynamic.rb +186 -0
- data/lib/chef/policy_builder/expand_node_object.rb +30 -15
- data/lib/chef/policy_builder/policyfile.rb +155 -18
- data/lib/chef/property.rb +568 -0
- data/lib/chef/provider.rb +222 -13
- data/lib/chef/provider/batch.rb +8 -0
- data/lib/chef/provider/deploy.rb +5 -7
- data/lib/chef/provider/directory.rb +14 -2
- data/lib/chef/provider/dsc_resource.rb +5 -9
- data/lib/chef/provider/group/pw.rb +1 -1
- data/lib/chef/provider/ifconfig.rb +2 -2
- data/lib/chef/provider/lwrp_base.rb +1 -75
- data/lib/chef/provider/mount.rb +7 -3
- data/lib/chef/provider/package.rb +1 -1
- data/lib/chef/provider/package/dpkg.rb +5 -11
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +2 -2
- data/lib/chef/provider/package/yum.rb +17 -5
- data/lib/chef/provider/powershell_script.rb +59 -23
- data/lib/chef/provider/registry_key.rb +5 -5
- data/lib/chef/provider/remote_directory.rb +190 -102
- data/lib/chef/provider/service.rb +12 -2
- data/lib/chef/provider/service/aix.rb +1 -1
- data/lib/chef/provider/service/debian.rb +3 -5
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/gentoo.rb +3 -3
- data/lib/chef/provider/service/init.rb +3 -3
- data/lib/chef/provider/service/insserv.rb +2 -4
- data/lib/chef/provider/service/invokercd.rb +2 -4
- data/lib/chef/provider/service/macosx.rb +5 -1
- data/lib/chef/provider/service/openbsd.rb +2 -1
- data/lib/chef/provider/service/redhat.rb +52 -16
- data/lib/chef/provider/service/simple.rb +2 -2
- data/lib/chef/provider/service/systemd.rb +3 -5
- data/lib/chef/provider/service/upstart.rb +4 -6
- data/lib/chef/provider/subversion.rb +13 -7
- data/lib/chef/provider/template/content.rb +16 -6
- data/lib/chef/provider/user/solaris.rb +32 -4
- data/lib/chef/provider/windows_script.rb +3 -5
- data/lib/chef/provider_resolver.rb +2 -2
- data/lib/chef/recipe.rb +1 -8
- data/lib/chef/resource.rb +563 -90
- data/lib/chef/resource/action_class.rb +83 -0
- data/lib/chef/resource/chef_gem.rb +3 -3
- data/lib/chef/resource/deploy.rb +8 -2
- data/lib/chef/resource/dsc_script.rb +2 -0
- data/lib/chef/resource/file/verification.rb +7 -1
- data/lib/chef/resource/lwrp_base.rb +1 -7
- data/lib/chef/resource/registry_key.rb +1 -1
- data/lib/chef/resource/service.rb +10 -2
- data/lib/chef/resource/subversion.rb +5 -0
- data/lib/chef/resource/windows_script.rb +6 -2
- data/lib/chef/resource/yum_package.rb +10 -1
- data/lib/chef/resource_resolver.rb +3 -3
- data/lib/chef/run_context.rb +402 -83
- data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
- data/lib/chef/run_lock.rb +30 -21
- data/lib/chef/util/powershell/ps_credential.rb +4 -0
- data/lib/chef/util/windows.rb +0 -32
- data/lib/chef/util/windows/net_group.rb +85 -106
- data/lib/chef/util/windows/net_use.rb +35 -71
- data/lib/chef/util/windows/net_user.rb +0 -1
- data/lib/chef/util/windows/volume.rb +19 -19
- data/lib/chef/version.rb +3 -3
- data/lib/chef/win32/api.rb +1 -0
- data/lib/chef/win32/api/file.rb +20 -0
- data/lib/chef/win32/api/net.rb +163 -43
- data/lib/chef/win32/api/registry.rb +51 -0
- data/lib/chef/win32/api/system.rb +23 -0
- data/lib/chef/win32/api/unicode.rb +0 -43
- data/lib/chef/win32/crypto.rb +2 -1
- data/lib/chef/win32/file.rb +28 -3
- data/lib/chef/win32/mutex.rb +1 -2
- data/lib/chef/win32/net.rb +162 -8
- data/lib/chef/win32/process.rb +13 -0
- data/lib/chef/win32/registry.rb +35 -30
- data/lib/chef/win32/security.rb +1 -1
- data/lib/chef/win32/security/token.rb +1 -1
- data/lib/chef/win32/system.rb +62 -0
- data/lib/chef/win32/unicode.rb +7 -2
- data/lib/chef/win32/version.rb +0 -4
- data/lib/chef/workstation_config_loader.rb +3 -158
- data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
- data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
- data/spec/data/dsc_lcm.pfx +0 -0
- data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
- data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
- data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
- data/spec/functional/knife/ssh_spec.rb +16 -0
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/deploy_revision_spec.rb +1 -1
- data/spec/functional/resource/dsc_resource_spec.rb +2 -0
- data/spec/functional/resource/dsc_script_spec.rb +91 -2
- data/spec/functional/resource/group_spec.rb +67 -44
- data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
- data/spec/functional/resource/windows_service_spec.rb +1 -1
- data/spec/functional/run_lock_spec.rb +368 -189
- data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
- data/spec/functional/win32/service_manager_spec.rb +2 -2
- data/spec/integration/client/client_spec.rb +51 -0
- data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
- data/spec/integration/knife/download_spec.rb +4 -0
- data/spec/integration/knife/list_spec.rb +8 -0
- data/spec/integration/knife/upload_spec.rb +1 -1
- data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
- data/spec/integration/recipes/remote_directory.rb +74 -0
- data/spec/integration/recipes/resource_action_spec.rb +363 -0
- data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
- data/spec/integration/recipes/resource_load_spec.rb +206 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/support/platform_helpers.rb +13 -0
- data/spec/support/shared/context/win32.rb +34 -0
- data/spec/support/shared/functional/win32_service.rb +2 -1
- data/spec/support/shared/functional/windows_script.rb +63 -26
- data/spec/support/shared/unit/mock_shellout.rb +46 -0
- data/spec/support/shared/unit/provider/file.rb +10 -4
- data/spec/unit/application/client_spec.rb +16 -3
- data/spec/unit/application/knife_spec.rb +2 -2
- data/spec/unit/application/solo_spec.rb +4 -3
- data/spec/unit/chef_class_spec.rb +23 -4
- data/spec/unit/chef_fs/path_util_spec.rb +108 -0
- data/spec/unit/client_spec.rb +6 -1
- data/spec/unit/config_spec.rb +31 -0
- data/spec/unit/cookbook/metadata_spec.rb +23 -3
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
- data/spec/unit/deprecation_spec.rb +3 -6
- data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
- data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
- data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
- data/spec/unit/formatters/doc_spec.rb +32 -0
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
- data/spec/unit/json_compat_spec.rb +4 -3
- data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
- data/spec/unit/knife/bootstrap_spec.rb +55 -3
- data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
- data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
- data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
- data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
- data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
- data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
- data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
- data/spec/unit/knife/ssl_check_spec.rb +4 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
- data/spec/unit/mixin/params_validate_spec.rb +4 -2
- data/spec/unit/mixin/template_spec.rb +5 -1
- data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
- data/spec/unit/node_spec.rb +220 -0
- data/spec/unit/platform/query_helpers_spec.rb +146 -3
- data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
- data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
- data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
- data/spec/unit/property/state_spec.rb +506 -0
- data/spec/unit/property/validation_spec.rb +663 -0
- data/spec/unit/property_spec.rb +1094 -0
- data/spec/unit/provider/deploy_spec.rb +5 -5
- data/spec/unit/provider/directory_spec.rb +35 -0
- data/spec/unit/provider/dsc_resource_spec.rb +3 -10
- data/spec/unit/provider/ifconfig_spec.rb +22 -2
- data/spec/unit/provider/mount/aix_spec.rb +2 -1
- data/spec/unit/provider/mount/mount_spec.rb +6 -0
- data/spec/unit/provider/mount/windows_spec.rb +14 -0
- data/spec/unit/provider/mount_spec.rb +12 -1
- data/spec/unit/provider/package/dpkg_spec.rb +8 -1
- data/spec/unit/provider/package/rpm_spec.rb +18 -1
- data/spec/unit/provider/package/rubygems_spec.rb +18 -0
- data/spec/unit/provider/package/yum_spec.rb +97 -24
- data/spec/unit/provider/powershell_script_spec.rb +106 -0
- data/spec/unit/provider/registry_key_spec.rb +12 -0
- data/spec/unit/provider/remote_directory_spec.rb +1 -2
- data/spec/unit/provider/service/aix_service_spec.rb +3 -3
- data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
- data/spec/unit/provider/service/macosx_spec.rb +4 -4
- data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
- data/spec/unit/provider/service/redhat_spec.rb +88 -8
- data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
- data/spec/unit/provider/service/windows_spec.rb +211 -200
- data/spec/unit/provider/subversion_spec.rb +50 -31
- data/spec/unit/provider/template/content_spec.rb +93 -2
- data/spec/unit/provider/user/solaris_spec.rb +66 -9
- data/spec/unit/provider_resolver_spec.rb +707 -650
- data/spec/unit/provider_spec.rb +1 -3
- data/spec/unit/recipe_spec.rb +0 -4
- data/spec/unit/resource/deploy_spec.rb +7 -1
- data/spec/unit/resource/dsc_script_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +33 -5
- data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
- data/spec/unit/resource/service_spec.rb +4 -4
- data/spec/unit/resource/subversion_spec.rb +4 -0
- data/spec/unit/resource/yum_package_spec.rb +10 -1
- data/spec/unit/resource_spec.rb +2 -2
- data/spec/unit/run_context/child_run_context_spec.rb +133 -0
- data/spec/unit/run_context_spec.rb +7 -0
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
- data/spec/unit/win32/registry_spec.rb +394 -0
- data/tasks/external_tests.rb +47 -23
- data/tasks/maintainers.rb +155 -14
- metadata +64 -53
- data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
- data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
- data/spec/unit/provider/powershell_spec.rb +0 -80
- data/spec/unit/registry_helper_spec.rb +0 -376
- data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -0,0 +1,275 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@getchef.com>)
|
3
|
+
# Copyright:: Copyright 2014 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'chef/policy_builder'
|
21
|
+
|
22
|
+
describe Chef::PolicyBuilder::Dynamic do
|
23
|
+
|
24
|
+
let(:node_name) { "joe_node" }
|
25
|
+
let(:ohai_data) { {"platform" => "ubuntu", "platform_version" => "13.04", "fqdn" => "joenode.example.com"} }
|
26
|
+
let(:json_attribs) { {"custom_attr" => "custom_attr_value"} }
|
27
|
+
let(:override_runlist) { nil }
|
28
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
29
|
+
|
30
|
+
let(:err_namespace) { Chef::PolicyBuilder::Policyfile }
|
31
|
+
|
32
|
+
let(:base_node) do
|
33
|
+
node = Chef::Node.new
|
34
|
+
node.name(node_name)
|
35
|
+
node
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:node) { base_node }
|
39
|
+
|
40
|
+
subject(:policy_builder) { Chef::PolicyBuilder::Dynamic.new(node_name, ohai_data, json_attribs, override_runlist, events) }
|
41
|
+
|
42
|
+
describe "loading policy data" do
|
43
|
+
|
44
|
+
describe "delegating PolicyBuilder API to the correct implementation" do
|
45
|
+
|
46
|
+
let(:implementation) { instance_double("Chef::PolicyBuilder::Policyfile") }
|
47
|
+
|
48
|
+
before do
|
49
|
+
allow(policy_builder).to receive(:implementation).and_return(implementation)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Dynamic should load_node, figure out the correct backend, then forward
|
53
|
+
# messages to it after. That behavior is tested below.
|
54
|
+
it "responds to #load_node" do
|
55
|
+
expect(policy_builder).to respond_to(:load_node)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "forwards #original_runlist" do
|
59
|
+
expect(implementation).to receive(:original_runlist)
|
60
|
+
policy_builder.original_runlist
|
61
|
+
end
|
62
|
+
|
63
|
+
it "forwards #run_context" do
|
64
|
+
expect(implementation).to receive(:run_context)
|
65
|
+
policy_builder.run_context
|
66
|
+
end
|
67
|
+
|
68
|
+
it "forwards #run_list_expansion" do
|
69
|
+
expect(implementation).to receive(:run_list_expansion)
|
70
|
+
policy_builder.run_list_expansion
|
71
|
+
end
|
72
|
+
|
73
|
+
it "forwards #build_node to the implementation object" do
|
74
|
+
expect(implementation).to receive(:build_node)
|
75
|
+
policy_builder.build_node
|
76
|
+
end
|
77
|
+
|
78
|
+
it "forwards #setup_run_context to the implementation object" do
|
79
|
+
expect(implementation).to receive(:setup_run_context)
|
80
|
+
policy_builder.setup_run_context
|
81
|
+
|
82
|
+
arg = Object.new
|
83
|
+
|
84
|
+
expect(implementation).to receive(:setup_run_context).with(arg)
|
85
|
+
policy_builder.setup_run_context(arg)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "forwards #expand_run_list to the implementation object" do
|
89
|
+
expect(implementation).to receive(:expand_run_list)
|
90
|
+
policy_builder.expand_run_list
|
91
|
+
end
|
92
|
+
|
93
|
+
it "forwards #sync_cookbooks to the implementation object" do
|
94
|
+
expect(implementation).to receive(:sync_cookbooks)
|
95
|
+
policy_builder.sync_cookbooks
|
96
|
+
end
|
97
|
+
|
98
|
+
it "forwards #temporary_policy? to the implementation object" do
|
99
|
+
expect(implementation).to receive(:temporary_policy?)
|
100
|
+
policy_builder.temporary_policy?
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "selecting a backend implementation" do
|
106
|
+
|
107
|
+
let(:implementation) do
|
108
|
+
policy_builder.select_implementation(node)
|
109
|
+
policy_builder.implementation
|
110
|
+
end
|
111
|
+
|
112
|
+
context "when no policyfile attributes are present on the node" do
|
113
|
+
|
114
|
+
context "and json_attribs are not given" do
|
115
|
+
|
116
|
+
let(:json_attribs) { {} }
|
117
|
+
|
118
|
+
it "uses the ExpandNodeObject implementation" do
|
119
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::ExpandNodeObject)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
context "and no policyfile attributes are present in json_attribs" do
|
125
|
+
|
126
|
+
let(:json_attribs) { {"foo" => "bar"} }
|
127
|
+
|
128
|
+
it "uses the ExpandNodeObject implementation" do
|
129
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::ExpandNodeObject)
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
context "and :use_policyfile is set in Chef::Config" do
|
135
|
+
|
136
|
+
before do
|
137
|
+
Chef::Config[:use_policyfile] = true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "uses the Policyfile implementation" do
|
141
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
context "and policy_name and policy_group are set on Chef::Config" do
|
147
|
+
|
148
|
+
before do
|
149
|
+
Chef::Config[:policy_name] = "example-policy"
|
150
|
+
Chef::Config[:policy_group] = "testing"
|
151
|
+
end
|
152
|
+
|
153
|
+
it "uses the Policyfile implementation" do
|
154
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "and deployment_group and policy_document_native_api are set on Chef::Config" do
|
160
|
+
|
161
|
+
before do
|
162
|
+
Chef::Config[:deployment_group] = "example-policy-staging"
|
163
|
+
Chef::Config[:policy_document_native_api] = false
|
164
|
+
end
|
165
|
+
|
166
|
+
it "uses the Policyfile implementation" do
|
167
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
context "and policyfile attributes are present in json_attribs" do
|
173
|
+
|
174
|
+
let(:json_attribs) { {"policy_name" => "example-policy", "policy_group" => "testing"} }
|
175
|
+
|
176
|
+
it "uses the Policyfile implementation" do
|
177
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
context "when policyfile attributes are present on the node" do
|
185
|
+
|
186
|
+
let(:node) do
|
187
|
+
base_node.policy_name = "example-policy"
|
188
|
+
base_node.policy_group = "staging"
|
189
|
+
base_node
|
190
|
+
end
|
191
|
+
|
192
|
+
it "uses the Policyfile implementation" do
|
193
|
+
expect(implementation).to be_a(Chef::PolicyBuilder::Policyfile)
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "loading a node" do
|
201
|
+
|
202
|
+
let(:implementation) { instance_double("Chef::PolicyBuilder::Policyfile") }
|
203
|
+
|
204
|
+
before do
|
205
|
+
allow(policy_builder).to receive(:implementation).and_return(implementation)
|
206
|
+
end
|
207
|
+
|
208
|
+
context "when not running chef solo" do
|
209
|
+
|
210
|
+
|
211
|
+
context "when successful" do
|
212
|
+
|
213
|
+
before do
|
214
|
+
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
215
|
+
expect(policy_builder).to receive(:select_implementation).with(node)
|
216
|
+
expect(implementation).to receive(:finish_load_node).with(node)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "selects the backend implementation and continues node loading" do
|
220
|
+
policy_builder.load_node
|
221
|
+
end
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
context "when an error occurs finding the node" do
|
226
|
+
|
227
|
+
before do
|
228
|
+
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_raise("oops")
|
229
|
+
end
|
230
|
+
|
231
|
+
it "sends a node_load_failed event and re-raises" do
|
232
|
+
expect(events).to receive(:node_load_failed)
|
233
|
+
expect { policy_builder.load_node }.to raise_error("oops")
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
context "when an error occurs in the implementation's finish_load_node call" do
|
239
|
+
|
240
|
+
before do
|
241
|
+
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
242
|
+
expect(policy_builder).to receive(:select_implementation).with(node)
|
243
|
+
expect(implementation).to receive(:finish_load_node).and_raise("oops")
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
it "sends a node_load_failed event and re-raises" do
|
248
|
+
expect(events).to receive(:node_load_failed)
|
249
|
+
expect { policy_builder.load_node }.to raise_error("oops")
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
context "when running chef solo" do
|
257
|
+
|
258
|
+
before do
|
259
|
+
Chef::Config[:solo] = true
|
260
|
+
expect(Chef::Node).to receive(:build).with(node_name).and_return(node)
|
261
|
+
expect(policy_builder).to receive(:select_implementation).with(node)
|
262
|
+
expect(implementation).to receive(:finish_load_node).with(node)
|
263
|
+
end
|
264
|
+
|
265
|
+
it "selects the backend implementation and continues node loading" do
|
266
|
+
policy_builder.load_node
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
@@ -34,10 +34,18 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
34
34
|
expect(policy_builder).to respond_to(:node)
|
35
35
|
end
|
36
36
|
|
37
|
-
it "implements a load_node method" do
|
37
|
+
it "implements a load_node method for backwards compatibility until Chef 13" do
|
38
38
|
expect(policy_builder).to respond_to(:load_node)
|
39
39
|
end
|
40
40
|
|
41
|
+
it "has removed the deprecated #load_node method", :chef_gte_13_only do
|
42
|
+
expect(policy_builder).to_not respond_to(:load_node)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "implements a finish_load_node method" do
|
46
|
+
expect(policy_builder).to respond_to(:finish_load_node)
|
47
|
+
end
|
48
|
+
|
41
49
|
it "implements a build_node method" do
|
42
50
|
expect(policy_builder).to respond_to(:build_node)
|
43
51
|
end
|
@@ -63,39 +71,13 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
63
71
|
expect(policy_builder).to respond_to(:temporary_policy?)
|
64
72
|
end
|
65
73
|
|
66
|
-
describe "loading the node" do
|
67
|
-
|
68
|
-
context "on chef-solo" do
|
69
|
-
|
70
|
-
before do
|
71
|
-
Chef::Config[:solo] = true
|
72
|
-
end
|
73
|
-
|
74
|
-
it "creates a new in-memory node object with the given name" do
|
75
|
-
policy_builder.load_node
|
76
|
-
expect(policy_builder.node.name).to eq(node_name)
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
context "on chef-client" do
|
82
|
-
|
83
|
-
let(:node) { Chef::Node.new.tap { |n| n.name(node_name) } }
|
84
|
-
|
85
|
-
it "loads or creates a node on the server" do
|
86
|
-
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
87
|
-
policy_builder.load_node
|
88
|
-
expect(policy_builder.node).to eq(node)
|
89
|
-
end
|
74
|
+
describe "finishing loading the node" do
|
90
75
|
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "building the node" do
|
76
|
+
let(:node) { Chef::Node.new.tap { |n| n.name(node_name) } }
|
95
77
|
|
96
|
-
|
97
|
-
|
98
|
-
|
78
|
+
it "stores the node" do
|
79
|
+
policy_builder.finish_load_node(node)
|
80
|
+
expect(policy_builder.node).to eq(node)
|
99
81
|
end
|
100
82
|
|
101
83
|
end
|
@@ -124,7 +106,8 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
124
106
|
|
125
107
|
end
|
126
108
|
|
127
|
-
context "
|
109
|
+
context "deprecated #load_node method" do
|
110
|
+
|
128
111
|
let(:node) do
|
129
112
|
node = Chef::Node.new
|
130
113
|
node.name(node_name)
|
@@ -133,10 +116,29 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
133
116
|
end
|
134
117
|
|
135
118
|
before do
|
119
|
+
Chef::Config[:treat_deprecation_warnings_as_errors] = false
|
136
120
|
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
137
121
|
policy_builder.load_node
|
138
122
|
end
|
139
123
|
|
124
|
+
it "loads the node" do
|
125
|
+
expect(policy_builder.node).to eq(node)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
context "once the node has been loaded" do
|
131
|
+
let(:node) do
|
132
|
+
node = Chef::Node.new
|
133
|
+
node.name(node_name)
|
134
|
+
node.run_list(["recipe[a::default]", "recipe[b::server]"])
|
135
|
+
node
|
136
|
+
end
|
137
|
+
|
138
|
+
before do
|
139
|
+
policy_builder.finish_load_node(node)
|
140
|
+
end
|
141
|
+
|
140
142
|
it "expands the run_list" do
|
141
143
|
expect(policy_builder.expand_run_list).to be_a(Chef::RunList::RunListExpansion)
|
142
144
|
expect(policy_builder.run_list_expansion).to be_a(Chef::RunList::RunListExpansion)
|
@@ -167,8 +169,7 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
167
169
|
|
168
170
|
before do
|
169
171
|
Chef::Config[:environment] = configured_environment
|
170
|
-
|
171
|
-
policy_builder.load_node
|
172
|
+
policy_builder.finish_load_node(node)
|
172
173
|
policy_builder.build_node
|
173
174
|
end
|
174
175
|
|
@@ -302,11 +303,9 @@ describe Chef::PolicyBuilder::ExpandNodeObject do
|
|
302
303
|
let(:cookbook_synchronizer) { double("CookbookSynchronizer") }
|
303
304
|
|
304
305
|
before do
|
305
|
-
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
306
|
-
|
307
306
|
allow(policy_builder).to receive(:api_service).and_return(chef_http)
|
308
307
|
|
309
|
-
policy_builder.
|
308
|
+
policy_builder.finish_load_node(node)
|
310
309
|
policy_builder.build_node
|
311
310
|
|
312
311
|
run_list_expansion = policy_builder.run_list_expansion
|
@@ -76,8 +76,11 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
76
76
|
|
77
77
|
let(:policyfile_run_list) { ["recipe[example1::default]", "recipe[example2::server]"] }
|
78
78
|
|
79
|
-
let(:
|
79
|
+
let(:basic_valid_policy_data) do
|
80
80
|
{
|
81
|
+
"name" => "example-policy",
|
82
|
+
"revision_id" => "123abc",
|
83
|
+
|
81
84
|
"run_list" => policyfile_run_list,
|
82
85
|
|
83
86
|
"cookbook_locks" => {
|
@@ -90,6 +93,8 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
90
93
|
}
|
91
94
|
end
|
92
95
|
|
96
|
+
let(:parsed_policyfile_json) { basic_valid_policy_data }
|
97
|
+
|
93
98
|
let(:err_namespace) { Chef::PolicyBuilder::Policyfile }
|
94
99
|
|
95
100
|
it "configures a Chef HTTP API client" do
|
@@ -181,19 +186,13 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
181
186
|
let(:error404) { Net::HTTPServerException.new("404 message", :body) }
|
182
187
|
|
183
188
|
before do
|
184
|
-
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
185
189
|
expect(http_api).to receive(:get).
|
186
190
|
with("data/policyfiles/example-policy-stage").
|
187
191
|
and_raise(error404)
|
188
192
|
end
|
189
193
|
|
190
194
|
it "raises an error" do
|
191
|
-
expect { policy_builder.
|
192
|
-
end
|
193
|
-
|
194
|
-
it "sends error message to the event system" do
|
195
|
-
expect(events).to receive(:node_load_failed).with(node_name, an_instance_of(err_namespace::ConfigurationError), Chef::Config)
|
196
|
-
expect { policy_builder.load_node }.to raise_error(err_namespace::ConfigurationError)
|
195
|
+
expect { policy_builder.finish_load_node(node) }.to raise_error(err_namespace::ConfigurationError)
|
197
196
|
end
|
198
197
|
|
199
198
|
end
|
@@ -201,20 +200,12 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
201
200
|
context "when the deployment_group is not configured" do
|
202
201
|
before do
|
203
202
|
Chef::Config[:deployment_group] = nil
|
204
|
-
expect(Chef::Node).to receive(:find_or_create).with(node_name).and_return(node)
|
205
203
|
end
|
206
204
|
|
207
205
|
it "errors while loading the node" do
|
208
|
-
expect { policy_builder.
|
206
|
+
expect { policy_builder.finish_load_node(node) }.to raise_error(err_namespace::ConfigurationError)
|
209
207
|
end
|
210
208
|
|
211
|
-
|
212
|
-
it "passes error information to the event system" do
|
213
|
-
# TODO: also make sure something acceptable happens with the error formatters
|
214
|
-
err_class = err_namespace::ConfigurationError
|
215
|
-
expect(events).to receive(:node_load_failed).with(node_name, an_instance_of(err_class), Chef::Config)
|
216
|
-
expect { policy_builder.load_node }.to raise_error(err_class)
|
217
|
-
end
|
218
209
|
end
|
219
210
|
|
220
211
|
context "when deployment_group is correctly configured" do
|
@@ -307,8 +298,7 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
307
298
|
end
|
308
299
|
|
309
300
|
it "implements #expand_run_list in a manner compatible with ExpandNodeObject" do
|
310
|
-
|
311
|
-
policy_builder.load_node
|
301
|
+
policy_builder.finish_load_node(node)
|
312
302
|
expect(policy_builder.expand_run_list).to respond_to(:recipes)
|
313
303
|
expect(policy_builder.expand_run_list.recipes).to eq(["example1::default", "example2::server"])
|
314
304
|
expect(policy_builder.expand_run_list.roles).to eq([])
|
@@ -345,46 +335,261 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
345
335
|
|
346
336
|
describe "building the node object" do
|
347
337
|
|
338
|
+
let(:extra_chef_config) { {} }
|
339
|
+
|
348
340
|
before do
|
349
|
-
|
341
|
+
# must be set before #build_node is called to have the proper effect
|
342
|
+
extra_chef_config.each do |key, value|
|
343
|
+
Chef::Config[key] = value
|
344
|
+
end
|
350
345
|
|
351
|
-
policy_builder.
|
346
|
+
policy_builder.finish_load_node(node)
|
352
347
|
policy_builder.build_node
|
353
348
|
end
|
354
349
|
|
350
|
+
# it sets policy_name and policy_group in the following priority order:
|
351
|
+
# -j JSON > config file > node object
|
352
|
+
|
353
|
+
describe "selecting policy_name and policy_group from the various sources" do
|
354
|
+
|
355
|
+
context "when only set in node JSON" do
|
356
|
+
|
357
|
+
let(:json_attribs) do
|
358
|
+
{
|
359
|
+
"policy_name" => "policy_name_from_node_json",
|
360
|
+
"policy_group" => "policy_group_from_node_json"
|
361
|
+
}
|
362
|
+
end
|
363
|
+
|
364
|
+
it "sets policy_name and policy_group on Chef::Config" do
|
365
|
+
expect(Chef::Config[:policy_name]).to eq("policy_name_from_node_json")
|
366
|
+
expect(Chef::Config[:policy_group]).to eq("policy_group_from_node_json")
|
367
|
+
end
|
368
|
+
|
369
|
+
it "sets policy_name and policy_group on the node object" do
|
370
|
+
expect(node.policy_name).to eq("policy_name_from_node_json")
|
371
|
+
expect(node.policy_group).to eq("policy_group_from_node_json")
|
372
|
+
end
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
context "when only set in Chef::Config" do
|
377
|
+
|
378
|
+
let(:extra_chef_config) do
|
379
|
+
{
|
380
|
+
policy_name: "policy_name_from_config",
|
381
|
+
policy_group: "policy_group_from_config"
|
382
|
+
}
|
383
|
+
end
|
384
|
+
|
385
|
+
it "sets policy_name and policy_group on the node object" do
|
386
|
+
expect(node.policy_name).to eq("policy_name_from_config")
|
387
|
+
expect(node.policy_group).to eq("policy_group_from_config")
|
388
|
+
end
|
389
|
+
|
390
|
+
end
|
391
|
+
|
392
|
+
context "when only set on the node" do
|
393
|
+
|
394
|
+
let(:node) do
|
395
|
+
node = Chef::Node.new
|
396
|
+
node.name(node_name)
|
397
|
+
node.policy_name = "policy_name_from_node"
|
398
|
+
node.policy_group = "policy_group_from_node"
|
399
|
+
node
|
400
|
+
end
|
401
|
+
|
402
|
+
it "sets policy_name and policy_group on Chef::Config" do
|
403
|
+
expect(Chef::Config[:policy_name]).to eq("policy_name_from_node")
|
404
|
+
expect(Chef::Config[:policy_group]).to eq("policy_group_from_node")
|
405
|
+
end
|
406
|
+
|
407
|
+
end
|
408
|
+
|
409
|
+
context "when set in Chef::Config and the fetched node" do
|
410
|
+
|
411
|
+
let(:node) do
|
412
|
+
node = Chef::Node.new
|
413
|
+
node.name(node_name)
|
414
|
+
node.policy_name = "policy_name_from_node"
|
415
|
+
node.policy_group = "policy_group_from_node"
|
416
|
+
node
|
417
|
+
end
|
418
|
+
|
419
|
+
let(:extra_chef_config) do
|
420
|
+
{
|
421
|
+
policy_name: "policy_name_from_config",
|
422
|
+
policy_group: "policy_group_from_config"
|
423
|
+
}
|
424
|
+
end
|
425
|
+
|
426
|
+
it "prefers the policy_name and policy_group from Chef::Config" do
|
427
|
+
expect(node.policy_name).to eq("policy_name_from_config")
|
428
|
+
expect(node.policy_group).to eq("policy_group_from_config")
|
429
|
+
end
|
430
|
+
|
431
|
+
end
|
432
|
+
|
433
|
+
context "when set in node json and the fetched node" do
|
434
|
+
|
435
|
+
let(:json_attribs) do
|
436
|
+
{
|
437
|
+
"policy_name" => "policy_name_from_node_json",
|
438
|
+
"policy_group" => "policy_group_from_node_json"
|
439
|
+
}
|
440
|
+
end
|
441
|
+
|
442
|
+
let(:node) do
|
443
|
+
node = Chef::Node.new
|
444
|
+
node.name(node_name)
|
445
|
+
node.policy_name = "policy_name_from_node"
|
446
|
+
node.policy_group = "policy_group_from_node"
|
447
|
+
node
|
448
|
+
end
|
449
|
+
|
450
|
+
|
451
|
+
it "prefers the policy_name and policy_group from the node json" do
|
452
|
+
expect(policy_builder.policy_name).to eq("policy_name_from_node_json")
|
453
|
+
expect(policy_builder.policy_group).to eq("policy_group_from_node_json")
|
454
|
+
|
455
|
+
expect(Chef::Config[:policy_name]).to eq("policy_name_from_node_json")
|
456
|
+
expect(Chef::Config[:policy_group]).to eq("policy_group_from_node_json")
|
457
|
+
expect(node.policy_name).to eq("policy_name_from_node_json")
|
458
|
+
expect(node.policy_group).to eq("policy_group_from_node_json")
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
context "when set in all sources" do
|
464
|
+
|
465
|
+
let(:json_attribs) do
|
466
|
+
{
|
467
|
+
"policy_name" => "policy_name_from_node_json",
|
468
|
+
"policy_group" => "policy_group_from_node_json"
|
469
|
+
}
|
470
|
+
end
|
471
|
+
|
472
|
+
let(:node) do
|
473
|
+
node = Chef::Node.new
|
474
|
+
node.name(node_name)
|
475
|
+
node.policy_name = "policy_name_from_node"
|
476
|
+
node.policy_group = "policy_group_from_node"
|
477
|
+
node
|
478
|
+
end
|
479
|
+
|
480
|
+
let(:extra_chef_config) do
|
481
|
+
{
|
482
|
+
policy_name: "policy_name_from_config",
|
483
|
+
policy_group: "policy_group_from_config"
|
484
|
+
}
|
485
|
+
end
|
486
|
+
|
487
|
+
it "prefers the policy_name and group from node json" do
|
488
|
+
expect(policy_builder.policy_name).to eq("policy_name_from_node_json")
|
489
|
+
expect(policy_builder.policy_group).to eq("policy_group_from_node_json")
|
490
|
+
|
491
|
+
expect(Chef::Config[:policy_name]).to eq("policy_name_from_node_json")
|
492
|
+
expect(Chef::Config[:policy_group]).to eq("policy_group_from_node_json")
|
493
|
+
expect(node.policy_name).to eq("policy_name_from_node_json")
|
494
|
+
expect(node.policy_group).to eq("policy_group_from_node_json")
|
495
|
+
end
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
end
|
500
|
+
|
355
501
|
it "resets default and override data" do
|
356
502
|
expect(node["default_key"]).to be_nil
|
357
503
|
expect(node["override_key"]).to be_nil
|
358
504
|
end
|
359
505
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
506
|
+
describe "setting attribute values" do
|
507
|
+
|
508
|
+
before do
|
509
|
+
policy_builder.build_node
|
364
510
|
end
|
365
|
-
end
|
366
511
|
|
367
|
-
|
368
|
-
|
369
|
-
|
512
|
+
it "resets default and override data" do
|
513
|
+
expect(node["default_key"]).to be_nil
|
514
|
+
expect(node["override_key"]).to be_nil
|
515
|
+
end
|
370
516
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
517
|
+
it "applies ohai data" do
|
518
|
+
expect(ohai_data).to_not be_empty # ensure test is testing something
|
519
|
+
ohai_data.each do |key, value|
|
520
|
+
expect(node.automatic_attrs[key]).to eq(value)
|
521
|
+
end
|
522
|
+
end
|
375
523
|
|
376
|
-
|
377
|
-
|
378
|
-
|
524
|
+
it "applies attributes from json file" do
|
525
|
+
expect(node["custom_attr"]).to eq("custom_attr_value")
|
526
|
+
end
|
379
527
|
|
380
|
-
|
381
|
-
|
382
|
-
|
528
|
+
it "applies attributes from the policyfile" do
|
529
|
+
expect(node["policyfile_default_attr"]).to eq("policyfile_default_value")
|
530
|
+
expect(node["policyfile_override_attr"]).to eq("policyfile_override_value")
|
531
|
+
end
|
532
|
+
|
533
|
+
it "sets the policyfile's run_list on the node object" do
|
534
|
+
expect(node.run_list).to eq(policyfile_run_list)
|
535
|
+
end
|
536
|
+
|
537
|
+
it "creates node.automatic_attrs[:roles]" do
|
538
|
+
expect(node.automatic_attrs[:roles]).to eq([])
|
539
|
+
end
|
383
540
|
|
384
|
-
|
385
|
-
|
541
|
+
it "create node.automatic_attrs[:recipes]" do
|
542
|
+
expect(node.automatic_attrs[:recipes]).to eq(["example1::default", "example2::server"])
|
543
|
+
end
|
386
544
|
end
|
387
545
|
|
546
|
+
context "when a named run_list is given" do
|
547
|
+
|
548
|
+
before do
|
549
|
+
Chef::Config[:named_run_list] = "deploy-app"
|
550
|
+
end
|
551
|
+
|
552
|
+
context "and the named run_list is not present in the policy" do
|
553
|
+
|
554
|
+
it "raises a ConfigurationError" do
|
555
|
+
err_class = Chef::PolicyBuilder::Policyfile::ConfigurationError
|
556
|
+
err_text = "Policy 'example-policy' revision '123abc' does not have named_run_list 'deploy-app'(available named_run_lists: [])"
|
557
|
+
expect { policy_builder.build_node }.to raise_error(err_class, err_text)
|
558
|
+
end
|
559
|
+
|
560
|
+
end
|
561
|
+
|
562
|
+
context "and the named run_list is present in the policy" do
|
563
|
+
|
564
|
+
let(:parsed_policyfile_json) do
|
565
|
+
basic_valid_policy_data.dup.tap do |p|
|
566
|
+
p["named_run_lists"] = {
|
567
|
+
"deploy-app" => [ "recipe[example1::default]" ]
|
568
|
+
}
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
before do
|
573
|
+
policy_builder.build_node
|
574
|
+
end
|
575
|
+
|
576
|
+
it "sets the run list to the desired named run list" do
|
577
|
+
expect(policy_builder.run_list).to eq([ "recipe[example1::default]" ])
|
578
|
+
expected_expansion = Chef::PolicyBuilder::Policyfile::RunListExpansionIsh.new([ "example1::default" ], [])
|
579
|
+
expect(policy_builder.run_list_expansion).to eq(expected_expansion)
|
580
|
+
expect(policy_builder.run_list_with_versions_for_display).to eq(["example1::default@2.3.5 (168d210)"])
|
581
|
+
expect(node.run_list).to eq([ Chef::RunList::RunListItem.new("recipe[example1::default]") ])
|
582
|
+
expect(node[:roles]).to eq( [] )
|
583
|
+
expect(node[:recipes]).to eq( ["example1::default"] )
|
584
|
+
end
|
585
|
+
|
586
|
+
it "disables the cookbook cache cleaner" do
|
587
|
+
expect(Chef::CookbookCacheCleaner.instance.skip_removal).to be(true)
|
588
|
+
end
|
589
|
+
|
590
|
+
end
|
591
|
+
|
592
|
+
end
|
388
593
|
end
|
389
594
|
|
390
595
|
|
@@ -414,9 +619,7 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
414
619
|
let(:error404) { Net::HTTPServerException.new("404 message", :body) }
|
415
620
|
|
416
621
|
before do
|
417
|
-
|
418
|
-
|
419
|
-
policy_builder.load_node
|
622
|
+
policy_builder.finish_load_node(node)
|
420
623
|
policy_builder.build_node
|
421
624
|
|
422
625
|
expect(http_api).to receive(:get).with(cookbook1_url).
|
@@ -433,9 +636,9 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
433
636
|
shared_examples_for "fetching cookbooks when they exist" do
|
434
637
|
context "and the cookbooks can be fetched" do
|
435
638
|
before do
|
436
|
-
|
639
|
+
Chef.reset!
|
437
640
|
|
438
|
-
policy_builder.
|
641
|
+
policy_builder.finish_load_node(node)
|
439
642
|
policy_builder.build_node
|
440
643
|
|
441
644
|
allow(Chef::CookbookSynchronizer).to receive(:new).
|
@@ -443,6 +646,10 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
443
646
|
and_return(cookbook_synchronizer)
|
444
647
|
end
|
445
648
|
|
649
|
+
after do
|
650
|
+
Chef.reset!
|
651
|
+
end
|
652
|
+
|
446
653
|
it "builds a Hash of the form 'cookbook_name' => Chef::CookbookVersion" do
|
447
654
|
expect(policy_builder.cookbooks_to_sync).to eq(expected_cookbook_hash)
|
448
655
|
end
|
@@ -460,6 +667,13 @@ describe Chef::PolicyBuilder::Policyfile do
|
|
460
667
|
expect(run_context.cookbook_collection.keys).to match_array(["example1", "example2"])
|
461
668
|
end
|
462
669
|
|
670
|
+
it "makes the run context available via static method on Chef" do
|
671
|
+
expect(cookbook_synchronizer).to receive(:sync_cookbooks)
|
672
|
+
expect_any_instance_of(Chef::RunContext).to receive(:load).with(policy_builder.run_list_expansion_ish)
|
673
|
+
run_context = policy_builder.setup_run_context
|
674
|
+
expect(Chef.run_context).to eq(run_context)
|
675
|
+
end
|
676
|
+
|
463
677
|
end
|
464
678
|
end # shared_examples_for "fetching cookbooks"
|
465
679
|
|