summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-18 17:24:15 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-01-18 17:24:15 +0000
commit6bab167dcbb274fd302a65d567d6af0ef6621b79 (patch)
tree92093e971bab20400ac8218a5cf1b159e64b5cbb /lib/puppet
parented39be9dd2ecdbe9a8624ed2f6c03334e123e81d (diff)
downloadpuppet-6bab167dcbb274fd302a65d567d6af0ef6621b79.tar.gz
puppet-6bab167dcbb274fd302a65d567d6af0ef6621b79.tar.xz
puppet-6bab167dcbb274fd302a65d567d6af0ef6621b79.zip
Made lots of small changes, mostly to help usability but also fixed a couple of key bugs
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@841 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/client.rb35
-rw-r--r--lib/puppet/event.rb7
-rw-r--r--lib/puppet/parameter.rb25
-rw-r--r--lib/puppet/parser/ast.rb27
-rw-r--r--lib/puppet/parser/ast/astarray.rb3
-rw-r--r--lib/puppet/parser/ast/classdef.rb2
-rw-r--r--lib/puppet/parser/ast/compdef.rb4
-rw-r--r--lib/puppet/parser/ast/component.rb7
-rw-r--r--lib/puppet/parser/ast/leaf.rb7
-rw-r--r--lib/puppet/parser/ast/nodedef.rb5
-rw-r--r--lib/puppet/parser/ast/objectdef.rb52
-rw-r--r--lib/puppet/parser/ast/objectref.rb20
-rw-r--r--lib/puppet/parser/ast/typedefaults.rb2
-rw-r--r--lib/puppet/parser/ast/vardef.rb2
-rw-r--r--lib/puppet/parser/grammar.ra18
-rw-r--r--lib/puppet/parser/interpreter.rb10
-rw-r--r--lib/puppet/parser/parser.rb26
-rw-r--r--lib/puppet/parser/scope.rb45
-rwxr-xr-xlib/puppet/server/fileserver.rb12
-rw-r--r--lib/puppet/transaction.rb3
-rw-r--r--lib/puppet/transportable.rb12
-rw-r--r--lib/puppet/type.rb65
-rw-r--r--lib/puppet/type/component.rb12
-rwxr-xr-xlib/puppet/type/cron.rb6
-rwxr-xr-xlib/puppet/type/exec.rb39
-rwxr-xr-xlib/puppet/type/group.rb4
-rwxr-xr-xlib/puppet/type/nameservice.rb8
-rw-r--r--lib/puppet/type/package.rb40
-rw-r--r--lib/puppet/type/pfile.rb35
-rwxr-xr-xlib/puppet/type/pfile/checksum.rb31
-rwxr-xr-xlib/puppet/type/pfile/group.rb8
-rwxr-xr-xlib/puppet/type/pfile/uid.rb2
-rwxr-xr-xlib/puppet/type/pfilebucket.rb4
-rw-r--r--lib/puppet/type/service.rb11
-rw-r--r--lib/puppet/type/state.rb17
-rwxr-xr-xlib/puppet/type/symlink.rb24
-rwxr-xr-xlib/puppet/type/tidy.rb10
-rwxr-xr-xlib/puppet/type/user.rb9
38 files changed, 380 insertions, 269 deletions
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb
index a0fb994d8..adc6b09ba 100644
--- a/lib/puppet/client.rb
+++ b/lib/puppet/client.rb
@@ -101,8 +101,6 @@ module Puppet
hash[:Path] ||= "/RPC2"
hash[:Server] ||= "localhost"
hash[:Port] ||= Puppet[:masterport]
- Puppet.info "Starting Puppet client version %s for %s" %
- [Puppet.version, hash[:Server]]
@puppetserver = hash[:Server]
@@ -240,24 +238,11 @@ module Puppet
# objects. For now, just descend into the tree and perform and
# necessary manipulations.
def apply
+ dostorage()
unless defined? @objects
raise Puppet::Error, "Cannot apply; objects not defined"
end
- begin
- Puppet::Storage.init
- Puppet::Storage.load
- rescue => detail
- Puppet.err "Corrupt state file %s" % Puppet[:checksumfile]
- begin
- File.unlink(Puppet[:checksumfile])
- retry
- rescue => detail
- raise Puppet::Error.new("Cannot remove %s: %s" %
- [Puppet[statefile], detail])
- end
- end
-
#Puppet.err :yay
#p @objects
#Puppet.err :mark
@@ -291,10 +276,28 @@ module Puppet
return transaction
end
+ # Initialize and load storage
+ def dostorage
+ begin
+ Puppet::Storage.init
+ Puppet::Storage.load
+ rescue => detail
+ Puppet.err "Corrupt state file %s" % Puppet[:checksumfile]
+ begin
+ File.unlink(Puppet[:checksumfile])
+ retry
+ rescue => detail
+ raise Puppet::Error.new("Cannot remove %s: %s" %
+ [Puppet[statefile], detail])
+ end
+ end
+ end
+
# Retrieve the config from a remote server. If this fails, then
# use the cached copy.
def getconfig
Puppet.debug("getting config")
+ dostorage()
facts = self.class.facts
diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb
index a7070bb3e..9576ea4be 100644
--- a/lib/puppet/event.rb
+++ b/lib/puppet/event.rb
@@ -158,7 +158,12 @@ module Puppet
end
def source
- self.class.retrieve(@source)
+ if source = self.class.retrieve(@source)
+ return source
+ else
+ raise Puppet::Error, "Could not retreive dependency %s[%s]" %
+ @source
+ end
end
def sourcearray
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb
index d6662ef1a..a4fe00b7b 100644
--- a/lib/puppet/parameter.rb
+++ b/lib/puppet/parameter.rb
@@ -152,6 +152,31 @@ module Puppet
# end
#end
+ def devfail(msg)
+ self.fail(Puppet::DevError, msg)
+ end
+
+ def fail(*args)
+ type = nil
+ if args[0].is_a?(Class)
+ type = args.shift
+ else
+ type = Puppet::Error
+ end
+
+ error = type.new(args.join(" "))
+
+ if defined? @parent and @parent and @parent.line
+ error.line = @parent.line
+ end
+
+ if defined? @parent and @parent and @parent.file
+ error.file = @parent.file
+ end
+
+ raise error
+ end
+
# This should only be called for parameters, but go ahead and make
# it possible to call for states, too.
def value
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index 9854b5d34..c8cc74f04 100644
--- a/lib/puppet/parser/ast.rb
+++ b/lib/puppet/parser/ast.rb
@@ -58,19 +58,24 @@ module Puppet
def safeevaluate(*args)
begin
self.evaluate(*args)
- rescue Puppet::DevError
+ rescue Puppet::DevError => except
+ except.line ||= @line
+ except.file ||= @file
raise
- rescue Puppet::ParseError
+ rescue Puppet::ParseError => except
+ except.line ||= @line
+ except.file ||= @file
raise
rescue => detail
if Puppet[:debug]
- puts caller
+ puts detail.backtrace
end
error = Puppet::DevError.new(
"Child of type %s failed with error %s: %s" %
[self.class, detail.class, detail.to_s]
)
- error.stack = caller
+ error.line ||= @line
+ error.file ||= @file
raise error
end
end
@@ -83,23 +88,22 @@ module Puppet
"(" + self.class.to_s.sub(/.+::/,'') + ")"
end
- # Initialize the object. Requires a hash as the argument, and takes
- # each of the parameters of the hash and calls the settor method for
- # them. This is probably pretty inefficient and should likely be changed
- # at some point.
+ # Initialize the object. Requires a hash as the argument, and
+ # takes each of the parameters of the hash and calls the settor
+ # method for them. This is probably pretty inefficient and should
+ # likely be changed at some point.
def initialize(args)
@file = nil
@line = nil
args.each { |param,value|
method = param.to_s + "="
unless self.respond_to?(method)
- error = Puppet::DevError.new(
+ error = Puppet::ParseError.new(
"Invalid parameter %s to object class %s" %
[param,self.class.to_s]
)
error.line = self.line
error.file = self.file
- error.stack = caller
raise error
end
@@ -111,7 +115,8 @@ module Puppet
"Could not set parameter %s on class %s: %s" %
[method,self.class.to_s,detail]
)
- error.stack = caller
+ error.line ||= self.line
+ error.file ||= self.file
raise error
end
}
diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb
index 3a02c58ea..1e7bdb81c 100644
--- a/lib/puppet/parser/ast/astarray.rb
+++ b/lib/puppet/parser/ast/astarray.rb
@@ -43,7 +43,10 @@ class Puppet::Parser::AST
item.safeevaluate(scope)
}
end
+
rets = rets.reject { |obj| obj.nil? }
+
+ return rets
end
def push(*ary)
diff --git a/lib/puppet/parser/ast/classdef.rb b/lib/puppet/parser/ast/classdef.rb
index b9f1c1c6b..7386b25eb 100644
--- a/lib/puppet/parser/ast/classdef.rb
+++ b/lib/puppet/parser/ast/classdef.rb
@@ -47,7 +47,7 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
end
diff --git a/lib/puppet/parser/ast/compdef.rb b/lib/puppet/parser/ast/compdef.rb
index ffd0dc0e0..4118c7184 100644
--- a/lib/puppet/parser/ast/compdef.rb
+++ b/lib/puppet/parser/ast/compdef.rb
@@ -36,7 +36,7 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
end
@@ -45,7 +45,7 @@ class Puppet::Parser::AST
@parentclass = nil
super
- Puppet.debug "Defining type %s" % @name.value
+ #Puppet.debug "Defining type %s" % @name.value
# we need to both mark that a given argument is valid,
# and we need to also store any provided default arguments
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb
index f1e6b9648..841977b2f 100644
--- a/lib/puppet/parser/ast/component.rb
+++ b/lib/puppet/parser/ast/component.rb
@@ -48,8 +48,8 @@ class Puppet::Parser::AST
unless hash.include?(arg)
if defined? default and ! default.nil?
hash[arg] = default
- Puppet.debug "Got default %s for %s in %s" %
- [default.inspect, arg.inspect, objname.inspect]
+ #Puppet.debug "Got default %s for %s in %s" %
+ # [default.inspect, arg.inspect, objname.inspect]
else
error = Puppet::ParseError.new(
"Must pass %s to %s of type %s" %
@@ -57,7 +57,6 @@ class Puppet::Parser::AST
)
error.line = self.line
error.file = self.file
- error.stack = caller
raise error
end
end
@@ -82,7 +81,7 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(except.message)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = except.backtrace
raise error
end
}
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 53cefdeb3..d25527864 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -29,11 +29,8 @@ class Puppet::Parser::AST
super
unless @value == 'true' or @value == 'false'
- error = Puppet::DevError.new(
+ raise Puppet::DevError,
"'%s' is not a boolean" % @value
- )
- error.stack = caller
- raise error
end
if @value == 'true'
@value = true
@@ -80,7 +77,7 @@ class Puppet::Parser::AST
error = Puppet::DevError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
end
diff --git a/lib/puppet/parser/ast/nodedef.rb b/lib/puppet/parser/ast/nodedef.rb
index 1cd0f683e..c0e1ee63e 100644
--- a/lib/puppet/parser/ast/nodedef.rb
+++ b/lib/puppet/parser/ast/nodedef.rb
@@ -18,8 +18,8 @@ class Puppet::Parser::AST
end
names.each { |name|
- Puppet.debug("defining host '%s' in scope %s" %
- [name, scope.object_id])
+ #Puppet.debug("defining host '%s' in scope %s" %
+ # [name, scope.object_id])
arghash = {
:name => name,
:code => @code
@@ -41,7 +41,6 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
raise error
end
}
diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb
index 05be941ac..8999e921d 100644
--- a/lib/puppet/parser/ast/objectdef.rb
+++ b/lib/puppet/parser/ast/objectdef.rb
@@ -63,25 +63,24 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
unless object
# If not, verify that it's a builtin type
- begin
- object = Puppet::Type.type(objtype)
- rescue TypeError
- # otherwise, the user specified an invalid type
- error = Puppet::ParseError.new(
- "Invalid type %s" % objtype
- )
- error.line = @line
- error.file = @file
+ object = Puppet::Type.type(objtype)
+
+ # Type.type returns nil on object types that aren't found
+ unless object
+ error = Puppet::ParseError.new("Invalid type %s" % objtype)
+ error.line = self.line
+ error.file = self.file
raise error
end
end
+
# Autogenerate the name if one was not passed.
if defined? @name
objnames = @name.safeevaluate(scope)
@@ -110,12 +109,12 @@ class Puppet::Parser::AST
# If the object is a class, that means it's a builtin type
if object.is_a?(Class)
begin
- Puppet.debug(
- ("Setting object '%s' " +
- "in scope %s " +
- "with arguments %s") %
- [objname, scope.object_id, hash.inspect]
- )
+ #Puppet.debug(
+ # ("Setting object '%s' " +
+ # "in scope %s " +
+ # "with arguments %s") %
+ # [objname, scope.object_id, hash.inspect]
+ #)
obj = scope.setobject(
objtype,
objname,
@@ -131,14 +130,14 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
else
# but things like components create a new type; if we find
# one of those, evaluate that with our arguments
- Puppet.debug("Calling object '%s' with arguments %s" %
- [object.name, hash.inspect])
+ #Puppet.debug("Calling object '%s' with arguments %s" %
+ # [object.name, hash.inspect])
object.safeevaluate(scope,hash,objtype,objname)
end
}.reject { |obj| obj.nil? }
@@ -150,8 +149,8 @@ class Puppet::Parser::AST
begin
defaults = scope.lookupdefaults(objtype)
if defaults.length > 0
- Puppet.debug "Got defaults for %s: %s" %
- [objtype,defaults.inspect]
+ #Puppet.debug "Got defaults for %s: %s" %
+ # [objtype,defaults.inspect]
end
rescue => detail
raise Puppet::DevError,
@@ -219,7 +218,6 @@ class Puppet::Parser::AST
"Invalid parameter '%s' for type '%s'" %
[pname,type.name]
)
- error.stack = caller
error.line = self.line
error.file = self.file
raise error
@@ -243,7 +241,6 @@ class Puppet::Parser::AST
"Invalid parameter '%s' for type '%s'" %
[pname,objtype]
)
- error.stack = caller
error.line = self.line
error.file = self.file
raise error
@@ -277,7 +274,7 @@ class Puppet::Parser::AST
error = Puppet::DevError.new(
"failed to tree a %s" % self.class
)
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
}.join("\n")
@@ -306,13 +303,12 @@ class Puppet::Parser::AST
)
error.line = self.line
error.file = self.file
- error.stack = caller
raise error
end
- unless builtin
- Puppet.debug "%s is a defined type" % objtype
- end
+ #unless builtin
+ # Puppet.debug "%s is a defined type" % objtype
+ #end
self.paramcheck(builtin, objtype)
diff --git a/lib/puppet/parser/ast/objectref.rb b/lib/puppet/parser/ast/objectref.rb
index e9561d65d..6418c14fb 100644
--- a/lib/puppet/parser/ast/objectref.rb
+++ b/lib/puppet/parser/ast/objectref.rb
@@ -21,7 +21,7 @@ class Puppet::Parser::AST
objnames = [objnames]
end
- # Verify we can find the object.
+ # See if we can look the object up in our scope tree.
begin
object = scope.lookuptype(objtype)
rescue Puppet::ParseError => except
@@ -32,20 +32,32 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
+ raise error
+ end
+
+ # If the type isn't defined, verify that it's builtin
+ unless object or Puppet::Type.type(objtype)
+ error = Puppet::ParseError.new("Could not find type %s" %
+ objtype.inspect)
+ error.line = self.line
+ error.file = self.file
raise error
end
- Puppet.debug "ObjectRef returned type %s" % object
# should we implicitly iterate here?
# yes, i believe that we essentially have to...
- objnames.collect { |objname|
+ ret = objnames.collect { |objname|
if object.is_a?(AST::Component)
objname = "%s[%s]" % [objtype,objname]
objtype = "component"
end
[objtype,objname]
}.reject { |obj| obj.nil? }
+
+ # Return a flattened array, since we know that we've created an
+ # array
+ return *ret
end
def tree(indent = 0)
diff --git a/lib/puppet/parser/ast/typedefaults.rb b/lib/puppet/parser/ast/typedefaults.rb
index 17ef94589..c1f8cce52 100644
--- a/lib/puppet/parser/ast/typedefaults.rb
+++ b/lib/puppet/parser/ast/typedefaults.rb
@@ -24,7 +24,7 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
end
diff --git a/lib/puppet/parser/ast/vardef.rb b/lib/puppet/parser/ast/vardef.rb
index 6ada75589..52548a42c 100644
--- a/lib/puppet/parser/ast/vardef.rb
+++ b/lib/puppet/parser/ast/vardef.rb
@@ -19,7 +19,7 @@ class Puppet::Parser::AST
error = Puppet::ParseError.new(detail)
error.line = self.line
error.file = self.file
- error.stack = caller
+ error.backtrace = detail.backtrace
raise error
end
end
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index 469bb5dee..3630d27ef 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -662,8 +662,11 @@ array: LBRACK rvalues RBRACK {
if val[1].is_a?(AST::ASTArray)
result = val[1]
else
- result = AST::ASTArray.new
- result.push val[1]
+ result = AST::ASTArray.new(
+ :line => @lexer.line,
+ :file => @lexer.file,
+ :children => [val[1]]
+ )
end
}
@@ -682,10 +685,7 @@ require 'puppet/parser/ast'
#require 'puppet/parser/interpreter'
module Puppet
- # this exception class already has a :stack accessor
- class ParseError < Puppet::Error
- attr_accessor :line, :file
- end
+ class ParseError < Puppet::Error; end
class ImportError < Racc::ParseError; end
end
@@ -764,7 +764,7 @@ def parse
error = Puppet::ParseError.new(except)
error.line = @lexer.line
error.file = @lexer.file
- error.stack = caller
+ error.backtrace = except.backtrace
raise error
rescue Puppet::ParseError => except
except.line ||= @lexer.line
@@ -774,7 +774,6 @@ def parse
# and this is a framework error
except.line ||= @lexer.line
except.file ||= @lexer.file
- except.stack ||= except.stack
#if Puppet[:debug]
# puts except.stack
#end
@@ -782,7 +781,6 @@ def parse
rescue Puppet::DevError => except
except.line ||= @lexer.line
except.file ||= @lexer.file
- except.stack ||= caller
#if Puppet[:debug]
# puts except.stack
#end
@@ -791,7 +789,7 @@ def parse
error = Puppet::DevError.new(except.message)
error.line = @lexer.line
error.file = @lexer.file
- error.stack = caller
+ error.backtrace = except.backtrace
#if Puppet[:debug]
# puts caller
#end
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index 96555faa1..b1cf4207c 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -82,19 +82,15 @@ module Puppet
#Puppet.err "File %s, line %s: %s" %
# [except.file, except.line, except.message]
if Puppet[:debug]
- puts except.stack
- end
- if Puppet[:debug]
- puts caller
+ puts except.backtrace
end
#exit(1)
raise
rescue => except
error = Puppet::DevError.new("%s: %s" %
[except.class, except.message])
- error.stack = caller
if Puppet[:debug]
- puts caller
+ puts except.backtrace
end
raise error
end
@@ -111,6 +107,8 @@ module Puppet
# entire configuration each time we get a connect.
def evaluate
+ # FIXME When this produces errors, it should specify which
+ # node caused those errors.
if @usenodes
@scope = Puppet::Parser::Scope.new() # no parent scope
@scope.name = "top"
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index c50e65cac..582283704 100644
--- a/lib/puppet/parser/parser.rb
+++ b/lib/puppet/parser/parser.rb
@@ -14,10 +14,7 @@ require 'puppet/parser/ast'
#require 'puppet/parser/interpreter'
module Puppet
- # this exception class already has a :stack accessor
- class ParseError < Puppet::Error
- attr_accessor :line, :file
- end
+ class ParseError < Puppet::Error; end
class ImportError < Racc::ParseError; end
end
@@ -32,7 +29,7 @@ module Puppet
class Parser < Racc::Parser
-module_eval <<'..end grammar.ra modeval..id082f0a899d', 'grammar.ra', 697
+module_eval <<'..end grammar.ra modeval..idc16574e75e', 'grammar.ra', 697
attr_reader :file
attr_accessor :files
@@ -103,7 +100,7 @@ def parse
error = Puppet::ParseError.new(except)
error.line = @lexer.line
error.file = @lexer.file
- error.stack = caller
+ error.backtrace = except.backtrace
raise error
rescue Puppet::ParseError => except
except.line ||= @lexer.line
@@ -113,7 +110,6 @@ def parse
# and this is a framework error
except.line ||= @lexer.line
except.file ||= @lexer.file
- except.stack ||= except.stack
#if Puppet[:debug]
# puts except.stack
#end
@@ -121,7 +117,6 @@ def parse
rescue Puppet::DevError => except
except.line ||= @lexer.line
except.file ||= @lexer.file
- except.stack ||= caller
#if Puppet[:debug]
# puts except.stack
#end
@@ -130,7 +125,7 @@ def parse
error = Puppet::DevError.new(except.message)
error.line = @lexer.line
error.file = @lexer.file
- error.stack = caller
+ error.backtrace = except.backtrace
#if Puppet[:debug]
# puts caller
#end
@@ -149,7 +144,7 @@ def string=(string)
end
# $Id$
-..end grammar.ra modeval..id082f0a899d
+..end grammar.ra modeval..idc16574e75e
##### racc 1.4.4 generates ###
@@ -1404,13 +1399,16 @@ module_eval <<'.,.,', 'grammar.ra', 659
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 668
+module_eval <<'.,.,', 'grammar.ra', 671
def _reduce_90( val, _values, result )
if val[1].is_a?(AST::ASTArray)
result = val[1]
else
- result = AST::ASTArray.new
- result.push val[1]
+ result = AST::ASTArray.new(
+ :line => @lexer.line,
+ :file => @lexer.file,
+ :children => [val[1]]
+ )
end
result
end
@@ -1422,7 +1420,7 @@ module_eval <<'.,.,', 'grammar.ra', 668
# reduce 93 omitted
-module_eval <<'.,.,', 'grammar.ra', 673
+module_eval <<'.,.,', 'grammar.ra', 676
def _reduce_94( val, _values, result )
result = nil
result
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 598c67b5e..c2c59fc5a 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -360,7 +360,6 @@ module Puppet
"Could not retrieve %s table at level %s" %
[type,self.level]
)
- error.stack = caller
raise error
end
@@ -412,32 +411,32 @@ module Puppet
# Look up a node by name
def lookupnode(name)
- Puppet.debug "Looking up type %s" % name
+ #Puppet.debug "Looking up type %s" % name
value = self.lookup("type",name)
if value == :undefined
return nil
else
- Puppet.debug "Found type %s" % name
+ #Puppet.debug "Found node %s" % name
return value
end
end
# Look up a defined type.
def lookuptype(name)
- Puppet.debug "Looking up type %s" % name
+ #Puppet.debug "Looking up type %s" % name
value = self.lookup("type",name)
if value == :undefined
return nil
else
- Puppet.debug "Found type %s" % name
+ #Puppet.debug "Found type %s" % name
return value
end
end
# Look up an object by name and type.
def lookupobject(name,type)
- Puppet.debug "Looking up object %s of type %s in level %s" %
- [name, type, @level]
+ #Puppet.debug "Looking up object %s of type %s in level %s" %
+ # [name, type, @level]
sub = proc { |table|
if table.include?(type)
if table[type].include?(name)
@@ -457,13 +456,12 @@ module Puppet
# Look up a variable. The simplest value search we do.
def lookupvar(name)
- Puppet.debug "Looking up variable %s" % name
+ #Puppet.debug "Looking up variable %s" % name
value = self.lookup("variable", name)
if value == :undefined
error = Puppet::ParseError.new(
"Undefined variable '%s'" % name
)
- error.stack = caller
raise error
else
#Puppet.debug "Value of '%s' is '%s'" % [name,value]
@@ -473,7 +471,7 @@ module Puppet
# Create a new scope.
def newscope
- Puppet.debug "Creating new scope, level %s" % [self.level + 1]
+ #Puppet.debug "Creating new scope, level %s" % [self.level + 1]
return Puppet::Parser::Scope.new(self)
end
@@ -498,15 +496,14 @@ module Puppet
end
params.each { |ary|
- Puppet.debug "Default for %s is %s => %s" %
- [type,ary[0].inspect,ary[1].inspect]
+ #Puppet.debug "Default for %s is %s => %s" %
+ # [type,ary[0].inspect,ary[1].inspect]
if @@declarative
if table.include?(ary[0])
error = Puppet::ParseError.new(
"Default already defined for %s { %s }" %
[type,ary[0]]
)
- error.stack = caller
raise error
end
else
@@ -601,14 +598,10 @@ module Puppet
# in scopes above, but will not allow variables in the current scope
# to be reassigned if we're declarative (which is the default).
def setvar(name,value)
- Puppet.debug "Setting %s to '%s' at level %s" %
- [name.inspect,value,self.level]
+ #Puppet.debug "Setting %s to '%s' at level %s" %
+ # [name.inspect,value,self.level]
if @@declarative and @symtable.include?(name)
- error = Puppet::ParseError.new(
- "Cannot reassign variable %s" % name
- )
- error.stack = caller
- raise error
+ raise Puppet::ParseError, "Cannot reassign variable %s" % name
else
if @symtable.include?(name)
Puppet.warning "Reassigning %s to %s" % [name,value]
@@ -699,12 +692,9 @@ module Puppet
@topscope.addtags(child)
results.push(child)
else
- error = Puppet::DevError.new(
+ raise Puppet::DevError,
"Puppet::Parse::Scope cannot handle objects of type %s" %
child.class
- )
- error.stack = caller
- raise error
end
}
@@ -728,11 +718,8 @@ module Puppet
if defined? @type
bucket.type = @type
else
- error = Puppet::ParseError.new(
+ raise Puppet::ParseError,
"No type for scope %s" % @name
- )
- error.stack = caller
- raise error
end
#Puppet.debug(
# "TransBucket with name %s and type %s in scope %s" %
@@ -752,7 +739,7 @@ module Puppet
# [bucket.name,self.object_id]
return bucket
else
- Puppet.debug "nameless scope; just returning a list"
+ #Puppet.debug "nameless scope; just returning a list"
return results
end
end
diff --git a/lib/puppet/server/fileserver.rb b/lib/puppet/server/fileserver.rb
index 4712a344b..3349256ba 100755
--- a/lib/puppet/server/fileserver.rb
+++ b/lib/puppet/server/fileserver.rb
@@ -59,6 +59,10 @@ class Server
authcheck(file, mount, client, clientip)
+ if client
+ Puppet.debug "Describing %s for %s" % [file, client]
+ end
+
sdir = nil
unless sdir = subdir(mount, path)
mount.notice "Could not find subdirectory %s" %
@@ -148,6 +152,10 @@ class Server
authcheck(dir, mount, client, clientip)
+ if client
+ Puppet.debug "Listing %s for %s" % [dir, client]
+ end
+
subdir = nil
unless subdir = subdir(mount, path)
mount.notice "Could not find subdirectory %s" %
@@ -307,6 +315,10 @@ class Server
authcheck(file, mount, client, clientip)
+ if client
+ Puppet.info "Sending %s to %s" % [file, client]
+ end
+
fpath = nil
if path
fpath = File.join(mount.path, path)
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index cf579a8f0..612cee87e 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -41,7 +41,8 @@ class Transaction
# then, we need to pass the event to the object's containing component,
# to see if it or any of its parents have subscriptions on the event
def evaluate
- Puppet.debug "executing %s changes " % @changes.length
+ Puppet.debug "Beginning transaction %s with %s changes" %
+ [self.object_id, @changes.length]
events = @changes.collect { |change|
if change.is_a?(Puppet::StateChange)
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 129e80bac..cbc60450d 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -26,7 +26,6 @@ module Puppet
@type = type
@name = name
@params = {"name" => name}
- #Puppet.info @params.inspect
#self.class.add(self)
end
@@ -53,13 +52,11 @@ module Puppet
end
def to_type(parent = nil)
- if parent
- self[:parent] = parent
- end
retobj = nil
if type = Puppet::Type.type(self.type)
unless retobj = type.create(self)
- Puppet.info "Could not create object"
+ Puppet.notice "Could not create %s[%s]" %
+ [self.type, self.name]
return nil
end
#retobj.file = @file
@@ -74,11 +71,10 @@ module Puppet
#end
if parent
+ self[:parent] = parent
parent.push retobj
end
- Puppet.info retobj.class
-
return retobj
end
end
@@ -147,7 +143,7 @@ module Puppet
hash[param] = value
}
else
- Puppet.debug "%s[%s] has no parameters" % [@type, @name]
+ #Puppet.debug "%s[%s] has no parameters" % [@type, @name]
end
if parent
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 097359915..b13831727 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -231,6 +231,7 @@ class Type < Puppet::Element
if name.is_a?(String)
name = name.intern
end
+
@types[name]
end
@@ -344,7 +345,6 @@ class Type < Puppet::Element
self.eachtype do |type|
type.each do |object|
unless finished.has_key?(object)
- Puppet.debug "Finishing %s" % object.name
object.finish
finished[object] = true
end
@@ -794,6 +794,32 @@ class Type < Puppet::Element
}
end
+ def devfail(msg)
+ self.fail(Puppet::DevError, msg)
+ end
+
+ # Throw an error, defaulting to a Puppet::Error
+ def fail(*args)
+ type = nil
+ if args[0].is_a?(Class)
+ type = args.shift
+ else
+ type = Puppet::Error
+ end
+
+ error = type.new(args.join(" "))
+
+ if @line
+ error.line = @line
+ end
+
+ if @file
+ error.file = @file
+ end
+
+ raise error
+ end
+
# retrieve the 'is' value for a specified state
def is(state)
if @states.include?(state)
@@ -868,7 +894,7 @@ class Type < Puppet::Element
when :param
@parameters[klass.name] = param
else
- raise Puppet::DevError, "Invalid param type %s" % type
+ self.devfail("Invalid param type %s" % type)
end
return param
@@ -883,7 +909,7 @@ class Type < Puppet::Element
else
stateklass = self.class.validstate?(name)
unless stateklass
- raise Puppet::Error, "Invalid state %s" % name
+ self.fail("Invalid state %s" % name)
end
end
if @states.include?(name)
@@ -983,8 +1009,9 @@ class Type < Puppet::Element
end
}
unless tmpstates.length == @states.length
- raise Puppet::DevError,
+ self.devfail(
"Something went very wrong with tmpstates creation"
+ )
end
return tmpstates
end
@@ -1160,7 +1187,7 @@ class Type < Puppet::Element
begin
self[name] = hash[name]
rescue => detail
- raise Puppet::DevError.new(
+ self.devfail(
"Could not set %s on %s: %s" % [name, self.class.name, detail]
)
end
@@ -1174,7 +1201,7 @@ class Type < Puppet::Element
if hash.length > 0
self.debug hash.inspect
- raise Puppet::Error.new("Class %s does not accept argument(s) %s" %
+ self.fail("Class %s does not accept argument(s) %s" %
[self.class.name, hash.keys.join(" ")])
end
@@ -1229,7 +1256,7 @@ class Type < Puppet::Element
when :param: return @parameters.include?(attr)
when :meta: return @metaparams.include?(attr)
else
- raise Puppet::DevError, "Invalid set type %s" % [type]
+ self.devfail "Invalid set type %s" % [type]
end
end
@@ -1245,7 +1272,7 @@ class Type < Puppet::Element
klass = self.class.attrclass(attr)
unless klass
- raise Puppet::DevError, "Could not retrieve class for %s" % attr
+ self.devfail "Could not retrieve class for %s" % attr
end
if klass.method_defined?(:default)
obj = self.newattr(type, klass)
@@ -1286,10 +1313,10 @@ class Type < Puppet::Element
# take the intersection
newvals = oldvals & value
if newvals.empty?
- raise Puppet::Error, "No common values for %s on %s(%s)" %
+ self.fail "No common values for %s on %s(%s)" %
[param, self.class.name, self.name]
elsif newvals.length > 1
- raise Puppet::Error, "Too many values for %s on %s(%s)" %
+ self.fail "Too many values for %s on %s(%s)" %
[param, self.class.name, self.name]
else
self.debug "Reduced old values %s and new values %s to %s" %
@@ -1313,13 +1340,13 @@ class Type < Puppet::Element
elsif self.class.validstate?(namevar)
@name = self.should(namevar)
else
- raise Puppet::DevError, "Could not find namevar %s for %s" %
+ self.devfail "Could not find namevar %s for %s" %
[namevar, self.class.name]
end
end
unless @name
- raise Puppet::DevError, "Could not find namevar '%s' for %s" %
+ self.devfail "Could not find namevar '%s' for %s" %
[namevar, self.class.name]
end
@@ -1550,7 +1577,6 @@ class Type < Puppet::Element
def self.mkdepends
@types.each { |name, type|
type.each { |obj|
- Puppet.info "building depends for %s(%s)" % [type.name, obj.name]
obj.builddepends
}
}
@@ -1605,11 +1631,11 @@ class Type < Puppet::Element
object = nil
tname = rname[0]
unless type = Puppet::Type.type(tname)
- raise Puppet::Error, "Could not find type %s" % tname
+ self.fail "Could not find type %s" % tname.inspect
end
name = rname[1]
unless object = type[name]
- raise Puppet::Error, "Could not retrieve object '%s' of type '%s'" %
+ self.fail "Could not retrieve object '%s' of type '%s'" %
[name,type]
end
self.debug("subscribes to %s" % [object])
@@ -1728,7 +1754,7 @@ class Type < Puppet::Element
elsif noop == "false" or noop == false
return false
else
- raise Puppet::Error.new("Invalid noop value '%s'" % noop)
+ self.fail("Invalid noop value '%s'" % noop)
end
end
end
@@ -1752,7 +1778,7 @@ class Type < Puppet::Element
end
unless defined? @parent
- raise Puppet::DevError, "No parent for %s, %s?" %
+ self.devfail "No parent for %s, %s?" %
[self.class, self.name]
end
@@ -1863,7 +1889,7 @@ class Type < Puppet::Element
loglevel = loglevel.intern
end
unless Puppet::Log.validlevel?(loglevel)
- raise Puppet::Error, "Invalid log level %s" % loglevel
+ self.fail "Invalid log level %s" % loglevel
end
end
@@ -1908,9 +1934,10 @@ class Type < Puppet::Element
aliases.each do |other|
if obj = @parent.class[other]
unless obj == @parent
- raise Puppet::Error,
+ self.fail(
"%s an not create alias %s: object already exists" %
[@parent.name, other]
+ )
end
next
end
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 1ffe05f19..5f7e7656a 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -41,9 +41,13 @@ module Puppet
return
end
inlist[obj.object_id] = true
- obj.eachdependency { |req|
- self.recurse(req, inlist, list)
- }
+ begin
+ obj.eachdependency { |req|
+ self.recurse(req, inlist, list)
+ }
+ rescue Puppet::Error => detail
+ raise Puppet::Error, "%s: %s" % [obj.path, detail]
+ end
if obj.is_a? self
obj.each { |child|
@@ -112,7 +116,7 @@ module Puppet
ary.each { |child|
unless child.is_a?(Puppet::Element)
self.debug "Got object of type %s" % child.class
- raise Puppet::DevError.new(
+ self.devfail(
"Containers can only contain Puppet::Elements, not %s" %
child.class
)
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index 03b27eef5..21794e5f6 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -96,7 +96,7 @@ module Puppet
if retval
return retval.to_s
else
- raise Puppet::Error, "%s is not a valid %s" %
+ self.fail "%s is not a valid %s" %
[value, self.class.name]
end
end
@@ -180,7 +180,7 @@ module Puppet
obj = Etc.getpwnam(user)
parent.uid = obj.uid
rescue ArgumentError
- raise Puppet::Error, "User %s not found" % user
+ self.fail "User %s not found" % user
end
user
@@ -469,7 +469,7 @@ module Puppet
# the +@filetype+ retrieve method.
def retrieve
unless @parameters.include?(:user)
- raise Puppet::Error, "You must specify the cron user"
+ self.fail "You must specify the cron user"
end
self.class.retrieve(self[:user])
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 78f96d9a7..5512bc10d 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -67,29 +67,29 @@ module Puppet
if cmd =~ /^\//
exe = cmd.split(/ /)[0]
unless FileTest.exists?(exe)
- raise TypeError.new(
+ self.fail(
"Could not find executable %s" % exe
)
end
unless FileTest.executable?(exe)
- raise TypeError.new(
+ self.fail(
"%s is not executable" % exe
)
end
elsif path = self.parent[:path]
exe = cmd.split(/ /)[0]
tmppath = ENV["PATH"]
- ENV["PATH"] = self.parent[:path]
+ ENV["PATH"] = self.parent[:path].join(":")
path = %{which #{exe}}.chomp
if path == ""
- raise TypeError.new(
+ self.fail(
"Could not find command '%s'" % exe
)
end
ENV["PATH"] = tmppath
else
- raise TypeError.new(
+ self.fail(
"%s is somehow not qualified with no search path" %
self.parent[:command]
)
@@ -132,7 +132,9 @@ module Puppet
begin
# Do our chdir
Dir.chdir(dir) {
- ENV["PATH"] = self.parent[:path]
+ if self.parent[:path]
+ ENV["PATH"] = self.parent[:path].join(":")
+ end
# The user and group default to nil, which 'asuser'
# handlers correctly
@@ -168,7 +170,7 @@ module Puppet
}
}
rescue Errno::ENOENT => detail
- raise Puppet::Error, detail.to_s
+ self.fail detail.to_s
ensure
# reset things to how we found them
ENV["PATH"] = tmppath
@@ -191,7 +193,14 @@ module Puppet
newparam(:path) do
desc "The search path used for command execution.
Commands must be fully qualified if no path is specified. Paths
- must be specified as an array, not as a colon-separated list."
+ can be specified as an array or as a colon-separated list."
+
+ # Support both arrays and colon-separated fields.
+ def value=(*values)
+ @value = values.collect { |val|
+ val.split(":")
+ }.flatten
+ end
end
newparam(:user) do
@@ -201,8 +210,7 @@ module Puppet
munge do |user|
unless Process.uid == 0
- raise Puppet::Error,
- "Only root can execute commands as other users"
+ self.fail "Only root can execute commands as other users"
end
require 'etc'
@@ -217,7 +225,7 @@ module Puppet
begin
Etc.send(method, user)
rescue ArgumentError
- raise Puppet::Error, "No such user %s" % user
+ self.fail "No such user %s" % user
end
return user
@@ -244,7 +252,7 @@ module Puppet
begin
Etc.send(method, group)
rescue ArgumentError
- raise Puppet::Error, "No such group %s" % group
+ self.fail "No such group %s" % group
end
group
@@ -261,7 +269,7 @@ module Puppet
end
unless File.directory?(dir)
- raise Puppet::Error, "Directory '%s' does not exist" % dir
+ self.fail "Directory '%s' does not exist" % dir
end
dir
@@ -308,7 +316,7 @@ module Puppet
# fail the entire exec, right?
validate do |file|
unless file =~ %r{^#{File::SEPARATOR}}
- raise Puppet::Error, "'creates' files must be fully qualified."
+ self.fail "'creates' files must be fully qualified."
end
end
end
@@ -320,8 +328,7 @@ module Puppet
# if we're not fully qualified, require a path
if self[:command] !~ /^\//
if self[:path].nil?
- raise TypeError,
- "both unqualifed and specified no search path"
+ self.fail "both unqualifed and specified no search path"
end
end
end
diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb
index 4bb5f9d95..bc7f6cf1e 100755
--- a/lib/puppet/type/group.rb
+++ b/lib/puppet/type/group.rb
@@ -57,11 +57,11 @@ module Puppet
if gid =~ /^[-0-9]+$/
gid = Integer(gid)
else
- raise Puppet::Error, "Invalid GID %s" % gid
+ self.fail "Invalid GID %s" % gid
end
when Symbol
unless gid == :auto or gid == :absent
- raise Puppet::DevError, "Invalid GID %s" % gid
+ self.devfail "Invalid GID %s" % gid
end
if gid == :auto
unless self.class.autogen?
diff --git a/lib/puppet/type/nameservice.rb b/lib/puppet/type/nameservice.rb
index ea4d4b6ea..9d6c2ba62 100755
--- a/lib/puppet/type/nameservice.rb
+++ b/lib/puppet/type/nameservice.rb
@@ -119,8 +119,7 @@ class State
if method = self.class.posixmethod || self.class.name
@is = obj.send(method)
else
- raise Puppet::DevError,
- "%s has no posixmethod" % self.class
+ self.devfail "%s has no posixmethod" % self.class
end
else
@is = :absent
@@ -157,8 +156,7 @@ class State
# end
unless @parent.exists?
- raise Puppet::DevError,
- "%s %s does not exist; cannot set %s" %
+ self.devfail "%s %s does not exist; cannot set %s" %
[@parent.class.name, @parent.name, self.class.name]
end
@@ -172,7 +170,7 @@ class State
unless $? == 0
- raise Puppet::Error, "Could not modify %s on %s %s: %s" %
+ self.fail "Could not modify %s on %s %s: %s" %
[self.class.name, @parent.class.name,
@parent.name, output]
end
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index a685352bb..c7242cd14 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -116,7 +116,17 @@ module Puppet
#end
newvalue(:latest) do
- @parent.update
+ unless @parent.respond_to?(:latest)
+ self.fail(
+ "Package type %s does not support specifying 'latest'" %
+ @parent[:type]
+ )
+ end
+ begin
+ @parent.update
+ rescue => detail
+ self.fail "Could not update: %s" % detail
+ end
if self.is == :absent
return :package_created
@@ -138,7 +148,18 @@ module Puppet
return true
end
when :latest
- latest = @parent.latest
+ unless @parent.respond_to?(:latest)
+ self.fail(
+ "Package type %s does not support specifying 'latest'" %
+ @parent[:type]
+ )
+ end
+
+ begin
+ latest = @parent.latest
+ rescue => detail
+ self.fail "Could not get latest version: %s" % detail
+ end
case @is
when latest:
return true
@@ -229,8 +250,8 @@ module Puppet
end
newparam(:type) do
- desc "The package format. You will seldom need to specify this -- Puppet
- will discover the appropriate format for your platform."
+ desc "The package format. You will seldom need to specify this --
+ Puppet will discover the appropriate format for your platform."
defaultto { @parent.class.default }
@@ -246,8 +267,9 @@ module Puppet
validate do |value|
unless value =~ /^#{File::SEPARATOR}/ or value =~ /\w+:\/\//
- raise Puppet::Error,
+ self.fail(
"Package sources must be fully qualified files or URLs, depending on the platform."
+ )
end
end
end
@@ -360,7 +382,7 @@ module Puppet
# pull all of the objects
typeobj.list
else
- raise "Could not find package type '%s'" % type
+ raise Puppet::Error, "Could not find package type '%s'" % type
end
}.flatten
@listed = true
@@ -481,7 +503,7 @@ module Puppet
return type
else
- raise Puppet::Error, "Invalid package type %s" % typename
+ self.fail "Invalid package type %s" % typename
end
end
end # Puppet.type(:package)
@@ -499,7 +521,7 @@ module Puppet
if source = @@sources[type]
return source.retrieve(file)
else
- raise "Unknown package source: %s" % type
+ raise Puppet::Error, "Unknown package source: %s" % type
end
end
@@ -525,7 +547,7 @@ module Puppet
if FileTest.exists?(file)
return file
else
- raise "File %s does not exist" % file
+ raise Puppet::Error, "File %s does not exist" % file
end
}
}
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index b1e8b325d..12b162845 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -44,16 +44,15 @@ module Puppet
if bucket = Puppet.type(:filebucket).bucket(value[1])
bucket
else
- raise Puppet::Error,
- "Could not retrieve filebucket %s" %
+ self.fail "Could not retrieve filebucket %s" %
value[1]
end
else
- raise Puppet::Error, "Invalid backup object type %s" %
+ self.fail "Invalid backup object type %s" %
value[0].inspect
end
else
- raise Puppet::Error, "Invalid backup type %s" %
+ self.fail "Invalid backup type %s" %
value.inspect
end
end
@@ -67,6 +66,10 @@ module Puppet
newparam(:recurse) do
desc "Whether and how deeply to do recursive
management. **false**/*true*/*inf*/*number*"
+
+ munge do |value|
+ value
+ end
end
newparam(:ignore) do
@@ -80,7 +83,7 @@ module Puppet
validate do |value|
unless value.is_a?(Array) or value.is_a?(String) or value == false
- raise Puppet::DevError.new("Ignore must be a string or an Array")
+ self.devfail "Ignore must be a string or an Array"
end
end
end
@@ -97,7 +100,7 @@ module Puppet
validate do
if self[:content] and self[:source]
- raise Puppet::Error, "You cannot specify both content and a source"
+ self.fail "You cannot specify both content and a source"
end
end
@@ -151,8 +154,8 @@ module Puppet
rescue => detail
# since they said they want a backup, let's error out
# if we couldn't make one
- raise Puppet::Error.new("Could not back %s up: %s" %
- [file, detail.message])
+ self.fail "Could not back %s up: %s" %
+ [file, detail.message]
end
else
self.err "Invalid backup type %s" % backup
@@ -201,7 +204,7 @@ module Puppet
args = @arghash.dup
if path =~ %r{^#{File::SEPARATOR}}
- raise Puppet::DevError.new(
+ self.devfail(
"Must pass relative paths to PFile#newchild()"
)
else
@@ -366,7 +369,7 @@ module Puppet
end
unless FileTest.directory? self.name
- raise Puppet::Error.new(
+ self.devfail(
"Uh, somehow trying to manage non-dir %s" % self.name
)
end
@@ -402,6 +405,11 @@ module Puppet
def sourcerecurse(recurse)
# FIXME sourcerecurse should support purging non-remote files
source = @states[:source].source
+
+ unless ! source.nil? and source !~ /^\s*$/
+ self.notice "source %s does not exist" % @states[:source].should
+ return nil
+ end
sourceobj, path = uri2obj(source)
@@ -503,7 +511,7 @@ module Puppet
begin
uri = URI.parse(source)
rescue => detail
- raise Puppet::Error, "Could not understand source %s: %s" %
+ self.fail "Could not understand source %s: %s" %
[source, detail.to_s]
end
@@ -537,11 +545,10 @@ module Puppet
path = tmp
#path = tmp.sub(%r{^/\w+},'') || "/"
else
- raise Puppet::Error, "Invalid source path %s" % tmp
+ self.fail "Invalid source path %s" % tmp
end
else
- raise Puppet::Error,
- "Got other recursive file proto %s from %s" %
+ self.fail "Got other recursive file proto %s from %s" %
[uri.scheme, source]
end
diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/pfile/checksum.rb
index 2e8d68d96..2f71a1a30 100755
--- a/lib/puppet/type/pfile/checksum.rb
+++ b/lib/puppet/type/pfile/checksum.rb
@@ -25,8 +25,8 @@ module Puppet
case checktype
when "md5", "md5lite":
unless FileTest.file?(@parent[:path])
- #@parent.info "Cannot MD5 sum directory %s" %
- # @parent[:path]
+ @parent.info "Cannot MD5 sum directory %s" %
+ @parent[:path]
# because we cannot sum directories, just delete ourselves
# from the file so we won't sync
@@ -76,28 +76,34 @@ module Puppet
@checktypes = []
end
unless self.class.validtype?(value)
- raise Puppet::Error, "Invalid checksum type '%s'" % value
+ self.fail "Invalid checksum type '%s'" % value
+ end
+
+ if FileTest.directory?(@parent.name)
+ self.info "Reverting directory sum type to timestamp"
+ value = "time"
end
@checktypes << value
state = Puppet::Storage.state(self)
unless state
- raise Puppet::DevError, "Did not get state back from Storage"
+ self.devfail "Did not get state back from Storage"
end
if hash = state[@parent[:path]]
if hash.include?(value)
+ #self.notice "Found checksum %s for %s" %
+ # [hash[value] ,@parent[:path]]
return hash[value]
- #@parent.debug "Found checksum %s for %s" %
- # [self.should,@parent[:path]]
else
- #@parent.debug "Found checksum for %s but not of type %s" %
- # [@parent[:path],@checktype]
+ #self.notice "Found checksum for %s but not of type %s" %
+ # [@parent[:path],@checktypes[0]]
return :nosum
end
else
# We can't use :absent here, because then it'll match on
# non-existent files
+ #self.notice "Could not find sum of type %s" % @checktypes[0]
return :nosum
end
end
@@ -115,6 +121,11 @@ module Puppet
return
end
+ if FileTest.directory?(@parent.name) and @checktypes[0] =~ /md5/
+ self.info "Using timestamp on directory"
+ @checktypes = ["time"]
+ end
+
# Just use the first allowed check type
@is = getsum(@checktypes[0])
@@ -123,6 +134,7 @@ module Puppet
# out of sync. We don't want to generate an event the first
# time we get a sum.
if ! defined? @should or @should == [:nosum]
+ self.info "@should is %s" % @should.inspect
@should = [@is]
# FIXME we should support an updatechecksums-like mechanism
self.updatesum
@@ -179,7 +191,7 @@ module Puppet
result = false
state = Puppet::Storage.state(self)
unless state.include?(@parent.name)
- self.debug "Initializing state hash"
+ self.debug "Initializing state hash for %s" % @parent.name
state[@parent.name] = Hash.new
end
@@ -212,7 +224,6 @@ module Puppet
result = false
end
state[@parent.name][@checktypes[0]] = @is
- self.info "result is %s" % result.inspect
return result
end
end
diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/pfile/group.rb
index c523f612e..8d401b722 100755
--- a/lib/puppet/type/pfile/group.rb
+++ b/lib/puppet/type/pfile/group.rb
@@ -31,7 +31,11 @@ module Puppet
def retrieve
stat = @parent.stat(true)
- self.is = stat.gid
+ if stat
+ self.is = stat.gid
+ else
+ self.is = :absent
+ end
end
munge do |value|
@@ -100,7 +104,7 @@ module Puppet
self.retrieve
if @is == :absent
- self.err "File '%s' does not exist; cannot chgrp" %
+ self.info "File '%s' does not exist; cannot chgrp" %
@parent[:path]
return nil
end
diff --git a/lib/puppet/type/pfile/uid.rb b/lib/puppet/type/pfile/uid.rb
index fc9129669..698915aff 100755
--- a/lib/puppet/type/pfile/uid.rb
+++ b/lib/puppet/type/pfile/uid.rb
@@ -131,8 +131,8 @@ module Puppet
else
self.notice "user %s does not exist" % tmp
@@usermissing[tmp] = 1
- return nil
end
+ return nil
end
if @is == :absent
diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/pfilebucket.rb
index 2c56ebc30..0753bafe1 100755
--- a/lib/puppet/type/pfilebucket.rb
+++ b/lib/puppet/type/pfilebucket.rb
@@ -60,7 +60,7 @@ module Puppet
:Port => self[:port]
)
rescue => detail
- raise Puppet::Error.new(
+ self.fail(
"Could not create remote filebucket: %s" % detail
)
end
@@ -73,7 +73,7 @@ module Puppet
:Path => self[:path]
)
rescue => detail
- raise Puppet::Error.new(
+ self.fail(
"Could not create local filebucket: %s" % detail
)
end
diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb
index 464da9b8d..fca9ff4d3 100644
--- a/lib/puppet/type/service.rb
+++ b/lib/puppet/type/service.rb
@@ -305,7 +305,7 @@ module Puppet
self.info "Executing %s" % cmd.inspect
output = %x(#{cmd} 2>&1)
unless $? == 0
- raise Puppet::Error, "Could not %s %s: %s" %
+ self.fail "Could not %s %s: %s" %
[type, self.name, output.chomp]
end
end
@@ -314,13 +314,13 @@ module Puppet
# parameter.
def getpid
unless self[:pattern]
- raise Puppet::Error,
- "Either a stop command or a pattern must be specified"
+ self.fail "Either a stop command or a pattern must be specified"
end
ps = Facter["ps"].value
unless ps and ps != ""
- raise Puppet::Error,
+ self.fail(
"You must upgrade Facter to a version that includes 'ps'"
+ )
end
regex = Regexp.new(self[:pattern])
IO.popen(ps) { |table|
@@ -418,8 +418,7 @@ module Puppet
end
output = %x("kill #{pid} 2>&1")
if $? != 0
- raise Puppet::Error,
- "Could not kill %s, PID %s: %s" %
+ self.fail "Could not kill %s, PID %s: %s" %
[self.name, pid, output]
end
return true
diff --git a/lib/puppet/type/state.rb b/lib/puppet/type/state.rb
index 0e8824a71..6e1600083 100644
--- a/lib/puppet/type/state.rb
+++ b/lib/puppet/type/state.rb
@@ -86,7 +86,7 @@ class State < Puppet::Parameter
value = self.should
method = "set_" + value.to_s
unless self.respond_to?(method)
- raise Puppet::Error, "%s is not a valid value for %s" %
+ self.fail "%s is not a valid value for %s" %
[value, self.class.name]
end
self.debug "setting %s (currently %s)" % [value, self.is]
@@ -99,7 +99,7 @@ class State < Puppet::Parameter
if Puppet[:debug]
puts detail.backtrace
end
- raise Puppet::Error, "Could not set %s on %s: %s" %
+ self.fail "Could not set %s on %s: %s" %
[value, self.class.name, detail]
end
@@ -127,7 +127,7 @@ class State < Puppet::Parameter
@is = nil
unless hash.include?(:parent)
- raise Puppet::DevError, "State %s was not passed a parent" % self
+ self.devfail "State %s was not passed a parent" % self
end
@parent = hash[:parent]
@@ -169,7 +169,7 @@ class State < Puppet::Parameter
end
unless @should.is_a?(Array)
- raise Puppet::DevError, "%s's should is not array" % self.class.name
+ self.devfail "%s's should is not array" % self.class.name
end
# an empty array is analogous to no should values
@@ -191,7 +191,7 @@ class State < Puppet::Parameter
def log(msg)
unless @parent[:loglevel]
p @parent
- raise Puppet::DevError, "Parent %s has no loglevel" %
+ self.devfail "Parent %s has no loglevel" %
@parent.name
end
Puppet::Log.create(
@@ -229,7 +229,7 @@ class State < Puppet::Parameter
def should
if defined? @should
unless @should.is_a?(Array)
- raise Puppet::DevError, "should for %s on %s is not an array" %
+ self.devfail "should for %s on %s is not an array" %
[self.class.name, @parent.name]
end
return @should[0]
@@ -270,7 +270,7 @@ class State < Puppet::Parameter
#self.info "%s vs %s" % [self.is.inspect, self.should.inspect]
end
unless self.class.values
- raise Puppet::DevError, "No values defined for %s" %
+ self.devfail "No values defined for %s" %
self.class.name
end
@@ -306,8 +306,7 @@ class State < Puppet::Parameter
value = value.to_s.intern
end
unless self.class.values.include?(value) or self.class.alias(value)
- raise Puppet::Error,
- "Invalid '%s' value '%s'. Valid values are '%s'" %
+ self.fail "Invalid '%s' value '%s'. Valid values are '%s'" %
[self.class.name, value, self.class.values.join(", ")]
end
end
diff --git a/lib/puppet/type/symlink.rb b/lib/puppet/type/symlink.rb
index 37e60d6f6..40a58c0da 100755
--- a/lib/puppet/type/symlink.rb
+++ b/lib/puppet/type/symlink.rb
@@ -17,15 +17,15 @@ module Puppet
def create
begin
- debug("Creating symlink '%s' to '%s'" %
+ @parent.debug("Creating symlink '%s' to '%s'" %
[self.parent[:path],self.should])
unless File.symlink(self.should,self.parent[:path])
- raise TypeError.new("Could not create symlink '%s'" %
- self.parent[:path])
+ self.fail "Could not create symlink '%s'" %
+ self.parent[:path]
end
rescue => detail
- raise TypeError.new("Cannot create symlink '%s': %s" %
- [self.parent[:path],detail])
+ self.fail "Cannot create symlink '%s': %s" %
+ [self.parent[:path],detail]
end
end
@@ -35,14 +35,14 @@ module Puppet
begin
File.unlink(self.parent[:path])
rescue
- raise TypeError.new("Failed to remove symlink '%s'" %
- self.parent[:path])
+ self.fail "Failed to remove symlink '%s'" %
+ self.parent[:path]
end
elsif FileTest.exists?(self.parent[:path])
- raise TypeError.new("Cannot remove normal file '%s'" %
- self.parent[:path])
+ self.fail "Cannot remove normal file '%s'" %
+ self.parent[:path]
else
- debug("Symlink '%s' does not exist" %
+ @parent.debug("Symlink '%s' does not exist" %
self.parent[:path])
end
end
@@ -73,8 +73,8 @@ module Puppet
self.create()
end
elsif FileTest.exists?(self.parent[:path])
- raise TypeError.new("Cannot replace normal file '%s'" %
- self.parent[:path])
+ self.fail "Cannot replace normal file '%s'" %
+ self.parent[:path]
else
self.create()
end
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index 235d26e95..144141c56 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -31,7 +31,7 @@ module Puppet
when /^[0-9]+[sS]/:
Integer(age.gsub(/[^0-9]+/,''))
else
- raise Puppet::Error.new("Invalid tidy age %s" % age)
+ self.fail "Invalid tidy age %s" % age
end
end
end
@@ -57,7 +57,7 @@ module Puppet
Integer(size.gsub(/[^0-9]+/,'')) *
1024 * 1024
else
- raise Puppet::Error.new("Invalid tidy size %s" % size)
+ self.fail "Invalid tidy size %s" % size
end
end
end
@@ -71,7 +71,7 @@ module Puppet
when "atime", "mtime", "ctime":
type.intern
else
- raise Puppet::Error.new("Invalid tidy type %s" % type)
+ self.fail "Invalid tidy type %s" % type
end
end
end
@@ -145,7 +145,7 @@ module Puppet
File.unlink(file)
when "symlink": File.unlink(file)
else
- raise Puppet::Error, "Cannot tidy files of type %s" %
+ self.fail "Cannot tidy files of type %s" %
File.lstat(file).ftype
end
@@ -167,7 +167,7 @@ module Puppet
@parameters.include?(:size)
unless FileTest.directory?(self[:path])
# don't do size comparisons for directories
- raise Puppet::Error, "Tidy must specify size, age, or both"
+ self.fail "Tidy must specify size, age, or both"
end
end
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index 317d86422..9ae07e679 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -47,7 +47,7 @@ module Puppet
end
when Symbol
unless value == :absent or value == :auto
- raise Puppet::DevError, "Invalid UID %s" % value
+ self.devfail "Invalid UID %s" % value
end
if value == :auto
@@ -76,7 +76,7 @@ module Puppet
end
when Symbol
unless gid == :auto or gid == :absent
- raise Puppet::DevError, "Invalid GID %s" % gid
+ self.devfail "Invalid GID %s" % gid
end
# these are treated specially by sync()
return gid
@@ -88,7 +88,7 @@ module Puppet
begin
ginfo = Etc.send(method, gid)
rescue ArgumentError => detail
- raise Puppet::Error, "Could not find group %s: %s" %
+ self.fail "Could not find group %s: %s" %
[gid, detail]
end
@@ -198,8 +198,7 @@ module Puppet
if state.method_defined?(:autogen)
self[state.name] = :auto
else
- raise Puppet::Error,
- "Users require a value for %s" % state.name
+ self.fail "Users require a value for %s" % state.name
end
end
}