I'm guessing that this has slipped through a filter somewhere, but I'm hoping it could be reviewed and included soon.
This should address 2 issues: https://projects.puppetlabs.com/issues/2728 http://projects.puppetlabs.com/issues/5400 This 2nd implementation should also provide a performance improvement by only calling augeas once per run. Cheers On Apr 6, 1:49 pm, Michael Knox <[email protected]> wrote: > Also utilise the *.augnew file so that augeas is only run once if changes > are made. > > Signed-off-by: Mike Knox <[email protected]> > --- > Local-branch: feature/master/2728 > lib/puppet/provider/augeas/augeas.rb | 36 +++++++++++++++++++++++++++------ > 1 files changed, 29 insertions(+), 7 deletions(-) > > diff --git a/lib/puppet/provider/augeas/augeas.rb > b/lib/puppet/provider/augeas/augeas.rb > index 5488c66..1e99f28 100644 > --- a/lib/puppet/provider/augeas/augeas.rb > +++ b/lib/puppet/provider/augeas/augeas.rb > @@ -22,6 +22,7 @@ require 'strscan' > > Puppet::Type.type(:augeas).provide(:augeas) do > include Puppet::Util > + include Puppet::Util::Diff > > confine :true => Puppet.features.augeas? > > @@ -29,6 +30,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do > > SAVE_NOOP = "noop" > SAVE_OVERWRITE = "overwrite" > + SAVE_NEWFILE = "newfile" > + SAVE_BACKUP = "backup" > > COMMANDS = { > "set" => [ :path, :string ], > @@ -291,20 +294,29 @@ Puppet::Type.type(:augeas).provide(:augeas) do > # actually do the save. > if return_value and get_augeas_version >= "0.3.6" > debug("Will attempt to save and only run if files changed") > - set_augeas_save_mode(SAVE_NOOP) > + set_augeas_save_mode(SAVE_NEWFILE) > do_execute_changes > save_result = @aug.save > - saved_files = @aug.match("/augeas/events/saved") > + saved_files = @aug.get("/augeas/events/saved") > if save_result and not files_changed? > debug("Skipping because no files were changed") > return_value = false > else > + saved_files.each do |tmp_file| > + saved_file = tmp_file.sub(/^\/files/, '') > + info(diff(saved_file, saved_file + ".augnew")) > + if Puppet[:noop] > + File.delete(saved_file + ".augnew") > + end > + end > debug("Files changed, should execute") > end > end > end > ensure > - close_augeas > + if Puppet[:noop] > + close_augeas > + end > end > return_value > end > @@ -313,10 +325,20 @@ Puppet::Type.type(:augeas).provide(:augeas) do > # Re-connect to augeas, and re-execute the changes > begin > open_augeas > - set_augeas_save_mode(SAVE_OVERWRITE) if get_augeas_version >= "0.3.6" > - > - do_execute_changes > - > + saved_files = @aug.get("/augeas/events/saved") > + if saved_files > + saved_files.each do |tmp_file| > + saved_file = tmp_file.sub(/^\/files/, '') > + if File.exists?(saved_file + ".augnew") > + File.rename(saved_file + ".augnew", saved_file) > + debug(saved_file + ".augnew moved to " + saved_file) > + end > + end > + else > + debug("No saved files, re-executing augeas") > + set_augeas_save_mode(SAVE_OVERWRITE) if get_augeas_version >= "0.3.6" > + do_execute_changes > + end > success = @aug.save > fail("Save failed with return code #{success}") if success != true > ensure > -- > 1.7.3.5 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
