diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2020-03-02 16:05:50 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2020-03-02 16:05:50 -0800 |
commit | 812fcb568e06afdcdaad5d624c97b666a43a65b1 (patch) | |
tree | ad8b78eb755684239cfa8d5724b0fd3ad204d415 | |
parent | 36a727691ea93d1f5fe8cf267fae5dd92516a9f0 (diff) | |
download | chef-812fcb568e06afdcdaad5d624c97b666a43a65b1.tar.gz |
Use the action DSL consistently
May be a potentially breaking change if I noodle hard enough on it, it
does mean that all the actions are now (correctly) encapsulated in a
sub-resource collection, whereas before they never had one.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
37 files changed, 128 insertions, 128 deletions
diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index dd70497a35..a5669b0a4a 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -95,7 +95,7 @@ class Chef end end - def action_create + action :create do crontab = "" newcron = "" cron_found = false @@ -155,7 +155,7 @@ class Chef end end - def action_delete + action :delete do if @cron_exists crontab = "" cron_found = false diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb index ad627757f8..28ddb202be 100644 --- a/lib/chef/provider/directory.rb +++ b/lib/chef/provider/directory.rb @@ -121,7 +121,7 @@ class Chef end end - def action_create + action :create do unless ::File.exists?(new_resource.path) converge_by("create new directory #{new_resource.path}") do if new_resource.recursive == true @@ -137,7 +137,7 @@ class Chef load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run] end - def action_delete + action :delete do if ::File.exists?(new_resource.path) converge_by("delete existing directory #{new_resource.path}") do if new_resource.recursive == true diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index da8b17ed04..7a211c8c9f 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -33,7 +33,7 @@ class Chef @reboot_resource = nil end - def action_run + action :run do unless test_resource converge_by(generate_description) do result = set_resource diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb index 999ea9f33e..b927e00558 100644 --- a/lib/chef/provider/dsc_script.rb +++ b/lib/chef/provider/dsc_script.rb @@ -40,7 +40,7 @@ class Chef end } end - def action_run + action :run do unless @resource_converged converge_by(generate_description) do run_configuration(:set) diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb index 61107a84ba..e358f925ec 100644 --- a/lib/chef/provider/execute.rb +++ b/lib/chef/provider/execute.rb @@ -47,7 +47,7 @@ class Chef new_resource.timeout || 3600 end - def action_run + action :run do if creates && sentinel_file.exist? logger.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do") return false diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 1b1f73b9d5..9d9980d2fb 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -137,7 +137,7 @@ class Chef end end - def action_create + action :create do do_generate_content do_validate_content do_unlink @@ -148,7 +148,7 @@ class Chef load_resource_attributes_from_file(new_resource) unless Chef::Config[:why_run] end - def action_create_if_missing + action :create_if_missing do unless ::File.exist?(new_resource.path) action_create else @@ -156,7 +156,7 @@ class Chef end end - def action_delete + action :delete do if ::File.exists?(new_resource.path) converge_by("delete file #{new_resource.path}") do do_backup unless file_class.symlink?(new_resource.path) @@ -166,7 +166,7 @@ class Chef end end - def action_touch + action :touch do action_create converge_by("update utime on file #{new_resource.path}") do time = Time.now diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index b7ca81b3f8..1ef1481c9e 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -71,7 +71,7 @@ class Chef end end - def action_checkout + action :checkout do if target_dir_non_existent_or_empty? clone if new_resource.enable_checkout @@ -84,14 +84,14 @@ class Chef end end - def action_export + action :export do action_checkout converge_by("complete the export by removing #{cwd}.git after checkout") do FileUtils.rm_rf(::File.join(cwd, ".git")) end end - def action_sync + action :sync do if existing_git_clone? logger.trace "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}" unless current_revision_matches_target_revision? diff --git a/lib/chef/provider/group.rb b/lib/chef/provider/group.rb index 1c8a18c037..7673a6fc91 100644 --- a/lib/chef/provider/group.rb +++ b/lib/chef/provider/group.rb @@ -122,7 +122,7 @@ class Chef true end - def action_create + action :create do case @group_exists when false converge_by("create group #{new_resource.group_name}") do @@ -139,7 +139,7 @@ class Chef end end - def action_remove + action :remove do return unless @group_exists converge_by("remove group #{new_resource.group_name}") do @@ -148,7 +148,7 @@ class Chef end end - def action_manage + action :manage do return unless @group_exists && compare_group converge_by(["manage group #{new_resource.group_name}"] + change_desc) do @@ -157,7 +157,7 @@ class Chef end end - def action_modify + action :modify do return unless compare_group converge_by(["modify group #{new_resource.group_name}"] + change_desc) do diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb index 3f475f005f..9a0ebd3dfe 100644 --- a/lib/chef/provider/http_request.rb +++ b/lib/chef/provider/http_request.rb @@ -32,7 +32,7 @@ class Chef end # Send a HEAD request to new_resource.url - def action_head + action :head do message = check_message(new_resource.message) # CHEF-4762: we expect a nil return value from Chef::HTTP for a "200 Success" response # and false for a "304 Not Modified" response @@ -49,7 +49,7 @@ class Chef end # Send a GET request to new_resource.url - def action_get + action :get do converge_by("#{new_resource} GET to #{new_resource.url}") do message = check_message(new_resource.message) @@ -63,7 +63,7 @@ class Chef end # Send a PATCH request to new_resource.url, with the message as the payload - def action_patch + action :patch do converge_by("#{new_resource} PATCH to #{new_resource.url}") do message = check_message(new_resource.message) body = @http.patch( @@ -77,7 +77,7 @@ class Chef end # Send a PUT request to new_resource.url, with the message as the payload - def action_put + action :put do converge_by("#{new_resource} PUT to #{new_resource.url}") do message = check_message(new_resource.message) body = @http.put( @@ -91,7 +91,7 @@ class Chef end # Send a POST request to new_resource.url, with the message as the payload - def action_post + action :post do converge_by("#{new_resource} POST to #{new_resource.url}") do message = check_message(new_resource.message) body = @http.post( @@ -105,7 +105,7 @@ class Chef end # Send a DELETE request to new_resource.url - def action_delete + action :delete do converge_by("#{new_resource} DELETE to #{new_resource.url}") do body = @http.delete( (new_resource.url).to_s, diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb index b2ea6e095e..79f5bb78fe 100644 --- a/lib/chef/provider/ifconfig.rb +++ b/lib/chef/provider/ifconfig.rb @@ -171,7 +171,7 @@ class Chef end end - def action_add + action :add do # check to see if load_current_resource found interface in ifconfig unless current_resource.inet_addr unless new_resource.device == loopback_device @@ -186,7 +186,7 @@ class Chef generate_config end - def action_enable + action :enable do # check to see if load_current_resource found ifconfig # enables, but does not manage config files return if current_resource.inet_addr @@ -199,7 +199,7 @@ class Chef end end - def action_delete + action :delete do # check to see if load_current_resource found the interface if current_resource.device command = delete_command @@ -213,7 +213,7 @@ class Chef delete_config end - def action_disable + action :disable do # check to see if load_current_resource found the interface # disables, but leaves config files in place. if current_resource.device diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb index 16fe34f6ea..b33ba097bb 100644 --- a/lib/chef/provider/launchd.rb +++ b/lib/chef/provider/launchd.rb @@ -55,15 +55,15 @@ class Chef types[type] end - def action_create + action :create do manage_plist(:create) end - def action_create_if_missing + action :create_if_missing do manage_plist(:create_if_missing) end - def action_delete + action :delete do # If you delete a service you want to make sure its not loaded or # the service will be in memory and you wont be able to stop it. if ::File.exists?(@path) @@ -72,7 +72,7 @@ class Chef manage_plist(:delete) end - def action_enable + action :enable do if manage_plist(:create) manage_service(:restart) else @@ -80,11 +80,11 @@ class Chef end end - def action_disable + action :disable do manage_service(:disable) end - def action_restart + action :restart do manage_service(:restart) end diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb index f69d5cb01e..636e2c0472 100644 --- a/lib/chef/provider/link.rb +++ b/lib/chef/provider/link.rb @@ -85,7 +85,7 @@ class Chef ChefUtils.windows? ? path.tr("/", '\\') : path end - def action_create + action :create do # current_resource is the symlink that currently exists # new_resource is the symlink we need to create # to - the location to link to @@ -141,7 +141,7 @@ class Chef end end - def action_delete + action :delete do if current_resource.to # Exists if ChefUtils.windows? && ::File.directory?(current_resource.target_file) converge_by("delete link to dir at #{new_resource.target_file}") do diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb index f0943f9795..54e324cc11 100644 --- a/lib/chef/provider/log.rb +++ b/lib/chef/provider/log.rb @@ -33,7 +33,7 @@ class Chef # Write the log to Chef's log # # @return [true] Always returns true - def action_write + action :write do logger.send(new_resource.level, new_resource.message) new_resource.updated_by_last_action(true) if Chef::Config[:count_log_resource_updates] end diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb index f7843319f0..76c0bd155f 100644 --- a/lib/chef/provider/mount.rb +++ b/lib/chef/provider/mount.rb @@ -37,7 +37,7 @@ class Chef self.unmount_retries = 20 end - def action_mount + action :mount do unless current_resource.mounted converge_by("mount #{current_resource.device} to #{current_resource.mount_point}") do mount_fs @@ -48,7 +48,7 @@ class Chef end end - def action_umount + action :umount do if current_resource.mounted converge_by("unmount #{current_resource.device}") do umount_fs @@ -59,7 +59,7 @@ class Chef end end - def action_remount + action :remount do if current_resource.mounted if new_resource.supports[:remount] converge_by("remount #{current_resource.device}") do @@ -82,7 +82,7 @@ class Chef end end - def action_enable + action :enable do unless current_resource.enabled && mount_options_unchanged? && device_unchanged? converge_by("enable #{current_resource.device}") do enable_fs @@ -93,7 +93,7 @@ class Chef end end - def action_disable + action :disable do if current_resource.enabled converge_by("disable #{current_resource.device}") do disable_fs diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb index f05cd198e3..1a5484ccbf 100644 --- a/lib/chef/provider/osx_profile.rb +++ b/lib/chef/provider/osx_profile.rb @@ -95,7 +95,7 @@ class Chef end end - def action_install + action :install do unless profile_installed? converge_by("install profile #{@new_profile_identifier}") do profile_path = write_profile_to_disk @@ -105,7 +105,7 @@ class Chef end end - def action_remove + action :remove do # Clean up profile after removing it if profile_installed? converge_by("remove profile #{@new_profile_identifier}") do diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 5ccb264adf..bf3e179937 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -189,7 +189,7 @@ class Chef end end - def action_lock + action :lock do packages_locked = if respond_to?(:packages_all_locked?, true) packages_all_locked?(Array(new_resource.package_name), Array(new_resource.version)) else @@ -208,7 +208,7 @@ class Chef end end - def action_unlock + action :unlock do packages_unlocked = if respond_to?(:packages_all_unlocked?, true) packages_all_unlocked?(Array(new_resource.package_name), Array(new_resource.version)) else diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb index 3e0f2422cf..52616f0702 100644 --- a/lib/chef/provider/package/windows.rb +++ b/lib/chef/provider/package/windows.rb @@ -139,7 +139,7 @@ class Chef end end - def action_install + action :install do if uri_scheme?(new_resource.source) download_source_file load_current_resource diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index 418948e614..ec419bf791 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -30,7 +30,7 @@ class Chef add_exit_status_wrapper end - def action_run + action :run do validate_script_syntax! super end diff --git a/lib/chef/provider/registry_key.rb b/lib/chef/provider/registry_key.rb index c7489caea8..385dc326e4 100644 --- a/lib/chef/provider/registry_key.rb +++ b/lib/chef/provider/registry_key.rb @@ -113,7 +113,7 @@ class Chef end end - def action_create + action :create do unless registry.key_exists?(current_resource.key) converge_by("create key #{new_resource.key}") do registry.create_key(new_resource.key, new_resource.recursive) @@ -150,7 +150,7 @@ class Chef end end - def action_create_if_missing + action :create_if_missing do unless registry.key_exists?(new_resource.key) converge_by("create key #{new_resource.key}") do registry.create_key(new_resource.key, new_resource.recursive) @@ -171,7 +171,7 @@ class Chef end end - def action_delete + action :delete do if registry.key_exists?(new_resource.key) new_resource.unscrubbed_values.each do |value| if @name_hash.key?(value[:name].downcase) @@ -186,7 +186,7 @@ class Chef end end - def action_delete_key + action :delete_key do if registry.key_exists?(new_resource.key) converge_by("delete key #{new_resource.key}") do registry.delete_key(new_resource.key, new_resource.recursive) diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb index 4d6039751d..724f7401e8 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/lib/chef/provider/remote_directory.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2018, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -58,8 +58,8 @@ class Chef # Handle action :create. # - def action_create - super + action :create do + super() # Transfer files files_to_transfer.each do |cookbook_file_relative_path| @@ -73,7 +73,7 @@ class Chef # Handle action :create_if_missing. # - def action_create_if_missing + action :create_if_missing do # if this action is called, ignore the existing overwrite flag @overwrite = false action_create diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb index 484d4490bb..cd0dd682ae 100644 --- a/lib/chef/provider/route.rb +++ b/lib/chef/provider/route.rb @@ -1,7 +1,7 @@ # # Author:: Bryan McLellan (btm@loftninjas.org), Jesse Nelson (spheromak@gmail.com) # Copyright:: Copyright 2009-2016, Bryan McLellan -# Copyright:: Copyright 2020, Chef Software, Inc. +# Copyright:: Copyright 2020-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -128,7 +128,7 @@ class Chef route_file.close end - def action_add + action :add do # check to see if load_current_resource found the route if is_running logger.trace("#{new_resource} route already active - nothing to do") @@ -144,7 +144,7 @@ class Chef generate_config end - def action_delete + action :delete do if is_running command = generate_command(:delete) converge_by("run #{command.join(" ")} to delete route ") do @@ -162,8 +162,10 @@ class Chef def generate_config if platform_family?("rhel", "amazon", "fedora") conf = {} + # FIXME FIXME FIXME FIXME: whatever this walking-the-run-context API is, it needs to be removed. # walk the collection - run_context.resource_collection.each do |resource| + rc = run_context.parent_run_context || run_context + rc.resource_collection.each do |resource| next unless resource.is_a? Chef::Resource::Route # default to eth0 diff --git a/lib/chef/provider/ruby_block.rb b/lib/chef/provider/ruby_block.rb index f5efc42054..f965445d9f 100644 --- a/lib/chef/provider/ruby_block.rb +++ b/lib/chef/provider/ruby_block.rb @@ -26,7 +26,7 @@ class Chef true end - def action_run + action :run do converge_by("execute the ruby block #{new_resource.name}") do new_resource.block.call logger.info("#{new_resource} called") diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb index 6124615eaa..ee689ad615 100644 --- a/lib/chef/provider/script.rb +++ b/lib/chef/provider/script.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@chef.io>) -# Copyright:: Copyright 2008-2019, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -51,13 +51,13 @@ class Chef super end - def action_run + action :run do script_file.puts(code) script_file.close set_owner_and_group - super + super() unlink_script_file end diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb index c9662b7ba4..90f80045aa 100644 --- a/lib/chef/provider/service.rb +++ b/lib/chef/provider/service.rb @@ -80,7 +80,7 @@ class Chef end end - def action_enable + action :enable do if current_resource.enabled logger.trace("#{new_resource} already enabled - nothing to do") else @@ -93,7 +93,7 @@ class Chef new_resource.enabled(true) end - def action_disable + action :disable do if current_resource.enabled converge_by("disable service #{new_resource}") do disable_service @@ -106,7 +106,7 @@ class Chef new_resource.enabled(false) end - def action_mask + action :mask do if current_resource.masked logger.trace("#{new_resource} already masked - nothing to do") else @@ -119,7 +119,7 @@ class Chef new_resource.masked(true) end - def action_unmask + action :unmask do if current_resource.masked converge_by("unmask service #{new_resource}") do unmask_service @@ -132,7 +132,7 @@ class Chef new_resource.masked(false) end - def action_start + action :start do unless current_resource.running converge_by("start service #{new_resource}") do start_service @@ -145,7 +145,7 @@ class Chef new_resource.running(true) end - def action_stop + action :stop do if current_resource.running converge_by("stop service #{new_resource}") do stop_service @@ -158,7 +158,7 @@ class Chef new_resource.running(false) end - def action_restart + action :restart do converge_by("restart service #{new_resource}") do restart_service logger.info("#{new_resource} restarted") @@ -167,7 +167,7 @@ class Chef new_resource.running(true) end - def action_reload + action :reload do if current_resource.running converge_by("reload service #{new_resource}") do reload_service diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb index 05cdc2befe..ab84f6daa6 100644 --- a/lib/chef/provider/service/aixinit.rb +++ b/lib/chef/provider/service/aixinit.rb @@ -38,7 +38,7 @@ class Chef @current_resource end - def action_enable + action :enable do if @new_resource.priority.nil? priority_ok = true else diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index 46ac38fa6c..76628f92ca 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -130,7 +130,7 @@ class Chef end # Override method from parent to ensure priority is up-to-date - def action_enable + action :enable do if new_resource.priority.nil? priority_ok = true else diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index 5074261e01..059c907039 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -217,7 +217,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service converge_delayed_start end - def action_enable + action :enable do if current_startup_type != :automatic converge_by("enable service #{@new_resource}") do enable_service @@ -230,7 +230,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service @new_resource.enabled(true) end - def action_disable + action :disable do if current_startup_type != :disabled converge_by("disable service #{@new_resource}") do disable_service @@ -243,7 +243,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service @new_resource.enabled(false) end - def action_configure_startup + action :configure_startup do startup_type = @new_resource.startup_type if current_startup_type != startup_type converge_by("set service #{@new_resource} startup type to #{startup_type}") do diff --git a/lib/chef/provider/subversion.rb b/lib/chef/provider/subversion.rb index 2f25ed5fc7..a215ac59fc 100644 --- a/lib/chef/provider/subversion.rb +++ b/lib/chef/provider/subversion.rb @@ -55,7 +55,7 @@ class Chef end end - def action_checkout + action :checkout do if target_dir_non_existent_or_empty? converge_by("perform checkout of #{new_resource.repository} into #{new_resource.destination}") do shell_out!(checkout_command, run_options) @@ -65,7 +65,7 @@ class Chef end end - def action_export + action :export do if target_dir_non_existent_or_empty? action_force_export else @@ -73,13 +73,13 @@ class Chef end end - def action_force_export + action :force_export do converge_by("export #{new_resource.repository} into #{new_resource.destination}") do shell_out!(export_command, run_options) end end - def action_sync + action :sync do assert_target_directory_valid! if ::File.exist?(::File.join(new_resource.destination, ".svn")) current_rev = find_current_revision diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb index b7bd2b4e2d..c5cd9a1960 100644 --- a/lib/chef/provider/systemd_unit.rb +++ b/lib/chef/provider/systemd_unit.rb @@ -57,7 +57,7 @@ class Chef end end - def action_create + action :create do if current_resource.content != new_resource.to_ini converge_by("creating unit: #{new_resource.unit_name}") do manage_unit_file(:create) @@ -66,7 +66,7 @@ class Chef end end - def action_delete + action :delete do if ::File.exist?(unit_path) converge_by("deleting unit: #{new_resource.unit_name}") do manage_unit_file(:delete) @@ -75,19 +75,19 @@ class Chef end end - def action_preset + action :preset do converge_by("restoring enable/disable preset configuration for unit: #{new_resource.unit_name}") do systemctl_execute!(:preset, new_resource.unit_name) end end - def action_revert + action :revert do converge_by("reverting to vendor version of unit: #{new_resource.unit_name}") do systemctl_execute!(:revert, new_resource.unit_name) end end - def action_enable + action :enable do if current_resource.static logger.trace("#{new_resource.unit_name} is a static unit, enabling is a NOP.") end @@ -103,7 +103,7 @@ class Chef end end - def action_disable + action :disable do if current_resource.static logger.trace("#{new_resource.unit_name} is a static unit, disabling is a NOP.") end @@ -120,14 +120,14 @@ class Chef end end - def action_reenable + action :reenable do converge_by("reenabling unit: #{new_resource.unit_name}") do systemctl_execute!(:reenable, new_resource.unit_name) logger.info("#{new_resource} reenabled") end end - def action_mask + action :mask do unless current_resource.masked converge_by("masking unit: #{new_resource.unit_name}") do systemctl_execute!(:mask, new_resource.unit_name) @@ -136,7 +136,7 @@ class Chef end end - def action_unmask + action :unmask do if current_resource.masked converge_by("unmasking unit: #{new_resource.unit_name}") do systemctl_execute!(:unmask, new_resource.unit_name) @@ -145,7 +145,7 @@ class Chef end end - def action_start + action :start do unless current_resource.active converge_by("starting unit: #{new_resource.unit_name}") do systemctl_execute!(:start, new_resource.unit_name, default_env: false) @@ -154,7 +154,7 @@ class Chef end end - def action_stop + action :stop do if current_resource.active converge_by("stopping unit: #{new_resource.unit_name}") do systemctl_execute!(:stop, new_resource.unit_name, default_env: false) @@ -163,14 +163,14 @@ class Chef end end - def action_restart + action :restart do converge_by("restarting unit: #{new_resource.unit_name}") do systemctl_execute!(:restart, new_resource.unit_name, default_env: false) logger.info("#{new_resource} restarted") end end - def action_reload + action :reload do if current_resource.active converge_by("reloading unit: #{new_resource.unit_name}") do systemctl_execute!(:reload, new_resource.unit_name, default_env: false) @@ -181,21 +181,21 @@ class Chef end end - def action_try_restart + action :try_restart do converge_by("try-restarting unit: #{new_resource.unit_name}") do systemctl_execute!("try-restart", new_resource.unit_name, default_env: false) logger.info("#{new_resource} try-restarted") end end - def action_reload_or_restart + action :reload_or_restart do converge_by("reload-or-restarting unit: #{new_resource.unit_name}") do systemctl_execute!("reload-or-restart", new_resource.unit_name, default_env: false) logger.info("#{new_resource} reload-or-restarted") end end - def action_reload_or_try_restart + action :reload_or_try_restart do converge_by("reload-or-try-restarting unit: #{new_resource.unit_name}") do systemctl_execute!("reload-or-try-restart", new_resource.unit_name, default_env: false) logger.info("#{new_resource} reload-or-try-restarted") diff --git a/lib/chef/provider/whyrun_safe_ruby_block.rb b/lib/chef/provider/whyrun_safe_ruby_block.rb index ee4a659b00..e261cb4386 100644 --- a/lib/chef/provider/whyrun_safe_ruby_block.rb +++ b/lib/chef/provider/whyrun_safe_ruby_block.rb @@ -21,7 +21,7 @@ class Chef class WhyrunSafeRubyBlock < Chef::Provider::RubyBlock provides :whyrun_safe_ruby_block - def action_run + action :run do new_resource.block.call new_resource.updated_by_last_action(true) @run_context.events.resource_update_applied(new_resource, :create, "execute the whyrun_safe_ruby_block #{new_resource.name}") diff --git a/lib/chef/provider/windows_env.rb b/lib/chef/provider/windows_env.rb index aad42ac10b..f60dc79c5b 100644 --- a/lib/chef/provider/windows_env.rb +++ b/lib/chef/provider/windows_env.rb @@ -78,7 +78,7 @@ class Chef alias_method :compare_value, :requires_modify_or_create? - def action_create + action :create do if @key_exists if requires_modify_or_create? modify_env @@ -123,7 +123,7 @@ class Chef end end - def action_delete + action :delete do if ( ENV[new_resource.key_name] || @key_exists ) && !delete_element delete_env logger.info("#{new_resource} deleted") @@ -131,7 +131,7 @@ class Chef end end - def action_modify + action :modify do if @key_exists if requires_modify_or_create? modify_env diff --git a/lib/chef/provider/windows_script.rb b/lib/chef/provider/windows_script.rb index 172b07d712..c4ea244ea1 100644 --- a/lib/chef/provider/windows_script.rb +++ b/lib/chef/provider/windows_script.rb @@ -46,7 +46,7 @@ class Chef public - def action_run + action :run do wow64_redirection_state = nil if @is_wow64 diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index 90e0f3e9de..9775ce4487 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -115,7 +115,7 @@ class Chef @current_resource end - def action_create + action :create do set_command_and_arguments if new_resource.command if current_resource.exists @@ -152,7 +152,7 @@ class Chef end end - def action_run + action :run do if current_resource.exists logger.trace "#{new_resource} task exists" if current_resource.task.status == "running" @@ -167,7 +167,7 @@ class Chef end end - def action_delete + action :delete do if current_resource.exists logger.trace "#{new_resource} task exists" converge_by("delete scheduled task #{new_resource}") do @@ -179,7 +179,7 @@ class Chef end end - def action_end + action :end do if current_resource.exists logger.trace "#{new_resource} task exists" if current_resource.task.status != "running" @@ -194,7 +194,7 @@ class Chef end end - def action_enable + action :enable do if current_resource.exists logger.trace "#{new_resource} task exists" if current_resource.task.status == "not scheduled" @@ -211,7 +211,7 @@ class Chef end end - def action_disable + action :disable do if current_resource.exists logger.info "#{new_resource} task exists" if %w{ready running}.include?(current_resource.task.status) diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index e1ef3c63d8..67df3c1f97 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -1,7 +1,7 @@ # # Author:: Daniel DeLeo (<dan@chef.io>) # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2009-2016, Chef Software Inc. +# Copyright:: Copyright 2009-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,10 +23,10 @@ require "ostruct" require "support/shared/unit/provider/file" describe Chef::Provider::CookbookFile do - let(:node) { double("Chef::Node") } - let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:logger) { double("Mixlib::Log::Child").as_null_object } - let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb index 311ef4c55a..cb4be033f0 100644 --- a/spec/unit/provider/file_spec.rb +++ b/spec/unit/provider/file_spec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,10 +32,10 @@ describe Chef::Provider::File do content = double("Chef::Provider::File::Content") end - let(:node) { double("Chef::Node") } - let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:logger) { double("Mixlib::Log::Child").as_null_object } - let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } + let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb index 07b854da6b..5f3caa3db4 100644 --- a/spec/unit/provider/remote_file_spec.rb +++ b/spec/unit/provider/remote_file_spec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,10 +34,9 @@ describe Chef::Provider::RemoteFile do content = double("Chef::Provider::File::Content::RemoteFile") end - let(:node) { double("Chef::Node") } - let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:logger) { double("Mixlib::Log::Child").as_null_object } - let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb index a65846ecb2..80a01ac1d4 100644 --- a/spec/unit/provider/template_spec.rb +++ b/spec/unit/provider/template_spec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Lamont Granquist (<lamont@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2020, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,10 +24,9 @@ require "ostruct" require "support/shared/unit/provider/file" describe Chef::Provider::Template do - let(:node) { double("Chef::Node") } - let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:logger) { double("Mixlib::Log::Child").as_null_object } - let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) } + let(:node) { Chef::Node.new } + let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end |