chef 12.5.0.alpha.1 → 12.5.1
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 +5 -110
- data/distro/common/html/knife_cookbook_site.html +18 -18
- data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
- 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/windows_service_manager.rb +9 -7
- data/lib/chef/chef_class.rb +39 -0
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
- 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 +3 -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/client.rb +2 -3
- data/lib/chef/config.rb +34 -2
- 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/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 +6 -5
- data/lib/chef/dsl/resources.rb +2 -2
- data/lib/chef/event_dispatch/base.rb +12 -7
- data/lib/chef/event_dispatch/dispatcher.rb +21 -6
- data/lib/chef/exceptions.rb +22 -0
- data/lib/chef/file_content_management/tempfile.rb +1 -1
- data/lib/chef/formatters/base.rb +3 -0
- data/lib/chef/formatters/doc.rb +53 -5
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
- data/lib/chef/formatters/minimal.rb +2 -2
- 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/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/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 +2 -2
- 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 +97 -3
- data/lib/chef/node_map.rb +2 -2
- data/lib/chef/platform/provider_mapping.rb +5 -6
- data/lib/chef/platform/query_helpers.rb +46 -4
- 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 +38 -9
- data/lib/chef/provider.rb +104 -12
- data/lib/chef/provider/batch.rb +8 -0
- data/lib/chef/provider/deploy.rb +2 -2
- 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/mount.rb +7 -3
- 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 +27 -4
- 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/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/resource.rb +85 -27
- 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 +1 -1
- 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 +6 -8
- 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 +25 -28
- 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/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/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/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_script_spec.rb +104 -15
- 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} +4 -23
- data/spec/integration/client/client_spec.rb +51 -0
- 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 -1
- data/spec/integration/recipes/remote_directory.rb +74 -0
- data/spec/integration/recipes/resource_action_spec.rb +42 -22
- 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 +8 -0
- data/spec/support/platform_helpers.rb +13 -0
- data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
- 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/chef_class_spec.rb +0 -4
- 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 +0 -4
- 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/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/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
- 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 +213 -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/validation_spec.rb +5 -0
- data/spec/unit/property_spec.rb +152 -26
- 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 +52 -26
- 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/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/resource/deploy_spec.rb +7 -1
- data/spec/unit/resource/dsc_script_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +1 -1
- data/spec/unit/resource/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/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 +51 -26
- 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/registry_helper_spec.rb +0 -390
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Serdar Sutay (<serdar@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013-2015 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
|
+
class Chef
|
20
|
+
module Deprecation
|
21
|
+
module Provider
|
22
|
+
module RemoteDirectory
|
23
|
+
|
24
|
+
def directory_root_in_cookbook_cache
|
25
|
+
Chef.log_deprecation "the Chef::Provider::RemoteDirectory#directory_root_in_cookbook_cache method is deprecated"
|
26
|
+
|
27
|
+
@directory_root_in_cookbook_cache ||=
|
28
|
+
begin
|
29
|
+
cookbook = run_context.cookbook_collection[resource_cookbook]
|
30
|
+
cookbook.preferred_filename_on_disk_location(node, :files, source, path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# List all excluding . and ..
|
35
|
+
def ls(path)
|
36
|
+
files = Dir.glob(::File.join(Chef::Util::PathHelper.escape_glob(path), '**', '*'),
|
37
|
+
::File::FNM_DOTMATCH)
|
38
|
+
|
39
|
+
# Remove current directory and previous directory
|
40
|
+
files = files.reject do |name|
|
41
|
+
basename = Pathname.new(name).basename().to_s
|
42
|
+
['.', '..'].include?(basename)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Clean all the paths... this is required because of the join
|
46
|
+
files.map {|f| Chef::Util::PathHelper.cleanpath(f)}
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -23,7 +23,7 @@ class Chef
|
|
23
23
|
# == Deprecation::Provider::RemoteFile
|
24
24
|
# This module contains the deprecated functions of
|
25
25
|
# Chef::Provider::RemoteFile. These functions are refactored to different
|
26
|
-
# components. They are frozen and will be removed in Chef
|
26
|
+
# components. They are frozen and will be removed in Chef 13.
|
27
27
|
#
|
28
28
|
module RemoteFile
|
29
29
|
|
@@ -83,4 +83,3 @@ class Chef
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
@@ -25,7 +25,7 @@ class Chef
|
|
25
25
|
# == Deprecation::Provider::Template
|
26
26
|
# This module contains the deprecated functions of
|
27
27
|
# Chef::Provider::Template. These functions are refactored to different
|
28
|
-
# components. They are frozen and will be removed in Chef
|
28
|
+
# components. They are frozen and will be removed in Chef 13.
|
29
29
|
#
|
30
30
|
module Template
|
31
31
|
|
@@ -25,10 +25,9 @@ class Chef
|
|
25
25
|
m = instance_method(name)
|
26
26
|
define_method(name) do |*args|
|
27
27
|
message = []
|
28
|
-
message << "Method '#{name}' of '#{self.class}' is deprecated. It will be removed in Chef
|
29
|
-
message << "Please update your cookbooks accordingly.
|
30
|
-
|
31
|
-
Chef::Log.deprecation message
|
28
|
+
message << "Method '#{name}' of '#{self.class}' is deprecated. It will be removed in Chef 13."
|
29
|
+
message << "Please update your cookbooks accordingly."
|
30
|
+
Chef.log_deprecation(message)
|
32
31
|
super(*args)
|
33
32
|
end
|
34
33
|
end
|
@@ -45,11 +45,12 @@ class Chef
|
|
45
45
|
registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') ||
|
46
46
|
|
47
47
|
# Vista + Server 2008 and newer may have reboots pending from CBS
|
48
|
-
registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\
|
48
|
+
registry_key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending') ||
|
49
49
|
|
50
50
|
# The mere existence of the UpdateExeVolatile key should indicate a pending restart for certain updates
|
51
51
|
# http://support.microsoft.com/kb/832475
|
52
|
-
|
52
|
+
Chef::Platform.windows_server_2003? &&
|
53
|
+
(registry_key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
|
53
54
|
!registry_get_values('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').select { |v| v[:name] == "Flags" }[0].nil? &&
|
54
55
|
[1,2,3].include?(registry_get_values('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').select { |v| v[:name] == "Flags" }[0][:data]))
|
55
56
|
elsif platform?("ubuntu")
|
data/lib/chef/dsl/recipe.rb
CHANGED
@@ -19,12 +19,10 @@
|
|
19
19
|
|
20
20
|
require 'chef/mixin/convert_to_class_name'
|
21
21
|
require 'chef/exceptions'
|
22
|
-
require 'chef/resource_builder'
|
23
22
|
require 'chef/mixin/shell_out'
|
24
23
|
require 'chef/mixin/powershell_out'
|
25
24
|
require 'chef/dsl/resources'
|
26
25
|
require 'chef/dsl/definitions'
|
27
|
-
require 'chef/resource'
|
28
26
|
|
29
27
|
class Chef
|
30
28
|
module DSL
|
@@ -142,8 +140,7 @@ class Chef
|
|
142
140
|
# method_missing manually. Not a fan. Not. A. Fan.
|
143
141
|
#
|
144
142
|
if respond_to?(method_symbol)
|
145
|
-
Chef
|
146
|
-
Chef::Log.deprecation("Use public_send() or send() instead.")
|
143
|
+
Chef.log_deprecation("Calling method_missing(#{method_symbol.inspect}) directly is deprecated in Chef 12 and will be removed in Chef 13. Use public_send() or send() instead.")
|
147
144
|
return send(method_symbol, *args, &block)
|
148
145
|
end
|
149
146
|
|
@@ -152,7 +149,7 @@ class Chef
|
|
152
149
|
# never called. DEPRECATED.
|
153
150
|
#
|
154
151
|
if run_context.definitions.has_key?(method_symbol.to_sym)
|
155
|
-
Chef
|
152
|
+
Chef.log_deprecation("Definition #{method_symbol} (#{run_context.definitions[method_symbol.to_sym]}) was added to the run_context without calling Chef::DSL::Definitions.add_definition(#{method_symbol.to_sym.inspect}). This will become required in Chef 13.")
|
156
153
|
Chef::DSL::Definitions.add_definition(method_symbol)
|
157
154
|
return send(method_symbol, *args, &block)
|
158
155
|
end
|
@@ -198,6 +195,10 @@ class Chef
|
|
198
195
|
end
|
199
196
|
end
|
200
197
|
|
198
|
+
# Avoid circular references for things that are only used in instance methods
|
199
|
+
require 'chef/resource_builder'
|
200
|
+
require 'chef/resource'
|
201
|
+
|
201
202
|
# **DEPRECATED**
|
202
203
|
# This used to be part of chef/mixin/recipe_definition_dsl_core. Load the file to activate the deprecation code.
|
203
204
|
require 'chef/mixin/recipe_definition_dsl_core'
|
data/lib/chef/dsl/resources.rb
CHANGED
@@ -11,14 +11,14 @@ class Chef
|
|
11
11
|
begin
|
12
12
|
module_eval(<<-EOM, __FILE__, __LINE__+1)
|
13
13
|
def #{dsl_name}(*args, &block)
|
14
|
-
Chef
|
14
|
+
Chef.log_deprecation("Cannot create resource #{dsl_name} with more than one argument. All arguments except the name (\#{args[0].inspect}) will be ignored. This will cause an error in Chef 13. Arguments: \#{args}") if args.size > 1
|
15
15
|
declare_resource(#{dsl_name.inspect}, args[0], caller[0], &block)
|
16
16
|
end
|
17
17
|
EOM
|
18
18
|
rescue SyntaxError
|
19
19
|
# Handle the case where dsl_name has spaces, etc.
|
20
20
|
define_method(dsl_name.to_sym) do |*args, &block|
|
21
|
-
Chef
|
21
|
+
Chef.log_deprecation("Cannot create resource #{dsl_name} with more than one argument. All arguments except the name (#{args[0].inspect}) will be ignored. This will cause an error in Chef 13. Arguments: #{args}") if args.size > 1
|
22
22
|
declare_resource(dsl_name, args[0], caller[0], &block)
|
23
23
|
end
|
24
24
|
end
|
@@ -47,14 +47,19 @@ class Chef
|
|
47
47
|
def ohai_completed(node)
|
48
48
|
end
|
49
49
|
|
50
|
-
#
|
50
|
+
# Announce that we're not going to register the client. Generally because
|
51
|
+
# we already have the private key, or because we're deliberately not using
|
52
|
+
# a key.
|
51
53
|
def skipping_registration(node_name, config)
|
52
54
|
end
|
53
55
|
|
54
|
-
# About to attempt to
|
56
|
+
# About to attempt to create a private key registered to the server with
|
57
|
+
# client +node_name+.
|
55
58
|
def registration_start(node_name, config)
|
56
59
|
end
|
57
60
|
|
61
|
+
# Successfully created the private key and registered this client with the
|
62
|
+
# server.
|
58
63
|
def registration_completed
|
59
64
|
end
|
60
65
|
|
@@ -118,8 +123,8 @@ class Chef
|
|
118
123
|
def cookbook_sync_start(cookbook_count)
|
119
124
|
end
|
120
125
|
|
121
|
-
# Called when cookbook +
|
122
|
-
def synchronized_cookbook(cookbook_name)
|
126
|
+
# Called when cookbook +cookbook+ has been sync'd
|
127
|
+
def synchronized_cookbook(cookbook_name, cookbook)
|
123
128
|
end
|
124
129
|
|
125
130
|
# Called when an individual file in a cookbook has been updated
|
@@ -340,7 +345,6 @@ class Chef
|
|
340
345
|
def resource_completed(resource)
|
341
346
|
end
|
342
347
|
|
343
|
-
|
344
348
|
# A stream has opened.
|
345
349
|
def stream_opened(stream, options = {})
|
346
350
|
end
|
@@ -376,8 +380,9 @@ class Chef
|
|
376
380
|
def whyrun_assumption(action, resource, message)
|
377
381
|
end
|
378
382
|
|
379
|
-
|
380
|
-
|
383
|
+
# Emit a message about something being deprecated.
|
384
|
+
def deprecation(message, location=caller(2..2)[0])
|
385
|
+
end
|
381
386
|
|
382
387
|
# An uncategorized message. This supports the case that a user needs to
|
383
388
|
# pass output that doesn't fit into one of the callbacks above. Note that
|
@@ -25,18 +25,33 @@ class Chef
|
|
25
25
|
# define the forwarding in one go:
|
26
26
|
#
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def call_subscribers(method_name, *args)
|
29
|
+
@subscribers.each do |s|
|
30
|
+
# Skip new/unsupported event names.
|
31
|
+
next if !s.respond_to?(method_name)
|
32
|
+
mth = s.method(method_name)
|
33
|
+
# Trim arguments to match what the subscriber expects to allow
|
34
|
+
# adding new arguments without breaking compat.
|
35
|
+
if mth.arity < args.size && mth.arity >= 0
|
36
|
+
mth.call(*args.take(mth.arity))
|
37
|
+
else
|
38
|
+
mth.call(*args)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
34
42
|
|
35
43
|
(Base.instance_methods - Object.instance_methods).each do |method_name|
|
36
|
-
|
44
|
+
class_eval <<-EOM
|
45
|
+
def #{method_name}(*args)
|
46
|
+
call_subscribers(#{method_name.inspect}, *args)
|
47
|
+
end
|
48
|
+
EOM
|
37
49
|
end
|
38
50
|
|
51
|
+
# Special case deprecation, since it needs to know its caller
|
52
|
+
def deprecation(message, location=caller(2..2)[0])
|
53
|
+
call_subscribers(:deprecation, message, location)
|
54
|
+
end
|
39
55
|
end
|
40
56
|
end
|
41
57
|
end
|
42
|
-
|
data/lib/chef/exceptions.rb
CHANGED
@@ -105,6 +105,9 @@ class Chef
|
|
105
105
|
class VerificationNotFound < RuntimeError; end
|
106
106
|
class InvalidEventType < ArgumentError; end
|
107
107
|
class MultipleIdentityError < RuntimeError; end
|
108
|
+
# Used in Resource::ActionClass#load_current_resource to denote that
|
109
|
+
# the resource doesn't actually exist (for example, the file does not exist)
|
110
|
+
class CurrentValueDoesNotExist < RuntimeError; end
|
108
111
|
|
109
112
|
# Can't find a Resource of this type that is valid on this platform.
|
110
113
|
class NoSuchResourceType < NameError
|
@@ -113,6 +116,8 @@ class Chef
|
|
113
116
|
end
|
114
117
|
end
|
115
118
|
|
119
|
+
class InvalidPolicybuilderCall < ArgumentError; end
|
120
|
+
|
116
121
|
class InvalidResourceSpecification < ArgumentError; end
|
117
122
|
class SolrConnectionError < RuntimeError; end
|
118
123
|
class IllegalChecksumRevert < RuntimeError; end
|
@@ -126,6 +131,23 @@ class Chef
|
|
126
131
|
class EnclosingDirectoryDoesNotExist < ArgumentError; end
|
127
132
|
# Errors originating from calls to the Win32 API
|
128
133
|
class Win32APIError < RuntimeError; end
|
134
|
+
|
135
|
+
class Win32NetAPIError < Win32APIError
|
136
|
+
attr_reader :msg, :error_code
|
137
|
+
def initialize(msg, error_code)
|
138
|
+
@msg = msg
|
139
|
+
@error_code = error_code
|
140
|
+
|
141
|
+
formatted_message = ""
|
142
|
+
formatted_message << "---- Begin Win32 API output ----\n"
|
143
|
+
formatted_message << "Net Api Error Code: #{error_code}\n"
|
144
|
+
formatted_message << "Net Api Error Message: #{msg}\n"
|
145
|
+
formatted_message << "---- End Win32 API output ----\n"
|
146
|
+
|
147
|
+
super(formatted_message)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
129
151
|
# Thrown when Win32 API layer binds to non-existent Win32 function. Occurs
|
130
152
|
# when older versions of Windows don't support newer Win32 API functions.
|
131
153
|
class Win32APIFunctionNotImplemented < NotImplementedError; end
|
@@ -49,7 +49,7 @@ class Chef
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
raise Chef::Exceptions::FileContentStagingError
|
52
|
+
raise Chef::Exceptions::FileContentStagingError, errors if tf.nil?
|
53
53
|
|
54
54
|
# We always process the tempfile in binmode so that we
|
55
55
|
# preserve the line endings of the content.
|
data/lib/chef/formatters/base.rb
CHANGED
data/lib/chef/formatters/doc.rb
CHANGED
@@ -29,6 +29,18 @@ class Chef
|
|
29
29
|
end_time - start_time
|
30
30
|
end
|
31
31
|
|
32
|
+
def pretty_elapsed_time
|
33
|
+
time = elapsed_time
|
34
|
+
if time < 60 then
|
35
|
+
message = Time.at(time).utc.strftime("%S seconds")
|
36
|
+
elsif time < 3600 then
|
37
|
+
message = Time.at(time).utc.strftime("%M minutes %S seconds")
|
38
|
+
else
|
39
|
+
message = Time.at(time).utc.strftime("%H hours %M minutes %S seconds")
|
40
|
+
end
|
41
|
+
message
|
42
|
+
end
|
43
|
+
|
32
44
|
def run_start(version)
|
33
45
|
puts_line "Starting Chef Client, version #{version}"
|
34
46
|
end
|
@@ -43,10 +55,30 @@ class Chef
|
|
43
55
|
|
44
56
|
def run_completed(node)
|
45
57
|
@end_time = Time.now
|
58
|
+
# Print out deprecations.
|
59
|
+
if !deprecations.empty?
|
60
|
+
puts_line ""
|
61
|
+
puts_line "Deprecated features used!"
|
62
|
+
deprecations.each do |message, locations|
|
63
|
+
if locations.size == 1
|
64
|
+
puts_line " #{message} at #{locations.size} location:"
|
65
|
+
else
|
66
|
+
puts_line " #{message} at #{locations.size} locations:"
|
67
|
+
end
|
68
|
+
locations.each do |location|
|
69
|
+
prefix = " - "
|
70
|
+
Array(location).each do |line|
|
71
|
+
puts_line "#{prefix}#{line}"
|
72
|
+
prefix = " "
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
puts_line ""
|
77
|
+
end
|
46
78
|
if Chef::Config[:why_run]
|
47
79
|
puts_line "Chef Client finished, #{@updated_resources}/#{total_resources} resources would have been updated"
|
48
80
|
else
|
49
|
-
puts_line "Chef Client finished, #{@updated_resources}/#{total_resources} resources updated in #{
|
81
|
+
puts_line "Chef Client finished, #{@updated_resources}/#{total_resources} resources updated in #{pretty_elapsed_time}"
|
50
82
|
if total_audits > 0
|
51
83
|
puts_line " #{successful_audits}/#{total_audits} controls succeeded"
|
52
84
|
end
|
@@ -58,7 +90,7 @@ class Chef
|
|
58
90
|
if Chef::Config[:why_run]
|
59
91
|
puts_line "Chef Client failed. #{@updated_resources} resources would have been updated"
|
60
92
|
else
|
61
|
-
puts_line "Chef Client failed. #{@updated_resources} resources updated in #{
|
93
|
+
puts_line "Chef Client failed. #{@updated_resources} resources updated in #{pretty_elapsed_time}"
|
62
94
|
if total_audits > 0
|
63
95
|
puts_line " #{successful_audits} controls succeeded"
|
64
96
|
end
|
@@ -133,9 +165,9 @@ class Chef
|
|
133
165
|
indent
|
134
166
|
end
|
135
167
|
|
136
|
-
# Called when cookbook +
|
137
|
-
def synchronized_cookbook(cookbook_name)
|
138
|
-
puts_line "- #{
|
168
|
+
# Called when cookbook +cookbook+ has been sync'd
|
169
|
+
def synchronized_cookbook(cookbook_name, cookbook)
|
170
|
+
puts_line "- #{cookbook.name} (#{cookbook.version})"
|
139
171
|
end
|
140
172
|
|
141
173
|
# Called when an individual file in a cookbook has been updated
|
@@ -336,6 +368,16 @@ class Chef
|
|
336
368
|
end
|
337
369
|
end
|
338
370
|
|
371
|
+
def deprecation(message, location=caller(2..2)[0])
|
372
|
+
if Chef::Config[:treat_deprecation_warnings_as_errors]
|
373
|
+
super
|
374
|
+
end
|
375
|
+
|
376
|
+
# Save deprecations to the screen until the end
|
377
|
+
deprecations[message] ||= Set.new
|
378
|
+
deprecations[message] << location
|
379
|
+
end
|
380
|
+
|
339
381
|
def indent
|
340
382
|
indent_by(2)
|
341
383
|
end
|
@@ -343,6 +385,12 @@ class Chef
|
|
343
385
|
def unindent
|
344
386
|
indent_by(-2)
|
345
387
|
end
|
388
|
+
|
389
|
+
protected
|
390
|
+
|
391
|
+
def deprecations
|
392
|
+
@deprecations ||= {}
|
393
|
+
end
|
346
394
|
end
|
347
395
|
end
|
348
396
|
end
|
@@ -44,6 +44,38 @@ class Chef
|
|
44
44
|
error_description.section("Cookbook Trace:", traceback)
|
45
45
|
error_description.section("Relevant File Content:", context)
|
46
46
|
end
|
47
|
+
|
48
|
+
if exception_message_modifying_frozen?
|
49
|
+
msg = <<-MESSAGE
|
50
|
+
Ruby objects are often frozen to prevent further modifications
|
51
|
+
when they would negatively impact the process (e.g. values inside
|
52
|
+
Ruby's ENV class) or to prevent polluting other objects when default
|
53
|
+
values are passed by reference to many instances of an object (e.g.
|
54
|
+
the empty Array as a Chef resource default, passed by reference
|
55
|
+
to every instance of the resource).
|
56
|
+
|
57
|
+
Chef uses Object#freeze to ensure the default values of properties
|
58
|
+
inside Chef resources are not modified, so that when a new instance
|
59
|
+
of a Chef resource is created, and Object#dup copies values by
|
60
|
+
reference, the new resource is not receiving a default value that
|
61
|
+
has been by a previous instance of that resource.
|
62
|
+
|
63
|
+
Instead of modifying an object that contains a default value for all
|
64
|
+
instances of a Chef resource, create a new object and assign it to
|
65
|
+
the resource's parameter, e.g.:
|
66
|
+
|
67
|
+
fruit_basket = resource(:fruit_basket, 'default')
|
68
|
+
|
69
|
+
# BAD: modifies 'contents' object for all new fruit_basket instances
|
70
|
+
fruit_basket.contents << 'apple'
|
71
|
+
|
72
|
+
# GOOD: allocates new array only owned by this fruit_basket instance
|
73
|
+
fruit_basket.contents %w(apple)
|
74
|
+
|
75
|
+
MESSAGE
|
76
|
+
|
77
|
+
error_description.section("Additional information:", msg.gsub(/^ {6}/, ''))
|
78
|
+
end
|
47
79
|
end
|
48
80
|
|
49
81
|
def context
|
@@ -111,6 +143,10 @@ class Chef
|
|
111
143
|
end
|
112
144
|
end
|
113
145
|
|
146
|
+
def exception_message_modifying_frozen?
|
147
|
+
exception.message.include?("can't modify frozen")
|
148
|
+
end
|
149
|
+
|
114
150
|
end
|
115
151
|
|
116
152
|
end
|