diff options
-rw-r--r-- | lib/puppet/transaction.rb | 10 | ||||
-rw-r--r-- | lib/puppet/util/settings.rb | 25 | ||||
-rwxr-xr-x | spec/unit/util/settings.rb | 19 |
3 files changed, 34 insertions, 20 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index e00a57f40..3c72f6e97 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -43,6 +43,16 @@ class Transaction return true end + # Are there any failed resources in this transaction? + def any_failed? + failures = @failures.inject(0) { |failures, array| failures += array[1]; failures } + if failures > 0 + failures + else + false + end + end + # Apply all changes for a resource, returning a list of the events # generated. def apply(resource) diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index ab55fbd2b..0bd288ec2 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -654,28 +654,13 @@ Generated on #{Time.now}. config = bucket.to_configuration config.host_config = false - config.apply + config.apply do |transaction| + if failures = transaction.any_failed? + raise "Could not configure for running; got %s failure(s)" % failures + end + end config.clear -# tags = nil -# if Puppet[:tags] -# tags = Puppet[:tags] -# Puppet[:tags] = "" -# end -# trans = objects.evaluate -# trans.ignoretags = true -# trans.configurator = true -# trans.evaluate -# if tags -# Puppet[:tags] = tags -# end -# -# # Remove is a recursive process, so it's sufficient to just call -# # it on the component. -# objects.remove(true) -# -# objects = nil - runners.each { |s| @used << s } end end diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb index 8d11737b3..e647ce1cd 100755 --- a/spec/unit/util/settings.rb +++ b/spec/unit/util/settings.rb @@ -395,6 +395,17 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d @settings.setdefaults :files, :myfile => {:default => "/myfile", :desc => "a", :mode => 0755} end + def stub_transaction + @bucket = mock 'bucket' + @config = mock 'config' + @trans = mock 'transaction' + + @settings.expects(:to_transportable).with(:whatever).returns(@bucket) + @bucket.expects(:to_configuration).returns(@config) + @config.expects(:apply).yields(@trans) + @config.stubs(:host_config=) + end + it "should provide a method that writes files with the correct modes" do pending "Not converted from test/unit yet" end @@ -518,6 +529,7 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d Puppet::Util::Storage.expects(:store).never Puppet::Util::Storage.expects(:load).never Dir.expects(:mkdir).with("/maindir") + Dir.expects(:mkdir).with("/seconddir") @settings.use(:main) end @@ -532,4 +544,11 @@ describe Puppet::Util::Settings, " when being used to manage the host machine" d @settings.use(:other) @settings.reuse end + + it "should fail if any resources fail" do + stub_transaction + @trans.expects(:any_failed?).returns(true) + + proc { @settings.use(:whatever) }.should raise_error(RuntimeError) + end end |