summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-03-12 16:51:28 -0700
committerTim Smith <tsmith84@gmail.com>2020-03-12 16:51:28 -0700
commit04bf2a950cb46dc0f48585992cfa7ce9c911b721 (patch)
tree0643324e35b3df20147238e9049fe8c87f028c4f
parent03d92084982f7e69d251cf4c9fd90059ac6f8ef5 (diff)
downloadchef-04bf2a950cb46dc0f48585992cfa7ce9c911b721.tar.gz
Move exception handling into an assertionalternatives
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/alternatives.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/chef/resource/alternatives.rb b/lib/chef/resource/alternatives.rb
index a1ecb50439..a2f08ad864 100644
--- a/lib/chef/resource/alternatives.rb
+++ b/lib/chef/resource/alternatives.rb
@@ -35,12 +35,20 @@ class Chef
property :priority, [String, Integer], coerce: proc { |n| n.to_i }
def define_resource_requirements
+ requirements.assert(:install) do |a|
+ a.assertion do
+ !new_resource.priority.nil?
+ end
+
+ a.failure_message("Could not set alternatives for #{new_resource.link_name}, you must provide the :priority property")
+ end
+
requirements.assert(:install, :set, :remove) do |a|
a.assertion do
!new_resource.path.nil?
end
- a.failure_message("Could not set alternatives for #{new_resource.link_name}, must provide :path property")
+ a.failure_message("Could not set alternatives for #{new_resource.link_name}, you must provide the :path property")
end
requirements.assert(:install, :set, :remove) do |a|
@@ -54,8 +62,6 @@ class Chef
end
action :install do
- raise "missing :priority" unless new_resource.priority
-
if path_priority != new_resource.priority
converge_by("adding alternative #{new_resource.link} #{new_resource.link_name} #{new_resource.path} #{new_resource.priority}") do
output = shell_out(alternatives_cmd, "--install", new_resource.link, new_resource.link_name, new_resource.path, new_resource.priority)