chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- 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,83 @@
|
|
1
|
+
#
|
2
|
+
# Author:: John Keiser (<jkeiser@chef.io)
|
3
|
+
# Copyright:: Copyright (c) 2015 Opscode, 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 'chef/exceptions'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Resource
|
23
|
+
module ActionClass
|
24
|
+
#
|
25
|
+
# If load_current_value! is defined on the resource, use that.
|
26
|
+
#
|
27
|
+
def load_current_resource
|
28
|
+
if new_resource.respond_to?(:load_current_value!)
|
29
|
+
# dup the resource and then reset desired-state properties.
|
30
|
+
current_resource = new_resource.dup
|
31
|
+
|
32
|
+
# We clear desired state in the copy, because it is supposed to be actual state.
|
33
|
+
# We keep identity properties and non-desired-state, which are assumed to be
|
34
|
+
# "control" values like `recurse: true`
|
35
|
+
current_resource.class.properties.each do |name,property|
|
36
|
+
if property.desired_state? && !property.identity? && !property.name_property?
|
37
|
+
property.reset(current_resource)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Call the actual load_current_value! method. If it raises
|
42
|
+
# CurrentValueDoesNotExist, set current_resource to `nil`.
|
43
|
+
begin
|
44
|
+
# If the user specifies load_current_value do |desired_resource|, we
|
45
|
+
# pass in the desired resource as well as the current one.
|
46
|
+
if current_resource.method(:load_current_value!).arity > 0
|
47
|
+
current_resource.load_current_value!(new_resource)
|
48
|
+
else
|
49
|
+
current_resource.load_current_value!
|
50
|
+
end
|
51
|
+
rescue Chef::Exceptions::CurrentValueDoesNotExist
|
52
|
+
current_resource = nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@current_resource = current_resource
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.included(other)
|
60
|
+
other.extend(ClassMethods)
|
61
|
+
other.use_inline_resources
|
62
|
+
other.include_resource_dsl true
|
63
|
+
end
|
64
|
+
|
65
|
+
module ClassMethods
|
66
|
+
#
|
67
|
+
# The Chef::Resource class this ActionClass was declared against.
|
68
|
+
#
|
69
|
+
# @return [Class] The Chef::Resource class this ActionClass was declared against.
|
70
|
+
#
|
71
|
+
attr_accessor :resource_class
|
72
|
+
|
73
|
+
def to_s
|
74
|
+
"#{resource_class} action provider"
|
75
|
+
end
|
76
|
+
|
77
|
+
def inspect
|
78
|
+
to_s
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -50,9 +50,9 @@ class Chef
|
|
50
50
|
# Chef::Resource.run_action: Caveat: this skips Chef::Runner.run_action, where notifications are handled
|
51
51
|
# Action could be an array of symbols, but probably won't (think install + enable for a package)
|
52
52
|
if compile_time.nil?
|
53
|
-
Chef
|
54
|
-
Chef
|
55
|
-
Chef
|
53
|
+
Chef.log_deprecation "#{self} chef_gem compile_time installation is deprecated"
|
54
|
+
Chef.log_deprecation "#{self} Please set `compile_time false` on the resource to use the new behavior."
|
55
|
+
Chef.log_deprecation "#{self} or set `compile_time true` on the resource if compile_time behavior is required."
|
56
56
|
end
|
57
57
|
|
58
58
|
if compile_time || compile_time.nil?
|
data/lib/chef/resource/deploy.rb
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
# migration_command "rake db:migrate"
|
28
28
|
# environment "RAILS_ENV" => "production", "OTHER_ENV" => "foo"
|
29
29
|
# shallow_clone true
|
30
|
+
# depth 1
|
30
31
|
# action :deploy # or :rollback
|
31
32
|
# restart_command "touch tmp/restart.txt"
|
32
33
|
# git_ssh_wrapper "wrap-ssh4git.sh"
|
@@ -74,6 +75,7 @@ class Chef
|
|
74
75
|
@remote = "origin"
|
75
76
|
@enable_submodules = false
|
76
77
|
@shallow_clone = false
|
78
|
+
@depth = nil
|
77
79
|
@scm_provider = Chef::Provider::Git
|
78
80
|
@svn_force_export = false
|
79
81
|
@additional_remotes = Hash[]
|
@@ -97,8 +99,12 @@ class Chef
|
|
97
99
|
@current_path ||= @deploy_to + "/current"
|
98
100
|
end
|
99
101
|
|
100
|
-
def depth
|
101
|
-
|
102
|
+
def depth(arg=@shallow_clone ? 5 : nil)
|
103
|
+
set_or_return(
|
104
|
+
:depth,
|
105
|
+
arg,
|
106
|
+
:kind_of => [ Integer ]
|
107
|
+
)
|
102
108
|
end
|
103
109
|
|
104
110
|
# note: deploy_to is your application "meta-root."
|
@@ -106,7 +106,13 @@ class Chef
|
|
106
106
|
# We reuse Chef::GuardInterpreter in order to support
|
107
107
|
# the same set of options that the not_if/only_if blocks do
|
108
108
|
def verify_command(path, opts)
|
109
|
-
|
109
|
+
# First implementation interpolated `file`; docs & RFC claim `path`
|
110
|
+
# is interpolated. Until `file` can be deprecated, interpolate both.
|
111
|
+
Chef.log_deprecation(
|
112
|
+
'%{file} is deprecated in verify command and will not be '\
|
113
|
+
'supported in Chef 13. Please use %{path} instead.'
|
114
|
+
) if @command.include?('%{file}')
|
115
|
+
command = @command % {:file => path, :path => path}
|
110
116
|
interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts)
|
111
117
|
interpreter.evaluate
|
112
118
|
end
|
@@ -74,13 +74,7 @@ class Chef
|
|
74
74
|
resource_class
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
# parameters.
|
79
|
-
def attribute(attr_name, validation_opts={})
|
80
|
-
define_method(attr_name) do |arg=nil|
|
81
|
-
set_or_return(attr_name.to_sym, arg, validation_opts)
|
82
|
-
end
|
83
|
-
end
|
77
|
+
alias :attribute :property
|
84
78
|
|
85
79
|
# Adds +action_names+ to the list of valid actions for this resource.
|
86
80
|
# Does not include superclass's action list when appending.
|
@@ -93,7 +93,7 @@ class Chef
|
|
93
93
|
raise ArgumentError, "Bad key #{key} in RegistryKey values hash" unless [:name,:type,:data].include?(key)
|
94
94
|
end
|
95
95
|
raise ArgumentError, "Type of name => #{v[:name]} should be string" unless v[:name].is_a?(String)
|
96
|
-
raise
|
96
|
+
raise ArgumentError, "Type of type => #{v[:type]} should be symbol" unless v[:type].is_a?(Symbol)
|
97
97
|
end
|
98
98
|
@unscrubbed_values = @values
|
99
99
|
elsif self.instance_variable_defined?(:@values)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@hjksolutions.com>)
|
3
3
|
# Author:: Tyler Cloke (<tyler@opscode.com>)
|
4
|
-
# Copyright:: Copyright (c) 2008
|
4
|
+
# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -44,7 +44,8 @@ class Chef
|
|
44
44
|
@init_command = nil
|
45
45
|
@priority = nil
|
46
46
|
@timeout = nil
|
47
|
-
@
|
47
|
+
@run_levels = nil
|
48
|
+
@supports = { :restart => nil, :reload => nil, :status => nil }
|
48
49
|
end
|
49
50
|
|
50
51
|
def service_name(arg=nil)
|
@@ -174,6 +175,13 @@ class Chef
|
|
174
175
|
)
|
175
176
|
end
|
176
177
|
|
178
|
+
def run_levels(arg=nil)
|
179
|
+
set_or_return(
|
180
|
+
:run_levels,
|
181
|
+
arg,
|
182
|
+
:kind_of => [ Array ] )
|
183
|
+
end
|
184
|
+
|
177
185
|
def supports(args={})
|
178
186
|
if args.is_a? Array
|
179
187
|
args.each { |arg| @supports[arg] = true }
|
@@ -28,12 +28,17 @@ class Chef
|
|
28
28
|
super
|
29
29
|
@svn_arguments = '--no-auth-cache'
|
30
30
|
@svn_info_args = '--no-auth-cache'
|
31
|
+
@svn_binary = nil
|
31
32
|
end
|
32
33
|
|
33
34
|
# Override exception to strip password if any, so it won't appear in logs and different Chef notifications
|
34
35
|
def custom_exception_message(e)
|
35
36
|
"#{self} (#{defined_at}) had an error: #{e.class.name}: #{svn_password ? e.message.gsub(svn_password, "[hidden_password]") : e.message}"
|
36
37
|
end
|
38
|
+
|
39
|
+
def svn_binary(arg=nil)
|
40
|
+
set_or_return(:svn_binary, arg, :kind_of => [String])
|
41
|
+
end
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
@@ -16,6 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
+
require 'chef/platform/query_helpers'
|
19
20
|
require 'chef/resource/script'
|
20
21
|
require 'chef/mixin/windows_architecture_helper'
|
21
22
|
|
@@ -51,9 +52,12 @@ class Chef
|
|
51
52
|
protected
|
52
53
|
|
53
54
|
def assert_architecture_compatible!(desired_architecture)
|
54
|
-
if
|
55
|
+
if desired_architecture == :i386 && Chef::Platform.windows_nano_server?
|
55
56
|
raise Chef::Exceptions::Win32ArchitectureIncorrect,
|
56
|
-
|
57
|
+
"cannot execute script with requested architecture 'i386' on Windows Nano Server"
|
58
|
+
elsif ! node_supports_windows_architecture?(node, desired_architecture)
|
59
|
+
raise Chef::Exceptions::Win32ArchitectureIncorrect,
|
60
|
+
"cannot execute script with requested architecture '#{desired_architecture.to_s}' on a system with architecture '#{node_windows_architecture(node)}'"
|
57
61
|
end
|
58
62
|
end
|
59
63
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: AJ Christensen (<aj@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2008
|
3
|
+
# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -28,6 +28,7 @@ class Chef
|
|
28
28
|
super
|
29
29
|
@flush_cache = { :before => false, :after => false }
|
30
30
|
@allow_downgrade = false
|
31
|
+
@yum_binary = nil
|
31
32
|
end
|
32
33
|
|
33
34
|
# Install a specific arch
|
@@ -57,6 +58,14 @@ class Chef
|
|
57
58
|
)
|
58
59
|
end
|
59
60
|
|
61
|
+
def yum_binary(arg=nil)
|
62
|
+
set_or_return(
|
63
|
+
:yum_binary,
|
64
|
+
arg,
|
65
|
+
:kind_of => [ String ]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
60
69
|
end
|
61
70
|
end
|
62
71
|
end
|
@@ -56,7 +56,7 @@ class Chef
|
|
56
56
|
attr_reader :resource_name
|
57
57
|
# @api private
|
58
58
|
def resource
|
59
|
-
Chef
|
59
|
+
Chef.log_deprecation("Chef::ResourceResolver.resource deprecated. Use resource_name instead.")
|
60
60
|
resource_name
|
61
61
|
end
|
62
62
|
# @api private
|
@@ -174,8 +174,8 @@ class Chef
|
|
174
174
|
if handlers.empty?
|
175
175
|
handlers = resources.select { |handler| overrode_provides?(handler) && handler.provides?(node, resource_name) }
|
176
176
|
handlers.each do |handler|
|
177
|
-
Chef
|
178
|
-
Chef
|
177
|
+
Chef.log_deprecation("#{handler}.provides? returned true when asked if it provides DSL #{resource_name}, but provides #{resource_name.inspect} was never called!")
|
178
|
+
Chef.log_deprecation("In Chef 13, this will break: you must call provides to mark the names you provide, even if you also override provides? yourself.")
|
179
179
|
end
|
180
180
|
end
|
181
181
|
handlers
|
data/lib/chef/run_context.rb
CHANGED
@@ -25,118 +25,223 @@ require 'chef/log'
|
|
25
25
|
require 'chef/recipe'
|
26
26
|
require 'chef/run_context/cookbook_compiler'
|
27
27
|
require 'chef/event_dispatch/events_output_stream'
|
28
|
+
require 'forwardable'
|
28
29
|
|
29
30
|
class Chef
|
30
31
|
|
31
32
|
# == Chef::RunContext
|
32
33
|
# Value object that loads and tracks the context of a Chef run
|
33
34
|
class RunContext
|
35
|
+
#
|
36
|
+
# Global state
|
37
|
+
#
|
34
38
|
|
35
|
-
#
|
39
|
+
#
|
40
|
+
# The node for this run
|
41
|
+
#
|
42
|
+
# @return [Chef::Node]
|
43
|
+
#
|
36
44
|
attr_reader :node
|
37
45
|
|
38
|
-
#
|
46
|
+
#
|
47
|
+
# The set of cookbooks involved in this run
|
48
|
+
#
|
49
|
+
# @return [Chef::CookbookCollection]
|
50
|
+
#
|
39
51
|
attr_reader :cookbook_collection
|
40
52
|
|
53
|
+
#
|
41
54
|
# Resource Definitions for this run. Populated when the files in
|
42
55
|
# +definitions/+ are evaluated (this is triggered by #load).
|
56
|
+
#
|
57
|
+
# @return [Array[Chef::ResourceDefinition]]
|
58
|
+
#
|
43
59
|
attr_reader :definitions
|
44
60
|
|
45
|
-
|
46
|
-
#
|
47
|
-
#
|
61
|
+
#
|
62
|
+
# Event dispatcher for this run.
|
63
|
+
#
|
64
|
+
# @return [Chef::EventDispatch::Dispatcher]
|
65
|
+
#
|
66
|
+
attr_reader :events
|
48
67
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
68
|
+
#
|
69
|
+
# Hash of factoids for a reboot request.
|
70
|
+
#
|
71
|
+
# @return [Hash]
|
72
|
+
#
|
73
|
+
attr_accessor :reboot_info
|
52
74
|
|
75
|
+
#
|
76
|
+
# Scoped state
|
77
|
+
#
|
78
|
+
|
79
|
+
#
|
80
|
+
# The parent run context.
|
81
|
+
#
|
82
|
+
# @return [Chef::RunContext] The parent run context, or `nil` if this is the
|
83
|
+
# root context.
|
84
|
+
#
|
85
|
+
attr_reader :parent_run_context
|
86
|
+
|
87
|
+
#
|
88
|
+
# The collection of resources intended to be converged (and able to be
|
89
|
+
# notified).
|
90
|
+
#
|
91
|
+
# @return [Chef::ResourceCollection]
|
92
|
+
#
|
93
|
+
# @see CookbookCompiler
|
94
|
+
#
|
95
|
+
attr_reader :resource_collection
|
96
|
+
|
97
|
+
#
|
53
98
|
# The list of control groups to execute during the audit phase
|
54
|
-
|
99
|
+
#
|
100
|
+
attr_reader :audits
|
55
101
|
|
102
|
+
#
|
103
|
+
# Notification handling
|
104
|
+
#
|
105
|
+
|
106
|
+
#
|
56
107
|
# A Hash containing the immediate notifications triggered by resources
|
57
108
|
# during the converge phase of the chef run.
|
58
|
-
|
109
|
+
#
|
110
|
+
# @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
|
111
|
+
# <notifying resource name> => <list of notifications it sent>
|
112
|
+
#
|
113
|
+
attr_reader :immediate_notification_collection
|
59
114
|
|
115
|
+
#
|
60
116
|
# A Hash containing the delayed (end of run) notifications triggered by
|
61
117
|
# resources during the converge phase of the chef run.
|
62
|
-
|
63
|
-
|
64
|
-
#
|
65
|
-
|
66
|
-
|
67
|
-
# Hash of factoids for a reboot request.
|
68
|
-
attr_reader :reboot_info
|
118
|
+
#
|
119
|
+
# @return [Hash[String, Array[Chef::Resource::Notification]]] A hash from
|
120
|
+
# <notifying resource name> => <list of notifications it sent>
|
121
|
+
#
|
122
|
+
attr_reader :delayed_notification_collection
|
69
123
|
|
70
124
|
# Creates a new Chef::RunContext object and populates its fields. This object gets
|
71
125
|
# used by the Chef Server to generate a fully compiled recipe list for a node.
|
72
126
|
#
|
73
|
-
#
|
74
|
-
#
|
127
|
+
# @param node [Chef::Node] The node to run against.
|
128
|
+
# @param cookbook_collection [Chef::CookbookCollection] The cookbooks
|
129
|
+
# involved in this run.
|
130
|
+
# @param events [EventDispatch::Dispatcher] The event dispatcher for this
|
131
|
+
# run.
|
132
|
+
#
|
75
133
|
def initialize(node, cookbook_collection, events)
|
76
134
|
@node = node
|
77
135
|
@cookbook_collection = cookbook_collection
|
78
|
-
@resource_collection = Chef::ResourceCollection.new
|
79
|
-
@audits = {}
|
80
|
-
@immediate_notification_collection = Hash.new {|h,k| h[k] = []}
|
81
|
-
@delayed_notification_collection = Hash.new {|h,k| h[k] = []}
|
82
|
-
@definitions = Hash.new
|
83
|
-
@loaded_recipes = {}
|
84
|
-
@loaded_attributes = {}
|
85
136
|
@events = events
|
86
|
-
@reboot_info = {}
|
87
137
|
|
88
|
-
|
89
|
-
|
138
|
+
node.run_context = self
|
139
|
+
node.set_cookbook_attribute
|
140
|
+
|
141
|
+
@definitions = Hash.new
|
142
|
+
@loaded_recipes_hash = {}
|
143
|
+
@loaded_attributes_hash = {}
|
144
|
+
@reboot_info = {}
|
90
145
|
@cookbook_compiler = nil
|
146
|
+
|
147
|
+
initialize_child_state
|
91
148
|
end
|
92
149
|
|
93
|
-
#
|
94
|
-
#
|
150
|
+
#
|
151
|
+
# Triggers the compile phase of the chef run.
|
152
|
+
#
|
153
|
+
# @param run_list_expansion [Chef::RunList::RunListExpansion] The run list.
|
154
|
+
# @see Chef::RunContext::CookbookCompiler
|
155
|
+
#
|
95
156
|
def load(run_list_expansion)
|
96
157
|
@cookbook_compiler = CookbookCompiler.new(self, run_list_expansion, events)
|
97
|
-
|
158
|
+
cookbook_compiler.compile
|
98
159
|
end
|
99
160
|
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
161
|
+
#
|
162
|
+
# Initialize state that applies to both Chef::RunContext and Chef::ChildRunContext
|
163
|
+
#
|
164
|
+
def initialize_child_state
|
165
|
+
@audits = {}
|
166
|
+
@resource_collection = Chef::ResourceCollection.new
|
167
|
+
@immediate_notification_collection = Hash.new {|h,k| h[k] = []}
|
168
|
+
@delayed_notification_collection = Hash.new {|h,k| h[k] = []}
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# Adds an immediate notification to the +immediate_notification_collection+.
|
173
|
+
#
|
174
|
+
# @param [Chef::Resource::Notification] The notification to add.
|
175
|
+
#
|
103
176
|
def notifies_immediately(notification)
|
104
177
|
nr = notification.notifying_resource
|
105
178
|
if nr.instance_of?(Chef::Resource)
|
106
|
-
|
179
|
+
immediate_notification_collection[nr.name] << notification
|
107
180
|
else
|
108
|
-
|
181
|
+
immediate_notification_collection[nr.declared_key] << notification
|
109
182
|
end
|
110
183
|
end
|
111
184
|
|
112
|
-
#
|
113
|
-
#
|
185
|
+
#
|
186
|
+
# Adds a delayed notification to the +delayed_notification_collection+.
|
187
|
+
#
|
188
|
+
# @param [Chef::Resource::Notification] The notification to add.
|
189
|
+
#
|
114
190
|
def notifies_delayed(notification)
|
115
191
|
nr = notification.notifying_resource
|
116
192
|
if nr.instance_of?(Chef::Resource)
|
117
|
-
|
193
|
+
delayed_notification_collection[nr.name] << notification
|
118
194
|
else
|
119
|
-
|
195
|
+
delayed_notification_collection[nr.declared_key] << notification
|
120
196
|
end
|
121
197
|
end
|
122
198
|
|
199
|
+
#
|
200
|
+
# Get the list of immediate notifications sent by the given resource.
|
201
|
+
#
|
202
|
+
# TODO seriously, this is actually wrong. resource.name is not unique,
|
203
|
+
# you need the type as well.
|
204
|
+
#
|
205
|
+
# @return [Array[Notification]]
|
206
|
+
#
|
123
207
|
def immediate_notifications(resource)
|
124
208
|
if resource.instance_of?(Chef::Resource)
|
125
|
-
return
|
209
|
+
return immediate_notification_collection[resource.name]
|
126
210
|
else
|
127
|
-
return
|
211
|
+
return immediate_notification_collection[resource.declared_key]
|
128
212
|
end
|
129
213
|
end
|
130
214
|
|
215
|
+
#
|
216
|
+
# Get the list of delayed (end of run) notifications sent by the given
|
217
|
+
# resource.
|
218
|
+
#
|
219
|
+
# TODO seriously, this is actually wrong. resource.name is not unique,
|
220
|
+
# you need the type as well.
|
221
|
+
#
|
222
|
+
# @return [Array[Notification]]
|
223
|
+
#
|
131
224
|
def delayed_notifications(resource)
|
132
225
|
if resource.instance_of?(Chef::Resource)
|
133
|
-
return
|
226
|
+
return delayed_notification_collection[resource.name]
|
134
227
|
else
|
135
|
-
return
|
228
|
+
return delayed_notification_collection[resource.declared_key]
|
136
229
|
end
|
137
230
|
end
|
138
231
|
|
232
|
+
#
|
233
|
+
# Cookbook and recipe loading
|
234
|
+
#
|
235
|
+
|
236
|
+
#
|
139
237
|
# Evaluates the recipes +recipe_names+. Used by DSL::IncludeRecipe
|
238
|
+
#
|
239
|
+
# @param recipe_names [Array[String]] The list of recipe names (e.g.
|
240
|
+
# 'my_cookbook' or 'my_cookbook::my_resource').
|
241
|
+
# @param current_cookbook The cookbook we are currently running in.
|
242
|
+
#
|
243
|
+
# @see DSL::IncludeRecipe#include_recipe
|
244
|
+
#
|
140
245
|
def include_recipe(*recipe_names, current_cookbook: nil)
|
141
246
|
result_recipes = Array.new
|
142
247
|
recipe_names.flatten.each do |recipe_name|
|
@@ -147,7 +252,21 @@ class Chef
|
|
147
252
|
result_recipes
|
148
253
|
end
|
149
254
|
|
255
|
+
#
|
150
256
|
# Evaluates the recipe +recipe_name+. Used by DSL::IncludeRecipe
|
257
|
+
#
|
258
|
+
# TODO I am sort of confused why we have both this and include_recipe ...
|
259
|
+
# I don't see anything different beyond accepting and returning an
|
260
|
+
# array of recipes.
|
261
|
+
#
|
262
|
+
# @param recipe_names [Array[String]] The recipe name (e.g 'my_cookbook' or
|
263
|
+
# 'my_cookbook::my_resource').
|
264
|
+
# @param current_cookbook The cookbook we are currently running in.
|
265
|
+
#
|
266
|
+
# @return A truthy value if the load occurred; `false` if already loaded.
|
267
|
+
#
|
268
|
+
# @see DSL::IncludeRecipe#load_recipe
|
269
|
+
#
|
151
270
|
def load_recipe(recipe_name, current_cookbook: nil)
|
152
271
|
Chef::Log.debug("Loading Recipe #{recipe_name} via include_recipe")
|
153
272
|
|
@@ -175,6 +294,15 @@ ERROR_MESSAGE
|
|
175
294
|
end
|
176
295
|
end
|
177
296
|
|
297
|
+
#
|
298
|
+
# Load the given recipe from a filename.
|
299
|
+
#
|
300
|
+
# @param recipe_file [String] The recipe filename.
|
301
|
+
#
|
302
|
+
# @return [Chef::Recipe] The loaded recipe.
|
303
|
+
#
|
304
|
+
# @raise [Chef::Exceptions::RecipeNotFound] If the file does not exist.
|
305
|
+
#
|
178
306
|
def load_recipe_file(recipe_file)
|
179
307
|
if !File.exist?(recipe_file)
|
180
308
|
raise Chef::Exceptions::RecipeNotFound, "could not find recipe file #{recipe_file}"
|
@@ -186,8 +314,19 @@ ERROR_MESSAGE
|
|
186
314
|
recipe
|
187
315
|
end
|
188
316
|
|
189
|
-
#
|
190
|
-
#
|
317
|
+
#
|
318
|
+
# Look up an attribute filename.
|
319
|
+
#
|
320
|
+
# @param cookbook_name [String] The cookbook name of the attribute file.
|
321
|
+
# @param attr_file_name [String] The attribute file's name (not path).
|
322
|
+
#
|
323
|
+
# @return [String] The filename.
|
324
|
+
#
|
325
|
+
# @see DSL::IncludeAttribute#include_attribute
|
326
|
+
#
|
327
|
+
# @raise [Chef::Exceptions::CookbookNotFound] If the cookbook could not be found.
|
328
|
+
# @raise [Chef::Exceptions::AttributeNotFound] If the attribute file could not be found.
|
329
|
+
#
|
191
330
|
def resolve_attribute(cookbook_name, attr_file_name)
|
192
331
|
cookbook = cookbook_collection[cookbook_name]
|
193
332
|
raise Chef::Exceptions::CookbookNotFound, "could not find cookbook #{cookbook_name} while loading attribute #{name}" unless cookbook
|
@@ -198,76 +337,152 @@ ERROR_MESSAGE
|
|
198
337
|
attribute_filename
|
199
338
|
end
|
200
339
|
|
201
|
-
# An Array of all recipes that have been loaded. This is stored internally
|
202
|
-
# as a Hash, so ordering is predictable.
|
203
340
|
#
|
204
|
-
#
|
205
|
-
#
|
341
|
+
# A list of all recipes that have been loaded.
|
342
|
+
#
|
343
|
+
# This is stored internally as a Hash, so ordering is predictable.
|
344
|
+
#
|
345
|
+
# TODO is the above statement true in a 1.9+ ruby world? Is it relevant?
|
346
|
+
#
|
347
|
+
# @return [Array[String]] A list of recipes in fully qualified form, e.g.
|
348
|
+
# the recipe "nginx" will be given as "nginx::default".
|
349
|
+
#
|
350
|
+
# @see #loaded_recipe? To determine if a particular recipe has been loaded.
|
206
351
|
#
|
207
|
-
# To determine if a particular recipe has been loaded, use #loaded_recipe?
|
208
352
|
def loaded_recipes
|
209
|
-
|
353
|
+
loaded_recipes_hash.keys
|
210
354
|
end
|
211
355
|
|
212
|
-
# An Array of all attributes files that have been loaded. Stored internally
|
213
|
-
# using a Hash, so order is predictable.
|
214
356
|
#
|
215
|
-
#
|
216
|
-
#
|
357
|
+
# A list of all attributes files that have been loaded.
|
358
|
+
#
|
359
|
+
# Stored internally using a Hash, so order is predictable.
|
360
|
+
#
|
361
|
+
# TODO is the above statement true in a 1.9+ ruby world? Is it relevant?
|
362
|
+
#
|
363
|
+
# @return [Array[String]] A list of attribute file names in fully qualified
|
364
|
+
# form, e.g. the "nginx" will be given as "nginx::default".
|
365
|
+
#
|
217
366
|
def loaded_attributes
|
218
|
-
|
367
|
+
loaded_attributes_hash.keys
|
219
368
|
end
|
220
369
|
|
370
|
+
#
|
371
|
+
# Find out if a given recipe has been loaded.
|
372
|
+
#
|
373
|
+
# @param cookbook [String] Cookbook name.
|
374
|
+
# @param recipe [String] Recipe name.
|
375
|
+
#
|
376
|
+
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
|
377
|
+
#
|
221
378
|
def loaded_fully_qualified_recipe?(cookbook, recipe)
|
222
|
-
|
379
|
+
loaded_recipes_hash.has_key?("#{cookbook}::#{recipe}")
|
223
380
|
end
|
224
381
|
|
225
|
-
#
|
226
|
-
#
|
227
|
-
#
|
382
|
+
#
|
383
|
+
# Find out if a given recipe has been loaded.
|
384
|
+
#
|
385
|
+
# @param recipe [String] Recipe name. "nginx" and "nginx::default" yield
|
386
|
+
# the same results.
|
387
|
+
#
|
388
|
+
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
|
389
|
+
#
|
228
390
|
def loaded_recipe?(recipe)
|
229
391
|
cookbook, recipe_name = Chef::Recipe.parse_recipe_name(recipe)
|
230
392
|
loaded_fully_qualified_recipe?(cookbook, recipe_name)
|
231
393
|
end
|
232
394
|
|
395
|
+
#
|
396
|
+
# Mark a given recipe as having been loaded.
|
397
|
+
#
|
398
|
+
# @param cookbook [String] Cookbook name.
|
399
|
+
# @param recipe [String] Recipe name.
|
400
|
+
#
|
401
|
+
def loaded_recipe(cookbook, recipe)
|
402
|
+
loaded_recipes_hash["#{cookbook}::#{recipe}"] = true
|
403
|
+
end
|
404
|
+
|
405
|
+
#
|
406
|
+
# Find out if a given attribute file has been loaded.
|
407
|
+
#
|
408
|
+
# @param cookbook [String] Cookbook name.
|
409
|
+
# @param attribute_file [String] Attribute file name.
|
410
|
+
#
|
411
|
+
# @return [Boolean] `true` if the recipe has been loaded, `false` otherwise.
|
412
|
+
#
|
233
413
|
def loaded_fully_qualified_attribute?(cookbook, attribute_file)
|
234
|
-
|
414
|
+
loaded_attributes_hash.has_key?("#{cookbook}::#{attribute_file}")
|
235
415
|
end
|
236
416
|
|
417
|
+
#
|
418
|
+
# Mark a given attribute file as having been loaded.
|
419
|
+
#
|
420
|
+
# @param cookbook [String] Cookbook name.
|
421
|
+
# @param attribute_file [String] Attribute file name.
|
422
|
+
#
|
237
423
|
def loaded_attribute(cookbook, attribute_file)
|
238
|
-
|
424
|
+
loaded_attributes_hash["#{cookbook}::#{attribute_file}"] = true
|
239
425
|
end
|
240
426
|
|
241
427
|
##
|
242
428
|
# Cookbook File Introspection
|
243
429
|
|
430
|
+
#
|
431
|
+
# Find out if the cookbook has the given template.
|
432
|
+
#
|
433
|
+
# @param cookbook [String] Cookbook name.
|
434
|
+
# @param template_name [String] Template name.
|
435
|
+
#
|
436
|
+
# @return [Boolean] `true` if the template is in the cookbook, `false`
|
437
|
+
# otherwise.
|
438
|
+
# @see Chef::CookbookVersion#has_template_for_node?
|
439
|
+
#
|
244
440
|
def has_template_in_cookbook?(cookbook, template_name)
|
245
441
|
cookbook = cookbook_collection[cookbook]
|
246
442
|
cookbook.has_template_for_node?(node, template_name)
|
247
443
|
end
|
248
444
|
|
445
|
+
#
|
446
|
+
# Find out if the cookbook has the given file.
|
447
|
+
#
|
448
|
+
# @param cookbook [String] Cookbook name.
|
449
|
+
# @param cb_file_name [String] File name.
|
450
|
+
#
|
451
|
+
# @return [Boolean] `true` if the file is in the cookbook, `false`
|
452
|
+
# otherwise.
|
453
|
+
# @see Chef::CookbookVersion#has_cookbook_file_for_node?
|
454
|
+
#
|
249
455
|
def has_cookbook_file_in_cookbook?(cookbook, cb_file_name)
|
250
456
|
cookbook = cookbook_collection[cookbook]
|
251
457
|
cookbook.has_cookbook_file_for_node?(node, cb_file_name)
|
252
458
|
end
|
253
459
|
|
254
|
-
#
|
255
|
-
#
|
256
|
-
#
|
460
|
+
#
|
461
|
+
# Find out whether the given cookbook is in the cookbook dependency graph.
|
462
|
+
#
|
463
|
+
# @param cookbook_name [String] Cookbook name.
|
464
|
+
#
|
465
|
+
# @return [Boolean] `true` if the cookbook is reachable, `false` otherwise.
|
466
|
+
#
|
467
|
+
# @see Chef::CookbookCompiler#unreachable_cookbook?
|
257
468
|
def unreachable_cookbook?(cookbook_name)
|
258
|
-
|
469
|
+
cookbook_compiler.unreachable_cookbook?(cookbook_name)
|
259
470
|
end
|
260
471
|
|
472
|
+
#
|
261
473
|
# Open a stream object that can be printed into and will dispatch to events
|
262
474
|
#
|
263
|
-
#
|
264
|
-
# options
|
265
|
-
#
|
475
|
+
# @param name [String] The name of the stream.
|
476
|
+
# @param options [Hash] Other options for the stream.
|
477
|
+
#
|
478
|
+
# @return [EventDispatch::EventsOutputStream] The created stream.
|
266
479
|
#
|
267
|
-
#
|
268
|
-
#
|
269
|
-
|
270
|
-
|
480
|
+
# @yield If a block is passed, it will be run and the stream will be closed
|
481
|
+
# afterwards.
|
482
|
+
# @yieldparam stream [EventDispatch::EventsOutputStream] The created stream.
|
483
|
+
#
|
484
|
+
def open_stream(name: nil, **options)
|
485
|
+
stream = EventDispatch::EventsOutputStream.new(events, name: name, **options)
|
271
486
|
if block_given?
|
272
487
|
begin
|
273
488
|
yield stream
|
@@ -280,31 +495,135 @@ ERROR_MESSAGE
|
|
280
495
|
end
|
281
496
|
|
282
497
|
# there are options for how to handle multiple calls to these functions:
|
283
|
-
# 1. first call always wins (never change
|
284
|
-
# 2. last call always wins (happily change
|
498
|
+
# 1. first call always wins (never change reboot_info once set).
|
499
|
+
# 2. last call always wins (happily change reboot_info whenever).
|
285
500
|
# 3. raise an exception on the first conflict.
|
286
501
|
# 4. disable reboot after this run if anyone ever calls :cancel.
|
287
502
|
# 5. raise an exception on any second call.
|
288
503
|
# 6. ?
|
289
504
|
def request_reboot(reboot_info)
|
290
|
-
Chef::Log::info "Changing reboot status from #{
|
505
|
+
Chef::Log::info "Changing reboot status from #{self.reboot_info.inspect} to #{reboot_info.inspect}"
|
291
506
|
@reboot_info = reboot_info
|
292
507
|
end
|
293
508
|
|
294
509
|
def cancel_reboot
|
295
|
-
Chef::Log::info "Changing reboot status from #{
|
510
|
+
Chef::Log::info "Changing reboot status from #{reboot_info.inspect} to {}"
|
296
511
|
@reboot_info = {}
|
297
512
|
end
|
298
513
|
|
299
514
|
def reboot_requested?
|
300
|
-
|
515
|
+
reboot_info.size > 0
|
516
|
+
end
|
517
|
+
|
518
|
+
#
|
519
|
+
# Create a child RunContext.
|
520
|
+
#
|
521
|
+
def create_child
|
522
|
+
ChildRunContext.new(self)
|
301
523
|
end
|
302
524
|
|
303
|
-
private
|
525
|
+
# @api private
|
526
|
+
attr_writer :resource_collection
|
304
527
|
|
305
|
-
|
306
|
-
|
528
|
+
protected
|
529
|
+
|
530
|
+
attr_reader :cookbook_compiler
|
531
|
+
attr_reader :loaded_attributes_hash
|
532
|
+
attr_reader :loaded_recipes_hash
|
533
|
+
|
534
|
+
module Deprecated
|
535
|
+
###
|
536
|
+
# These need to be settable so deploy can run a resource_collection
|
537
|
+
# independent of any cookbooks via +recipe_eval+
|
538
|
+
def audits=(value)
|
539
|
+
Chef.log_deprecation("Setting run_context.audits will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
|
540
|
+
@audits = value
|
541
|
+
end
|
542
|
+
|
543
|
+
def immediate_notification_collection=(value)
|
544
|
+
Chef.log_deprecation("Setting run_context.immediate_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
|
545
|
+
@immediate_notification_collection = value
|
546
|
+
end
|
547
|
+
|
548
|
+
def delayed_notification_collection=(value)
|
549
|
+
Chef.log_deprecation("Setting run_context.delayed_notification_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.")
|
550
|
+
@delayed_notification_collection = value
|
551
|
+
end
|
307
552
|
end
|
553
|
+
prepend Deprecated
|
554
|
+
|
555
|
+
|
556
|
+
#
|
557
|
+
# A child run context. Delegates all root context calls to its parent.
|
558
|
+
#
|
559
|
+
# @api private
|
560
|
+
#
|
561
|
+
class ChildRunContext < RunContext
|
562
|
+
extend Forwardable
|
563
|
+
def_delegators :parent_run_context, *%w(
|
564
|
+
cancel_reboot
|
565
|
+
config
|
566
|
+
cookbook_collection
|
567
|
+
cookbook_compiler
|
568
|
+
definitions
|
569
|
+
events
|
570
|
+
has_cookbook_file_in_cookbook?
|
571
|
+
has_template_in_cookbook?
|
572
|
+
load
|
573
|
+
loaded_attribute
|
574
|
+
loaded_attributes
|
575
|
+
loaded_attributes_hash
|
576
|
+
loaded_fully_qualified_attribute?
|
577
|
+
loaded_fully_qualified_recipe?
|
578
|
+
loaded_recipe
|
579
|
+
loaded_recipe?
|
580
|
+
loaded_recipes
|
581
|
+
loaded_recipes_hash
|
582
|
+
node
|
583
|
+
open_stream
|
584
|
+
reboot_info
|
585
|
+
reboot_info=
|
586
|
+
reboot_requested?
|
587
|
+
request_reboot
|
588
|
+
resolve_attribute
|
589
|
+
unreachable_cookbook?
|
590
|
+
)
|
591
|
+
|
592
|
+
def initialize(parent_run_context)
|
593
|
+
@parent_run_context = parent_run_context
|
594
|
+
|
595
|
+
# We don't call super, because we don't bother initializing stuff we're
|
596
|
+
# going to delegate to the parent anyway. Just initialize things that
|
597
|
+
# every instance needs.
|
598
|
+
initialize_child_state
|
599
|
+
end
|
308
600
|
|
601
|
+
CHILD_STATE = %w(
|
602
|
+
audits
|
603
|
+
audits=
|
604
|
+
create_child
|
605
|
+
delayed_notification_collection
|
606
|
+
delayed_notification_collection=
|
607
|
+
delayed_notifications
|
608
|
+
immediate_notification_collection
|
609
|
+
immediate_notification_collection=
|
610
|
+
immediate_notifications
|
611
|
+
include_recipe
|
612
|
+
initialize_child_state
|
613
|
+
load_recipe
|
614
|
+
load_recipe_file
|
615
|
+
notifies_immediately
|
616
|
+
notifies_delayed
|
617
|
+
parent_run_context
|
618
|
+
resource_collection
|
619
|
+
resource_collection=
|
620
|
+
).map { |x| x.to_sym }
|
621
|
+
|
622
|
+
# Verify that we didn't miss any methods
|
623
|
+
missing_methods = superclass.instance_methods(false) - instance_methods(false) - CHILD_STATE
|
624
|
+
if !missing_methods.empty?
|
625
|
+
raise "ERROR: not all methods of RunContext accounted for in ChildRunContext! All methods must be marked as child methods with CHILD_STATE or delegated to the parent_run_context. Missing #{missing_methods.join(", ")}."
|
626
|
+
end
|
627
|
+
end
|
309
628
|
end
|
310
629
|
end
|