summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-06-06 16:19:19 -0700
committerMatt Robinson <matt@puppetlabs.com>2011-06-06 16:19:19 -0700
commite0573603c5780e79c2461ece604c6388e4222504 (patch)
tree6e09e2fcbc4db7447dedc939fb4231c97423718e /lib
parent4801e10c81264b20c2d35b0d44c10cfb0668d1b9 (diff)
parent4922409a2bdf3ad6a094762c9e2e60371ed16a1b (diff)
downloadpuppet-e0573603c5780e79c2461ece604c6388e4222504.tar.gz
puppet-e0573603c5780e79c2461ece604c6388e4222504.tar.xz
puppet-e0573603c5780e79c2461ece604c6388e4222504.zip
Merge branch '2.7.x'
* 2.7.x: (#7624) Manually fetch all properties in instances. (#7193) Fix path issues with acceptance tests that call old shell tests (#7632) Make secret_agent application compatible with secret_agent face (#7624) Auditing should not be enabled by default for purged resources. maint: Confine augeas specs to require the augeas feature (#2728) Add diff output for changes made by Augeas provider
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/application/secret_agent.rb21
-rw-r--r--lib/puppet/face/secret_agent.rb1
-rw-r--r--lib/puppet/provider/augeas/augeas.rb59
-rw-r--r--lib/puppet/type.rb10
4 files changed, 54 insertions, 37 deletions
diff --git a/lib/puppet/application/secret_agent.rb b/lib/puppet/application/secret_agent.rb
index d704d14b2..6bdbc9232 100644
--- a/lib/puppet/application/secret_agent.rb
+++ b/lib/puppet/application/secret_agent.rb
@@ -1,23 +1,6 @@
-require 'puppet/application'
+require 'puppet/application/face_base'
require 'puppet/face'
-class Puppet::Application::Secret_agent < Puppet::Application
- should_parse_config
+class Puppet::Application::Secret_agent < Puppet::Application::FaceBase
run_mode :agent
-
- option("--debug", "-d")
- option("--verbose", "-v")
-
- def setup
- if options[:debug] or options[:verbose]
- Puppet::Util::Log.level = options[:debug] ? :debug : :info
- end
-
- Puppet::Util::Log.newdestination(:console)
- end
-
- def run_command
- report = Puppet::Face[:secret_agent, '0.0.1'].synchronize(Puppet[:certname])
- Puppet::Face[:report, '0.0.1'].submit(report)
- end
end
diff --git a/lib/puppet/face/secret_agent.rb b/lib/puppet/face/secret_agent.rb
index 105850cd3..79241da72 100644
--- a/lib/puppet/face/secret_agent.rb
+++ b/lib/puppet/face/secret_agent.rb
@@ -15,6 +15,7 @@ Puppet::Face.define(:secret_agent, '0.0.1') do
EOT
action(:synchronize) do
+ default
summary "Run secret_agent once."
arguments "[-v | --verbose] [-d | --debug]" # Remove this once options are introspectible
description <<-'EOT'
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index a16f54bd7..95142568e 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -15,9 +15,12 @@
require 'augeas' if Puppet.features.augeas?
require 'strscan'
+require 'puppet/util'
+require 'puppet/util/diff'
Puppet::Type.type(:augeas).provide(:augeas) do
include Puppet::Util
+ include Puppet::Util::Diff
confine :true => Puppet.features.augeas?
@@ -25,6 +28,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do
SAVE_NOOP = "noop"
SAVE_OVERWRITE = "overwrite"
+ SAVE_NEWFILE = "newfile"
+ SAVE_BACKUP = "backup"
COMMANDS = {
"set" => [ :path, :string ],
@@ -254,11 +259,6 @@ Puppet::Type.type(:augeas).provide(:augeas) do
@aug.set("/augeas/save", mode)
end
- def files_changed?
- saved_files = @aug.match("/augeas/events/saved")
- saved_files.size > 0
- end
-
# Determines if augeas acutally needs to run.
def need_to_run?
force = resource[:force]
@@ -287,20 +287,33 @@ 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")
- if save_result and not files_changed?
- debug("Skipping because no files were changed")
- return_value = false
- else
+ if save_result and saved_files.size > 0
+ root = resource[:root].sub(/^\/$/, "")
+ saved_files.each do |key|
+ saved_file = @aug.get(key).to_s.sub(/^\/files/, root)
+ if Puppet[:show_diff]
+ print diff(saved_file, saved_file + ".augnew")
+ end
+ if resource.noop?
+ File.delete(saved_file + ".augnew")
+ end
+ end
debug("Files changed, should execute")
+ return_value = true
+ else
+ debug("Skipping because no files were changed or save failed")
+ return_value = false
end
end
end
ensure
- close_augeas
+ if not return_value or resource.noop?
+ close_augeas
+ end
end
return_value
end
@@ -309,12 +322,24 @@ 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
-
- success = @aug.save
- fail("Save failed with return code #{success}") if success != true
+ saved_files = @aug.match("/augeas/events/saved")
+ if saved_files
+ saved_files.each do |key|
+ root = resource[:root].sub(/^\/$/, "")
+ saved_file = @aug.get(key).to_s.sub(/^\/files/, root)
+ if File.exists?(saved_file + ".augnew")
+ success = File.rename(saved_file + ".augnew", saved_file)
+ debug(saved_file + ".augnew moved to " + saved_file)
+ fail("Rename failed with return code #{success}") if success != 0
+ 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
+ success = @aug.save
+ fail("Save failed with return code #{success}") if success != true
+ end
ensure
close_augeas
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 1dbf12451..558491a7f 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -876,6 +876,12 @@ class Type
# Put the default provider first, then the rest of the suitable providers.
provider_instances = {}
providers_by_source.collect do |provider|
+ all_properties = self.properties.find_all do |property|
+ provider.supports_parameter?(property)
+ end.collect do |property|
+ property.name
+ end
+
provider.instances.collect do |instance|
# We always want to use the "first" provider instance we find, unless the resource
# is already managed and has a different provider set
@@ -886,7 +892,9 @@ class Type
end
provider_instances[instance.name] = instance
- new(:name => instance.name, :provider => instance, :audit => :all)
+ result = new(:name => instance.name, :provider => instance)
+ properties.each { |name| result.newattr(name) }
+ result
end
end.flatten.compact
end