diff options
-rw-r--r-- | lib/puppet.rb | 75 | ||||
-rw-r--r-- | lib/puppet/client.rb | 4 | ||||
-rwxr-xr-x | lib/puppet/filebucket.rb | 2 | ||||
-rw-r--r-- | lib/puppet/storage.rb | 22 | ||||
-rw-r--r-- | lib/puppet/type.rb | 14 | ||||
-rwxr-xr-x | lib/puppet/type/pfilebucket.rb | 4 | ||||
-rw-r--r-- | test/other/tc_metrics.rb | 2 | ||||
-rw-r--r-- | test/other/tc_state.rb | 6 | ||||
-rw-r--r-- | test/other/tc_transactions.rb | 4 | ||||
-rwxr-xr-x | test/puppet/tc_defaults.rb | 10 | ||||
-rw-r--r-- | test/types/tc_file.rb | 6 | ||||
-rwxr-xr-x | test/types/tc_filebucket.rb | 6 |
12 files changed, 102 insertions, 53 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 99ab48860..67b407ae3 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -15,6 +15,25 @@ require 'puppet/log' # # it's also a place to find top-level commands like 'debug' module Puppet +# if Process.uid == 0 +# PUPPETCONF = "/etc/puppet" +# PUPPETVAR = "/var/puppet" +# else +# PUPPETCONF = File.expand_path("~/.puppet") +# PUPPETVAR = File.expand_path("~/.puppet/var") +# end +# +# CERTDIR = File.join(PUPPETCONF, "certs") +# CERTFILE = File.join(CERTDIR, "localhost.crt") +# CERTKEY = File.join(CERTDIR, "localhost.key") +# +# RRDDIR = File.join(PUPPETROOT, "rrd") +# LOGDIR = File.join(PUPPETROOT, "log") +# LOGFILE = File.join(LOGDIR, "puppet.log") +# +# STATEDIR = File.join(PUPPETROOT, "state") +# CHECKSUMFILE = File.join(STATEDIR, "checksums") +# class Error < RuntimeError attr_accessor :stack, :line, :file def initialize(message) @@ -51,6 +70,11 @@ module Puppet # configuration parameter access and stuff def self.[](param) + if param.is_a?(String) + param = param.intern + elsif ! param.is_a?(Symbol) + raise ArgumentError, "Invalid parameter type %s" % param.class + end case param when :debug: if Puppet::Log.level == :debug @@ -63,7 +87,44 @@ module Puppet when :logdest: return Puppet::Log.destination else - return @@config[param] + if @@config.include?(param) + return @@config[param] + else + # here's where we define our defaults + returnval = case param + when :puppetconf: + if Process.uid == 0 + "/etc/puppet" + else + File.expand_path("~/.puppet/var") + end + when :puppetvar: + if Process.uid == 0 + "/var/puppet" + else + File.expand_path("~/.puppet") + end + when :rrdgraph: false + when :noop: false + when :puppetport: 8139 + when :masterport: 8140 + when :rrddir: File.join(self[:puppetvar], "rrd") + when :logdir: File.join(self[:puppetvar], "log") + when :bucketdir: File.join(self[:puppetvar], "bucket") + when :logfile: File.join(self[:logdir], "puppet.log") + when :statedir: File.join(self[:puppetvar], "state") + when :checksumfile: File.join(self[:statedir], "checksums") + when :certdir: File.join(self[:puppetconf], "certs") + when :localcert: File.join(self[:certdir], "localhost.crt") + when :localkey: File.join(self[:certdir], "localhost.key") + when :localpub: File.join(self[:certdir], "localhost.pub") + when :mastercert: File.join(self[:certdir], "puppetmaster.crt") + when :masterkey: File.join(self[:certdir], "puppetmaster.key") + when :masterpub: File.join(self[:certdir], "puppetmaster.pub") + else + raise ArgumentError, "Invalid parameter %s" % param + end + end end end @@ -100,18 +161,6 @@ module Puppet end } end - - self[:rrdgraph] = false - if Process.uid == 0 - self[:puppetroot] = "/var/puppet" - else - self[:puppetroot] = File.expand_path("~/.puppet") - end - - self[:rrddir] = File.join(self[:puppetroot],"rrd") - self[:logdir] = File.join(self[:puppetroot],"log") - self[:logfile] = File.join(self[:puppetroot],"log/puppet.log") - self[:statefile] = File.join(self[:puppetroot],"log/state") end require 'puppet/type' diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb index e4dd00801..d96bc158d 100644 --- a/lib/puppet/client.rb +++ b/lib/puppet/client.rb @@ -141,9 +141,9 @@ module Puppet Puppet::Storage.init Puppet::Storage.load rescue => detail - Puppet.err "Corrupt state file %s" % Puppet[:statefile] + Puppet.err "Corrupt state file %s" % Puppet[:checksumfile] begin - File.unlink(Puppet[:statefile]) + File.unlink(Puppet[:checksumfile]) retry rescue => detail raise Puppet::Error.new("Cannot remove %s: %s" % diff --git a/lib/puppet/filebucket.rb b/lib/puppet/filebucket.rb index e67b58668..f0e717146 100755 --- a/lib/puppet/filebucket.rb +++ b/lib/puppet/filebucket.rb @@ -61,7 +61,7 @@ module FileBucket hash.delete(:Path) else if defined? Puppet - @bucket = File.join(Puppet[:puppetroot], "bucket") + @bucket = Puppet[:bucketdir] else @bucket = File.expand_path("~/.filebucket") end diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb index 67c2dbeab..c7c4a7ae1 100644 --- a/lib/puppet/storage.rb +++ b/lib/puppet/storage.rb @@ -25,16 +25,16 @@ module Puppet self.init def self.load - if Puppet[:statefile].nil? + if Puppet[:checksumfile].nil? raise "Somehow the statefile is nil" end - unless File.exists?(Puppet[:statefile]) - Puppet.info "Statefile %s does not exist" % Puppet[:statefile] + unless File.exists?(Puppet[:checksumfile]) + Puppet.info "Statefile %s does not exist" % Puppet[:checksumfile] return end - #Puppet.debug "Loading statefile %s" % Puppet[:statefile] - File.open(Puppet[:statefile]) { |file| + #Puppet.debug "Loading statefile %s" % Puppet[:checksumfile] + File.open(Puppet[:checksumfile]) { |file| file.each { |line| myclass, key, value = line.split(@@splitchar) @@ -61,22 +61,22 @@ module Puppet end def self.store - unless FileTest.directory?(File.dirname(Puppet[:statefile])) + unless FileTest.directory?(File.dirname(Puppet[:checksumfile])) begin - Puppet.recmkdir(File.dirname(Puppet[:statefile])) + Puppet.recmkdir(File.dirname(Puppet[:checksumfile])) Puppet.info "Creating state directory %s" % - File.dirname(Puppet[:statefile]) + File.dirname(Puppet[:checksumfile]) rescue => detail Puppet.err "Could not create state file: %s" % detail return end end - unless FileTest.exist?(Puppet[:statefile]) - Puppet.info "Creating state file %s" % Puppet[:statefile] + unless FileTest.exist?(Puppet[:checksumfile]) + Puppet.info "Creating state file %s" % Puppet[:checksumfile] end - File.open(Puppet[:statefile], File::CREAT|File::WRONLY, 0600) { |file| + File.open(Puppet[:checksumfile], File::CREAT|File::WRONLY, 0600) { |file| @@state.each { |klass, thash| thash.each { |key,value| mvalue = Marshal::dump(value) diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 4f58a971c..b96b01daa 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -57,7 +57,7 @@ class Type < Puppet::Element #@paramdoc = Hash.new # the methods that can be called from within the language - @allowedmethods = [:noop,:debug,:statefile] + @allowedmethods = [:noop,:debug,:checksumfile] # the parameters that all instances will accept @@metaparams = [ @@ -246,7 +246,7 @@ class Type < Puppet::Element def Type.statefile(value) if value =~ /^\// - Puppet[:statefile] = value + Puppet[:checksumfile] = value else raise "Statefile %s must be fully qualified" % value end @@ -1076,14 +1076,14 @@ class Type < Puppet::Element end # Puppet::Type end -require 'puppet/type/service' +require 'puppet/statechange' +require 'puppet/type/component' require 'puppet/type/exec' -require 'puppet/type/filebucket' +require 'puppet/type/package' require 'puppet/type/pfile' +require 'puppet/type/pfilebucket' +require 'puppet/type/service' require 'puppet/type/symlink' -require 'puppet/type/package' -require 'puppet/type/component' -require 'puppet/statechange' #require 'puppet/type/typegen' #require 'puppet/type/typegen/filetype' #require 'puppet/type/typegen/filerecord' diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb index 16a323960..7fa059979 100755 --- a/lib/puppet/type/pfilebucket.rb +++ b/lib/puppet/type/pfilebucket.rb @@ -43,9 +43,7 @@ module Puppet ) end else - @parameters[:path] ||= File.join( - Puppet[:puppetroot], "bucket" - ) + @parameters[:path] ||= Puppet[:bucketdir] begin @bucket = FileBucket::Dipper.new( :Path => @parameters[:path] diff --git a/test/other/tc_metrics.rb b/test/other/tc_metrics.rb index 24be0f9b1..7ba03d554 100644 --- a/test/other/tc_metrics.rb +++ b/test/other/tc_metrics.rb @@ -54,7 +54,7 @@ if $haverrd end def setup - Puppet[:rrddir] = "/tmp/rrdtests" + Puppet[:rrddir] = File.join(Puppet[:puppetvar], "rrdtesting") Puppet[:rrdgraph] = true Puppet[:loglevel] = :debug if __FILE__ == $0 end diff --git a/test/other/tc_state.rb b/test/other/tc_state.rb index e98c21b67..d4262f015 100644 --- a/test/other/tc_state.rb +++ b/test/other/tc_state.rb @@ -16,11 +16,11 @@ end class TestStorage < Test::Unit::TestCase def setup Puppet[:loglevel] = :debug if __FILE__ == $0 - Puppet[:statefile] = "/var/tmp/puppetteststate" + Puppet[:checksumfile] = "/var/tmp/puppetteststate" end def teardown - system("rm -f %s" % Puppet[:statefile]) + system("rm -f %s" % Puppet[:checksumfile]) Puppet::Storage.clear end @@ -73,7 +73,7 @@ class TestStorage < Test::Unit::TestCase state = Puppet::Storage.state(StorageTestingClass) state["testing"] = "yayness" Puppet::Storage.store - assert(FileTest.exists?(Puppet[:statefile])) + assert(FileTest.exists?(Puppet[:checksumfile])) end def test_hashstorage diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb index 8b0ab1f93..3383b3b34 100644 --- a/test/other/tc_transactions.rb +++ b/test/other/tc_transactions.rb @@ -29,7 +29,7 @@ class TestTransactions < Test::Unit::TestCase Puppet::Type.allclear @@tmpfiles = [] Puppet[:loglevel] = :debug if __FILE__ == $0 - Puppet[:statefile] = "/var/tmp/puppetstate" + Puppet[:checksumfile] = File.join(Puppet[:statedir], "checksumtestfile") @groups = %x{groups}.chomp.split(/ /) unless @groups.length > 1 p @groups @@ -46,7 +46,7 @@ class TestTransactions < Test::Unit::TestCase end } @@tmpfiles.clear - system("rm -f %s" % Puppet[:statefile]) + system("rm -f %s" % Puppet[:checksumfile]) print "\n\n" if Puppet[:debug] end diff --git a/test/puppet/tc_defaults.rb b/test/puppet/tc_defaults.rb index 1fc45a89e..d6fe09146 100755 --- a/test/puppet/tc_defaults.rb +++ b/test/puppet/tc_defaults.rb @@ -10,9 +10,9 @@ require 'test/unit' # $Id$ class TestPuppetDefaults < Test::Unit::TestCase - @@dirs = %w{rrddir puppetconf puppetvar logdir statedir certdir} + @@dirs = %w{rrddir puppetconf puppetvar logdir statedir certdir bucketdir} @@files = %w{logfile checksumfile localcert localkey localpub mastercert masterkey masterpub} - @@booleans = %w{rrdgraph} + @@booleans = %w{rrdgraph noop} def testStringOrParam [@@dirs,@@files,@@booleans].flatten.each { |param| assert_nothing_raised { Puppet[param] } @@ -40,7 +40,8 @@ class TestPuppetDefaults < Test::Unit::TestCase value = Puppet[param] unless value =~ confdir or value =~ vardir - assert_nothing_raised { raise "%s is in wrong dir" % value } + assert_nothing_raised { raise "%s is in wrong dir: %s" % + [param,value] } end } end @@ -68,7 +69,8 @@ class TestPuppetDefaults < Test::Unit::TestCase value = Puppet[param] unless value !~ notval - assert_nothing_raised { raise "%s is in wrong dir" % value } + assert_nothing_raised { raise "%s is in wrong dir: %s" % + [param,value] } end } end diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb index 1e7b8ade3..fa25972ff 100644 --- a/test/types/tc_file.rb +++ b/test/types/tc_file.rb @@ -36,11 +36,11 @@ class TestFile < Test::Unit::TestCase def setup @@tmpfiles = [] Puppet[:loglevel] = :debug if __FILE__ == $0 - Puppet[:statefile] = "/var/tmp/puppetstate" + Puppet[:checksumfile] = File.join(Puppet[:statedir], "checksumtestfile") begin initstorage rescue - system("rm -rf %s" % Puppet[:statefile]) + system("rm -rf %s" % Puppet[:checksumfile]) end end @@ -54,7 +54,7 @@ class TestFile < Test::Unit::TestCase end } @@tmpfiles.clear - system("rm -f %s" % Puppet[:statefile]) + system("rm -f %s" % Puppet[:checksumfile]) end def initstorage diff --git a/test/types/tc_filebucket.rb b/test/types/tc_filebucket.rb index b8568ae77..091ff3af3 100755 --- a/test/types/tc_filebucket.rb +++ b/test/types/tc_filebucket.rb @@ -50,11 +50,11 @@ class TestFileBucket < Test::Unit::TestCase def setup @@tmpfiles = [] Puppet[:loglevel] = :debug if __FILE__ == $0 - Puppet[:statefile] = "/var/tmp/puppetstate" + Puppet[:checksumfile] = File.join(Puppet[:statedir], "checksumtestfile") begin initstorage rescue - system("rm -rf %s" % Puppet[:statefile]) + system("rm -rf %s" % Puppet[:checksumfile]) end end @@ -68,7 +68,7 @@ class TestFileBucket < Test::Unit::TestCase end } @@tmpfiles.clear - system("rm -f %s" % Puppet[:statefile]) + system("rm -f %s" % Puppet[:checksumfile]) end def initstorage |