From c02b226cab5d82bd09b3b77bdc6d079351046b82 Mon Sep 17 00:00:00 2001 From: PrajaktaPurohit Date: Thu, 25 Oct 2012 12:03:01 -0700 Subject: [PATCH] Adding whyrun support to python LWRP. --- providers/pip.rb | 31 ++++++++++++++++++++----------- providers/virtualenv.rb | 13 ++++++++++--- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/providers/pip.rb b/providers/pip.rb index 1c58e5e..9851fbf 100644 --- a/providers/pip.rb +++ b/providers/pip.rb @@ -22,6 +22,10 @@ require 'chef/mixin/language' include Chef::Mixin::ShellOut +def whyrun_supported? + true +end + # the logic in all action methods mirror that of # the Chef::Provider::Package which will make # refactoring into core chef easy @@ -42,10 +46,11 @@ end if install_version - Chef::Log.info("Installing #{@new_resource} version #{install_version}") - status = install_package(@new_resource.package_name, install_version, timeout) - if status - @new_resource.updated_by_last_action(true) + description = [] + description << "install package #{@new_resource} version #{install_version}" + converge_by(description) do + Chef::Log.info("Installing #{@new_resource} version #{install_version}") + status = install_package(@new_resource.package_name, install_version, timeout) end end end @@ -59,10 +64,11 @@ if @current_resource.version != candidate_version orig_version = @current_resource.version || "uninstalled" - Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}") - status = upgrade_package(@new_resource.package_name, candidate_version, timeout) - if status - @new_resource.updated_by_last_action(true) + description = [] + description << "upgrade #{@current_resource} version from #{@current_resource.version} to #{candidate_version}" + converge_by(description) do + Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}") + status = upgrade_package(@new_resource.package_name, candidate_version, timeout) end end end @@ -75,9 +81,12 @@ end if removing_package? - Chef::Log.info("Removing #{@new_resource}") - remove_package(@current_resource.package_name, @new_resource.version, timeout) - @new_resource.updated_by_last_action(true) + description = [] + description << "remove package #{@new_resource}" + converge_by(description) do + Chef::Log.info("Removing #{@new_resource}") + remove_package(@current_resource.package_name, @new_resource.version, timeout) + end else end end diff --git a/providers/virtualenv.rb b/providers/virtualenv.rb index d10f099..161359b 100644 --- a/providers/virtualenv.rb +++ b/providers/virtualenv.rb @@ -22,6 +22,10 @@ require 'chef/mixin/language' include Chef::Mixin::ShellOut +def whyrun_supported? + true +end + action :create do unless exists? Chef::Log.info("Creating virtualenv #{@new_resource} at #{@new_resource.path}") @@ -35,9 +39,12 @@ action :delete do if exists? - Chef::Log.info("Deleting virtualenv #{@new_resource} at #{@new_resource.path}") - FileUtils.rm_rf(@new_resource.path) - new_resource.updated_by_last_action(true) + description = [] + description << "delete virtualenv #{@new_resource} at #{@new_resource.path}" + converge_by(description) do + Chef::Log.info("Deleting virtualenv #{@new_resource} at #{@new_resource.path}") + FileUtils.rm_rf(@new_resource.path) + end end end