diff options
author | Nick Lewis <nick@puppetlabs.com> | 2011-05-26 13:51:56 -0700 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2011-05-26 13:51:56 -0700 |
commit | 2ebd2d9eda3c556244cda1ae62da95965a92d79b (patch) | |
tree | ce999b3219533d12cd0d182c2fef5ea1c68f2ed2 | |
parent | 76ad2bb2ea14a915344acd19da2c8a1edb3067b0 (diff) | |
parent | 163ff6b39120815d52811b20ef5f7f46f2fd950f (diff) | |
download | puppet-2ebd2d9eda3c556244cda1ae62da95965a92d79b.tar.gz puppet-2ebd2d9eda3c556244cda1ae62da95965a92d79b.tar.xz puppet-2ebd2d9eda3c556244cda1ae62da95965a92d79b.zip |
Merge branch 'ticket/2.7rc/7681' into 2.7rc
-rw-r--r-- | acceptance/tests/language/resource_refs_with_nested_arrays.rb | 27 | ||||
-rw-r--r-- | lib/puppet/parser/ast/resource_reference.rb | 2 | ||||
-rwxr-xr-x | spec/unit/parser/ast/resource_reference_spec.rb | 24 |
3 files changed, 47 insertions, 6 deletions
diff --git a/acceptance/tests/language/resource_refs_with_nested_arrays.rb b/acceptance/tests/language/resource_refs_with_nested_arrays.rb new file mode 100644 index 000000000..7bc797885 --- /dev/null +++ b/acceptance/tests/language/resource_refs_with_nested_arrays.rb @@ -0,0 +1,27 @@ +test_name "#7681: Allow using array variables in resource references" + +test_manifest = <<MANIFEST +$exec_names = ["first", "second"] +exec { "first": + command => "echo the first command", + path => "/usr/bin:/bin", + logoutput => true, +} +exec { "second": + command => "echo the second command", + path => "/usr/bin:/bin", + logoutput => true, +} +exec { "third": + command => "echo the final command", + path => "/usr/bin:/bin", + logoutput => true, + require => Exec[$exec_names], +} +MANIFEST + +results = apply_manifest_on agents, test_manifest + +results.each do |result| + assert_match(/Exec\[third\].*the final command/, "#{result.stdout}") +end diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb index 0f8e655bf..256a99d75 100644 --- a/lib/puppet/parser/ast/resource_reference.rb +++ b/lib/puppet/parser/ast/resource_reference.rb @@ -7,7 +7,7 @@ class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch # Evaluate our object, but just return a simple array of the type # and name. def evaluate(scope) - titles = Array(title.safeevaluate(scope)) + titles = Array(title.safeevaluate(scope)).flatten a_type, titles = scope.resolve_type_and_titles(type, titles) diff --git a/spec/unit/parser/ast/resource_reference_spec.rb b/spec/unit/parser/ast/resource_reference_spec.rb index 627754dd1..4d1c191cf 100755 --- a/spec/unit/parser/ast/resource_reference_spec.rb +++ b/spec/unit/parser/ast/resource_reference_spec.rb @@ -9,21 +9,25 @@ describe Puppet::Parser::AST::ResourceReference do @scope = Puppet::Parser::Scope.new end + def ast_name(value) + Puppet::Parser::AST::Name.new(:value => value) + end + def newref(type, title) - title = stub 'title', :safeevaluate => title - ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title) + title_array = Puppet::Parser::AST::ASTArray.new(:children => [title]) + ref = Puppet::Parser::AST::ResourceReference.new(:type => type, :title => title_array) end it "should correctly produce reference strings" do - newref("File", "/tmp/yay").evaluate(@scope).to_s.should == "File[/tmp/yay]" + newref("File", ast_name("/tmp/yay")).evaluate(@scope).to_s.should == "File[/tmp/yay]" end it "should produce a single resource when the title evaluates to a string" do - newref("File", "/tmp/yay").evaluate(@scope).should == Puppet::Resource.new("file", "/tmp/yay") + newref("File", ast_name("/tmp/yay")).evaluate(@scope).should == Puppet::Resource.new("file", "/tmp/yay") end it "should return an array of resources if given an array of titles" do - titles = mock 'titles', :safeevaluate => ["title1","title2"] + titles = Puppet::Parser::AST::ASTArray.new(:children => [ast_name("title1"), ast_name("title2")]) ref = ast::ResourceReference.new( :title => titles, :type => "File" ) ref.evaluate(@scope).should == [ Puppet::Resource.new("file", "title1"), @@ -31,6 +35,16 @@ describe Puppet::Parser::AST::ResourceReference do ] end + it "should return an array of resources if given a variable containing an array of titles" do + @scope.setvar("my_files", ["foo", "bar"]) + titles = Puppet::Parser::AST::Variable.new(:value => "my_files") + ref = newref('File', titles) + ref.evaluate(@scope).should == [ + Puppet::Resource.new("file", "foo"), + Puppet::Resource.new("file", "bar") + ] + end + it "should return a correct representation when converting to string" do type = stub 'type', :is_a? => true, :to_s => "file" title = stub 'title', :is_a? => true, :to_s => "[/tmp/a, /tmp/b]" |