chef 12.0.3 → 12.1.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +4 -1
- data/README.md +42 -18
- data/distro/common/html/_sources/ctl_chef_client.txt +1 -1
- data/distro/common/html/_sources/ctl_chef_server.txt +53 -35
- data/distro/common/html/_sources/ctl_chef_solo.txt +1 -1
- data/distro/common/html/_sources/knife_bootstrap.txt +1 -1
- data/distro/common/html/_sources/knife_cookbook_site.txt +1 -1
- data/distro/common/html/_sources/knife_data_bag.txt +4 -4
- data/distro/common/html/_sources/knife_status.txt +1 -1
- data/distro/common/html/_static/searchtools.js +1 -1
- data/distro/common/html/ctl_chef_client.html +55 -7
- data/distro/common/html/ctl_chef_server.html +84 -41
- data/distro/common/html/ctl_chef_shell.html +45 -1
- data/distro/common/html/ctl_chef_solo.html +51 -5
- data/distro/common/html/index.html +2 -2
- data/distro/common/html/knife.html +1 -1
- data/distro/common/html/knife_bootstrap.html +30 -10
- data/distro/common/html/knife_cookbook_site.html +2 -0
- data/distro/common/html/knife_data_bag.html +4 -4
- data/distro/common/html/knife_node.html +2 -2
- data/distro/common/html/knife_raw.html +1 -1
- data/distro/common/html/knife_role.html +1 -1
- data/distro/common/html/knife_search.html +3 -3
- data/distro/common/html/knife_status.html +4 -0
- data/distro/common/html/searchindex.js +1 -1
- data/distro/common/man/man1/chef-shell.1 +72 -1
- data/distro/common/man/man1/knife-bootstrap.1 +71 -63
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +4 -1
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +5 -5
- data/distro/common/man/man1/knife-delete.1 +1 -1
- data/distro/common/man/man1/knife-deps.1 +1 -1
- data/distro/common/man/man1/knife-diff.1 +1 -1
- data/distro/common/man/man1/knife-download.1 +1 -1
- data/distro/common/man/man1/knife-edit.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index-rebuild.1 +1 -1
- data/distro/common/man/man1/knife-list.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +3 -3
- data/distro/common/man/man1/knife-raw.1 +2 -2
- data/distro/common/man/man1/knife-recipe-list.1 +1 -1
- data/distro/common/man/man1/knife-role.1 +2 -2
- data/distro/common/man/man1/knife-search.1 +4 -4
- data/distro/common/man/man1/knife-serve.1 +1 -1
- data/distro/common/man/man1/knife-show.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +1 -1
- data/distro/common/man/man1/knife-ssl-check.1 +1 -1
- data/distro/common/man/man1/knife-ssl-fetch.1 +1 -1
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife-upload.1 +1 -1
- data/distro/common/man/man1/knife-user.1 +1 -1
- data/distro/common/man/man1/knife-xargs.1 +1 -1
- data/distro/common/man/man1/knife.1 +1 -1
- data/distro/common/man/man8/chef-apply.8 +86 -0
- data/distro/common/man/man8/chef-client.8 +76 -5
- data/distro/common/man/man8/chef-solo.8 +79 -6
- data/distro/common/markdown/man1/knife-bootstrap.mkd +1 -1
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +1 -1
- data/distro/common/markdown/man1/knife-data-bag.mkd +1 -1
- data/distro/common/markdown/man1/knife-environment.mkd +1 -1
- data/distro/common/markdown/man1/knife.mkd +1 -1
- data/lib/chef.rb +0 -7
- data/lib/chef/api_client.rb +10 -2
- data/lib/chef/api_client/registration.rb +7 -9
- data/lib/chef/application.rb +28 -12
- data/lib/chef/application/apply.rb +17 -1
- data/lib/chef/application/client.rb +74 -6
- data/lib/chef/application/knife.rb +1 -2
- data/lib/chef/application/solo.rb +30 -0
- data/lib/chef/application/windows_service.rb +1 -0
- data/lib/chef/application/windows_service_manager.rb +8 -2
- data/lib/chef/applications.rb +0 -1
- data/lib/chef/audit/audit_event_proxy.rb +93 -0
- data/lib/chef/audit/audit_reporter.rb +169 -0
- data/lib/chef/audit/control_group_data.rb +140 -0
- data/lib/chef/audit/rspec_formatter.rb +37 -0
- data/lib/chef/audit/runner.rb +178 -0
- data/lib/chef/chef_fs/chef_fs_data_store.rb +11 -2
- data/lib/chef/chef_fs/config.rb +25 -4
- data/lib/chef/chef_fs/data_handler/policy_data_handler.rb +15 -0
- data/lib/chef/chef_fs/data_handler/user_data_handler.rb +1 -0
- data/lib/chef/chef_fs/file_system.rb +1 -1
- data/lib/chef/chef_fs/file_system/base_fs_dir.rb +5 -0
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +3 -2
- data/lib/chef/{shef/ext.rb → chef_fs/file_system/chef_repository_file_system_policies_dir.rb} +22 -3
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +4 -0
- data/lib/chef/client.rb +81 -52
- data/lib/chef/config.rb +35 -3
- data/lib/chef/cookbook/metadata.rb +3 -3
- data/lib/chef/cookbook_manifest.rb +275 -0
- data/lib/chef/cookbook_site_streaming_uploader.rb +24 -23
- data/lib/chef/cookbook_uploader.rb +11 -2
- data/lib/chef/cookbook_version.rb +71 -194
- data/lib/chef/data_bag.rb +5 -2
- data/lib/chef/data_bag_item.rb +6 -3
- data/lib/chef/deprecation/warnings.rb +5 -4
- data/lib/chef/dsl/audit.rb +51 -0
- data/lib/chef/dsl/include_recipe.rb +2 -3
- data/lib/chef/dsl/reboot_pending.rb +1 -1
- data/lib/chef/dsl/recipe.rb +49 -31
- data/lib/chef/encrypted_data_bag_item/assertions.rb +0 -3
- data/lib/chef/environment.rb +5 -2
- data/lib/chef/event_dispatch/base.rb +36 -1
- data/lib/chef/event_dispatch/dispatcher.rb +3 -5
- data/lib/chef/exceptions.rb +61 -2
- data/lib/chef/file_access_control/unix.rb +12 -0
- data/lib/chef/file_access_control/windows.rb +14 -0
- data/lib/chef/formatters/doc.rb +47 -1
- data/{spec/unit/monkey_patches/string_spec.rb → lib/chef/guard_interpreter.rb} +11 -16
- data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -2
- data/lib/chef/http.rb +1 -2
- data/lib/chef/knife.rb +5 -3
- data/lib/chef/knife/bootstrap.rb +84 -15
- data/lib/chef/knife/bootstrap/chef_vault_handler.rb +165 -0
- data/lib/chef/knife/bootstrap/client_builder.rb +190 -0
- data/lib/chef/knife/bootstrap/{README.md → templates/README.md} +0 -0
- data/lib/chef/knife/bootstrap/{archlinux-gems.erb → templates/archlinux-gems.erb} +9 -0
- data/lib/chef/knife/bootstrap/{chef-aix.erb → templates/chef-aix.erb} +9 -0
- data/lib/chef/knife/bootstrap/{chef-full.erb → templates/chef-full.erb} +10 -1
- data/lib/chef/knife/client_create.rb +8 -7
- 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_list.rb +1 -1
- data/lib/chef/knife/cookbook_site_search.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +39 -28
- data/lib/chef/knife/cookbook_site_show.rb +3 -3
- data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
- data/lib/chef/knife/cookbook_test.rb +1 -0
- data/lib/chef/knife/cookbook_upload.rb +13 -8
- data/lib/chef/knife/core/bootstrap_context.rb +14 -3
- data/lib/chef/knife/core/generic_presenter.rb +5 -2
- data/lib/chef/knife/core/object_loader.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +24 -0
- data/lib/chef/knife/core/ui.rb +9 -1
- data/lib/chef/knife/node_run_list_remove.rb +11 -3
- data/lib/chef/knife/raw.rb +14 -3
- data/lib/chef/knife/role_env_run_list_add.rb +86 -0
- data/lib/chef/knife/role_env_run_list_clear.rb +55 -0
- data/lib/chef/knife/role_env_run_list_remove.rb +57 -0
- data/lib/chef/knife/role_env_run_list_replace.rb +59 -0
- data/lib/chef/knife/role_env_run_list_set.rb +70 -0
- data/lib/chef/knife/role_run_list_add.rb +86 -0
- data/lib/chef/knife/role_run_list_clear.rb +55 -0
- data/lib/chef/knife/role_run_list_remove.rb +57 -0
- data/lib/chef/knife/role_run_list_replace.rb +59 -0
- data/lib/chef/knife/role_run_list_set.rb +70 -0
- data/lib/chef/knife/search.rb +4 -4
- data/lib/chef/knife/serve.rb +3 -0
- data/lib/chef/knife/ssh.rb +1 -1
- data/lib/chef/knife/ssl_check.rb +2 -2
- data/lib/chef/knife/ssl_fetch.rb +14 -1
- data/lib/chef/log.rb +10 -1
- data/lib/chef/mixin/command.rb +1 -1
- data/lib/chef/mixin/command/windows.rb +1 -5
- data/lib/chef/mixin/get_source_from_package.rb +1 -0
- data/lib/chef/mixin/params_validate.rb +2 -2
- data/lib/chef/mixin/securable.rb +1 -7
- data/lib/chef/mixin/shell_out.rb +7 -1
- data/lib/chef/mixin/template.rb +2 -14
- data/lib/chef/mixin/why_run.rb +1 -1
- data/lib/chef/monkey_patches/net_http.rb +4 -0
- data/lib/chef/monologger.rb +0 -2
- data/lib/chef/node.rb +5 -2
- data/lib/chef/node/attribute.rb +11 -9
- data/lib/chef/node/attribute_collections.rb +8 -12
- data/lib/chef/node/immutable_collections.rb +4 -10
- data/lib/chef/org.rb +148 -0
- data/lib/chef/platform/provider_mapping.rb +3 -2
- data/lib/chef/platform/provider_priority_map.rb +2 -0
- data/lib/chef/platform/query_helpers.rb +0 -3
- data/lib/chef/policy_builder/policyfile.rb +51 -8
- data/lib/chef/provider/deploy.rb +1 -2
- data/lib/chef/provider/directory.rb +3 -3
- data/lib/chef/provider/dsc_script.rb +13 -7
- data/lib/chef/provider/env.rb +8 -8
- data/lib/chef/provider/execute.rb +55 -36
- data/lib/chef/provider/file.rb +8 -0
- data/lib/chef/provider/group.rb +2 -0
- data/lib/chef/provider/group/dscl.rb +3 -4
- data/lib/chef/provider/ifconfig.rb +25 -25
- data/lib/chef/provider/ifconfig/aix.rb +25 -27
- data/lib/chef/provider/lwrp_base.rb +1 -1
- data/lib/chef/provider/mount.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +3 -4
- data/lib/chef/provider/mount/solaris.rb +1 -1
- data/lib/chef/provider/package.rb +297 -48
- data/lib/chef/provider/package/aix.rb +25 -30
- data/lib/chef/provider/package/apt.rb +63 -19
- data/lib/chef/provider/package/dpkg.rb +15 -16
- data/lib/chef/provider/package/macports.rb +7 -7
- data/lib/chef/provider/package/openbsd.rb +107 -0
- data/lib/chef/provider/package/pacman.rb +13 -15
- data/lib/chef/provider/package/portage.rb +3 -4
- data/lib/chef/provider/package/rpm.rb +28 -17
- data/lib/chef/provider/package/rubygems.rb +9 -9
- data/lib/chef/provider/package/solaris.rb +17 -21
- data/lib/chef/provider/package/windows/msi.rb +1 -1
- data/lib/chef/provider/package/yum-dump.py +2 -2
- data/lib/chef/provider/package/yum.rb +117 -51
- data/lib/chef/provider/package/zypper.rb +17 -18
- data/lib/chef/provider/powershell_script.rb +4 -4
- data/lib/chef/provider/registry_key.rb +2 -2
- data/lib/chef/provider/remote_directory.rb +1 -1
- data/lib/chef/provider/script.rb +25 -16
- data/lib/chef/provider/service.rb +1 -1
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/openbsd.rb +216 -0
- data/lib/chef/provider/service/upstart.rb +1 -1
- data/lib/chef/provider/service/windows.rb +99 -1
- data/lib/chef/provider/user.rb +1 -1
- data/lib/chef/provider/user/dscl.rb +19 -4
- data/lib/chef/providers.rb +2 -0
- data/lib/chef/recipe.rb +11 -5
- data/lib/chef/request_id.rb +1 -1
- data/lib/chef/resource.rb +839 -444
- data/lib/chef/resource/chef_gem.rb +20 -3
- data/lib/chef/resource/conditional.rb +3 -14
- data/lib/chef/resource/dsc_script.rb +14 -0
- data/lib/chef/resource/execute.rb +14 -7
- data/lib/chef/resource/file.rb +14 -0
- data/lib/chef/resource/file/verification.rb +122 -0
- data/lib/chef/resource/ips_package.rb +1 -1
- data/lib/chef/resource/lwrp_base.rb +2 -11
- data/lib/chef/resource/macports_package.rb +2 -1
- data/lib/chef/resource/openbsd_package.rb +51 -0
- data/lib/chef/resource/package.rb +2 -2
- data/lib/chef/resource/paludis_package.rb +1 -1
- data/lib/chef/resource/reboot.rb +1 -1
- data/lib/chef/resource/remote_file.rb +1 -0
- data/lib/chef/resource/rpm_package.rb +9 -0
- data/lib/chef/resource/script.rb +11 -0
- data/lib/chef/resource/template.rb +2 -3
- data/lib/chef/resource/windows_package.rb +1 -1
- data/lib/chef/resource/windows_service.rb +18 -0
- data/lib/chef/resource_builder.rb +137 -0
- data/lib/chef/resource_definition.rb +1 -1
- data/lib/chef/resource_reporter.rb +1 -1
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/role.rb +17 -4
- data/lib/chef/run_context.rb +10 -6
- data/lib/chef/search/query.rb +66 -87
- data/lib/chef/shell/ext.rb +2 -2
- data/lib/chef/util/diff.rb +1 -4
- data/lib/chef/util/dsc/configuration_generator.rb +30 -6
- data/lib/chef/util/dsc/lcm_output_parser.rb +7 -3
- data/lib/chef/util/dsc/local_configuration_manager.rb +8 -8
- data/lib/chef/util/file_edit.rb +2 -2
- data/lib/chef/util/path_helper.rb +1 -4
- data/lib/chef/util/windows/net_use.rb +3 -3
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +1 -0
- data/lib/chef/win32/api/security.rb +26 -0
- data/lib/chef/win32/file.rb +21 -0
- data/lib/chef/win32/security.rb +46 -0
- data/lib/chef/win32/security/token.rb +8 -0
- data/lib/chef/win32/version.rb +0 -4
- data/spec/data/recipes.tgz +0 -0
- data/spec/functional/application_spec.rb +1 -1
- data/spec/functional/audit/rspec_formatter_spec.rb +54 -0
- data/spec/functional/audit/runner_spec.rb +137 -0
- data/spec/functional/dsl/reboot_pending_spec.rb +10 -10
- data/spec/functional/dsl/registry_helper_spec.rb +6 -6
- data/spec/functional/event_loggers/windows_eventlog_spec.rb +5 -5
- data/spec/functional/file_content_management/deploy_strategies_spec.rb +12 -21
- data/spec/functional/http/simple_spec.rb +1 -1
- data/spec/functional/knife/cookbook_delete_spec.rb +24 -24
- data/spec/functional/knife/exec_spec.rb +2 -4
- data/spec/functional/knife/smoke_test.rb +1 -1
- data/spec/functional/knife/ssh_spec.rb +23 -23
- data/spec/functional/provider/remote_file/cache_control_data_spec.rb +8 -8
- data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +2 -2
- data/spec/functional/rebooter_spec.rb +1 -1
- data/spec/functional/resource/aix_service_spec.rb +3 -0
- data/spec/functional/resource/aixinit_service_spec.rb +3 -3
- data/spec/functional/resource/bash_spec.rb +88 -0
- data/spec/functional/resource/deploy_revision_spec.rb +99 -100
- data/spec/functional/resource/env_spec.rb +3 -3
- data/spec/functional/resource/execute_spec.rb +97 -63
- data/spec/functional/resource/file_spec.rb +7 -7
- data/spec/functional/resource/git_spec.rb +13 -13
- data/spec/functional/resource/group_spec.rb +28 -25
- data/spec/functional/resource/ifconfig_spec.rb +2 -2
- data/spec/functional/resource/link_spec.rb +77 -78
- data/spec/functional/resource/mount_spec.rb +5 -5
- data/spec/functional/resource/ohai_spec.rb +1 -1
- data/spec/functional/resource/package_spec.rb +22 -22
- data/spec/functional/resource/powershell_spec.rb +57 -42
- data/spec/functional/resource/reboot_spec.rb +2 -2
- data/spec/functional/resource/registry_spec.rb +91 -91
- data/spec/functional/resource/remote_directory_spec.rb +19 -19
- data/spec/functional/resource/remote_file_spec.rb +18 -18
- data/spec/functional/resource/template_spec.rb +4 -4
- data/spec/functional/resource/user/dscl_spec.rb +4 -4
- data/spec/functional/resource/user/useradd_spec.rb +64 -51
- data/spec/functional/resource/windows_service_spec.rb +98 -0
- data/spec/functional/run_lock_spec.rb +9 -9
- data/spec/functional/shell_spec.rb +3 -3
- data/spec/functional/tiny_server_spec.rb +12 -12
- data/spec/functional/util/path_helper_spec.rb +1 -1
- data/spec/functional/version_spec.rb +1 -1
- data/spec/functional/win32/registry_helper_spec.rb +125 -125
- data/spec/functional/win32/security_spec.rb +65 -2
- data/spec/functional/win32/service_manager_spec.rb +30 -84
- data/spec/functional/win32/versions_spec.rb +6 -6
- data/spec/integration/client/client_spec.rb +102 -9
- data/spec/integration/knife/chef_fs_data_store_spec.rb +12 -8
- data/spec/integration/knife/common_options_spec.rb +3 -3
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +2 -2
- data/spec/integration/knife/deps_spec.rb +4 -4
- data/spec/integration/knife/diff_spec.rb +6 -6
- data/spec/integration/knife/download_spec.rb +6 -6
- data/spec/integration/knife/list_spec.rb +2 -2
- data/spec/integration/knife/raw_spec.rb +5 -5
- data/spec/integration/knife/serve_spec.rb +3 -3
- data/spec/integration/knife/show_spec.rb +3 -3
- data/spec/integration/knife/upload_spec.rb +18 -18
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +1 -1
- data/spec/integration/solo/solo_spec.rb +11 -12
- data/spec/spec_helper.rb +27 -15
- data/spec/stress/win32/file_spec.rb +4 -4
- data/spec/stress/win32/security_spec.rb +4 -4
- data/spec/support/chef_helpers.rb +3 -3
- data/spec/support/matchers/leak.rb +2 -2
- data/spec/support/mock/platform.rb +1 -1
- data/spec/support/pedant/Gemfile +3 -0
- data/spec/support/pedant/pedant_config.rb +9 -2
- data/spec/support/pedant/run_pedant.rb +15 -16
- data/spec/support/platform_helpers.rb +8 -12
- data/spec/support/shared/functional/directory_resource.rb +13 -13
- data/spec/support/shared/functional/file_resource.rb +83 -83
- data/spec/support/shared/functional/http.rb +1 -1
- data/spec/support/shared/functional/securable_resource.rb +64 -64
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +43 -41
- data/spec/support/shared/functional/win32_service.rb +60 -0
- data/spec/support/shared/functional/windows_script.rb +8 -8
- data/spec/support/shared/integration/knife_support.rb +8 -5
- data/spec/support/shared/matchers/exit_with_code.rb +6 -2
- data/spec/support/shared/unit/api_error_inspector.rb +8 -8
- data/spec/support/shared/unit/execute_resource.rb +24 -20
- data/spec/support/shared/unit/file_system_support.rb +2 -2
- data/spec/support/shared/unit/platform_introspector.rb +21 -21
- data/spec/support/shared/unit/provider/file.rb +239 -210
- data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +69 -69
- data/spec/support/shared/unit/script_resource.rb +40 -32
- data/spec/support/shared/unit/windows_script_resource.rb +8 -8
- data/spec/unit/api_client/registration_spec.rb +47 -47
- data/spec/unit/api_client_spec.rb +107 -69
- data/spec/unit/application/apply_spec.rb +31 -15
- data/spec/unit/application/client_spec.rb +146 -45
- data/spec/unit/application/knife_spec.rb +31 -31
- data/spec/unit/application/solo_spec.rb +59 -43
- data/spec/unit/application_spec.rb +109 -74
- data/spec/unit/audit/audit_event_proxy_spec.rb +311 -0
- data/spec/unit/audit/audit_reporter_spec.rb +393 -0
- data/spec/unit/audit/control_group_data_spec.rb +478 -0
- data/{lib/chef/monkey_patches/file.rb → spec/unit/audit/rspec_formatter_spec.rb} +11 -8
- data/spec/unit/audit/runner_spec.rb +135 -0
- data/spec/unit/chef_fs/config_spec.rb +52 -0
- data/spec/unit/chef_fs/diff_spec.rb +12 -12
- data/spec/unit/chef_fs/file_pattern_spec.rb +276 -277
- data/spec/unit/chef_fs/file_system/operation_failed_error_spec.rb +6 -6
- data/spec/unit/chef_fs/file_system_spec.rb +26 -13
- data/spec/unit/chef_fs/parallelizer.rb +87 -87
- data/spec/unit/chef_spec.rb +1 -1
- data/spec/unit/client_spec.rb +263 -97
- data/spec/unit/config_fetcher_spec.rb +13 -13
- data/spec/unit/config_spec.rb +105 -66
- data/spec/unit/cookbook/chefignore_spec.rb +6 -6
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +3 -3
- data/spec/unit/cookbook/metadata_spec.rb +149 -149
- data/spec/unit/cookbook/syntax_check_spec.rb +36 -31
- data/spec/unit/cookbook_loader_spec.rb +62 -58
- data/spec/unit/cookbook_manifest_spec.rb +141 -468
- data/spec/unit/cookbook_site_streaming_uploader_spec.rb +27 -27
- data/spec/unit/cookbook_spec.rb +15 -15
- data/spec/unit/cookbook_uploader_spec.rb +37 -3
- data/spec/unit/cookbook_version_file_specificity_spec.rb +554 -0
- data/spec/unit/cookbook_version_spec.rb +98 -240
- data/spec/unit/daemon_spec.rb +31 -31
- data/spec/unit/data_bag_item_spec.rb +121 -89
- data/spec/unit/data_bag_spec.rb +35 -35
- data/spec/unit/deprecation_spec.rb +27 -14
- data/spec/unit/digester_spec.rb +3 -3
- data/spec/unit/dsl/audit_spec.rb +43 -0
- data/spec/unit/dsl/data_query_spec.rb +1 -1
- data/spec/unit/dsl/platform_introspection_spec.rb +14 -14
- data/spec/unit/dsl/reboot_pending_spec.rb +18 -18
- data/spec/unit/dsl/regsitry_helper_spec.rb +6 -6
- data/spec/unit/encrypted_data_bag_item_spec.rb +58 -82
- data/spec/unit/environment_spec.rb +105 -105
- data/spec/unit/exceptions_spec.rb +47 -1
- data/spec/unit/file_access_control_spec.rb +62 -56
- data/spec/unit/file_cache_spec.rb +11 -11
- data/spec/unit/file_content_management/deploy/cp_spec.rb +2 -2
- data/spec/unit/file_content_management/deploy/mv_unix_spec.rb +10 -10
- data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +23 -23
- data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +14 -14
- data/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +12 -12
- data/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb +1 -1
- data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +16 -16
- data/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +4 -4
- data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +103 -13
- data/spec/unit/guard_interpreter_spec.rb +41 -0
- data/spec/unit/handler/json_file_spec.rb +10 -10
- data/spec/unit/handler_spec.rb +39 -39
- data/spec/unit/http/basic_client_spec.rb +3 -3
- data/spec/unit/http/http_request_spec.rb +10 -10
- data/spec/unit/http/simple_spec.rb +3 -3
- data/spec/unit/http/ssl_policies_spec.rb +15 -15
- data/spec/unit/http/validate_content_length_spec.rb +18 -13
- data/spec/unit/http_spec.rb +16 -9
- data/spec/unit/knife/bootstrap/chef_vault_handler_spec.rb +153 -0
- data/spec/unit/knife/bootstrap/client_builder_spec.rb +178 -0
- data/spec/unit/knife/bootstrap_spec.rb +144 -91
- data/spec/unit/knife/client_bulk_delete_spec.rb +24 -24
- data/spec/unit/knife/client_create_spec.rb +57 -43
- data/spec/unit/knife/client_delete_spec.rb +15 -15
- data/spec/unit/knife/client_edit_spec.rb +4 -4
- data/spec/unit/knife/client_list_spec.rb +2 -2
- data/spec/unit/knife/client_reregister_spec.rb +9 -9
- data/spec/unit/knife/configure_client_spec.rb +20 -20
- data/spec/unit/knife/configure_spec.rb +85 -85
- data/spec/unit/knife/cookbook_bulk_delete_spec.rb +15 -15
- data/spec/unit/knife/cookbook_create_spec.rb +59 -59
- data/spec/unit/knife/cookbook_delete_spec.rb +49 -49
- data/spec/unit/knife/cookbook_download_spec.rb +56 -56
- data/spec/unit/knife/cookbook_list_spec.rb +9 -9
- data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +8 -8
- data/spec/unit/knife/cookbook_metadata_spec.rb +44 -44
- data/spec/unit/knife/cookbook_show_spec.rb +29 -29
- data/spec/unit/knife/cookbook_site_download_spec.rb +26 -26
- data/spec/unit/knife/cookbook_site_install_spec.rb +5 -1
- data/spec/unit/knife/cookbook_site_share_spec.rb +68 -59
- data/spec/unit/knife/cookbook_site_unshare_spec.rb +15 -15
- data/spec/unit/knife/cookbook_test_spec.rb +16 -16
- data/spec/unit/knife/cookbook_upload_spec.rb +105 -71
- data/spec/unit/knife/core/bootstrap_context_spec.rb +37 -22
- data/spec/unit/knife/core/cookbook_scm_repo_spec.rb +36 -36
- data/spec/unit/knife/core/object_loader_spec.rb +3 -3
- data/spec/unit/knife/core/subcommand_loader_spec.rb +107 -33
- data/spec/unit/knife/core/ui_spec.rb +84 -72
- data/spec/unit/knife/data_bag_from_file_spec.rb +1 -1
- data/spec/unit/knife/environment_compare_spec.rb +12 -12
- data/spec/unit/knife/environment_create_spec.rb +16 -16
- data/spec/unit/knife/environment_delete_spec.rb +14 -14
- data/spec/unit/knife/environment_edit_spec.rb +15 -15
- data/spec/unit/knife/environment_from_file_spec.rb +17 -17
- data/spec/unit/knife/environment_list_spec.rb +7 -7
- data/spec/unit/knife/environment_show_spec.rb +10 -10
- data/spec/unit/knife/index_rebuild_spec.rb +17 -17
- data/spec/unit/knife/knife_help.rb +24 -24
- data/spec/unit/knife/node_bulk_delete_spec.rb +14 -14
- data/spec/unit/knife/node_delete_spec.rb +11 -11
- data/spec/unit/knife/node_edit_spec.rb +17 -17
- data/spec/unit/knife/node_environment_set_spec.rb +12 -12
- data/spec/unit/knife/node_from_file_spec.rb +8 -8
- data/spec/unit/knife/node_list_spec.rb +9 -9
- data/spec/unit/knife/node_run_list_add_spec.rb +29 -29
- data/spec/unit/knife/node_run_list_remove_spec.rb +28 -13
- data/spec/unit/knife/node_run_list_set_spec.rb +27 -27
- data/spec/unit/knife/raw_spec.rb +43 -0
- data/spec/unit/knife/role_bulk_delete_spec.rb +12 -12
- data/spec/unit/knife/role_create_spec.rb +12 -12
- data/spec/unit/knife/role_delete_spec.rb +10 -10
- data/spec/unit/knife/role_edit_spec.rb +13 -13
- data/spec/unit/knife/role_env_run_list_add_spec.rb +217 -0
- data/spec/unit/knife/role_env_run_list_clear_spec.rb +100 -0
- data/spec/unit/knife/role_env_run_list_remove_spec.rb +108 -0
- data/spec/unit/knife/role_env_run_list_replace_spec.rb +108 -0
- data/spec/unit/knife/role_env_run_list_set_spec.rb +102 -0
- data/spec/unit/knife/role_from_file_spec.rb +10 -10
- data/spec/unit/knife/role_list_spec.rb +7 -7
- data/spec/unit/knife/role_run_list_add_spec.rb +179 -0
- data/spec/unit/knife/role_run_list_clear_spec.rb +90 -0
- data/spec/unit/knife/role_run_list_remove_spec.rb +98 -0
- data/spec/unit/knife/role_run_list_replace_spec.rb +101 -0
- data/spec/unit/knife/role_run_list_set_spec.rb +92 -0
- data/spec/unit/knife/ssh_spec.rb +66 -66
- data/spec/unit/knife/ssl_check_spec.rb +27 -27
- data/spec/unit/knife/ssl_fetch_spec.rb +45 -12
- data/spec/unit/knife/status_spec.rb +5 -5
- data/spec/unit/knife/tag_create_spec.rb +5 -5
- data/spec/unit/knife/tag_delete_spec.rb +6 -6
- data/spec/unit/knife/tag_list_spec.rb +4 -4
- data/spec/unit/knife/user_create_spec.rb +18 -18
- data/spec/unit/knife/user_delete_spec.rb +4 -4
- data/spec/unit/knife/user_edit_spec.rb +7 -7
- data/spec/unit/knife/user_list_spec.rb +2 -2
- data/spec/unit/knife/user_reregister_spec.rb +10 -10
- data/spec/unit/knife/user_show_spec.rb +5 -5
- data/spec/unit/knife_spec.rb +36 -36
- data/spec/unit/lwrp_spec.rb +63 -39
- data/spec/unit/mash_spec.rb +6 -6
- data/spec/unit/mixin/checksum_spec.rb +2 -2
- data/spec/unit/mixin/command_spec.rb +13 -13
- data/spec/unit/mixin/convert_to_class_name_spec.rb +6 -6
- data/spec/unit/mixin/deep_merge_spec.rb +49 -49
- data/spec/unit/mixin/deprecation_spec.rb +5 -5
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +14 -14
- data/spec/unit/mixin/homebrew_user_spec.rb +3 -3
- data/spec/unit/mixin/params_validate_spec.rb +71 -71
- data/spec/unit/mixin/path_sanity_spec.rb +14 -14
- data/spec/unit/mixin/securable_spec.rb +177 -177
- data/spec/unit/mixin/shell_out_spec.rb +56 -27
- data/spec/unit/mixin/template_spec.rb +31 -31
- data/spec/unit/mixin/windows_architecture_helper_spec.rb +5 -5
- data/spec/unit/mixin/xml_escape_spec.rb +7 -7
- data/spec/unit/monkey_patches/uri_spec.rb +1 -1
- data/spec/unit/monologger_spec.rb +3 -3
- data/spec/unit/node/attribute_spec.rb +185 -136
- data/spec/unit/node/immutable_collections_spec.rb +22 -22
- data/spec/unit/node_spec.rb +210 -179
- data/spec/unit/org_spec.rb +196 -0
- data/spec/unit/platform/query_helpers_spec.rb +5 -5
- data/spec/unit/platform_spec.rb +46 -46
- data/spec/unit/policy_builder/expand_node_object_spec.rb +17 -18
- data/spec/unit/policy_builder/policyfile_spec.rb +159 -71
- data/spec/unit/provider/directory_spec.rb +5 -5
- data/spec/unit/provider/dsc_script_spec.rb +6 -6
- data/spec/unit/provider/env_spec.rb +27 -14
- data/spec/unit/provider/execute_spec.rb +139 -68
- data/spec/unit/provider/file/content_spec.rb +8 -8
- data/spec/unit/provider/git_spec.rb +10 -5
- data/spec/unit/provider/group/dscl_spec.rb +8 -11
- data/spec/unit/provider/group_spec.rb +13 -13
- data/spec/unit/provider/ifconfig/aix_spec.rb +3 -2
- data/spec/unit/provider/ifconfig/debian_spec.rb +19 -19
- data/spec/unit/provider/ifconfig_spec.rb +2 -2
- data/spec/unit/provider/mdadm_spec.rb +2 -2
- data/spec/unit/provider/mount/aix_spec.rb +5 -5
- data/spec/unit/provider/mount/mount_spec.rb +22 -22
- data/spec/unit/provider/mount/solaris_spec.rb +20 -20
- data/spec/unit/provider/package/aix_spec.rb +23 -22
- data/spec/unit/provider/package/apt_spec.rb +23 -4
- data/spec/unit/provider/package/dpkg_spec.rb +14 -15
- data/spec/unit/provider/package/freebsd/pkgng_spec.rb +1 -1
- data/spec/unit/provider/package/freebsd/port_spec.rb +1 -1
- data/spec/unit/provider/package/ips_spec.rb +1 -2
- data/spec/unit/provider/package/macports_spec.rb +14 -14
- data/spec/unit/provider/package/openbsd_spec.rb +66 -0
- data/spec/unit/provider/package/pacman_spec.rb +15 -14
- data/spec/unit/provider/package/portage_spec.rb +11 -11
- data/spec/unit/provider/package/rpm_spec.rb +132 -84
- data/spec/unit/provider/package/rubygems_spec.rb +54 -25
- data/spec/unit/provider/package/solaris_spec.rb +22 -25
- data/spec/unit/provider/package/yum_spec.rb +237 -36
- data/spec/unit/provider/package/zypper_spec.rb +9 -12
- data/spec/unit/provider/package_spec.rb +276 -2
- data/spec/unit/provider/package_spec.rbe +0 -0
- data/spec/unit/provider/remote_directory_spec.rb +25 -25
- data/spec/unit/provider/remote_file/ftp_spec.rb +3 -3
- data/spec/unit/provider/route_spec.rb +3 -3
- data/spec/unit/provider/script_spec.rb +61 -43
- data/spec/unit/provider/service/aix_service_spec.rb +5 -5
- data/spec/unit/provider/service/arch_service_spec.rb +5 -5
- data/spec/unit/provider/service/debian_service_spec.rb +8 -8
- data/spec/unit/provider/service/freebsd_service_spec.rb +16 -2
- data/spec/unit/provider/service/gentoo_service_spec.rb +8 -8
- data/spec/unit/provider/service/init_service_spec.rb +5 -5
- data/spec/unit/provider/service/insserv_service_spec.rb +2 -2
- data/spec/unit/provider/service/invokercd_service_spec.rb +5 -5
- data/spec/unit/provider/service/macosx_spec.rb +7 -7
- data/spec/unit/provider/service/openbsd_service_spec.rb +543 -0
- data/spec/unit/provider/service/redhat_spec.rb +4 -4
- data/spec/unit/provider/service/simple_service_spec.rb +2 -2
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +14 -14
- data/spec/unit/provider/service/systemd_service_spec.rb +15 -7
- data/spec/unit/provider/service/upstart_service_spec.rb +4 -4
- data/spec/unit/provider/service/windows_spec.rb +119 -25
- data/spec/unit/provider/service_spec.rb +1 -1
- data/spec/unit/provider/user/dscl_spec.rb +38 -30
- data/spec/unit/provider/user_spec.rb +1 -1
- data/spec/unit/provider_resolver_spec.rb +7 -7
- data/spec/unit/provider_spec.rb +23 -23
- data/spec/unit/recipe_spec.rb +194 -83
- data/spec/unit/registry_helper_spec.rb +143 -143
- data/spec/unit/resource/chef_gem_spec.rb +117 -3
- data/spec/unit/resource/conditional_action_not_nothing_spec.rb +2 -2
- data/spec/unit/resource/conditional_spec.rb +56 -15
- data/spec/unit/resource/deploy_spec.rb +2 -2
- data/spec/unit/resource/dsc_script_spec.rb +32 -0
- data/spec/unit/resource/execute_spec.rb +4 -0
- data/spec/unit/resource/file/verification_spec.rb +111 -0
- data/spec/unit/resource/file_spec.rb +14 -0
- data/spec/unit/resource/openbsd_package_spec.rb +49 -0
- data/spec/unit/resource/remote_file_spec.rb +12 -12
- data/spec/unit/resource/resource_notification_spec.rb +18 -18
- data/spec/unit/resource/rpm_package_spec.rb +12 -0
- data/spec/unit/resource/scm_spec.rb +4 -4
- data/spec/unit/resource/script_spec.rb +3 -5
- data/spec/unit/resource/subversion_spec.rb +1 -1
- data/spec/unit/resource_builder_spec.rb +1 -0
- data/spec/unit/resource_collection/resource_list_spec.rb +2 -2
- data/spec/unit/resource_collection/resource_set_spec.rb +3 -3
- data/spec/unit/resource_collection/stepable_iterator_spec.rb +24 -24
- data/spec/unit/resource_collection_spec.rb +52 -52
- data/spec/unit/resource_definition_spec.rb +1 -1
- data/spec/unit/resource_reporter_spec.rb +118 -118
- data/spec/unit/resource_spec.rb +131 -125
- data/spec/unit/rest/auth_credentials_spec.rb +73 -73
- data/spec/unit/rest_spec.rb +12 -12
- data/spec/unit/role_spec.rb +85 -84
- data/spec/unit/run_context/cookbook_compiler_spec.rb +18 -18
- data/spec/unit/run_context_spec.rb +39 -68
- data/spec/unit/run_list/run_list_expansion_spec.rb +21 -21
- data/spec/unit/run_list/run_list_item_spec.rb +28 -28
- data/spec/unit/run_list/versioned_recipe_list_spec.rb +14 -14
- data/spec/unit/run_list_spec.rb +55 -55
- data/spec/unit/run_lock_spec.rb +14 -14
- data/spec/unit/run_status_spec.rb +24 -24
- data/spec/unit/scan_access_control_spec.rb +23 -23
- data/spec/unit/search/query_spec.rb +54 -66
- data/spec/unit/shell/model_wrapper_spec.rb +13 -13
- data/spec/unit/shell/shell_ext_spec.rb +32 -32
- data/spec/unit/shell/shell_session_spec.rb +24 -24
- data/spec/unit/shell_out_spec.rb +4 -4
- data/spec/unit/shell_spec.rb +27 -27
- data/spec/unit/user_spec.rb +50 -50
- data/spec/unit/util/backup_spec.rb +32 -32
- data/spec/unit/util/diff_spec.rb +31 -31
- data/spec/unit/util/dsc/configuration_generator_spec.rb +38 -16
- data/spec/unit/util/dsc/lcm_output_parser_spec.rb +21 -26
- data/spec/unit/util/dsc/local_configuration_manager_spec.rb +10 -10
- data/spec/unit/util/editor_spec.rb +10 -10
- data/spec/unit/util/file_edit_spec.rb +10 -10
- data/spec/unit/util/path_helper_spec.rb +38 -46
- data/spec/unit/util/powershell/cmdlet_spec.rb +9 -9
- data/spec/unit/util/selinux_spec.rb +30 -30
- data/spec/unit/util/threaded_job_queue_spec.rb +6 -6
- data/spec/unit/version/platform_spec.rb +5 -5
- data/spec/unit/version_class_spec.rb +15 -15
- data/spec/unit/version_constraint/platform_spec.rb +7 -7
- data/spec/unit/version_constraint_spec.rb +43 -43
- data/spec/unit/windows_service_spec.rb +15 -15
- data/spec/unit/workstation_config_loader_spec.rb +2 -2
- data/tasks/rspec.rb +16 -18
- metadata +126 -53
- data/bin/chef-service-manager +0 -37
- data/bin/chef-windows-service +0 -35
- data/bin/shef +0 -35
- data/lib/chef/application/agent.rb +0 -18
- data/lib/chef/monkey_patches/fileutils.rb +0 -65
- data/lib/chef/monkey_patches/numeric.rb +0 -15
- data/lib/chef/monkey_patches/object.rb +0 -9
- data/lib/chef/monkey_patches/pathname.rb +0 -32
- data/lib/chef/monkey_patches/regexp.rb +0 -34
- data/lib/chef/monkey_patches/securerandom.rb +0 -44
- data/lib/chef/monkey_patches/string.rb +0 -49
- data/lib/chef/monkey_patches/tempfile.rb +0 -64
- data/lib/chef/monkey_patches/uri.rb +0 -70
data/lib/chef/provider/user.rb
CHANGED
@@ -67,7 +67,7 @@ class Chef
|
|
67
67
|
@current_resource.shell(user_info.shell)
|
68
68
|
@current_resource.password(user_info.passwd)
|
69
69
|
|
70
|
-
if @new_resource.comment
|
70
|
+
if @new_resource.comment
|
71
71
|
user_info.gecos.force_encoding(@new_resource.comment.encoding)
|
72
72
|
end
|
73
73
|
@current_resource.comment(user_info.gecos)
|
@@ -39,7 +39,7 @@ class Chef
|
|
39
39
|
# > 10.7 => password shadow calculation format SALTED-SHA512-PBKDF2
|
40
40
|
# => stored in: /var/db/dslocal/nodes/Default/users/#{name}.plist
|
41
41
|
# => shadow binary length 128 bytes
|
42
|
-
# => Salt / Iterations are stored
|
42
|
+
# => Salt / Iterations are stored separately in the same file
|
43
43
|
#
|
44
44
|
# This provider only supports Mac OSX versions 10.7 and above
|
45
45
|
class Dscl < Chef::Provider::User
|
@@ -239,8 +239,18 @@ user password using shadow hash.")
|
|
239
239
|
#
|
240
240
|
def uid_used?(uid)
|
241
241
|
return false unless uid
|
242
|
-
users_uids = run_dscl("list /Users uid")
|
243
|
-
|
242
|
+
users_uids = run_dscl("list /Users uid").split("\n")
|
243
|
+
uid_map = users_uids.inject({}) do |tmap, tuid|
|
244
|
+
x = tuid.split
|
245
|
+
tmap[x[1]] = x[0]
|
246
|
+
tmap
|
247
|
+
end
|
248
|
+
if uid_map[uid.to_s]
|
249
|
+
unless uid_map[uid.to_s] == @new_resource.username.to_s
|
250
|
+
return true
|
251
|
+
end
|
252
|
+
end
|
253
|
+
return false
|
244
254
|
end
|
245
255
|
|
246
256
|
#
|
@@ -504,6 +514,11 @@ user password using shadow hash.")
|
|
504
514
|
# password to be updated.
|
505
515
|
return true if salted_sha512?(@current_resource.password)
|
506
516
|
|
517
|
+
# Some system users don't have salts; this can happen if the system is
|
518
|
+
# upgraded and the user hasn't logged in yet. In this case, we will force
|
519
|
+
# the password to be updated.
|
520
|
+
return true if @current_resource.salt.nil?
|
521
|
+
|
507
522
|
if salted_sha512_pbkdf2?(@new_resource.password)
|
508
523
|
diverged?(:password) || diverged?(:salt) || diverged?(:iterations)
|
509
524
|
else
|
@@ -535,7 +550,7 @@ user password using shadow hash.")
|
|
535
550
|
|
536
551
|
# A simple map of Chef's terms to DSCL's terms.
|
537
552
|
DSCL_PROPERTY_MAP = {
|
538
|
-
:uid => "
|
553
|
+
:uid => "uid",
|
539
554
|
:gid => "gid",
|
540
555
|
:home => "home",
|
541
556
|
:shell => "shell",
|
data/lib/chef/providers.rb
CHANGED
@@ -63,6 +63,7 @@ require 'chef/provider/package/freebsd/pkgng'
|
|
63
63
|
require 'chef/provider/package/homebrew'
|
64
64
|
require 'chef/provider/package/ips'
|
65
65
|
require 'chef/provider/package/macports'
|
66
|
+
require 'chef/provider/package/openbsd'
|
66
67
|
require 'chef/provider/package/pacman'
|
67
68
|
require 'chef/provider/package/portage'
|
68
69
|
require 'chef/provider/package/paludis'
|
@@ -80,6 +81,7 @@ require 'chef/provider/service/gentoo'
|
|
80
81
|
require 'chef/provider/service/init'
|
81
82
|
require 'chef/provider/service/invokercd'
|
82
83
|
require 'chef/provider/service/debian'
|
84
|
+
require 'chef/provider/service/openbsd'
|
83
85
|
require 'chef/provider/service/redhat'
|
84
86
|
require 'chef/provider/service/insserv'
|
85
87
|
require 'chef/provider/service/simple'
|
data/lib/chef/recipe.rb
CHANGED
@@ -24,6 +24,7 @@ require 'chef/dsl/platform_introspection'
|
|
24
24
|
require 'chef/dsl/include_recipe'
|
25
25
|
require 'chef/dsl/registry_helper'
|
26
26
|
require 'chef/dsl/reboot_pending'
|
27
|
+
require 'chef/dsl/audit'
|
27
28
|
|
28
29
|
require 'chef/mixin/from_file'
|
29
30
|
|
@@ -40,6 +41,7 @@ class Chef
|
|
40
41
|
include Chef::DSL::Recipe
|
41
42
|
include Chef::DSL::RegistryHelper
|
42
43
|
include Chef::DSL::RebootPending
|
44
|
+
include Chef::DSL::Audit
|
43
45
|
|
44
46
|
include Chef::Mixin::FromFile
|
45
47
|
include Chef::Mixin::Deprecation
|
@@ -52,12 +54,16 @@ class Chef
|
|
52
54
|
# For example:
|
53
55
|
# "aws::elastic_ip" returns [:aws, "elastic_ip"]
|
54
56
|
# "aws" returns [:aws, "default"]
|
57
|
+
# "::elastic_ip" returns [ current_cookbook, "elastic_ip" ]
|
55
58
|
#--
|
56
59
|
# TODO: Duplicates functionality of RunListItem
|
57
|
-
def self.parse_recipe_name(recipe_name)
|
58
|
-
|
59
|
-
|
60
|
-
[
|
60
|
+
def self.parse_recipe_name(recipe_name, current_cookbook: nil)
|
61
|
+
case recipe_name
|
62
|
+
when /(.+?)::(.+)/
|
63
|
+
[ $1.to_sym, $2 ]
|
64
|
+
when /^::(.+)/
|
65
|
+
raise "current_cookbook is nil, cannot resolve #{recipe_name}" if current_cookbook.nil?
|
66
|
+
[ current_cookbook.to_sym, $1 ]
|
61
67
|
else
|
62
68
|
[ recipe_name.to_sym, "default" ]
|
63
69
|
end
|
@@ -82,7 +88,7 @@ class Chef
|
|
82
88
|
run_context.resource_collection.find(*args)
|
83
89
|
end
|
84
90
|
|
85
|
-
# This was moved to Chef::Node#tag, redirecting here for
|
91
|
+
# This was moved to Chef::Node#tag, redirecting here for compatibility
|
86
92
|
def tag(*tags)
|
87
93
|
run_context.node.tag(*tags)
|
88
94
|
end
|
data/lib/chef/request_id.rb
CHANGED
data/lib/chef/resource.rb
CHANGED
@@ -38,37 +38,649 @@ require 'chef/mixin/descendants_tracker'
|
|
38
38
|
class Chef
|
39
39
|
class Resource
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
#
|
42
|
+
# Generic User DSL (not resource-specific)
|
43
|
+
#
|
44
|
+
|
45
|
+
include Chef::DSL::DataQuery
|
46
|
+
include Chef::DSL::PlatformIntrospection
|
47
|
+
include Chef::DSL::RegistryHelper
|
48
|
+
include Chef::DSL::RebootPending
|
49
|
+
|
50
|
+
#
|
51
|
+
# The node the current Chef run is using.
|
52
|
+
#
|
53
|
+
# Corresponds to `run_context.node`.
|
54
|
+
#
|
55
|
+
# @return [Chef::Node] The node the current Chef run is using.
|
56
|
+
#
|
57
|
+
def node
|
58
|
+
run_context && run_context.node
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Find existing resources by searching the list of existing resources. Possible
|
63
|
+
# forms are:
|
64
|
+
#
|
65
|
+
# find(:file => "foobar")
|
66
|
+
# find(:file => [ "foobar", "baz" ])
|
67
|
+
# find("file[foobar]", "file[baz]")
|
68
|
+
# find("file[foobar,baz]")
|
69
|
+
#
|
70
|
+
# Calls `run_context.resource_collection.find(*args)`
|
71
|
+
#
|
72
|
+
# @return the matching resource, or an Array of matching resources.
|
73
|
+
#
|
74
|
+
# @raise ArgumentError if you feed it bad lookup information
|
75
|
+
# @raise RuntimeError if it can't find the resources you are looking for.
|
76
|
+
#
|
77
|
+
def resources(*args)
|
78
|
+
run_context.resource_collection.find(*args)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#
|
83
|
+
# Resource User Interface (for users)
|
84
|
+
#
|
85
|
+
|
86
|
+
#
|
87
|
+
# Create a new Resource.
|
88
|
+
#
|
89
|
+
# @param name The name of this resource (corresponds to the #name attribute,
|
90
|
+
# used for notifications to this resource).
|
91
|
+
# @param run_context The context of the Chef run. Corresponds to #run_context.
|
92
|
+
#
|
93
|
+
def initialize(name, run_context=nil)
|
94
|
+
name(name)
|
95
|
+
@run_context = run_context
|
96
|
+
@noop = nil
|
97
|
+
@before = nil
|
98
|
+
@params = Hash.new
|
99
|
+
@provider = nil
|
100
|
+
@allowed_actions = [ :nothing ]
|
101
|
+
@action = :nothing
|
102
|
+
@updated = false
|
103
|
+
@updated_by_last_action = false
|
104
|
+
@supports = {}
|
105
|
+
@ignore_failure = false
|
106
|
+
@retries = 0
|
107
|
+
@retry_delay = 2
|
108
|
+
@not_if = []
|
109
|
+
@only_if = []
|
110
|
+
@source_line = nil
|
111
|
+
# We would like to raise an error when the user gives us a guard
|
112
|
+
# interpreter and a ruby_block to the guard. In order to achieve this
|
113
|
+
# we need to understand when the user overrides the default guard
|
114
|
+
# interpreter. Therefore we store the default separately in a different
|
115
|
+
# attribute.
|
116
|
+
@guard_interpreter = nil
|
117
|
+
@default_guard_interpreter = :default
|
118
|
+
@elapsed_time = 0
|
119
|
+
@sensitive = false
|
120
|
+
end
|
121
|
+
|
122
|
+
#
|
123
|
+
# The name of this particular resource.
|
124
|
+
#
|
125
|
+
# This special resource attribute is set automatically from the declaration
|
126
|
+
# of the resource, e.g.
|
127
|
+
#
|
128
|
+
# execute 'Vitruvius' do
|
129
|
+
# command 'ls'
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
# Will set the name to "Vitruvius".
|
133
|
+
#
|
134
|
+
# This is also used in to_s to show the resource name, e.g. `execute[Vitruvius]`.
|
135
|
+
#
|
136
|
+
# This is also used for resource notifications and subscribes in the same manner.
|
137
|
+
#
|
138
|
+
# This will coerce any object into a string via #to_s. Arrays are a special case
|
139
|
+
# so that `package ["foo", "bar"]` becomes package[foo, bar] instead of the more
|
140
|
+
# awkward `package[["foo", "bar"]]` that #to_s would produce.
|
141
|
+
#
|
142
|
+
# @param name [Object] The name to set, typically a String or Array
|
143
|
+
# @return [String] The name of this Resource.
|
144
|
+
#
|
145
|
+
def name(name=nil)
|
146
|
+
if !name.nil?
|
147
|
+
if name.is_a?(Array)
|
148
|
+
@name = name.join(', ')
|
149
|
+
else
|
150
|
+
@name = name.to_s
|
151
|
+
end
|
152
|
+
end
|
153
|
+
@name
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# The action or actions that will be taken when this resource is run.
|
158
|
+
#
|
159
|
+
# @param arg [Array[Symbol], Symbol] A list of actions (e.g. `:create`)
|
160
|
+
# @return [Array[Symbol]] the list of actions.
|
161
|
+
#
|
162
|
+
def action(arg=nil)
|
163
|
+
if arg
|
164
|
+
action_list = arg.kind_of?(Array) ? arg : [ arg ]
|
165
|
+
action_list = action_list.collect { |a| a.to_sym }
|
166
|
+
action_list.each do |action|
|
167
|
+
validate(
|
168
|
+
{ action: action },
|
169
|
+
{ action: { kind_of: Symbol, equal_to: @allowed_actions } }
|
170
|
+
)
|
171
|
+
end
|
172
|
+
@action = action_list
|
173
|
+
else
|
174
|
+
@action
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
#
|
179
|
+
# Sets up a notification that will run a particular action on another resource
|
180
|
+
# if and when *this* resource is updated by an action.
|
181
|
+
#
|
182
|
+
# If the action does nothing--does not update this resource, the
|
183
|
+
# notification never triggers.)
|
184
|
+
#
|
185
|
+
# Only one resource may be specified per notification.
|
186
|
+
#
|
187
|
+
# `delayed` notifications will only *ever* happen once per resource, so if
|
188
|
+
# multiple resources all notify a single resource to perform the same action,
|
189
|
+
# the action will only happen once. However, if they ask for different
|
190
|
+
# actions, each action will happen once, in the order they were updated.
|
191
|
+
#
|
192
|
+
# `immediate` notifications will cause the action to be triggered once per
|
193
|
+
# notification, regardless of how many other resources have triggered the
|
194
|
+
# notification as well.
|
195
|
+
#
|
196
|
+
# @param action The action to run on the other resource.
|
197
|
+
# @param resource_spec [String, Hash, Chef::Resource] The resource to run.
|
198
|
+
# @param timing [String, Symbol] When to notify. Has these values:
|
199
|
+
# - `delayed`: Will run the action on the other resource after all other
|
200
|
+
# actions have been run. This is the default.
|
201
|
+
# - `immediate`, `immediately`: Will run the action on the other resource
|
202
|
+
# immediately (before any other action is run).
|
203
|
+
#
|
204
|
+
# @example Resource by string
|
205
|
+
# file '/foo.txt' do
|
206
|
+
# content 'hi'
|
207
|
+
# notifies :create, 'file[/bar.txt]'
|
208
|
+
# end
|
209
|
+
# file '/bar.txt' do
|
210
|
+
# action :nothing
|
211
|
+
# content 'hi'
|
212
|
+
# end
|
213
|
+
# @example Resource by hash
|
214
|
+
# file '/foo.txt' do
|
215
|
+
# content 'hi'
|
216
|
+
# notifies :create, file: '/bar.txt'
|
217
|
+
# end
|
218
|
+
# file '/bar.txt' do
|
219
|
+
# action :nothing
|
220
|
+
# content 'hi'
|
221
|
+
# end
|
222
|
+
# @example Direct Resource
|
223
|
+
# bar = file '/bar.txt' do
|
224
|
+
# action :nothing
|
225
|
+
# content 'hi'
|
226
|
+
# end
|
227
|
+
# file '/foo.txt' do
|
228
|
+
# content 'hi'
|
229
|
+
# notifies :create, bar
|
230
|
+
# end
|
231
|
+
#
|
232
|
+
def notifies(action, resource_spec, timing=:delayed)
|
233
|
+
# when using old-style resources(:template => "/foo.txt") style, you
|
234
|
+
# could end up with multiple resources.
|
235
|
+
validate_resource_spec!(resource_spec)
|
236
|
+
|
237
|
+
resources = [ resource_spec ].flatten
|
238
|
+
resources.each do |resource|
|
239
|
+
|
240
|
+
case timing.to_s
|
241
|
+
when 'delayed'
|
242
|
+
notifies_delayed(action, resource)
|
243
|
+
when 'immediate', 'immediately'
|
244
|
+
notifies_immediately(action, resource)
|
245
|
+
else
|
246
|
+
raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} "\
|
247
|
+
"Valid timings are: :delayed, :immediate, :immediately"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
true
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# Subscribes to updates from other resources, causing a particular action to
|
256
|
+
# run on *this* resource when the other resource is updated.
|
257
|
+
#
|
258
|
+
# If multiple resources are specified, this resource action will be run if
|
259
|
+
# *any* of them change.
|
260
|
+
#
|
261
|
+
# This notification will only trigger *once*, no matter how many other
|
262
|
+
# resources are updated (or how many actions are run by a particular resource).
|
263
|
+
#
|
264
|
+
# @param action The action to run on the other resource.
|
265
|
+
# @param resources [String, Resource, Array[String, Resource]] The resources to subscribe to.
|
266
|
+
# @param timing [String, Symbol] When to notify. Has these values:
|
267
|
+
# - `delayed`: An update will cause the action to run after all other
|
268
|
+
# actions have been run. This is the default.
|
269
|
+
# - `immediate`, `immediately`: The action will run immediately following
|
270
|
+
# the other resource being updated.
|
271
|
+
#
|
272
|
+
# @example Resources by string
|
273
|
+
# file '/foo.txt' do
|
274
|
+
# content 'hi'
|
275
|
+
# action :nothing
|
276
|
+
# subscribes :create, 'file[/bar.txt]'
|
277
|
+
# end
|
278
|
+
# file '/bar.txt' do
|
279
|
+
# content 'hi'
|
280
|
+
# end
|
281
|
+
# @example Direct resource
|
282
|
+
# bar = file '/bar.txt' do
|
283
|
+
# content 'hi'
|
284
|
+
# end
|
285
|
+
# file '/foo.txt' do
|
286
|
+
# content 'hi'
|
287
|
+
# action :nothing
|
288
|
+
# subscribes :create, '/bar.txt'
|
289
|
+
# end
|
290
|
+
# @example Multiple resources by string
|
291
|
+
# file '/foo.txt' do
|
292
|
+
# content 'hi'
|
293
|
+
# action :nothing
|
294
|
+
# subscribes :create, [ 'file[/bar.txt]', 'file[/baz.txt]' ]
|
295
|
+
# end
|
296
|
+
# file '/bar.txt' do
|
297
|
+
# content 'hi'
|
298
|
+
# end
|
299
|
+
# file '/baz.txt' do
|
300
|
+
# content 'hi'
|
301
|
+
# end
|
302
|
+
# @example Multiple resources
|
303
|
+
# bar = file '/bar.txt' do
|
304
|
+
# content 'hi'
|
305
|
+
# end
|
306
|
+
# baz = file '/bar.txt' do
|
307
|
+
# content 'hi'
|
308
|
+
# end
|
309
|
+
# file '/foo.txt' do
|
310
|
+
# content 'hi'
|
311
|
+
# action :nothing
|
312
|
+
# subscribes :create, [ bar, baz ]
|
313
|
+
# end
|
314
|
+
#
|
315
|
+
def subscribes(action, resources, timing=:delayed)
|
316
|
+
resources = [resources].flatten
|
317
|
+
resources.each do |resource|
|
318
|
+
if resource.is_a?(String)
|
319
|
+
resource = Chef::Resource.new(resource, run_context)
|
320
|
+
end
|
321
|
+
if resource.run_context.nil?
|
322
|
+
resource.run_context = run_context
|
323
|
+
end
|
324
|
+
resource.notifies(action, self, timing)
|
325
|
+
end
|
326
|
+
true
|
327
|
+
end
|
328
|
+
|
329
|
+
#
|
330
|
+
# A command or block that indicates whether to actually run this resource.
|
331
|
+
# The command or block is run just before the action actually executes, and
|
332
|
+
# the action will be skipped if the block returns false.
|
333
|
+
#
|
334
|
+
# If a block is specified, it must return `true` in order for the Resource
|
335
|
+
# to be executed.
|
336
|
+
#
|
337
|
+
# If a command is specified, the resource's #guard_interpreter will run the
|
338
|
+
# command and interpret the results according to `opts`. For example, the
|
339
|
+
# default `execute` resource will be treated as `false` if the command
|
340
|
+
# returns a non-zero exit code, and `true` if it returns 0. Thus, in the
|
341
|
+
# default case:
|
342
|
+
#
|
343
|
+
# - `only_if "your command"` will perform the action only if `your command`
|
344
|
+
# returns 0.
|
345
|
+
# - `only_if "your command", valid_exit_codes: [ 1, 2, 3 ]` will perform the
|
346
|
+
# action only if `your command` returns 1, 2, or 3.
|
347
|
+
#
|
348
|
+
# @param command [String] A string to execute.
|
349
|
+
# @param opts [Hash] Options control the execution of the command
|
350
|
+
# @param block [Proc] A ruby block to run. Ignored if a command is given.
|
351
|
+
#
|
352
|
+
def only_if(command=nil, opts={}, &block)
|
353
|
+
if command || block_given?
|
354
|
+
@only_if << Conditional.only_if(self, command, opts, &block)
|
355
|
+
end
|
356
|
+
@only_if
|
357
|
+
end
|
358
|
+
|
359
|
+
#
|
360
|
+
# A command or block that indicates whether to actually run this resource.
|
361
|
+
# The command or block is run just before the action actually executes, and
|
362
|
+
# the action will be skipped if the block returns true.
|
363
|
+
#
|
364
|
+
# If a block is specified, it must return `false` in order for the Resource
|
365
|
+
# to be executed.
|
366
|
+
#
|
367
|
+
# If a command is specified, the resource's #guard_interpreter will run the
|
368
|
+
# command and interpret the results according to `opts`. For example, the
|
369
|
+
# default `execute` resource will be treated as `false` if the command
|
370
|
+
# returns a non-zero exit code, and `true` if it returns 0. Thus, in the
|
371
|
+
# default case:
|
372
|
+
#
|
373
|
+
# - `not_if "your command"` will perform the action only if `your command`
|
374
|
+
# returns a non-zero code.
|
375
|
+
# - `only_if "your command", valid_exit_codes: [ 1, 2, 3 ]` will perform the
|
376
|
+
# action only if `your command` returns something other than 1, 2, or 3.
|
377
|
+
#
|
378
|
+
# @param command [String] A string to execute.
|
379
|
+
# @param opts [Hash] Options control the execution of the command
|
380
|
+
# @param block [Proc] A ruby block to run. Ignored if a command is given.
|
381
|
+
#
|
382
|
+
def not_if(command=nil, opts={}, &block)
|
383
|
+
if command || block_given?
|
384
|
+
@not_if << Conditional.not_if(self, command, opts, &block)
|
385
|
+
end
|
386
|
+
@not_if
|
387
|
+
end
|
388
|
+
|
389
|
+
#
|
390
|
+
# The number of times to retry this resource if it fails by throwing an
|
391
|
+
# exception while running an action. Default: 0
|
392
|
+
#
|
393
|
+
# When the retries have run out, the Resource will throw the last
|
394
|
+
# exception.
|
395
|
+
#
|
396
|
+
# @param arg [Integer] The number of retries.
|
397
|
+
# @return [Integer] The number of retries.
|
398
|
+
#
|
399
|
+
def retries(arg=nil)
|
400
|
+
set_or_return(:retries, arg, kind_of: Integer)
|
401
|
+
end
|
402
|
+
attr_writer :retries
|
403
|
+
|
404
|
+
#
|
405
|
+
# The number of seconds to wait between retries. Default: 2.
|
406
|
+
#
|
407
|
+
# @param arg [Integer] The number of seconds to wait between retries.
|
408
|
+
# @return [Integer] The number of seconds to wait between retries.
|
409
|
+
#
|
410
|
+
def retry_delay(arg=nil)
|
411
|
+
set_or_return(:retry_delay, arg, kind_of: Integer)
|
412
|
+
end
|
413
|
+
attr_writer :retry_delay
|
414
|
+
|
415
|
+
#
|
416
|
+
# Whether to treat this resource's data as sensitive. If set, no resource
|
417
|
+
# data will be displayed in log output.
|
418
|
+
#
|
419
|
+
# @param arg [Boolean] Whether this resource is sensitive or not.
|
420
|
+
# @return [Boolean] Whether this resource is sensitive or not.
|
421
|
+
#
|
422
|
+
def sensitive(arg=nil)
|
423
|
+
set_or_return(:sensitive, arg, :kind_of => [ TrueClass, FalseClass ])
|
424
|
+
end
|
425
|
+
attr_writer :sensitive
|
426
|
+
|
427
|
+
# ??? TODO unreferenced. Delete?
|
428
|
+
attr_reader :not_if_args
|
429
|
+
# ??? TODO unreferenced. Delete?
|
430
|
+
attr_reader :only_if_args
|
431
|
+
|
432
|
+
#
|
433
|
+
# The time it took (in seconds) to run the most recently-run action. Not
|
434
|
+
# cumulative across actions. This is set to 0 as soon as a new action starts
|
435
|
+
# running, and set to the elapsed time at the end of the action.
|
436
|
+
#
|
437
|
+
# @return [Integer] The time (in seconds) it took to process the most recent
|
438
|
+
# action. Not cumulative.
|
439
|
+
#
|
440
|
+
attr_reader :elapsed_time
|
441
|
+
|
442
|
+
#
|
443
|
+
# The guard interpreter that will be used to process `only_if` and `not_if`
|
444
|
+
# statements. If left unset, the #default_guard_interpreter will be used.
|
445
|
+
#
|
446
|
+
# Must be a resource class like `Chef::Resource::Execute`, or
|
447
|
+
# a corresponding to the name of a resource. The resource must descend from
|
448
|
+
# `Chef::Resource::Execute`.
|
449
|
+
#
|
450
|
+
# TODO this needs to be coerced on input so that retrieval is consistent.
|
451
|
+
#
|
452
|
+
# @param arg [Class, Symbol, String] The Guard interpreter resource class/
|
453
|
+
# symbol/name.
|
454
|
+
# @return [Class, Symbol, String] The Guard interpreter resource.
|
455
|
+
#
|
456
|
+
def guard_interpreter(arg=nil)
|
457
|
+
if arg.nil?
|
458
|
+
@guard_interpreter || @default_guard_interpreter
|
459
|
+
else
|
460
|
+
set_or_return(:guard_interpreter, arg, :kind_of => Symbol)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
#
|
465
|
+
# Get the value of the state attributes in this resource as a hash.
|
466
|
+
#
|
467
|
+
# @return [Hash{Symbol => Object}] A Hash of attribute => value for the
|
468
|
+
# Resource class's `state_attrs`.
|
469
|
+
def state
|
470
|
+
self.class.state_attrs.inject({}) do |state_attrs, attr_name|
|
471
|
+
state_attrs[attr_name] = send(attr_name)
|
472
|
+
state_attrs
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
#
|
477
|
+
# The value of the identity attribute, if declared. Falls back to #name if
|
478
|
+
# no identity attribute is declared.
|
479
|
+
#
|
480
|
+
# @return The value of the identity attribute.
|
481
|
+
#
|
482
|
+
def identity
|
483
|
+
if identity_attr = self.class.identity_attr
|
484
|
+
send(identity_attr)
|
485
|
+
else
|
486
|
+
name
|
487
|
+
end
|
488
|
+
end
|
489
|
+
|
490
|
+
#
|
491
|
+
# Whether to ignore failures. If set to `true`, and this resource when an
|
492
|
+
# action is run, the resource will be marked as failed but no exception will
|
493
|
+
# be thrown (and no error will be output). Defaults to `false`.
|
494
|
+
#
|
495
|
+
# TODO ignore_failure and retries seem to be mutually exclusive; I doubt
|
496
|
+
# that was intended.
|
497
|
+
#
|
498
|
+
# @param arg [Boolean] Whether to ignore failures.
|
499
|
+
# @return Whether this resource will ignore failures.
|
500
|
+
#
|
501
|
+
def ignore_failure(arg=nil)
|
502
|
+
set_or_return(:ignore_failure, arg, kind_of: [ TrueClass, FalseClass ])
|
503
|
+
end
|
504
|
+
attr_writer :ignore_failure
|
505
|
+
|
506
|
+
#
|
507
|
+
# Equivalent to #ignore_failure.
|
508
|
+
#
|
509
|
+
def epic_fail(arg=nil)
|
510
|
+
ignore_failure(arg)
|
511
|
+
end
|
512
|
+
|
513
|
+
#
|
514
|
+
# Make this resource into an exact (shallow) copy of the other resource.
|
515
|
+
#
|
516
|
+
# @param resource [Chef::Resource] The resource to copy from.
|
517
|
+
#
|
518
|
+
def load_from(resource)
|
519
|
+
resource.instance_variables.each do |iv|
|
520
|
+
unless iv == :@source_line || iv == :@action || iv == :@not_if || iv == :@only_if
|
521
|
+
self.instance_variable_set(iv, resource.instance_variable_get(iv))
|
522
|
+
end
|
523
|
+
end
|
524
|
+
end
|
525
|
+
|
526
|
+
#
|
527
|
+
# Runs the given action on this resource, immediately.
|
528
|
+
#
|
529
|
+
# @param action The action to run (e.g. `:create`)
|
530
|
+
# @param notification_type The notification type that triggered this (if any)
|
531
|
+
# @param notifying_resource The resource that triggered this notification (if any)
|
532
|
+
#
|
533
|
+
# @raise Any error that occurs during the actual action.
|
534
|
+
#
|
535
|
+
def run_action(action, notification_type=nil, notifying_resource=nil)
|
536
|
+
# reset state in case of multiple actions on the same resource.
|
537
|
+
@elapsed_time = 0
|
538
|
+
start_time = Time.now
|
539
|
+
events.resource_action_start(self, action, notification_type, notifying_resource)
|
540
|
+
# Try to resolve lazy/forward references in notifications again to handle
|
541
|
+
# the case where the resource was defined lazily (ie. in a ruby_block)
|
542
|
+
resolve_notification_references
|
543
|
+
validate_action(action)
|
544
|
+
|
545
|
+
if Chef::Config[:verbose_logging] || Chef::Log.level == :debug
|
546
|
+
# This can be noisy
|
547
|
+
Chef::Log.info("Processing #{self} action #{action} (#{defined_at})")
|
548
|
+
end
|
549
|
+
|
550
|
+
# ensure that we don't leave @updated_by_last_action set to true
|
551
|
+
# on accident
|
552
|
+
updated_by_last_action(false)
|
553
|
+
|
554
|
+
# Don't modify @retries directly and keep it intact, so that the
|
555
|
+
# recipe_snippet from ResourceFailureInspector can print the value
|
556
|
+
# that was set in the resource block initially.
|
557
|
+
remaining_retries = retries
|
558
|
+
|
559
|
+
begin
|
560
|
+
return if should_skip?(action)
|
561
|
+
provider_for_action(action).run_action
|
562
|
+
rescue Exception => e
|
563
|
+
if ignore_failure
|
564
|
+
Chef::Log.error("#{custom_exception_message(e)}; ignore_failure is set, continuing")
|
565
|
+
events.resource_failed(self, action, e)
|
566
|
+
elsif remaining_retries > 0
|
567
|
+
events.resource_failed_retriable(self, action, remaining_retries, e)
|
568
|
+
remaining_retries -= 1
|
569
|
+
Chef::Log.info("Retrying execution of #{self}, #{remaining_retries} attempt(s) left")
|
570
|
+
sleep retry_delay
|
571
|
+
retry
|
572
|
+
else
|
573
|
+
events.resource_failed(self, action, e)
|
574
|
+
raise customize_exception(e)
|
575
|
+
end
|
576
|
+
ensure
|
577
|
+
@elapsed_time = Time.now - start_time
|
578
|
+
# Reporting endpoint doesn't accept a negative resource duration so set it to 0.
|
579
|
+
# A negative value can occur when a resource changes the system time backwards
|
580
|
+
@elapsed_time = 0 if @elapsed_time < 0
|
581
|
+
events.resource_completed(self)
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
585
|
+
#
|
586
|
+
# Generic Ruby and Data Structure Stuff (for user)
|
587
|
+
#
|
588
|
+
|
589
|
+
def to_s
|
590
|
+
"#{@resource_name}[#{@name}]"
|
591
|
+
end
|
592
|
+
|
593
|
+
def to_text
|
594
|
+
return "suppressed sensitive resource output" if sensitive
|
595
|
+
ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
|
596
|
+
text = "# Declared in #{@source_line}\n\n"
|
597
|
+
text << self.class.dsl_name + "(\"#{name}\") do\n"
|
598
|
+
ivars.each do |ivar|
|
599
|
+
if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
|
600
|
+
value_string = value.respond_to?(:to_text) ? value.to_text : value.inspect
|
601
|
+
text << " #{ivar.to_s.sub(/^@/,'')} #{value_string}\n"
|
602
|
+
end
|
603
|
+
end
|
604
|
+
[@not_if, @only_if].flatten.each do |conditional|
|
605
|
+
text << " #{conditional.to_text}\n"
|
606
|
+
end
|
607
|
+
text << "end\n"
|
608
|
+
end
|
609
|
+
|
610
|
+
def inspect
|
611
|
+
ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
612
|
+
ivars.inject("<#{to_s}") do |str, ivar|
|
613
|
+
str << " #{ivar}: #{instance_variable_get(ivar).inspect}"
|
614
|
+
end << ">"
|
615
|
+
end
|
43
616
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
617
|
+
# as_json does most of the to_json heavy lifted. It exists here in case activesupport
|
618
|
+
# is loaded. activesupport will call as_json and skip over to_json. This ensure
|
619
|
+
# json is encoded as expected
|
620
|
+
def as_json(*a)
|
621
|
+
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
622
|
+
instance_vars = Hash.new
|
623
|
+
safe_ivars.each do |iv|
|
624
|
+
instance_vars[iv.to_s.sub(/^@/, '')] = instance_variable_get(iv)
|
625
|
+
end
|
626
|
+
{
|
627
|
+
'json_class' => self.class.name,
|
628
|
+
'instance_vars' => instance_vars
|
629
|
+
}
|
630
|
+
end
|
51
631
|
|
52
|
-
|
53
|
-
|
632
|
+
# Serialize this object as a hash
|
633
|
+
def to_json(*a)
|
634
|
+
results = as_json
|
635
|
+
Chef::JSONCompat.to_json(results, *a)
|
636
|
+
end
|
54
637
|
|
55
|
-
|
56
|
-
|
57
|
-
|
638
|
+
def to_hash
|
639
|
+
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
640
|
+
instance_vars = Hash.new
|
641
|
+
safe_ivars.each do |iv|
|
642
|
+
key = iv.to_s.sub(/^@/,'').to_sym
|
643
|
+
instance_vars[key] = instance_variable_get(iv)
|
58
644
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
645
|
+
instance_vars
|
646
|
+
end
|
647
|
+
|
648
|
+
def self.json_create(o)
|
649
|
+
resource = self.new(o["instance_vars"]["@name"])
|
650
|
+
o["instance_vars"].each do |k,v|
|
651
|
+
resource.instance_variable_set("@#{k}".to_sym, v)
|
62
652
|
end
|
653
|
+
resource
|
63
654
|
end
|
64
655
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
656
|
+
#
|
657
|
+
# Resource Definition Interface (for resource developers)
|
658
|
+
#
|
659
|
+
|
660
|
+
include Chef::Mixin::ParamsValidate
|
661
|
+
include Chef::Mixin::Deprecation
|
662
|
+
|
663
|
+
#
|
664
|
+
# The provider class for this resource.
|
665
|
+
#
|
666
|
+
# If this is not set, `provider_for_action` will dynamically determine the
|
667
|
+
# provider.
|
668
|
+
#
|
669
|
+
# @param arg [String, Symbol, Class] Sets the provider class for this resource.
|
670
|
+
# If passed a String or Symbol, e.g. `:file` or `"file"`, looks up the
|
671
|
+
# provider based on the name.
|
672
|
+
# @return The provider class for this resource.
|
673
|
+
#
|
674
|
+
def provider(arg=nil)
|
675
|
+
klass = if arg.kind_of?(String) || arg.kind_of?(Symbol)
|
676
|
+
lookup_provider_constant(arg)
|
677
|
+
else
|
678
|
+
arg
|
679
|
+
end
|
680
|
+
set_or_return(:provider, klass, kind_of: [ Class ])
|
681
|
+
end
|
682
|
+
def provider=(arg)
|
683
|
+
provider(arg)
|
72
684
|
end
|
73
685
|
|
74
686
|
# Set or return the list of "state attributes" implemented by the Resource
|
@@ -113,83 +725,78 @@ class Chef
|
|
113
725
|
end
|
114
726
|
end
|
115
727
|
|
116
|
-
|
117
|
-
|
118
|
-
|
728
|
+
#
|
729
|
+
# The guard interpreter that will be used to process `only_if` and `not_if`
|
730
|
+
# statements by default. If left unset, or set to `:default`, the guard
|
731
|
+
# interpreter used will be Chef::GuardInterpreter::DefaultGuardInterpreter.
|
732
|
+
#
|
733
|
+
# Must be a resource class like `Chef::Resource::Execute`, or
|
734
|
+
# a corresponding to the name of a resource. The resource must descend from
|
735
|
+
# `Chef::Resource::Execute`.
|
736
|
+
#
|
737
|
+
# TODO this needs to be coerced on input so that retrieval is consistent.
|
738
|
+
#
|
739
|
+
# @return [Class, Symbol, String] the default Guard interpreter resource.
|
740
|
+
#
|
741
|
+
attr_reader :default_guard_interpreter
|
119
742
|
|
120
|
-
|
121
|
-
|
743
|
+
#
|
744
|
+
# The list of actions this Resource is allowed to have. Setting `action`
|
745
|
+
# will fail unless it is in this list. Default: [ :nothing ]
|
746
|
+
#
|
747
|
+
# @return [Array<Symbol>] The list of actions this Resource is allowed to
|
748
|
+
# have.
|
749
|
+
#
|
122
750
|
attr_accessor :allowed_actions
|
123
|
-
attr_accessor :run_context
|
124
|
-
attr_accessor :cookbook_name
|
125
|
-
attr_accessor :recipe_name
|
126
|
-
attr_accessor :enclosing_provider
|
127
|
-
attr_accessor :source_line
|
128
|
-
attr_accessor :retries
|
129
|
-
attr_accessor :retry_delay
|
130
|
-
attr_accessor :declared_type
|
131
751
|
|
752
|
+
#
|
753
|
+
# Whether or not this resource was updated during an action. If multiple
|
754
|
+
# actions are set on the resource, this will be `true` if *any* action
|
755
|
+
# caused an update to happen.
|
756
|
+
#
|
757
|
+
# @return [Boolean] Whether the resource was updated during an action.
|
758
|
+
#
|
132
759
|
attr_reader :updated
|
133
760
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
# Struct with a #resource and #action member
|
144
|
-
|
145
|
-
def initialize(name, run_context=nil)
|
146
|
-
@name = name
|
147
|
-
@run_context = run_context
|
148
|
-
@noop = nil
|
149
|
-
@before = nil
|
150
|
-
@params = Hash.new
|
151
|
-
@provider = nil
|
152
|
-
@allowed_actions = [ :nothing ]
|
153
|
-
@action = :nothing
|
154
|
-
@updated = false
|
155
|
-
@updated_by_last_action = false
|
156
|
-
@supports = {}
|
157
|
-
@ignore_failure = false
|
158
|
-
@retries = 0
|
159
|
-
@retry_delay = 2
|
160
|
-
@not_if = []
|
161
|
-
@only_if = []
|
162
|
-
@source_line = nil
|
163
|
-
# We would like to raise an error when the user gives us a guard
|
164
|
-
# interpreter and a ruby_block to the guard. In order to achieve this
|
165
|
-
# we need to understand when the user overrides the default guard
|
166
|
-
# interpreter. Therefore we store the default separately in a different
|
167
|
-
# attribute.
|
168
|
-
@guard_interpreter = nil
|
169
|
-
@default_guard_interpreter = :default
|
170
|
-
@elapsed_time = 0
|
171
|
-
@sensitive = false
|
761
|
+
#
|
762
|
+
# Whether or not this resource was updated during an action. If multiple
|
763
|
+
# actions are set on the resource, this will be `true` if *any* action
|
764
|
+
# caused an update to happen.
|
765
|
+
#
|
766
|
+
# @return [Boolean] Whether the resource was updated during an action.
|
767
|
+
#
|
768
|
+
def updated?
|
769
|
+
updated
|
172
770
|
end
|
173
771
|
|
174
|
-
#
|
175
|
-
#
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
772
|
+
#
|
773
|
+
# Whether or not this resource was updated during the most recent action.
|
774
|
+
# This is set to `false` at the beginning of each action.
|
775
|
+
#
|
776
|
+
# @param true_or_false [Boolean] Whether the resource was updated during the
|
777
|
+
# current / most recent action.
|
778
|
+
# @return [Boolean] Whether the resource was updated during the most recent action.
|
779
|
+
#
|
780
|
+
def updated_by_last_action(true_or_false)
|
781
|
+
@updated ||= true_or_false
|
782
|
+
@updated_by_last_action = true_or_false
|
181
783
|
end
|
182
784
|
|
183
|
-
#
|
184
|
-
#
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
785
|
+
#
|
786
|
+
# Whether or not this resource was updated during the most recent action.
|
787
|
+
# This is set to `false` at the beginning of each action.
|
788
|
+
#
|
789
|
+
# @return [Boolean] Whether the resource was updated during the most recent action.
|
790
|
+
#
|
791
|
+
def updated_by_last_action?
|
792
|
+
@updated_by_last_action
|
191
793
|
end
|
192
794
|
|
795
|
+
#
|
796
|
+
# Set whether this class was updated during an action.
|
797
|
+
#
|
798
|
+
# @deprecated Multiple actions are supported by resources. Please call {}#updated_by_last_action} instead.
|
799
|
+
#
|
193
800
|
def updated=(true_or_false)
|
194
801
|
Chef::Log.warn("Chef::Resource#updated=(true|false) is deprecated. Please call #updated_by_last_action(true|false) instead.")
|
195
802
|
Chef::Log.warn("Called from:")
|
@@ -198,41 +805,32 @@ class Chef
|
|
198
805
|
@updated = true_or_false
|
199
806
|
end
|
200
807
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
# block invokes new_resource.
|
208
|
-
def method_missing(method_symbol, *args, &block)
|
209
|
-
if enclosing_provider && enclosing_provider.respond_to?(method_symbol)
|
210
|
-
enclosing_provider.send(method_symbol, *args, &block)
|
211
|
-
else
|
212
|
-
raise NoMethodError, "undefined method `#{method_symbol.to_s}' for #{self.class.to_s}"
|
213
|
-
end
|
808
|
+
#
|
809
|
+
# The DSL name of this resource (e.g. `package` or `yum_package`)
|
810
|
+
#
|
811
|
+
# @return [String] The DSL name of this resource.
|
812
|
+
def self.dsl_name
|
813
|
+
convert_to_snake_case(name, 'Chef::Resource')
|
214
814
|
end
|
215
815
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
Chef::Log.warn("Cloning resource attributes for #{key} from prior resource (CHEF-3694)")
|
223
|
-
Chef::Log.warn("Previous #{prior_resource}: #{prior_resource.source_line}") if prior_resource.source_line
|
224
|
-
Chef::Log.warn("Current #{self}: #{self.source_line}") if self.source_line
|
225
|
-
prior_resource.instance_variables.each do |iv|
|
226
|
-
unless iv.to_sym == :@source_line || iv.to_sym == :@action || iv.to_sym == :@not_if || iv.to_sym == :@only_if
|
227
|
-
self.instance_variable_set(iv, prior_resource.instance_variable_get(iv))
|
228
|
-
end
|
229
|
-
end
|
230
|
-
true
|
231
|
-
rescue Chef::Exceptions::ResourceNotFound
|
232
|
-
true
|
233
|
-
end
|
234
|
-
end
|
816
|
+
#
|
817
|
+
# The name of this resource (e.g. `file`)
|
818
|
+
#
|
819
|
+
# @return [String] The name of this resource.
|
820
|
+
#
|
821
|
+
attr_reader :resource_name
|
235
822
|
|
823
|
+
#
|
824
|
+
# Sets a list of capabilities of the real resource. For example, `:remount`
|
825
|
+
# (for filesystems) and `:restart` (for services).
|
826
|
+
#
|
827
|
+
# TODO Calling resource.supports({}) will not set this to empty; it will do
|
828
|
+
# a get instead. That's wrong.
|
829
|
+
#
|
830
|
+
# @param args Hash{Symbol=>Boolean} If non-empty, sets the capabilities of
|
831
|
+
# this resource. Default: {}
|
832
|
+
# @return Hash{Symbol=>Boolean} An array of things this resource supports.
|
833
|
+
#
|
236
834
|
def supports(args={})
|
237
835
|
if args.any?
|
238
836
|
@supports = args
|
@@ -240,127 +838,86 @@ class Chef
|
|
240
838
|
@supports
|
241
839
|
end
|
242
840
|
end
|
243
|
-
|
244
|
-
|
245
|
-
klass = if arg.kind_of?(String) || arg.kind_of?(Symbol)
|
246
|
-
lookup_provider_constant(arg)
|
247
|
-
else
|
248
|
-
arg
|
249
|
-
end
|
250
|
-
set_or_return(
|
251
|
-
:provider,
|
252
|
-
klass,
|
253
|
-
:kind_of => [ Class ]
|
254
|
-
)
|
841
|
+
def supports=(args)
|
842
|
+
supports(args)
|
255
843
|
end
|
256
844
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
{
|
264
|
-
:action => action,
|
265
|
-
},
|
266
|
-
{
|
267
|
-
:action => { :kind_of => Symbol, :equal_to => @allowed_actions },
|
268
|
-
}
|
269
|
-
)
|
270
|
-
end
|
271
|
-
@action = action_list
|
272
|
-
else
|
273
|
-
@action
|
274
|
-
end
|
845
|
+
#
|
846
|
+
# A hook called after a resource is created. Meant to be overriden by
|
847
|
+
# subclasses.
|
848
|
+
#
|
849
|
+
def after_created
|
850
|
+
nil
|
275
851
|
end
|
276
852
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
853
|
+
#
|
854
|
+
# The module where Chef should look for providers for this resource.
|
855
|
+
# The provider for `MyResource` will be looked up using
|
856
|
+
# `provider_base::MyResource`. Defaults to `Chef::Provider`.
|
857
|
+
#
|
858
|
+
# @param arg [Module] The module containing providers for this resource
|
859
|
+
# @return [Module] The module containing providers for this resource
|
860
|
+
#
|
861
|
+
# @example
|
862
|
+
# class MyResource < Chef::Resource
|
863
|
+
# provider_base Chef::Provider::Deploy
|
864
|
+
# # ...other stuff
|
865
|
+
# end
|
866
|
+
#
|
867
|
+
def self.provider_base(arg=nil)
|
868
|
+
@provider_base ||= arg
|
869
|
+
@provider_base ||= Chef::Provider
|
283
870
|
end
|
284
871
|
|
285
|
-
def noop(tf=nil)
|
286
|
-
if !tf.nil?
|
287
|
-
raise ArgumentError, "noop must be true or false!" unless tf == true || tf == false
|
288
|
-
@noop = tf
|
289
|
-
end
|
290
|
-
@noop
|
291
|
-
end
|
292
872
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
arg,
|
297
|
-
:kind_of => [ TrueClass, FalseClass ]
|
298
|
-
)
|
299
|
-
end
|
873
|
+
#
|
874
|
+
# Internal Resource Interface (for Chef)
|
875
|
+
#
|
300
876
|
|
301
|
-
|
302
|
-
|
303
|
-
:retries,
|
304
|
-
arg,
|
305
|
-
:kind_of => Integer
|
306
|
-
)
|
307
|
-
end
|
877
|
+
FORBIDDEN_IVARS = [:@run_context, :@not_if, :@only_if, :@enclosing_provider]
|
878
|
+
HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider]
|
308
879
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
arg,
|
313
|
-
:kind_of => Integer
|
314
|
-
)
|
315
|
-
end
|
880
|
+
include Chef::Mixin::ConvertToClassName
|
881
|
+
extend Chef::Mixin::ConvertToClassName
|
882
|
+
extend Chef::Mixin::DescendantsTracker
|
316
883
|
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
arg,
|
321
|
-
:kind_of => [ TrueClass, FalseClass ]
|
322
|
-
)
|
323
|
-
end
|
884
|
+
# XXX: this is required for definition params inside of the scope of a
|
885
|
+
# subresource to work correctly.
|
886
|
+
attr_accessor :params
|
324
887
|
|
325
|
-
|
326
|
-
|
327
|
-
|
888
|
+
# @return [Chef::RunContext] The run context for this Resource. This is
|
889
|
+
# where the context for the current Chef run is stored, including the node
|
890
|
+
# and the resource collection.
|
891
|
+
attr_accessor :run_context
|
328
892
|
|
329
|
-
|
330
|
-
|
331
|
-
@guard_interpreter || @default_guard_interpreter
|
332
|
-
else
|
333
|
-
set_or_return(
|
334
|
-
:guard_interpreter,
|
335
|
-
arg,
|
336
|
-
:kind_of => Symbol
|
337
|
-
)
|
338
|
-
end
|
339
|
-
end
|
893
|
+
# @return [String] The cookbook this resource was declared in.
|
894
|
+
attr_accessor :cookbook_name
|
340
895
|
|
341
|
-
#
|
342
|
-
|
343
|
-
# when using old-style resources(:template => "/foo.txt") style, you
|
344
|
-
# could end up with multiple resources.
|
345
|
-
validate_resource_spec!(resource_spec)
|
896
|
+
# @return [String] The recipe this resource was declared in.
|
897
|
+
attr_accessor :recipe_name
|
346
898
|
|
347
|
-
|
348
|
-
|
899
|
+
# @return [Chef::Provider] The provider this resource was declared in (if
|
900
|
+
# it was declared in an LWRP). When you call methods that do not exist
|
901
|
+
# on this Resource, Chef will try to call the method on the provider
|
902
|
+
# as well before giving up.
|
903
|
+
attr_accessor :enclosing_provider
|
349
904
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
raise ArgumentError, "invalid timing: #{timing} for notifies(#{action}, #{resources.inspect}, #{timing}) resource #{self} "\
|
357
|
-
"Valid timings are: :delayed, :immediate, :immediately"
|
358
|
-
end
|
359
|
-
end
|
905
|
+
# @return [String] The source line where this resource was declared.
|
906
|
+
# Expected to come from caller() or a stack trace, it usually follows one
|
907
|
+
# of these formats:
|
908
|
+
# /some/path/to/file.rb:80:in `wombat_tears'
|
909
|
+
# C:/some/path/to/file.rb:80 in 1`wombat_tears'
|
910
|
+
attr_accessor :source_line
|
360
911
|
|
361
|
-
|
362
|
-
|
912
|
+
# @return [String] The actual name that was used to create this resource.
|
913
|
+
# Sometimes, when you say something like `package 'blah'`, the system will
|
914
|
+
# create a different resource (i.e. `YumPackage`). When this happens, the
|
915
|
+
# user will expect to see the thing they wrote, not the type that was
|
916
|
+
# returned. May be `nil`, in which case callers should read #resource_name.
|
917
|
+
# See #declared_key.
|
918
|
+
attr_accessor :declared_type
|
363
919
|
|
920
|
+
#
|
364
921
|
# Iterates over all immediate and delayed notifications, calling
|
365
922
|
# resolve_resource_reference on each in turn, causing them to
|
366
923
|
# resolve lazy/forward references.
|
@@ -373,52 +930,41 @@ class Chef
|
|
373
930
|
}
|
374
931
|
end
|
375
932
|
|
933
|
+
# Helper for #notifies
|
376
934
|
def notifies_immediately(action, resource_spec)
|
377
935
|
run_context.notifies_immediately(Notification.new(resource_spec, action, self))
|
378
936
|
end
|
379
937
|
|
938
|
+
# Helper for #notifies
|
380
939
|
def notifies_delayed(action, resource_spec)
|
381
940
|
run_context.notifies_delayed(Notification.new(resource_spec, action, self))
|
382
941
|
end
|
383
942
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
def resources(*args)
|
393
|
-
run_context.resource_collection.find(*args)
|
943
|
+
class << self
|
944
|
+
# back-compat
|
945
|
+
# NOTE: that we do not support unregistering classes as descendents like
|
946
|
+
# we used to for LWRP unloading because that was horrible and removed in
|
947
|
+
# Chef-12.
|
948
|
+
alias :resource_classes :descendants
|
949
|
+
alias :find_subclass_by_name :find_descendants_by_name
|
394
950
|
end
|
395
951
|
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
end
|
405
|
-
resource.notifies(action, self, timing)
|
952
|
+
# If an unknown method is invoked, determine whether the enclosing Provider's
|
953
|
+
# lexical scope can fulfill the request. E.g. This happens when the Resource's
|
954
|
+
# block invokes new_resource.
|
955
|
+
def method_missing(method_symbol, *args, &block)
|
956
|
+
if enclosing_provider && enclosing_provider.respond_to?(method_symbol)
|
957
|
+
enclosing_provider.send(method_symbol, *args, &block)
|
958
|
+
else
|
959
|
+
raise NoMethodError, "undefined method `#{method_symbol.to_s}' for #{self.class.to_s}"
|
406
960
|
end
|
407
|
-
true
|
408
961
|
end
|
409
962
|
|
963
|
+
# Helper for #notifies
|
410
964
|
def validate_resource_spec!(resource_spec)
|
411
965
|
run_context.resource_collection.validate_lookup_spec!(resource_spec)
|
412
966
|
end
|
413
967
|
|
414
|
-
def is(*args)
|
415
|
-
if args.size == 1
|
416
|
-
args.first
|
417
|
-
else
|
418
|
-
return *args
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
968
|
# We usually want to store and reference resources by their declared type and not the actual type that
|
423
969
|
# was looked up by the Resolver (IE, "package" becomes YumPackage class). If we have not been provided
|
424
970
|
# the declared key we want to fall back on the old to_s key.
|
@@ -427,105 +973,12 @@ class Chef
|
|
427
973
|
"#{declared_type}[#{@name}]"
|
428
974
|
end
|
429
975
|
|
430
|
-
def
|
431
|
-
|
432
|
-
end
|
433
|
-
|
434
|
-
def to_text
|
435
|
-
return "suppressed sensitive resource output" if sensitive
|
436
|
-
ivars = instance_variables.map { |ivar| ivar.to_sym } - HIDDEN_IVARS
|
437
|
-
text = "# Declared in #{@source_line}\n\n"
|
438
|
-
text << self.class.dsl_name + "(\"#{name}\") do\n"
|
439
|
-
ivars.each do |ivar|
|
440
|
-
if (value = instance_variable_get(ivar)) && !(value.respond_to?(:empty?) && value.empty?)
|
441
|
-
value_string = value.respond_to?(:to_text) ? value.to_text : value.inspect
|
442
|
-
text << " #{ivar.to_s.sub(/^@/,'')} #{value_string}\n"
|
443
|
-
end
|
444
|
-
end
|
445
|
-
[@not_if, @only_if].flatten.each do |conditional|
|
446
|
-
text << " #{conditional.to_text}\n"
|
447
|
-
end
|
448
|
-
text << "end\n"
|
449
|
-
end
|
450
|
-
|
451
|
-
def inspect
|
452
|
-
ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
453
|
-
ivars.inject("<#{to_s}") do |str, ivar|
|
454
|
-
str << " #{ivar}: #{instance_variable_get(ivar).inspect}"
|
455
|
-
end << ">"
|
456
|
-
end
|
457
|
-
|
458
|
-
# as_json does most of the to_json heavy lifted. It exists here in case activesupport
|
459
|
-
# is loaded. activesupport will call as_json and skip over to_json. This ensure
|
460
|
-
# json is encoded as expected
|
461
|
-
def as_json(*a)
|
462
|
-
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
463
|
-
instance_vars = Hash.new
|
464
|
-
safe_ivars.each do |iv|
|
465
|
-
instance_vars[iv.to_s.sub(/^@/, '')] = instance_variable_get(iv)
|
466
|
-
end
|
467
|
-
{
|
468
|
-
'json_class' => self.class.name,
|
469
|
-
'instance_vars' => instance_vars
|
470
|
-
}
|
471
|
-
end
|
472
|
-
|
473
|
-
# Serialize this object as a hash
|
474
|
-
def to_json(*a)
|
475
|
-
results = as_json
|
476
|
-
Chef::JSONCompat.to_json(results, *a)
|
477
|
-
end
|
478
|
-
|
479
|
-
def to_hash
|
480
|
-
safe_ivars = instance_variables.map { |ivar| ivar.to_sym } - FORBIDDEN_IVARS
|
481
|
-
instance_vars = Hash.new
|
482
|
-
safe_ivars.each do |iv|
|
483
|
-
key = iv.to_s.sub(/^@/,'').to_sym
|
484
|
-
instance_vars[key] = instance_variable_get(iv)
|
485
|
-
end
|
486
|
-
instance_vars
|
487
|
-
end
|
488
|
-
|
489
|
-
# If command is a block, returns true if the block returns true, false if it returns false.
|
490
|
-
# ("Only run this resource if the block is true")
|
491
|
-
#
|
492
|
-
# If the command is not a block, executes the command. If it returns any status other than
|
493
|
-
# 0, it returns false (clearly, a 0 status code is true)
|
494
|
-
#
|
495
|
-
# === Parameters
|
496
|
-
# command<String>:: A a string to execute.
|
497
|
-
# opts<Hash>:: Options control the execution of the command
|
498
|
-
# block<Proc>:: A ruby block to run. Ignored if a command is given.
|
499
|
-
#
|
500
|
-
# === Evaluation
|
501
|
-
# * evaluates to true if the block is true, or if the command returns 0
|
502
|
-
# * evaluates to false if the block is false, or if the command returns a non-zero exit code.
|
503
|
-
def only_if(command=nil, opts={}, &block)
|
504
|
-
if command || block_given?
|
505
|
-
@only_if << Conditional.only_if(self, command, opts, &block)
|
506
|
-
end
|
507
|
-
@only_if
|
976
|
+
def immediate_notifications
|
977
|
+
run_context.immediate_notifications(self)
|
508
978
|
end
|
509
979
|
|
510
|
-
|
511
|
-
|
512
|
-
#
|
513
|
-
# If the command is not a block, executes the command. If it returns a 0 exitstatus, returns false.
|
514
|
-
# ("Do not run this resource if the command returns 0")
|
515
|
-
#
|
516
|
-
# === Parameters
|
517
|
-
# command<String>:: A a string to execute.
|
518
|
-
# opts<Hash>:: Options control the execution of the command
|
519
|
-
# block<Proc>:: A ruby block to run. Ignored if a command is given.
|
520
|
-
#
|
521
|
-
# === Evaluation
|
522
|
-
# * evaluates to true if the block is false, or if the command returns a non-zero exit status.
|
523
|
-
# * evaluates to false if the block is true, or if the command returns a 0 exit status.
|
524
|
-
def not_if(command=nil, opts={}, &block)
|
525
|
-
if command || block_given?
|
526
|
-
@not_if << Conditional.not_if(self, command, opts, &block)
|
527
|
-
end
|
528
|
-
@not_if
|
980
|
+
def delayed_notifications
|
981
|
+
run_context.delayed_notifications(self)
|
529
982
|
end
|
530
983
|
|
531
984
|
def defined_at
|
@@ -543,6 +996,11 @@ class Chef
|
|
543
996
|
end
|
544
997
|
end
|
545
998
|
|
999
|
+
#
|
1000
|
+
# The cookbook in which this Resource was defined (if any).
|
1001
|
+
#
|
1002
|
+
# @return Chef::CookbookVersion The cookbook in which this Resource was defined.
|
1003
|
+
#
|
546
1004
|
def cookbook_version
|
547
1005
|
if cookbook_name
|
548
1006
|
run_context.cookbook_collection[cookbook_name]
|
@@ -553,56 +1011,6 @@ class Chef
|
|
553
1011
|
run_context.events
|
554
1012
|
end
|
555
1013
|
|
556
|
-
def run_action(action, notification_type=nil, notifying_resource=nil)
|
557
|
-
# reset state in case of multiple actions on the same resource.
|
558
|
-
@elapsed_time = 0
|
559
|
-
start_time = Time.now
|
560
|
-
events.resource_action_start(self, action, notification_type, notifying_resource)
|
561
|
-
# Try to resolve lazy/forward references in notifications again to handle
|
562
|
-
# the case where the resource was defined lazily (ie. in a ruby_block)
|
563
|
-
resolve_notification_references
|
564
|
-
validate_action(action)
|
565
|
-
|
566
|
-
if Chef::Config[:verbose_logging] || Chef::Log.level == :debug
|
567
|
-
# This can be noisy
|
568
|
-
Chef::Log.info("Processing #{self} action #{action} (#{defined_at})")
|
569
|
-
end
|
570
|
-
|
571
|
-
# ensure that we don't leave @updated_by_last_action set to true
|
572
|
-
# on accident
|
573
|
-
updated_by_last_action(false)
|
574
|
-
|
575
|
-
# Don't modify @retries directly and keep it intact, so that the
|
576
|
-
# recipe_snippet from ResourceFailureInspector can print the value
|
577
|
-
# that was set in the resource block initially.
|
578
|
-
remaining_retries = retries
|
579
|
-
|
580
|
-
begin
|
581
|
-
return if should_skip?(action)
|
582
|
-
provider_for_action(action).run_action
|
583
|
-
rescue Exception => e
|
584
|
-
if ignore_failure
|
585
|
-
Chef::Log.error("#{custom_exception_message(e)}; ignore_failure is set, continuing")
|
586
|
-
events.resource_failed(self, action, e)
|
587
|
-
elsif remaining_retries > 0
|
588
|
-
events.resource_failed_retriable(self, action, remaining_retries, e)
|
589
|
-
remaining_retries -= 1
|
590
|
-
Chef::Log.info("Retrying execution of #{self}, #{remaining_retries} attempt(s) left")
|
591
|
-
sleep retry_delay
|
592
|
-
retry
|
593
|
-
else
|
594
|
-
events.resource_failed(self, action, e)
|
595
|
-
raise customize_exception(e)
|
596
|
-
end
|
597
|
-
ensure
|
598
|
-
@elapsed_time = Time.now - start_time
|
599
|
-
# Reporting endpoint doesn't accept a negative resource duration so set it to 0.
|
600
|
-
# A negative value can occur when a resource changes the system time backwards
|
601
|
-
@elapsed_time = 0 if @elapsed_time < 0
|
602
|
-
events.resource_completed(self)
|
603
|
-
end
|
604
|
-
end
|
605
|
-
|
606
1014
|
def validate_action(action)
|
607
1015
|
raise ArgumentError, "nil is not a valid action for resource #{self}" if action.nil?
|
608
1016
|
end
|
@@ -613,6 +1021,30 @@ class Chef
|
|
613
1021
|
provider
|
614
1022
|
end
|
615
1023
|
|
1024
|
+
# ??? TODO Seems unused. Delete?
|
1025
|
+
def noop(tf=nil)
|
1026
|
+
if !tf.nil?
|
1027
|
+
raise ArgumentError, "noop must be true or false!" unless tf == true || tf == false
|
1028
|
+
@noop = tf
|
1029
|
+
end
|
1030
|
+
@noop
|
1031
|
+
end
|
1032
|
+
|
1033
|
+
# TODO Seems unused. Delete?
|
1034
|
+
def is(*args)
|
1035
|
+
if args.size == 1
|
1036
|
+
args.first
|
1037
|
+
else
|
1038
|
+
return *args
|
1039
|
+
end
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
#
|
1043
|
+
# Preface an exception message with generic Resource information.
|
1044
|
+
#
|
1045
|
+
# @param e [StandardError] An exception with `e.message`
|
1046
|
+
# @return [String] An exception message customized with class name.
|
1047
|
+
#
|
616
1048
|
def custom_exception_message(e)
|
617
1049
|
"#{self} (#{defined_at}) had an error: #{e.class.name}: #{e.message}"
|
618
1050
|
end
|
@@ -622,6 +1054,7 @@ class Chef
|
|
622
1054
|
new_exception.set_backtrace(e.backtrace)
|
623
1055
|
new_exception
|
624
1056
|
end
|
1057
|
+
|
625
1058
|
# Evaluates not_if and only_if conditionals. Returns a falsey value if any
|
626
1059
|
# of the conditionals indicate that this resource should be skipped, i.e.,
|
627
1060
|
# if an only_if evaluates to false or a not_if evaluates to true.
|
@@ -647,48 +1080,6 @@ class Chef
|
|
647
1080
|
end
|
648
1081
|
end
|
649
1082
|
|
650
|
-
def updated_by_last_action(true_or_false)
|
651
|
-
@updated ||= true_or_false
|
652
|
-
@updated_by_last_action = true_or_false
|
653
|
-
end
|
654
|
-
|
655
|
-
def updated_by_last_action?
|
656
|
-
@updated_by_last_action
|
657
|
-
end
|
658
|
-
|
659
|
-
def updated?
|
660
|
-
updated
|
661
|
-
end
|
662
|
-
|
663
|
-
def self.json_create(o)
|
664
|
-
resource = self.new(o["instance_vars"]["@name"])
|
665
|
-
o["instance_vars"].each do |k,v|
|
666
|
-
resource.instance_variable_set("@#{k}".to_sym, v)
|
667
|
-
end
|
668
|
-
resource
|
669
|
-
end
|
670
|
-
|
671
|
-
# Hook to allow a resource to run specific code after creation
|
672
|
-
def after_created
|
673
|
-
nil
|
674
|
-
end
|
675
|
-
|
676
|
-
# Resources that want providers namespaced somewhere other than
|
677
|
-
# Chef::Provider can set the namespace with +provider_base+
|
678
|
-
# Ex:
|
679
|
-
# class MyResource < Chef::Resource
|
680
|
-
# provider_base Chef::Provider::Deploy
|
681
|
-
# # ...other stuff
|
682
|
-
# end
|
683
|
-
def self.provider_base(arg=nil)
|
684
|
-
@provider_base ||= arg
|
685
|
-
@provider_base ||= Chef::Provider
|
686
|
-
end
|
687
|
-
|
688
|
-
def self.node_map
|
689
|
-
@@node_map ||= NodeMap.new
|
690
|
-
end
|
691
|
-
|
692
1083
|
# Maps a short_name (and optionally a platform and version) to a
|
693
1084
|
# Chef::Resource. This allows finer grained per platform resource
|
694
1085
|
# attributes and the end of overloaded resource definitions
|
@@ -731,6 +1122,10 @@ class Chef
|
|
731
1122
|
klass
|
732
1123
|
end
|
733
1124
|
|
1125
|
+
def self.node_map
|
1126
|
+
@@node_map ||= NodeMap.new
|
1127
|
+
end
|
1128
|
+
|
734
1129
|
# Returns the class of a Chef::Resource based on the short name
|
735
1130
|
# ==== Parameters
|
736
1131
|
# short_name<Symbol>:: short_name of the resource (ie :directory)
|