summaryrefslogtreecommitdiff
path: root/lib/chef/provider
diff options
context:
space:
mode:
authorMatt Wrock <matt@mattwrock.com>2016-01-12 09:06:07 -0800
committerMatt Wrock <matt@mattwrock.com>2016-01-12 09:06:07 -0800
commit7f32905c7b5600de2004f83bf4f05053db2b3b12 (patch)
tree3b4eda21353c637495b4a3912ce4e01a1c84c3b2 /lib/chef/provider
parent0944320b72ee1ab16a18a149f5ecb743ace0c0d3 (diff)
downloadchef-7f32905c7b5600de2004f83bf4f05053db2b3b12.tar.gz
assert candidates exist for alternate sources and when pinning versions
Diffstat (limited to 'lib/chef/provider')
-rw-r--r--lib/chef/provider/package/chocolatey.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb
index 3f52370939..7a9173e077 100644
--- a/lib/chef/provider/package/chocolatey.rb
+++ b/lib/chef/provider/package/chocolatey.rb
@@ -40,6 +40,19 @@ class Chef
current_resource
end
+ def define_resource_requirements
+ super
+
+ # Chocolatey source attribute points to an alternate feed
+ # and not a package specific alternate source like other providers
+ # so we want to assert candidates exist for the alternate source
+ requirements.assert(:upgrade, :install) do |a|
+ a.assertion { candidates_exist_for_all_uninstalled? }
+ a.failure_message(Chef::Exceptions::Package, "No candidate version available for #{packages_missing_candidates.join(", ")}")
+ a.whyrun("Assuming a repository that offers #{packages_missing_candidates.join(", ")} would have been configured")
+ end
+ end
+
# Lazy initializer for candidate_version. A nil value means that there is no candidate
# version and the package is not installable (generally an error).
#
@@ -191,15 +204,18 @@ class Chef
end
# Available packages in chocolatey as a Hash of names mapped to versions
+ # If pinning a package to a specific version, filter out all non matching versions
# (names are downcased for case-insensitive matching)
#
# @return [Hash] name-to-version mapping of available packages
def available_packages
@available_packages ||=
begin
- cmd = [ "list -r #{package_name_array.join ' '}" ]
+ cmd = [ "list -ar #{package_name_array.join ' '}" ]
cmd.push( "-source #{new_resource.source}" ) if new_resource.source
- parse_list_output(*cmd)
+ parse_list_output(*cmd).reject do |name,version|
+ desired_name_versions[name] && desired_name_versions[name] != version
+ end
end
end