summaryrefslogtreecommitdiff
path: root/lib/chef/provider/package.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-08-01 12:35:23 -0700
committerdanielsdeleo <dan@opscode.com>2013-08-02 09:29:05 -0700
commit4243345b93a5953c14a67b5f1c6e020f4f055765 (patch)
tree9c82748c4b1b42feb7aa37eb25de3167ec6ec7c6 /lib/chef/provider/package.rb
parente4fd4f0e00bc64abb5acf6517593063e2666ea7e (diff)
downloadchef-4243345b93a5953c14a67b5f1c6e020f4f055765.tar.gz
Remove deprecated method usage from package provider
Instead of using internal methods to trigger a template load and rescuing the resulting error when a template is not found, query the run context to determine if the cookbook has a given template.
Diffstat (limited to 'lib/chef/provider/package.rb')
-rw-r--r--lib/chef/provider/package.rb36
1 files changed, 23 insertions, 13 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index a28a6f93fb..572cc84877 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -92,7 +92,7 @@ class Chef
@new_resource.version(candidate_version)
orig_version = @current_resource.version || "uninstalled"
converge_by("upgrade package #{@new_resource.package_name} from #{orig_version} to #{candidate_version}") do
- status = upgrade_package(@new_resource.package_name, candidate_version)
+ upgrade_package(@new_resource.package_name, candidate_version)
Chef::Log.info("#{@new_resource} upgraded from #{orig_version} to #{candidate_version}")
end
end
@@ -146,7 +146,7 @@ class Chef
if preseed_file = get_preseed_file(@new_resource.package_name, @current_resource.version)
converge_by("reconfigure package #{@new_resource.package_name}") do
preseed_package(preseed_file)
- status = reconfig_package(@new_resource.package_name, @current_resource.version)
+ reconfig_package(@new_resource.package_name, @current_resource.version)
Chef::Log.info("#{@new_resource} reconfigured")
end
else
@@ -198,21 +198,21 @@ class Chef
Chef::Log.debug("#{@new_resource} fetching preseed file to #{cache_seed_to}")
- begin
+
+ if template_available?(@new_resource.response_file)
+ Chef::Log.debug("#{@new_resource} fetching preseed file via Template")
remote_file = Chef::Resource::Template.new(cache_seed_to, run_context)
- remote_file.cookbook_name = @new_resource.cookbook_name
- remote_file.source(@new_resource.response_file)
- remote_file.backup(false)
- provider = Chef::Platform.provider_for_resource(remote_file, :create)
- provider.template_location
- rescue
- Chef::Log.debug("#{@new_resource} fetching preseed file via Template resource failed, fallback to CookbookFile resource")
+ elsif cookbook_file_available?(@new_resource.response_file)
+ Chef::Log.debug("#{@new_resource} fetching preseed file via cookbook_file")
remote_file = Chef::Resource::CookbookFile.new(cache_seed_to, run_context)
- remote_file.cookbook_name = @new_resource.cookbook_name
- remote_file.source(@new_resource.response_file)
- remote_file.backup(false)
+ else
+ message = "No template or cookbook file found for response file #{@new_resource.response_file}"
+ raise Chef::Exceptions::FileNotFound, message
end
+ remote_file.cookbook_name = @new_resource.cookbook_name
+ remote_file.source(@new_resource.response_file)
+ remote_file.backup(false)
remote_file
end
@@ -224,6 +224,16 @@ class Chef
@new_resource.version == @current_resource.version
end
+ private
+
+ def template_available?(path)
+ run_context.has_template_in_cookbook?(@new_resource.cookbook_name, path)
+ end
+
+ def cookbook_file_available?(path)
+ run_context.has_cookbook_file_in_cookbook?(@new_resource.cookbook_name, path)
+ end
+
end
end
end