diff options
author | Luke Kanies <luke@madstop.com> | 2005-06-29 19:44:25 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-06-29 19:44:25 +0000 |
commit | bb7e2833f0ea9c97d55fcb76e5811c035161256f (patch) | |
tree | 560129341856ab4a29d9c3c9a40529627de521e4 | |
parent | c16ca53ea8d62ffb8e02afddb8ae93cfbae800b2 (diff) | |
download | puppet-bb7e2833f0ea9c97d55fcb76e5811c035161256f.tar.gz puppet-bb7e2833f0ea9c97d55fcb76e5811c035161256f.tar.xz puppet-bb7e2833f0ea9c97d55fcb76e5811c035161256f.zip |
fixing debugging to severely reduce output but allow it when debugging a specific service
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@319 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r-- | lib/puppet.rb | 36 | ||||
-rw-r--r-- | lib/puppet/client.rb | 18 | ||||
-rw-r--r-- | lib/puppet/event.rb | 8 | ||||
-rw-r--r-- | lib/puppet/log.rb | 6 | ||||
-rw-r--r-- | lib/puppet/metric.rb | 6 | ||||
-rw-r--r-- | lib/puppet/statechange.rb | 6 | ||||
-rw-r--r-- | lib/puppet/transaction.rb | 6 | ||||
-rw-r--r-- | lib/puppet/transportable.rb | 6 | ||||
-rw-r--r-- | lib/puppet/type.rb | 19 | ||||
-rw-r--r-- | lib/puppet/type/component.rb | 2 | ||||
-rw-r--r-- | lib/puppet/type/file.rb | 8 | ||||
-rw-r--r-- | lib/puppet/type/state.rb | 2 | ||||
-rw-r--r-- | test/other/tc_log.rb | 1 | ||||
-rw-r--r-- | test/other/tc_metrics.rb | 2 | ||||
-rw-r--r-- | test/other/tc_selector.rb | 4 | ||||
-rw-r--r-- | test/other/tc_state.rb | 2 | ||||
-rw-r--r-- | test/other/tc_transactions.rb | 2 | ||||
-rw-r--r-- | test/types/tc_basic.rb | 2 | ||||
-rw-r--r-- | test/types/tc_file.rb | 2 | ||||
-rw-r--r-- | test/types/tc_filetype.rb | 2 | ||||
-rw-r--r-- | test/types/tc_query.rb | 2 | ||||
-rw-r--r-- | test/types/tc_service.rb | 2 | ||||
-rw-r--r-- | test/types/tc_symlink.rb | 2 |
23 files changed, 83 insertions, 63 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 40c904e08..56f7ce39e 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -18,12 +18,16 @@ module Puppet # the hash that determines how our system behaves @@config = Hash.new(false) - @@config[:puppetroot] = "/var/puppet" - @@config[:rrddir] = "/var/puppet/rrd" @@config[:rrdgraph] = false - @@config[:logdir] = "/var/puppet/log" - @@config[:logfile] = "/var/puppet/log/puppet.log" - @@config[:statefile] = "/var/puppet/log/state" + if Process.uid == 0 + @@config[:puppetroot] = "/var/puppet" + else + @@config[:puppetroot] = File.expand_path("~/.puppet") + end + @@config[:rrddir] = File.join(@@config[:puppetroot],"rrd") + @@config[:logdir] = File.join(@@config[:puppetroot],"log") + @@config[:logfile] = File.join(@@config[:puppetroot],"log/puppet.log") + @@config[:statefile] = File.join(@@config[:puppetroot],"log/state") # handle the different message levels @@ -47,21 +51,33 @@ module Puppet # configuration parameter access and stuff def Puppet.[](param) - return @@config[param] + case param + when :debug: + if Puppet::Log.level == :debug + return true + else + return false + end + when :loglevel: + return Puppet::Log.level + else + return @@config[param] + end end # configuration parameter access and stuff def Puppet.[]=(param,value) - @@config[param] = value case param when :debug: if value - Puppet::Log.level(:debug) + Puppet::Log.level=(:debug) else - Puppet::Log.level(:notice) + Puppet::Log.level=(:notice) end when :loglevel: - Puppet::Log.level(value) + Puppet::Log.level=(value) + else + @@config[param] = value end end diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index 06808a4b4..15d1edf83 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -27,11 +27,11 @@ module Puppet @nil = nil @url = hash[:Server] if hash.include?(:Listen) and hash[:Listen] == false - Puppet.notice "We're a local client" + Puppet.debug "We're a local client" @localonly = true @driver = @url else - Puppet.notice "We're a networked client" + Puppet.debug "We're a networked client" @localonly = false @driver = SOAP::RPC::Driver.new(@url, 'urn:puppet-server') @driver.add_method("getconfig", "name") @@ -39,7 +39,7 @@ module Puppet unless @localonly hash.delete(:Server) - Puppet.notice "Server is %s" % @url + Puppet.debug "Server is %s" % @url hash[:BindAddress] ||= "0.0.0.0" hash[:Port] ||= 17444 @@ -53,7 +53,7 @@ module Puppet def getconfig Puppet.debug "server is %s" % @url #client.loadproperty('files/sslclient.properties') - Puppet.notice("getting config") + Puppet.debug("getting config") objects = nil if @localonly objects = @driver.getconfig(self) @@ -68,7 +68,7 @@ module Puppet # for now, just descend into the tree and perform and necessary # manipulations def config(tree) - Puppet.notice("Calling config") + Puppet.debug("Calling config") container = Marshal::load(tree).to_type # this is a gross hack... but i don't see a good way around it @@ -83,15 +83,15 @@ module Puppet transaction.evaluate Puppet::Metric.gather Puppet::Metric.tally - Metric.store - if @@config[:rrdgraph] == true - #Metric.store + if Puppet[:rrdgraph] == true + Metric.store + Metric.graph end self.shutdown end def callfunc(name,args) - Puppet.notice("Calling callfunc on %s" % name) + Puppet.debug("Calling callfunc on %s" % name) if function = Puppet::Function[name] #Puppet.debug("calling function %s" % function) value = function.call(args) diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb index 86205591d..3ca76a83b 100644 --- a/lib/puppet/event.rb +++ b/lib/puppet/event.rb @@ -24,7 +24,7 @@ module Puppet # this is probably wicked-slow self.send(method.to_s + "=",value) } - Puppet.warning "New Subscription: '%s' => '%s'" % + Puppet.debug "New Subscription: '%s' => '%s'" % [@source,@event] end @@ -71,16 +71,16 @@ module Puppet @@subscriptions = [] def Event.process - Puppet.warning "Processing events" + Puppet.debug "Processing events" @@events.each { |event| @@subscriptions.find_all { |sub| - #Puppet.warning "Sub source: '%s'; event object: '%s'" % + #Puppet.debug "Sub source: '%s'; event object: '%s'" % # [sub.source.inspect,event.object.inspect] sub.source == event.object and (sub.event == event.event or sub.event == :ALL_EVENTS) }.each { |sub| - Puppet.notice "Found sub" + Puppet.debug "Found subscription to %s" % event sub.trigger(event.transaction) } } diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb index 9cfcb3c1d..9eaa32682 100644 --- a/lib/puppet/log.rb +++ b/lib/puppet/log.rb @@ -83,7 +83,11 @@ module Puppet end end - def Log.level(level) + def Log.level + return @@levels[@@loglevel] + end + + def Log.level=(level) unless level.is_a?(Symbol) level = level.intern end diff --git a/lib/puppet/metric.rb b/lib/puppet/metric.rb index d66105bdf..ba2b1557e 100644 --- a/lib/puppet/metric.rb +++ b/lib/puppet/metric.rb @@ -22,14 +22,14 @@ module Puppet end def Metric.gather - metrics = Metric.init + Metric.init # first gather stats about all of the types Puppet::Type.eachtype { |type| type.each { |instance| - metrics[type][:total] += 1 + @@typemetrics[type][:total] += 1 if instance.managed - metrics[type][:managed] += 1 + @@typemetrics[type][:managed] += 1 end } } diff --git a/lib/puppet/statechange.rb b/lib/puppet/statechange.rb index 4b0cdda5a..f04c40f00 100644 --- a/lib/puppet/statechange.rb +++ b/lib/puppet/statechange.rb @@ -25,7 +25,7 @@ module Puppet #--------------------------------------------------------------- def go if @state.noop - #Puppet.notice "%s is noop" % @state + #Puppet.debug "%s is noop" % @state return nil end @@ -37,7 +37,7 @@ module Puppet if event.nil? event = @state.parent.class.name.id2name + "_changed" elsif ! event.is_a?(Symbol) - Puppet.notice "State '%s' returned invalid event '%s'; resetting to default" % + Puppet.warning "State '%s' returned invalid event '%s'; resetting to default" % [@state.class,event] event = @state.parent.class.name.id2name + "_changed" @@ -72,7 +72,7 @@ module Puppet #--------------------------------------------------------------- def forward - #Puppet.notice "moving change forward" + #Puppet.debug "moving change forward" unless defined? @transaction raise "StateChange '%s' tried to be executed outside of transaction" % diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 03f965a76..2b7d43f8f 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -42,7 +42,7 @@ class Transaction # thus, an object gets defined, then mentioned as a dependency, and the objects # are synced in that order automatically def evaluate - Puppet.notice "executing %s changes or transactions" % @changes.length + Puppet.debug "executing %s changes or transactions" % @changes.length return @changes.collect { |change| if change.is_a?(Puppet::StateChange) @@ -147,7 +147,7 @@ class Transaction #--------------------------------------------------------------- def triggercount(sub) - Puppet.notice "Triggercount on %s is %s" % [sub,@triggered[sub]] + Puppet.debug "Triggercount on %s is %s" % [sub,@triggered[sub]] return @triggered[sub] end #--------------------------------------------------------------- @@ -155,7 +155,7 @@ class Transaction #--------------------------------------------------------------- def triggered(sub) @triggered[sub] += 1 - Puppet.notice "%s was triggered; count is %s" % [sub,@triggered[sub]] + Puppet.debug "%s was triggered; count is %s" % [sub,@triggered[sub]] end #--------------------------------------------------------------- end diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index 519ca7460..c803a9e3d 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -132,12 +132,12 @@ module Puppet } if defined? @parameters @parameters.each { |param,value| - Puppet.warning "Defining %s on %s of type %s" % + Puppet.debug "Defining %s on %s of type %s" % [param,@name,@type] hash[param] = value } else - Puppet.warning "%s has no parameters" % @name + Puppet.debug "%s has no parameters" % @name end container = Puppet::Component.new(hash) nametable = {} @@ -165,7 +165,7 @@ module Puppet # don't rename; this shouldn't be possible anyway next if var == :name - Puppet.notice "Adding %s to %s" % [var,name] + Puppet.debug "Adding %s to %s" % [var,name] # override any existing values object[var] = value } diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 483d94d76..0eee5dbe0 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -152,7 +152,7 @@ class Type < Puppet::Element def Type.inherited(sub) sub.initvars - #Puppet.notice("subtype %s(%s) just created" % [sub,sub.superclass]) + #Puppet.debug("subtype %s(%s) just created" % [sub,sub.superclass]) # add it to the master list # unfortunately we can't yet call sub.name, because the #inherited # method gets called before any commands in the class definition @@ -200,7 +200,7 @@ class Type < Puppet::Element raise "Type.newtype called, but I don't know why" @@typeary.push(type) if @@typehash.has_key?(type.name) - Puppet.notice("Redefining object type %s" % type.name) + Puppet.debug("Redefining object type %s" % type.name) end @@typehash[type.name] = type end @@ -258,7 +258,7 @@ class Type < Puppet::Element # remove all type instances def Type.allclear @@typeary.each { |subtype| - Puppet.notice "Clearing %s of objects" % subtype + Puppet.debug "Clearing %s of objects" % subtype subtype.clear } end @@ -276,7 +276,7 @@ class Type < Puppet::Element #--------------------------------------------------------------- def Type.each return unless defined? @objects - @objects.each { |instance| + @objects.each { |name,instance| yield instance } end @@ -344,7 +344,7 @@ class Type < Puppet::Element #--------------------------------------------------------------- # this is probably only used by FileRecord objects def Type.parameters=(params) - Puppet.notice "setting parameters to [%s]" % params.join(" ") + Puppet.debug "setting parameters to [%s]" % params.join(" ") @parameters = params.collect { |param| if param.class == Symbol param @@ -443,7 +443,7 @@ class Type < Puppet::Element :parent => self, :should => value ) - #Puppet.notice "Adding parent to %s" % mname + #Puppet.debug "Adding parent to %s" % mname #@states[mname].parent = self end end @@ -556,7 +556,7 @@ class Type < Puppet::Element } # add this object to the specific class's list of objects - #Puppet.notice("Adding [%s] to %s" % [self.name,self.class]) + #Puppet.debug("Adding [%s] to %s" % [self.name,self.class]) self.class[self.name] = self # and then add it to the master list @@ -619,15 +619,14 @@ class Type < Puppet::Element if defined? @managed return @managed else + @managed = false self.states.each { |state| if state.should @managed = true - else - @managed = false end } + return @managed end - return @managed end #--------------------------------------------------------------- diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 74db00d00..cd1f65c6c 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -42,7 +42,7 @@ module Puppet def push(*ary) ary.each { |child| unless child.is_a?(Puppet::Element) - Puppet.notice "Got object of type %s" % child.class + Puppet.debug "Got object of type %s" % child.class raise "Containers can only contain Puppet::Elements" end @children.push child diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index f9d966608..28ac59447 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -155,7 +155,7 @@ module Puppet if @is == -1 self.parent.stat(true) self.retrieve - Puppet.notice "%s: after refresh, is '%s'" % [self.class.name,@is] + Puppet.debug "%s: after refresh, is '%s'" % [self.class.name,@is] end unless self.parent.stat @@ -206,7 +206,7 @@ module Puppet if @is == -1 self.parent.stat(true) self.retrieve - Puppet.notice "%s: after refresh, is '%s'" % [self.class.name,@is] + Puppet.debug "%s: after refresh, is '%s'" % [self.class.name,@is] end unless self.parent.stat @@ -243,7 +243,7 @@ module Puppet unless defined? @is or @is == -1 self.parent.stat(true) self.retrieve - Puppet.notice "%s: should is '%s'" % [self.class.name,self.should] + Puppet.debug "%s: should is '%s'" % [self.class.name,self.should] end tmp = 0 if self.is == true @@ -303,7 +303,7 @@ module Puppet if @is == -1 self.parent.stat(true) self.retrieve - Puppet.notice "%s: after refresh, is '%s'" % [self.class.name,@is] + Puppet.debug "%s: after refresh, is '%s'" % [self.class.name,@is] end unless self.parent.stat diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/state.rb index 306b2e5ce..8ba798b1e 100644 --- a/lib/puppet/type/state.rb +++ b/lib/puppet/type/state.rb @@ -93,7 +93,7 @@ class State < Puppet::Element @noop = false end tmp = @noop || self.parent.noop || Puppet[:noop] || false - Puppet.notice "noop is %s" % tmp + Puppet.debug "noop is %s" % tmp return tmp end #--------------------------------------------------------------- diff --git a/test/other/tc_log.rb b/test/other/tc_log.rb index edfb44f8e..b00024636 100644 --- a/test/other/tc_log.rb +++ b/test/other/tc_log.rb @@ -16,6 +16,7 @@ class TestLog < Test::Unit::TestCase def teardown system("rm -f %s" % @@logfile) Puppet::Log.destination(:console) + Puppet[:loglevel] = :notice end def getlevels diff --git a/test/other/tc_metrics.rb b/test/other/tc_metrics.rb index 5c0f33fd0..1dd73a305 100644 --- a/test/other/tc_metrics.rb +++ b/test/other/tc_metrics.rb @@ -48,7 +48,7 @@ class TestMetric < Test::Unit::TestCase def setup Puppet[:rrddir] = File.join(Dir.getwd,"rrdtests") Puppet[:rrdgraph] = true - Puppet[:loglevel] = :debug + Puppet[:loglevel] = :debug if __FILE__ == $0 end def teardown diff --git a/test/other/tc_selector.rb b/test/other/tc_selector.rb index 1f01ea87a..7c8ffbd68 100644 --- a/test/other/tc_selector.rb +++ b/test/other/tc_selector.rb @@ -13,11 +13,11 @@ class TestSelector < Test::Unit::TestCase def setup @os = Puppet::Fact["operatingsystem"] @hostname = Puppet::Fact["hostname"] + + Puppet[:loglevel] = :debug if __FILE__ == $0 end def test_values - Puppet[:debug] = 1 - selector = nil assert_nothing_raised() { selector = Puppet::Selector.new { |select| diff --git a/test/other/tc_state.rb b/test/other/tc_state.rb index bd8d1c24e..5ab5a7cb3 100644 --- a/test/other/tc_state.rb +++ b/test/other/tc_state.rb @@ -11,7 +11,7 @@ require 'test/unit' class TestStorage < Test::Unit::TestCase def setup - Puppet[:debug] = true + Puppet[:loglevel] = :debug if __FILE__ == $0 Puppet[:statefile] = "/var/tmp/puppetteststate" end diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb index d5f2c5da7..ec1b9f277 100644 --- a/test/other/tc_transactions.rb +++ b/test/other/tc_transactions.rb @@ -11,7 +11,7 @@ require 'test/unit' class TestTransactions < Test::Unit::TestCase def setup - Puppet[:debug] = true + Puppet[:loglevel] = :debug if __FILE__ == $0 @groups = %x{groups}.chomp.split(/ /) unless @groups.length > 1 diff --git a/test/types/tc_basic.rb b/test/types/tc_basic.rb index 0732624e5..a62bc4aba 100644 --- a/test/types/tc_basic.rb +++ b/test/types/tc_basic.rb @@ -18,7 +18,7 @@ class TestBasic < Test::Unit::TestCase @configfile = nil @sleeper = nil - Puppet[:debug] = 1 + Puppet[:loglevel] = :debug if __FILE__ == $0 assert_nothing_raised() { @component = Puppet::Component.new(:name => "yaytest") diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 9f7214e99..e40060c01 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -16,7 +16,7 @@ class TestFile < Test::Unit::TestCase def setup @file = nil @path = File.join($puppetbase,"examples/root/etc/configfile") - Puppet[:debug] = 1 + Puppet[:loglevel] = :debug if __FILE__ == $0 Puppet[:statefile] = "/var/tmp/puppetstate" assert_nothing_raised() { @file = Puppet::Type::File.new( diff --git a/test/types/tc_filetype.rb b/test/types/tc_filetype.rb index fcab4b6f8..521a4bbb5 100644 --- a/test/types/tc_filetype.rb +++ b/test/types/tc_filetype.rb @@ -14,7 +14,7 @@ require 'test/unit' #class TestFileType < Test::Unit::TestCase class TestFileType def disabled_setup - Puppet[:debug] = 1 + Puppet[:loglevel] = :debug if __FILE__ == $0 @passwdtype = Puppet::Type::FileType["passwd"] if @passwdtype.nil? diff --git a/test/types/tc_query.rb b/test/types/tc_query.rb index b00bf549b..9bb2dd72e 100644 --- a/test/types/tc_query.rb +++ b/test/types/tc_query.rb @@ -11,7 +11,7 @@ require 'test/unit' class TestQuery < Test::Unit::TestCase def setup - Puppet[:debug] = true + Puppet[:loglevel] = :debug if __FILE__ == $0 end def teardown diff --git a/test/types/tc_service.rb b/test/types/tc_service.rb index 96a14dbee..bda052f30 100644 --- a/test/types/tc_service.rb +++ b/test/types/tc_service.rb @@ -18,7 +18,7 @@ class TestService < Test::Unit::TestCase script = File.join($puppetbase,"examples/root/etc/init.d/sleeper") @status = script + " status" - Puppet[:debug] = 1 + Puppet[:loglevel] = :debug if __FILE__ == $0 assert_nothing_raised() { unless Puppet::Type::Service.has_key?("sleeper") Puppet::Type::Service.new( diff --git a/test/types/tc_symlink.rb b/test/types/tc_symlink.rb index 36a1ed28f..f322c1167 100644 --- a/test/types/tc_symlink.rb +++ b/test/types/tc_symlink.rb @@ -18,7 +18,7 @@ class TestSymlink < Test::Unit::TestCase @path = File.join($puppetbase,"examples/root/etc/symlink") Kernel.system("rm -f %s" % @path) - Puppet[:debug] = 1 + Puppet[:loglevel] = :debug if __FILE__ == $0 assert_nothing_raised() { unless Puppet::Type::Symlink.has_key?(@path) Puppet::Type::Symlink.new( |