diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-31 12:24:00 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-31 14:09:07 -0700 |
commit | 1b0cc1b541a9015fc925fc5d1ada6f85934fc0c7 (patch) | |
tree | 8a6f2b2c99faa926c705216a47fb0d1f94cd1cf0 /lib/chef/resource_collection | |
parent | 5dacd74ce5cccc4dbb651a45f9e591dd1921cc6e (diff) | |
download | chef-1b0cc1b541a9015fc925fc5d1ada6f85934fc0c7.tar.gz |
Chef-13: fix notifying array resources
this also deprecates the multi-resource notification syntax where
`foo[a,b]` would attempt to notify both `foo[a]` and `foo[b]` because
that is hella ambiguous.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/resource_collection')
-rw-r--r-- | lib/chef/resource_collection/resource_set.rb | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/lib/chef/resource_collection/resource_set.rb b/lib/chef/resource_collection/resource_set.rb index 111d23dc09..6ff29247a0 100644 --- a/lib/chef/resource_collection/resource_set.rb +++ b/lib/chef/resource_collection/resource_set.rb @@ -161,27 +161,39 @@ class Chef end def find_resource_by_string(arg) - results = Array.new - case arg - when MULTIPLE_RESOURCE_MATCH - resource_type = $1 - arg =~ /^.+\[(.+)\]$/ - resource_list = $1 - resource_list.split(",").each do |instance_name| - results << lookup(create_key(resource_type, instance_name)) - end - when SINGLE_RESOURCE_MATCH + begin + if arg =~ SINGLE_RESOURCE_MATCH resource_type = $1 name = $2 - results << lookup(create_key(resource_type, name)) - when NAMELESS_RESOURCE_MATCH - resource_type = $1 - name = "" - results << lookup(create_key(resource_type, name)) + return [ lookup(create_key(resource_type, name)) ] + end + rescue Chef::Exceptions::ResourceNotFound => e + if arg =~ MULTIPLE_RESOURCE_MATCH + begin + results = Array.new + resource_type = $1 + arg =~ /^.+\[(.+)\]$/ + resource_list = $1 + resource_list.split(",").each do |instance_name| + results << lookup(create_key(resource_type, instance_name)) + end + Chef.deprecated(:multiresource_match, "The resource_collection multi-resource syntax is deprecated") + return results + rescue Chef::Exceptions::ResourceNotFound + raise e + end else - raise ArgumentError, "Bad string format #{arg}, you must have a string like resource_type[name]!" + raise e + end end - results + + if arg =~ NAMELESS_RESOURCE_MATCH + resource_type = $1 + name = "" + return [ lookup(create_key(resource_type, name)) ] + end + + raise ArgumentError, "Bad string format #{arg}, you must have a string like resource_type[name]!" end end end |