diff options
| author | Luke Kanies <luke@reductivelabs.com> | 2010-01-30 23:36:32 -0600 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 9c867e6d79dcc56cd34683c9a339dc729ad2d291 (patch) | |
| tree | 27ee2a51648d11891a5168db1e63e064244eeef5 /spec/integration | |
| parent | 274d1c5e78250640b8d2c40201ca2586c0088f32 (diff) | |
| download | puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.tar.gz puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.tar.xz puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.zip | |
Fixing most of the broken tests in test/
This involves a bit of refactoring in the rest
of the code to make it all work, but most of the
changes are fixing or removing old tests.
Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'spec/integration')
| -rwxr-xr-x | spec/integration/transaction.rb | 219 |
1 files changed, 136 insertions, 83 deletions
diff --git a/spec/integration/transaction.rb b/spec/integration/transaction.rb index a387bf7c9..b87bfb3b5 100755 --- a/spec/integration/transaction.rb +++ b/spec/integration/transaction.rb @@ -4,10 +4,17 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet_spec/files' require 'puppet/transaction' +require 'puppet_spec/files' describe Puppet::Transaction do include PuppetSpec::Files + def mk_catalog(*resources) + catalog = Puppet::Resource::Catalog.new(Puppet::Node.new("mynode")) + resources.each { |res| catalog.add_resource res } + catalog + end + it "should not apply generated resources if the parent resource fails" do catalog = Puppet::Resource::Catalog.new resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false @@ -19,7 +26,8 @@ describe Puppet::Transaction do transaction = Puppet::Transaction.new(catalog) - resource.expects(:retrieve).raises "this is a failure" + resource.expects(:evaluate).raises "this is a failure" + resource.stubs(:err) child_resource.expects(:retrieve).never @@ -41,15 +49,13 @@ describe Puppet::Transaction do it "should apply exported resources" do catalog = Puppet::Resource::Catalog.new - resource = Puppet::Type.type(:file).new :path => "/foo/bar", :backup => false + path = tmpfile("exported_files") + resource = Puppet::Type.type(:file).new :path => path, :backup => false, :ensure => :file resource.exported = true catalog.add_resource resource - transaction = Puppet::Transaction.new(catalog) - - resource.expects(:evaluate).never - - transaction.evaluate + catalog.apply + FileTest.should be_exist(path) end it "should not apply virtual exported resources" do @@ -66,119 +72,166 @@ describe Puppet::Transaction do transaction.evaluate end - it "should refresh resources that subscribe to changed resources" do - name = tmpfile("something") + # Verify that one component requiring another causes the contained + # resources in the requiring component to get refreshed. + it "should propagate events from a contained resource through its container to its dependent container's contained resources" do + transaction = nil + file = Puppet::Type.type(:file).new :path => tmpfile("event_propagation"), :ensure => :present + execfile = File.join(tmpdir("exec_event"), "exectestingness2") + exec = Puppet::Type.type(:exec).new :command => "touch #{execfile}", :path => ENV['PATH'] + catalog = mk_catalog(file) + + fcomp = Puppet::Type.type(:component).new(:name => "Foo[file]") + catalog.add_resource fcomp + catalog.add_edge(fcomp, file) + + ecomp = Puppet::Type.type(:component).new(:name => "Foo[exec]") + catalog.add_resource ecomp + catalog.add_resource exec + catalog.add_edge(ecomp, exec) + + ecomp[:subscribe] = Puppet::Resource.new(:foo, "file") + exec[:refreshonly] = true + + exec.expects(:refresh) + catalog.apply + end + + # Make sure that multiple subscriptions get triggered. + it "should propagate events to all dependent resources" do + path = tmpfile("path") + file1 = tmpfile("file1") + file2 = tmpfile("file2") file = Puppet::Type.type(:file).new( - :name => name, + :path => path, :ensure => "file" ) - exec = Puppet::Type.type(:exec).new( - :name => "echo true", - :path => "/usr/bin:/bin", + exec1 = Puppet::Type.type(:exec).new( + :path => ENV["PATH"], + :command => "touch %s" % file1, :refreshonly => true, - :subscribe => Puppet::Resource::Reference.new(file.class.name, file.name) + :subscribe => Puppet::Resource.new(:file, path) + ) + exec2 = Puppet::Type.type(:exec).new( + :path => ENV["PATH"], + :command => "touch %s" % file2, + :refreshonly => true, + :subscribe => Puppet::Resource.new(:file, path) ) - catalog = Puppet::Resource::Catalog.new - catalog.add_resource file, exec + catalog = mk_catalog(file, exec1, exec2) + catalog.apply + FileTest.should be_exist(file1) + FileTest.should be_exist(file2) + end - exec.expects(:refresh) + it "should not let one failed refresh result in other refreshes failing" do + path = tmpfile("path") + newfile = tmpfile("file") + file = Puppet::Type.type(:file).new( + :path => path, + :ensure => "file" + ) + exec1 = Puppet::Type.type(:exec).new( + :path => ENV["PATH"], + :command => "touch /this/cannot/possibly/exist", + :logoutput => true, + :refreshonly => true, + :subscribe => file, + :title => "one" + ) + exec2 = Puppet::Type.type(:exec).new( + :path => ENV["PATH"], + :command => "touch %s" % newfile, + :logoutput => true, + :refreshonly => true, + :subscribe => [file, exec1], + :title => "two" + ) + + exec1.stubs(:err) + catalog = mk_catalog(file, exec1, exec2) catalog.apply + FileTest.should be_exists(newfile) end - it "should not refresh resources that only require changed resources" do - name = tmpfile("something") + it "should still trigger skipped resources" do + catalog = mk_catalog() + catalog.add_resource(*Puppet::Type.type(:schedule).mkdefaultschedules) + + Puppet[:ignoreschedules] = false file = Puppet::Type.type(:file).new( - :name => name, - :ensure => "file" + :name => tmpfile("file"), + :ensure => "file", + :backup => false ) + + fname = tmpfile("exec") exec = Puppet::Type.type(:exec).new( - :name => "echo true", + :name => "touch #{fname}", :path => "/usr/bin:/bin", - :refreshonly => true, - :require => Puppet::Resource::Reference.new(file.class.name, file.name) + :schedule => "monthly", + :subscribe => Puppet::Resource.new("file", file.name) ) + catalog.add_resource(file, exec) - catalog = Puppet::Resource::Catalog.new - catalog.add_resource file - catalog.add_resource exec + # Run it once + catalog.apply + FileTest.should be_exists(fname) - exec.expects(:refresh).never + exec.should_not be_scheduled - trans = catalog.apply + # Now remove it, so it can get created again + File.unlink(fname) - trans.events.length.should == 1 - end + file[:content] = "some content" + + catalog.apply + FileTest.should be_exists(fname) - it "should cascade events such that multiple refreshes result" do - files = [] + # Now remove it, so it can get created again + File.unlink(fname) - 4.times { |i| - files << Puppet::Type.type(:file).new( - :name => tmpfile("something"), - :ensure => "file" - ) - } + # And tag our exec + exec.tag("testrun") - fname = tmpfile("something") - exec = Puppet::Type.type(:exec).new( - :name => "touch %s" % fname, - :path => "/usr/bin:/bin", - :refreshonly => true - ) + # And our file, so it runs + file.tag("norun") - exec[:subscribe] = files.collect { |f| - Puppet::Resource::Reference.new(:file, f.name) - } + Puppet[:tags] = "norun" - catalog = Puppet::Resource::Catalog.new - catalog.add_resource(exec, *files) + file[:content] = "totally different content" catalog.apply - FileTest.should be_exist(fname) + FileTest.should be_exists(fname) end - # Make sure refreshing happens mid-transaction, rather than at the end. - it "should refresh resources as they're encountered rather than all at the end" do - file = tmpfile("something") - - exec1 = Puppet::Type.type(:exec).new( - :title => "one", - :name => "echo one >> %s" % file, - :path => "/usr/bin:/bin" + it "should not attempt to evaluate resources with failed dependencies" do + exec = Puppet::Type.type(:exec).new( + :command => "/bin/mkdir /this/path/cannot/possibly/exit", + :title => "mkdir" ) - exec2 = Puppet::Type.type(:exec).new( - :title => "two", - :name => "echo two >> %s" % file, - :path => "/usr/bin:/bin", - :refreshonly => true, - :subscribe => exec1 + file1 = Puppet::Type.type(:file).new( + :title => "file1", + :path => tmpfile("file1"), + :require => exec, + :ensure => :file ) - exec3 = Puppet::Type.type(:exec).new( - :title => "three", - :name => "echo three >> %s" % file, - :path => "/usr/bin:/bin", - :require => exec2 + file2 = Puppet::Type.type(:file).new( + :title => "file2", + :path => tmpfile("file2"), + :require => file1, + :ensure => :file ) - execs = [exec1, exec2, exec3] - - catalog = Puppet::Resource::Catalog.new - catalog.add_resource(exec1,exec2,exec3) - - trans = Puppet::Transaction.new(catalog) - execs.each { |e| catalog.should be_vertex(e) } - trans.prepare - execs.each { |e| catalog.should be_vertex(e) } - reverse = trans.relationship_graph.reversal - execs.each { |e| reverse.should be_vertex(e) } + catalog = mk_catalog(exec, file1, file2) catalog.apply - FileTest.should be_exist(file) - File.read(file).should == "one\ntwo\nthree\n" + FileTest.should_not be_exists(file1[:path]) + FileTest.should_not be_exists(file2[:path]) end end |
