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
data/lib/chef/property.rb
CHANGED
@@ -86,12 +86,32 @@ class Chef
|
|
86
86
|
#
|
87
87
|
def initialize(**options)
|
88
88
|
options.each { |k,v| options[k.to_sym] = v if k.is_a?(String) }
|
89
|
-
options[:name_property] = options.delete(:name_attribute) unless options.has_key?(:name_property)
|
90
|
-
@options = options
|
91
89
|
|
92
|
-
|
93
|
-
|
90
|
+
# Replace name_attribute with name_property
|
91
|
+
if options.has_key?(:name_attribute)
|
92
|
+
# If we have both name_attribute and name_property and they differ, raise an error
|
93
|
+
if options.has_key?(:name_property)
|
94
|
+
raise ArgumentError, "Cannot specify both name_property and name_attribute together on property #{options[:name]}#{options[:declared_in] ? " of resource #{options[:declared_in].resource_name}" : ""}."
|
95
|
+
end
|
96
|
+
# replace name_property with name_attribute in place
|
97
|
+
options = Hash[options.map { |k,v| k == :name_attribute ? [ :name_property, v ] : [ k,v ] }]
|
98
|
+
end
|
99
|
+
|
100
|
+
# Only pick the first of :default, :name_property and :name_attribute if
|
101
|
+
# more than one is specified.
|
102
|
+
if options.has_key?(:default) && options[:name_property]
|
103
|
+
if options[:default].nil? || options.keys.index(:name_property) < options.keys.index(:default)
|
104
|
+
options.delete(:default)
|
105
|
+
preferred_default = :name_property
|
106
|
+
else
|
107
|
+
options.delete(:name_property)
|
108
|
+
preferred_default = :default
|
109
|
+
end
|
110
|
+
Chef.log_deprecation("Cannot specify both default and name_property together on property #{options[:name]}#{options[:declared_in] ? " of resource #{options[:declared_in].resource_name}" : ""}. Only one (#{preferred_default}) will be obeyed. In Chef 13, this will become an error.")
|
94
111
|
end
|
112
|
+
|
113
|
+
@options = options
|
114
|
+
|
95
115
|
options[:name] = options[:name].to_sym if options[:name]
|
96
116
|
options[:instance_variable_name] = options[:instance_variable_name].to_sym if options[:instance_variable_name]
|
97
117
|
end
|
@@ -231,7 +251,7 @@ class Chef
|
|
231
251
|
if value.nil? && !explicitly_accepts_nil?(resource)
|
232
252
|
# If you say "my_property nil" and the property explicitly accepts
|
233
253
|
# nil values, we consider this a get.
|
234
|
-
Chef
|
254
|
+
Chef.log_deprecation("#{name} nil currently does not overwrite the value of #{name}. This will change in Chef 13, and the value will be set to nil instead. Please change your code to explicitly accept nil using \"property :#{name}, [MyType, nil]\", or stop setting this value to nil.")
|
235
255
|
return get(resource)
|
236
256
|
end
|
237
257
|
|
@@ -285,7 +305,7 @@ class Chef
|
|
285
305
|
# If the value is mutable (non-frozen), we set it on the instance
|
286
306
|
# so that people can mutate it. (All constant default values are
|
287
307
|
# frozen.)
|
288
|
-
if !value.frozen?
|
308
|
+
if !value.frozen? && !value.nil?
|
289
309
|
set_value(resource, value)
|
290
310
|
end
|
291
311
|
|
@@ -402,7 +422,16 @@ class Chef
|
|
402
422
|
# @return [Property] The new property type.
|
403
423
|
#
|
404
424
|
def derive(**modified_options)
|
405
|
-
|
425
|
+
# Since name_property, name_attribute and default override each other,
|
426
|
+
# if you specify one of them in modified_options it overrides anything in
|
427
|
+
# the original options.
|
428
|
+
options = self.options
|
429
|
+
if modified_options.has_key?(:name_property) ||
|
430
|
+
modified_options.has_key?(:name_attribute) ||
|
431
|
+
modified_options.has_key?(:default)
|
432
|
+
options = options.reject { |k,v| k == :name_attribute || k == :name_property || k == :default }
|
433
|
+
end
|
434
|
+
Property.new(options.merge(modified_options))
|
406
435
|
end
|
407
436
|
|
408
437
|
#
|
@@ -427,10 +456,10 @@ class Chef
|
|
427
456
|
EOM
|
428
457
|
rescue SyntaxError
|
429
458
|
# If the name is not a valid ruby name, we use define_method.
|
430
|
-
|
459
|
+
declared_in.define_method(name) do |value=NOT_PASSED|
|
431
460
|
self.class.properties[name].call(self, value)
|
432
461
|
end
|
433
|
-
|
462
|
+
declared_in.define_method("#{name}=") do |value|
|
434
463
|
self.class.properties[name].set(self, value)
|
435
464
|
end
|
436
465
|
end
|
data/lib/chef/provider.rb
CHANGED
@@ -175,6 +175,62 @@ class Chef
|
|
175
175
|
converge_actions.add_action(descriptions, &block)
|
176
176
|
end
|
177
177
|
|
178
|
+
#
|
179
|
+
# Handle patchy convergence safely.
|
180
|
+
#
|
181
|
+
# - Does *not* call the block if the current_resource's properties match
|
182
|
+
# the properties the user specified on the resource.
|
183
|
+
# - Calls the block if current_resource does not exist
|
184
|
+
# - Calls the block if the user has specified any properties in the resource
|
185
|
+
# whose values are *different* from current_resource.
|
186
|
+
# - Does *not* call the block if why-run is enabled (just prints out text).
|
187
|
+
# - Prints out automatic green text saying what properties have changed.
|
188
|
+
#
|
189
|
+
# @param properties An optional list of property names (symbols). If not
|
190
|
+
# specified, `new_resource.class.state_properties` will be used.
|
191
|
+
# @param converge_block The block to do the converging in.
|
192
|
+
#
|
193
|
+
# @return [Boolean] whether the block was executed.
|
194
|
+
#
|
195
|
+
def converge_if_changed(*properties, &converge_block)
|
196
|
+
if !converge_block
|
197
|
+
raise ArgumentError, "converge_if_changed must be passed a block!"
|
198
|
+
end
|
199
|
+
|
200
|
+
properties = new_resource.class.state_properties.map { |p| p.name } if properties.empty?
|
201
|
+
properties = properties.map { |p| p.to_sym }
|
202
|
+
if current_resource
|
203
|
+
# Collect the list of modified properties
|
204
|
+
specified_properties = properties.select { |property| new_resource.property_is_set?(property) }
|
205
|
+
modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) }
|
206
|
+
if modified.empty?
|
207
|
+
Chef::Log.debug("Skipping update of #{new_resource.to_s}: has not changed any of the specified properties #{specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ")}.")
|
208
|
+
return false
|
209
|
+
end
|
210
|
+
|
211
|
+
# Print the pretty green text and run the block
|
212
|
+
property_size = modified.map { |p| p.size }.max
|
213
|
+
modified = modified.map { |p| " set #{p.to_s.ljust(property_size)} to #{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})" }
|
214
|
+
converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block)
|
215
|
+
|
216
|
+
else
|
217
|
+
# The resource doesn't exist. Mark that we are *creating* this, and
|
218
|
+
# write down any properties we are setting.
|
219
|
+
property_size = properties.map { |p| p.size }.max
|
220
|
+
created = []
|
221
|
+
properties.each do |property|
|
222
|
+
if new_resource.property_is_set?(property)
|
223
|
+
created << " set #{property.to_s.ljust(property_size)} to #{new_resource.send(property).inspect}"
|
224
|
+
else
|
225
|
+
created << " set #{property.to_s.ljust(property_size)} to #{new_resource.send(property).inspect} (default value)"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
converge_by([ "create #{new_resource.identity}" ] + created, &converge_block)
|
230
|
+
end
|
231
|
+
true
|
232
|
+
end
|
233
|
+
|
178
234
|
def self.provides(short_name, opts={}, &block)
|
179
235
|
Chef.provider_handler_map.set(short_name, self, opts, &block)
|
180
236
|
end
|
@@ -209,12 +265,31 @@ class Chef
|
|
209
265
|
provider_class = self
|
210
266
|
@included_resource_dsl_module = Module.new do
|
211
267
|
extend Forwardable
|
212
|
-
define_singleton_method(:to_s) { "#{
|
268
|
+
define_singleton_method(:to_s) { "forwarder module for #{provider_class}" }
|
213
269
|
define_singleton_method(:inspect) { to_s }
|
270
|
+
# Add a delegator for each explicit property that will get the *current* value
|
271
|
+
# of the property by default instead of the *actual* value.
|
272
|
+
resource.class.properties.each do |name, property|
|
273
|
+
class_eval(<<-EOM, __FILE__, __LINE__)
|
274
|
+
def #{name}(*args, &block)
|
275
|
+
# If no arguments were passed, we process "get" by defaulting
|
276
|
+
# the value to current_resource, not new_resource. This helps
|
277
|
+
# avoid issues where resources accidentally overwrite perfectly
|
278
|
+
# valid stuff with default values.
|
279
|
+
if args.empty? && !block
|
280
|
+
if !new_resource.property_is_set?(__method__) && current_resource
|
281
|
+
return current_resource.public_send(__method__)
|
282
|
+
end
|
283
|
+
end
|
284
|
+
new_resource.public_send(__method__, *args, &block)
|
285
|
+
end
|
286
|
+
EOM
|
287
|
+
end
|
214
288
|
dsl_methods =
|
215
289
|
resource.class.public_instance_methods +
|
216
290
|
resource.class.protected_instance_methods -
|
217
|
-
provider_class.instance_methods
|
291
|
+
provider_class.instance_methods -
|
292
|
+
resource.class.properties.keys
|
218
293
|
def_delegators(:new_resource, *dsl_methods)
|
219
294
|
end
|
220
295
|
include @included_resource_dsl_module
|
@@ -278,17 +353,34 @@ class Chef
|
|
278
353
|
# compile the resources, converging them, and then checking if any
|
279
354
|
# were updated (and updating new-resource if so)
|
280
355
|
def action(name, &block)
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
356
|
+
# We first try to create the method using "def method_name", which is
|
357
|
+
# preferred because it actually shows up in stack traces. If that
|
358
|
+
# fails, we try define_method.
|
359
|
+
begin
|
360
|
+
class_eval <<-EOM, __FILE__, __LINE__+1
|
361
|
+
def action_#{name}
|
362
|
+
return_value = compile_action_#{name}
|
363
|
+
Chef::Runner.new(run_context).converge
|
364
|
+
return_value
|
365
|
+
ensure
|
366
|
+
if run_context.resource_collection.any? {|r| r.updated? }
|
367
|
+
new_resource.updated_by_last_action(true)
|
368
|
+
end
|
369
|
+
end
|
370
|
+
EOM
|
371
|
+
rescue SyntaxError
|
372
|
+
define_method("action_#{name}") do
|
373
|
+
begin
|
374
|
+
return_value = send("compile_action_#{name}")
|
375
|
+
Chef::Runner.new(run_context).converge
|
376
|
+
return_value
|
377
|
+
ensure
|
378
|
+
if run_context.resource_collection.any? {|r| r.updated? }
|
379
|
+
new_resource.updated_by_last_action(true)
|
380
|
+
end
|
289
381
|
end
|
290
382
|
end
|
291
|
-
|
383
|
+
end
|
292
384
|
# We put the action in its own method so that super() works.
|
293
385
|
define_method("compile_action_#{name}", &block)
|
294
386
|
end
|
@@ -329,7 +421,7 @@ class Chef
|
|
329
421
|
module DeprecatedLWRPClass
|
330
422
|
def const_missing(class_name)
|
331
423
|
if deprecated_constants[class_name.to_sym]
|
332
|
-
Chef
|
424
|
+
Chef.log_deprecation("Using an LWRP provider by its name (#{class_name}) directly is no longer supported in Chef 12 and will be removed. Use Chef::ProviderResolver.new(node, resource, action) instead.")
|
333
425
|
deprecated_constants[class_name.to_sym]
|
334
426
|
else
|
335
427
|
raise NameError, "uninitialized constant Chef::Provider::#{class_name}"
|
data/lib/chef/provider/batch.rb
CHANGED
@@ -28,6 +28,14 @@ class Chef
|
|
28
28
|
super(new_resource, run_context, '.bat')
|
29
29
|
end
|
30
30
|
|
31
|
+
def command
|
32
|
+
basepath = is_forced_32bit ? wow64_directory : run_context.node.kernel.os_info.system_directory
|
33
|
+
|
34
|
+
interpreter_path = Chef::Util::PathHelper.join(basepath, interpreter)
|
35
|
+
|
36
|
+
"\"#{interpreter_path}\" #{flags} \"#{script_file.path}\""
|
37
|
+
end
|
38
|
+
|
31
39
|
def flags
|
32
40
|
@new_resource.flags.nil? ? '/c' : new_resource.flags + ' /c'
|
33
41
|
end
|
data/lib/chef/provider/deploy.rb
CHANGED
@@ -201,7 +201,7 @@ class Chef
|
|
201
201
|
|
202
202
|
converge_by("execute migration command #{@new_resource.migration_command}") do
|
203
203
|
Chef::Log.info "#{@new_resource} migrating #{@new_resource.user} with environment #{env_info}"
|
204
|
-
|
204
|
+
shell_out!(@new_resource.migration_command,run_options(:cwd=>release_path, :log_level => :info))
|
205
205
|
end
|
206
206
|
end
|
207
207
|
end
|
@@ -221,7 +221,7 @@ class Chef
|
|
221
221
|
else
|
222
222
|
converge_by("restart app using command #{@new_resource.restart_command}") do
|
223
223
|
Chef::Log.info("#{@new_resource} restarting app")
|
224
|
-
|
224
|
+
shell_out!(@new_resource.restart_command,run_options(:cwd=>@new_resource.current_path))
|
225
225
|
end
|
226
226
|
end
|
227
227
|
end
|
@@ -64,7 +64,13 @@ class Chef
|
|
64
64
|
is_parent_writable = lambda do |base_dir|
|
65
65
|
base_dir = ::File.dirname(base_dir)
|
66
66
|
if ::File.exists?(base_dir)
|
67
|
-
Chef::FileAccessControl.writable?(base_dir)
|
67
|
+
if Chef::FileAccessControl.writable?(base_dir)
|
68
|
+
true
|
69
|
+
elsif Chef::Util::PathHelper.is_sip_path?(base_dir, node)
|
70
|
+
Chef::Util::PathHelper.writable_sip_path?(base_dir)
|
71
|
+
else
|
72
|
+
false
|
73
|
+
end
|
68
74
|
else
|
69
75
|
is_parent_writable.call(base_dir)
|
70
76
|
end
|
@@ -74,7 +80,13 @@ class Chef
|
|
74
80
|
# in why run mode & parent directory does not exist no permissions check is required
|
75
81
|
# If not in why run, permissions must be valid and we rely on prior assertion that dir exists
|
76
82
|
if !whyrun_mode? || ::File.exists?(parent_directory)
|
77
|
-
Chef::FileAccessControl.writable?(parent_directory)
|
83
|
+
if Chef::FileAccessControl.writable?(parent_directory)
|
84
|
+
true
|
85
|
+
elsif Chef::Util::PathHelper.is_sip_path?(parent_directory, node)
|
86
|
+
Chef::Util::PathHelper.writable_sip_path?(@new_resource.path)
|
87
|
+
else
|
88
|
+
false
|
89
|
+
end
|
78
90
|
else
|
79
91
|
true
|
80
92
|
end
|
@@ -59,9 +59,7 @@ class Chef
|
|
59
59
|
a.block_action!
|
60
60
|
end
|
61
61
|
requirements.assert(:run) do |a|
|
62
|
-
a.assertion {
|
63
|
-
meta_configuration['RefreshMode'] == 'Disabled'
|
64
|
-
}
|
62
|
+
a.assertion { dsc_refresh_mode_disabled? }
|
65
63
|
err = ["The LCM must have its RefreshMode set to Disabled. "]
|
66
64
|
a.failure_message Chef::Exceptions::ProviderNotFound, err.join(' ')
|
67
65
|
a.whyrun err + ["Assuming a previous resource sets the RefreshMode."]
|
@@ -85,6 +83,10 @@ class Chef
|
|
85
83
|
def supports_dsc_invoke_resource?
|
86
84
|
run_context && Chef::Platform.supports_dsc_invoke_resource?(node)
|
87
85
|
end
|
86
|
+
|
87
|
+
def dsc_refresh_mode_disabled?
|
88
|
+
Chef::Platform.dsc_refresh_mode_disabled?(node)
|
89
|
+
end
|
88
90
|
|
89
91
|
def generate_description
|
90
92
|
@converge_description
|
@@ -153,12 +155,6 @@ class Chef
|
|
153
155
|
cmdlet.run!
|
154
156
|
end
|
155
157
|
|
156
|
-
def meta_configuration
|
157
|
-
cmdlet = Chef::Util::Powershell::Cmdlet.new(node, "Get-DscLocalConfigurationManager", :object)
|
158
|
-
result = cmdlet.run!
|
159
|
-
result.return_value
|
160
|
-
end
|
161
|
-
|
162
158
|
end
|
163
159
|
end
|
164
160
|
end
|
@@ -109,7 +109,7 @@ class Chef
|
|
109
109
|
else
|
110
110
|
# Append is not set so we're resetting the membership of
|
111
111
|
# the group to the given members.
|
112
|
-
members_to_be_added = @new_resource.members
|
112
|
+
members_to_be_added = @new_resource.members.dup
|
113
113
|
@current_resource.members.each do |member|
|
114
114
|
# No need to re-add a member if it's present in the new
|
115
115
|
# list of members
|
@@ -194,7 +194,7 @@ class Chef
|
|
194
194
|
|
195
195
|
private
|
196
196
|
def add_command
|
197
|
-
command = "ifconfig #{@new_resource.device} #{@new_resource.
|
197
|
+
command = "ifconfig #{@new_resource.device} #{@new_resource.target}"
|
198
198
|
command << " netmask #{@new_resource.mask}" if @new_resource.mask
|
199
199
|
command << " metric #{@new_resource.metric}" if @new_resource.metric
|
200
200
|
command << " mtu #{@new_resource.mtu}" if @new_resource.mtu
|
@@ -202,7 +202,7 @@ class Chef
|
|
202
202
|
end
|
203
203
|
|
204
204
|
def enable_command
|
205
|
-
command = "ifconfig #{@new_resource.device} #{@new_resource.
|
205
|
+
command = "ifconfig #{@new_resource.device} #{@new_resource.target}"
|
206
206
|
command << " netmask #{@new_resource.mask}" if @new_resource.mask
|
207
207
|
command << " metric #{@new_resource.metric}" if @new_resource.metric
|
208
208
|
command << " mtu #{@new_resource.mtu}" if @new_resource.mtu
|
data/lib/chef/provider/mount.rb
CHANGED
@@ -42,13 +42,17 @@ class Chef
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def action_mount
|
45
|
-
|
45
|
+
if current_resource.mounted
|
46
|
+
if mount_options_unchanged?
|
47
|
+
Chef::Log.debug("#{new_resource} is already mounted")
|
48
|
+
else
|
49
|
+
action_remount
|
50
|
+
end
|
51
|
+
else
|
46
52
|
converge_by("mount #{current_resource.device} to #{current_resource.mount_point}") do
|
47
53
|
mount_fs
|
48
54
|
Chef::Log.info("#{new_resource} mounted")
|
49
55
|
end
|
50
|
-
else
|
51
|
-
Chef::Log.debug("#{new_resource} is already mounted")
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
@@ -25,8 +25,6 @@ class Chef
|
|
25
25
|
class Provider
|
26
26
|
class Package
|
27
27
|
class Dpkg < Chef::Provider::Package
|
28
|
-
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
|
29
|
-
DPKG_INFO = /([a-z\d\-\+\.]+)\t([\w\d.~:-]+)/
|
30
28
|
DPKG_INSTALLED = /^Status: install ok installed/
|
31
29
|
DPKG_VERSION = /^Version: (.+)$/
|
32
30
|
|
@@ -54,26 +52,22 @@ class Chef
|
|
54
52
|
@source_exists = true
|
55
53
|
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
56
54
|
@current_resource.package_name(@new_resource.package_name)
|
57
|
-
@new_resource.version(nil)
|
58
55
|
|
59
56
|
if @new_resource.source
|
60
57
|
@source_exists = ::File.exists?(@new_resource.source)
|
61
58
|
if @source_exists
|
62
59
|
# Get information from the package if supplied
|
63
60
|
Chef::Log.debug("#{@new_resource} checking dpkg status")
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
@candidate_version = pkginfo[2]
|
70
|
-
end
|
61
|
+
status = shell_out_with_timeout("dpkg-deb -W #{@new_resource.source}")
|
62
|
+
pkginfo = status.stdout.split("\t")
|
63
|
+
unless pkginfo.empty?
|
64
|
+
@current_resource.package_name(pkginfo[0])
|
65
|
+
@candidate_version = pkginfo[1].strip
|
71
66
|
end
|
72
67
|
else
|
73
68
|
# Source provided but not valid means we can't safely do further processing
|
74
69
|
return
|
75
70
|
end
|
76
|
-
|
77
71
|
end
|
78
72
|
|
79
73
|
# Check to see if it is installed
|
@@ -61,7 +61,7 @@ class Chef
|
|
61
61
|
Chef::Log.debug("#{@new_resource} checking rpm status")
|
62
62
|
shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}").stdout.each_line do |line|
|
63
63
|
case line
|
64
|
-
when /^(
|
64
|
+
when /^(\S+)\s(\S+)$/
|
65
65
|
@current_resource.package_name($1)
|
66
66
|
@new_resource.version($2)
|
67
67
|
@candidate_version = $2
|
@@ -78,7 +78,7 @@ class Chef
|
|
78
78
|
@rpm_status = shell_out_with_timeout("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}")
|
79
79
|
@rpm_status.stdout.each_line do |line|
|
80
80
|
case line
|
81
|
-
when /^(
|
81
|
+
when /^(\S+)\s(\S+)$/
|
82
82
|
Chef::Log.debug("#{@new_resource} current version is #{$2}")
|
83
83
|
@current_resource.version($2)
|
84
84
|
end
|
@@ -394,7 +394,7 @@ class Chef
|
|
394
394
|
end
|
395
395
|
|
396
396
|
def is_omnibus?
|
397
|
-
if RbConfig::CONFIG['bindir'] =~ %r!/
|
397
|
+
if RbConfig::CONFIG['bindir'] =~ %r!/(opscode|chef|chefdk)/embedded/bin!
|
398
398
|
Chef::Log.debug("#{@new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}")
|
399
399
|
# Omnibus installs to a static path because of linking on unix, find it.
|
400
400
|
true
|