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 | |
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')
-rw-r--r-- | lib/chef/deprecated.rb | 10 | ||||
-rw-r--r-- | lib/chef/dsl/declare_resource.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource_collection/resource_set.rb | 46 |
3 files changed, 40 insertions, 18 deletions
diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb index 461f65225b..d4db0813c7 100644 --- a/lib/chef/deprecated.rb +++ b/lib/chef/deprecated.rb @@ -218,6 +218,16 @@ class Chef end end + class MultiresourceMatch < Base + def id + 16 + end + + def target + "multiresource_match.html" + end + end + # id 3694 was deleted class Generic < Base diff --git a/lib/chef/dsl/declare_resource.rb b/lib/chef/dsl/declare_resource.rb index ac3776c92f..6869e77eca 100644 --- a/lib/chef/dsl/declare_resource.rb +++ b/lib/chef/dsl/declare_resource.rb @@ -241,7 +241,7 @@ class Chef resource = build_resource(type, name, created_at: created_at, &resource_attrs_block) - run_context.resource_collection.insert(resource, resource_type: type, instance_name: name) + run_context.resource_collection.insert(resource, resource_type: resource.declared_type, instance_name: resource.name) resource end 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 |