From c912a2af2f63f505a493137d4ff0b88bc3754cda Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 3 Feb 2011 13:46:08 -0800 Subject: (#4139) hook log autoflush into global defaults We previously had an ordering dependency in the autoflush option, which was statically read from defaults when the log destination was configured. We add a hook in the defaults to update the log subsystem, which in turn updates log destinations, when autoflush is changed. This would work as desired: puppet agent --autoflush --logdest=file This would not work, as autoflush would be false: puppet agent --logdest=file --autoflush Now those changes propagate correctly. Paired-with: matt@puppetlabs.com --- lib/puppet/defaults.rb | 6 +++++- lib/puppet/util/log.rb | 6 ++++++ lib/puppet/util/log/destinations.rb | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 764cbbe2b..687ac4eb0 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -14,7 +14,11 @@ module Puppet setdefaults(:main, :trace => [false, "Whether to print stack traces on some errors"], - :autoflush => [false, "Whether log files should always flush to disk."], + :autoflush => { + :default => false, + :desc => "Whether log files should always flush to disk.", + :hook => proc { |value| Log.autoflush = value } + }, :syslogfacility => ["daemon", "What syslog facility to use when logging to syslog. Syslog has a fixed list of valid facilities, and you must choose one of those; you cannot just make one up."], diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 3fdac3f69..ba1690078 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -67,6 +67,12 @@ class Puppet::Util::Log } end + def Log.autoflush=(v) + @destinations.each do |type, dest| + dest.autoflush = v if dest.respond_to?(:autoflush=) + end + end + # Create a new log message. The primary role of this method is to # avoid creating log messages below the loglevel. def Log.create(hash) diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb index 22b3dedb2..c70edeb02 100644 --- a/lib/puppet/util/log/destinations.rb +++ b/lib/puppet/util/log/destinations.rb @@ -50,6 +50,8 @@ Puppet::Util::Log.newdesttype :file do @file.flush if defined?(@file) end + attr_accessor :autoflush + def initialize(path) @name = path # first make sure the directory exists -- cgit From ac8d316a08cffd951a883936a9966388ca3e54ee Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Wed, 2 Feb 2011 14:12:45 -0800 Subject: Fix for #5755 -- making zaml serialization robust over projected objects The core problem arose when the fix for #5048 in 31118fe85aca4 introduced a hook to replace objects dynamically durring serialization so that they could be projected / rewritten to a different form for backward compatability. The serialization code assumed that all objects being serialized would remain valid until the serialization was complete, but nothing retained a copy of the temporary objects created in the hook. To resolve this, the serialization layer now maintains a ref to each such object and clears them (to allow GC) after serialization is complete. Paired-with: Jesse Wolfe Paired-with: Paul Berry --- lib/puppet/util/zaml.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb index 14aa90e5f..b22dfc199 100644 --- a/lib/puppet/util/zaml.rb +++ b/lib/puppet/util/zaml.rb @@ -20,6 +20,7 @@ class ZAML def self.dump(stuff, where='') z = new stuff.to_zaml(z) + Label.counter_reset where << z.to_s end # @@ -61,6 +62,7 @@ class ZAML end def initialize(obj) @this_label_number = nil + @obj = obj # prevent garbage collection so that object id isn't reused @@previously_emitted_object[obj.object_id] = self end def to_s -- cgit From bddfa1e22d8db53a16f71759a2d9c690bfc00417 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Thu, 3 Feb 2011 13:42:46 -0800 Subject: (6114) Update the audit metaparameter for 2.6.5. The audit metaparameter has some new behavior, its old behavior has changed, and the previous description was incomplete at any rate. This patch replaces its description string. --- lib/puppet/type.rb | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index e03650b54..f70a3ec0b 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -957,12 +957,25 @@ class Type end newmetaparam(:audit) do - desc "Audit specified attributes of resources over time, and report if any have changed. - This attribute can be used to track changes to any resource over time, and can - provide an audit trail of every change that happens on any given machine. - - Note that you cannot both audit and manage an attribute - managing it guarantees - the value, and any changes already get logged." + desc "Marks a subset of this resource's unmanaged attributes for auditing. Accepts an + attribute name or a list of attribute names. + + Auditing a resource attribute has two effects: First, whenever a catalog + is applied with puppet apply or puppet agent, Puppet will check whether + that attribute of the resource has been modified, comparing its current + value to the previous run; any change will be logged alongside any actions + performed by Puppet while applying the catalog. + + Secondly, marking a resource attribute for auditing will include that + attribute in inspection reports generated by puppet inspect; see the + puppet inspect documentation for more details. + + Managed attributes for a resource can also be audited, but note that + changes made by Puppet will be logged as additional modifications. (I.e. + if a user manually edits a file whose contents are audited and managed, + puppet agent's next two runs will both log an audit notice: the first run + will log the user's edit and then revert the file to the desired state, + and the second run will log the edit made by Puppet.)" validate do |list| list = Array(list).collect {|p| p.to_sym} -- cgit From 4ff5769119aefafa33e05449ebcfac78ba0c0fe0 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 3 Feb 2011 15:36:50 -0800 Subject: (#5823) run mode can now be set dynamically... Third party scripts, and complex command line tools, depend on being able to configure the run_mode value at runtime, not just when they fire up. For better or worse we used to allow this sort of thing to work, but stopped, and we have no sane, safe and consensual alternative, so we broke a bunch of client code. This enables the feature again, but does not add any safety catch; you can now happily slice off your own feet with this, if you really want to. --- lib/puppet/application.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 17ad69cee..b944a554e 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -264,9 +264,14 @@ class Application def initialize(command_line = nil) require 'puppet/util/command_line' @command_line = command_line || Puppet::Util::CommandLine.new - @run_mode = self.class.run_mode + set_run_mode self.class.run_mode @options = {} + require 'puppet' + end + + def set_run_mode(mode) + @run_mode = mode $puppet_application_mode = @run_mode $puppet_application_name = name @@ -281,8 +286,6 @@ class Application Puppet.settings.set_value(:rundir, Puppet.run_mode.run_dir, :mutable_defaults) Puppet.settings.set_value(:run_mode, Puppet.run_mode.name.to_s, :mutable_defaults) end - - require 'puppet' end # This is the main application entry point -- cgit From 04ea8269e70e9c1f81394ac6da2b48dcfb49b1d5 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Thu, 3 Feb 2011 16:19:03 -0800 Subject: (#5823) document the not-an-API status of set_run_mode Since this is totally not API, document that in big, threatening letters so that folks actually know what is going on. Include promises so they don't feel too unhappy with us. Paired-with: matt@puppetlabs.com --- lib/puppet/application.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index b944a554e..c3d7355f6 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -270,6 +270,13 @@ class Application require 'puppet' end + # WARNING: This is a totally scary, frightening, and nasty internal API. We + # strongly advise that you do not use this, and if you insist, we will + # politely allow you to keep both pieces of your broken code. + # + # We plan to provide a supported, long-term API to deliver this in a way + # that you can use. Please make sure that you let us know if you do require + # this, and this message is still present in the code. --daniel 2011-02-03 def set_run_mode(mode) @run_mode = mode $puppet_application_mode = @run_mode -- cgit From f108f0330623f643343709b29921608b6c76874a Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Thu, 3 Feb 2011 14:48:54 -0800 Subject: (#6018) Nick F's --help text for puppet inspect. --- lib/puppet/application/inspect.rb | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'lib') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index 77e8476a2..52ef97530 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -19,6 +19,59 @@ class Puppet::Application::Inspect < Puppet::Application end end + def help + puts <<-HELP ; exit # XXX + +SYNOPSIS +======== + +Prepare and submit an inspection report to the puppet master. + + +USAGE +===== + + puppet inspect + + +DESCRIPTION +=========== + +This command uses the cached catalog from the previous run of 'puppet +agent' to determine which attributes of which resources have been +marked as auditable with the 'audit' metaparameter. It then examines +the current state of the system, writes the state of the specified +resource attributes to a report, and submits the report to the puppet +master. + +Puppet inspect does not run as a daemon, and must be run manually or from cron. + + +OPTIONS +======= + +Any configuration setting which is valid in the configuration file is +also a valid long argument, e.g. '--server=master.domain.com'. See the +configuration file documentation at +http://docs.puppetlabs.com/references/latest/configuration.html for +the full list of acceptable settings. + + +AUTHOR +====== + +Puppet Labs + + +COPYRIGHT +========= + +Copyright (c) 2011 Puppet Labs, LLC +Licensed under the GNU General Public License version 2 + + HELP + end + def setup exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs? -- cgit