summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet.rb122
-rw-r--r--lib/puppet/client.rb2
-rw-r--r--lib/puppet/log.rb1
-rw-r--r--lib/puppet/type.rb9
-rw-r--r--lib/puppet/type/pfile.rb1
-rw-r--r--test/other/tc_log.rb2
-rwxr-xr-xtest/puppet/tc_defaults.rb19
-rw-r--r--test/types/tc_file.rb28
8 files changed, 129 insertions, 55 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index 67b407ae3..b6ca42348 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -15,25 +15,6 @@ 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)
@@ -43,7 +24,7 @@ module Puppet
end
def to_s
- if @file and @line
+ if defined? @file and defined? @line
return "%s at file %s, line %s" %
[@message, @file, @line]
else
@@ -68,6 +49,42 @@ module Puppet
# I keep wanting to use Puppet.error
alias :error :err
+ @defaults = {
+ :rrddir => [:puppetvar, "rrd"],
+ :logdir => [:puppetvar, "log"],
+ :bucketdir => [:puppetvar, "bucket"],
+ :statedir => [:puppetvar, "state"],
+
+ # then the files},
+ :manifest => [:puppetconf, "manifest.pp"],
+ :logfile => [:logdir, "puppet.log"],
+ :masterlog => [:logdir, "puppetmaster.log"],
+ :checksumfile => [:statedir, "checksums"],
+ :certdir => [:puppetconf, "certs"],
+ :rootcert => [:certdir, "ca.crt"],
+ :rootkey => [:certdir, "ca.key"],
+ :rootpub => [:certdir, "ca.pub"],
+ :localcert => [:certdir, "localhost.crt"],
+ :localkey => [:certdir, "localhost.key"],
+ :localpub => [:certdir, "localhost.pub"],
+
+ # and finally the simple answers,
+ :server => "puppet",
+ :rrdgraph => false,
+ :noop => false,
+ :puppetport => 8139,
+ :masterport => 8140,
+ :loglevel => :notice,
+ :logdest => :file,
+ }
+ if Process.uid == 0
+ @defaults[:puppetconf] = "/etc/puppet"
+ @defaults[:puppetvar] = "/var/puppet"
+ else
+ @defaults[:puppetconf] = File.expand_path("~/.puppet")
+ @defaults[:puppetvar] = File.expand_path("~/.puppet/var")
+ end
+
# configuration parameter access and stuff
def self.[](param)
if param.is_a?(String)
@@ -87,40 +104,19 @@ module Puppet
when :logdest:
return Puppet::Log.destination
else
+ # allow manual override
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"
+ if @defaults.include?(param)
+ default = @defaults[param]
+ if default.is_a?(Proc)
+ return default.call()
+ elsif default.is_a?(Array)
+ return File.join(self[default[0]], default[1])
else
- File.expand_path("~/.puppet/var")
+ return default
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
@@ -146,6 +142,34 @@ module Puppet
end
end
+ def self.setdefault(param,value)
+ if value.is_a?(Array)
+ if value[0].is_a?(Symbol)
+ unless @defaults.include?(value[0])
+ raise ArgumentError, "Unknown basedir %s for param %s" %
+ [value[0], param]
+ end
+ else
+ raise ArgumentError, "Invalid default %s for param %s" %
+ [value.inspect, param]
+ end
+
+ unless value[1].is_a?(String)
+ raise ArgumentError, "Invalid default %s for param %s" %
+ [value.inspect, param]
+ end
+
+ unless value.length == 2
+ raise ArgumentError, "Invalid default %s for param %s" %
+ [value.inspect, param]
+ end
+
+ @defaults[param] = value
+ else
+ @defaults[param] = value
+ end
+ end
+
def self.recmkdir(dir,mode = 0755)
tmp = dir.sub(/^\//,'')
path = [File::SEPARATOR]
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb
index d96bc158d..b6361a33c 100644
--- a/lib/puppet/client.rb
+++ b/lib/puppet/client.rb
@@ -46,7 +46,7 @@ module Puppet
def initialize(hash)
hash[:Path] ||= "/RPC2"
hash[:Server] ||= "localhost"
- hash[:Port] ||= 8080
+ hash[:Port] ||= Puppet[:masterport]
super(hash[:Server],hash[:Path],hash[:Port])
end
end
diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb
index 0224328d5..76308c735 100644
--- a/lib/puppet/log.rb
+++ b/lib/puppet/log.rb
@@ -99,6 +99,7 @@ module Puppet
end
end
+ Puppet[:logfile] = dest
begin
# create the log file, if it doesn't already exist
@@logfile = File.open(dest,File::WRONLY|File::CREAT|File::APPEND)
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index b96b01daa..c6b9dc5b1 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -692,9 +692,12 @@ class Type < Puppet::Element
# now get all of the arguments, in a specific order
order = [self.class.namevar]
- order << self.class.states.collect { |state| state.name }
- order << self.class.parameters
- order << self.class.eachmetaparam { |param| param }
+ order << [self.class.states.collect { |state| state.name },
+ self.class.parameters,
+ self.class.eachmetaparam { |param| param }].flatten.reject { |param|
+ # we don't want our namevar in there multiple times
+ param == self.class.namevar
+ }
order.flatten.each { |name|
if hash.include?(name)
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index 3b8469458..e953e92f6 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -51,6 +51,7 @@ module Puppet
mode = nil
if mstate = @parent.state(:mode)
mode = mstate.should
+ Puppet.notice "Mode is %s" % mode
end
begin
case @should
diff --git a/test/other/tc_log.rb b/test/other/tc_log.rb
index 98e62bb0d..f4a39d467 100644
--- a/test/other/tc_log.rb
+++ b/test/other/tc_log.rb
@@ -11,7 +11,7 @@ require 'test/unit'
# $Id$
class TestLog < Test::Unit::TestCase
- @@logfile = "/tmp/puppettest.log"
+ @@logfile = File.join(Puppet[:logdir], "puppettest.log")
def teardown
system("rm -f %s" % @@logfile)
diff --git a/test/puppet/tc_defaults.rb b/test/puppet/tc_defaults.rb
index d6fe09146..06edd7873 100755
--- a/test/puppet/tc_defaults.rb
+++ b/test/puppet/tc_defaults.rb
@@ -11,7 +11,9 @@ require 'test/unit'
class TestPuppetDefaults < Test::Unit::TestCase
@@dirs = %w{rrddir puppetconf puppetvar logdir statedir certdir bucketdir}
- @@files = %w{logfile checksumfile localcert localkey localpub mastercert masterkey masterpub}
+ @@files = %w{logfile checksumfile localcert localkey localpub
+ rootcert rootkey rootpub manifest masterlog}
+ @@normals = %w{puppetport masterport server}
@@booleans = %w{rrdgraph noop}
def testStringOrParam
[@@dirs,@@files,@@booleans].flatten.each { |param|
@@ -74,4 +76,19 @@ class TestPuppetDefaults < Test::Unit::TestCase
end
}
end
+
+ def test_settingdefaults
+ testvals = {
+ :fakeparam => [:puppetconf, "yaytest"],
+ :anotherparam => proc { File.join(Puppet[:puppetvar], "goodtest") },
+ :string => "a yay string",
+ :boolean => true
+ }
+
+ testvals.each { |param, default|
+ assert_nothing_raised {
+ Puppet.setdefault(param,default)
+ }
+ }
+ end
end
diff --git a/test/types/tc_file.rb b/test/types/tc_file.rb
index fa25972ff..e90a6cd57 100644
--- a/test/types/tc_file.rb
+++ b/test/types/tc_file.rb
@@ -370,6 +370,34 @@ class TestFile < Test::Unit::TestCase
@@tmpfiles.push path
end
+ # XXX disabled until i change how dependencies work
+ def disabled_test_recursionwithcreation
+ path = "/tmp/this/directory/structure/does/not/exist"
+ @@tmpfiles.push "/tmp/this"
+
+ file = nil
+ assert_nothing_raised {
+ file = mkfile(
+ :name => path,
+ :recurse => true,
+ :create => true
+ )
+ }
+
+ trans = nil
+ comp = newcomp("recursewithfiles", file)
+ assert_nothing_raised {
+ trans = comp.evaluate
+ }
+
+ events = nil
+ assert_nothing_raised {
+ events = trans.evaluate.collect { |e| e.event.to_s }
+ }
+
+ puts "events are %s" % events.join(", ")
+ end
+
def test_newchild
path = "/tmp/newchilddir"
@@tmpfiles.push path