diff options
| author | Luke Kanies <luke@madstop.com> | 2008-02-18 09:38:32 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-02-18 09:38:32 -0600 |
| commit | a53106cf08c28e996502cba703f64944250a4b29 (patch) | |
| tree | 4dee55340a4d91083e940fecb9087ecfaa7c279f /lib | |
| parent | be58bb5c4bc19e59685e0a8953eaf2d3b7844110 (diff) | |
| parent | 62d7616a457f33eb660454fcdcefe8dab84522c0 (diff) | |
Merge branch '0.24.x'
Conflicts:
CHANGELOG
man/man8/puppet.8
Diffstat (limited to 'lib')
29 files changed, 130 insertions, 138 deletions
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb index e0c37cd35..2699dc6e1 100644 --- a/lib/puppet/parser/collector.rb +++ b/lib/puppet/parser/collector.rb @@ -51,7 +51,7 @@ class Puppet::Parser::Collector search = "(exported=? AND restype=?)" values = [true, @type] - search += " AND (?)" and values << @equery if @equery + search += " AND (%s)" % @equery if @equery # We're going to collect objects from rails, but we don't want any # objects from this host. diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra index 0fd644b3a..484efe83c 100644 --- a/lib/puppet/parser/grammar.ra +++ b/lib/puppet/parser/grammar.ra @@ -151,7 +151,7 @@ resourceoverride: resourceref LBRACE anyparams endcomma RBRACE { virtualresource: at resource { type = val[0] - if type == :exported and ! Puppet[:storeconfigs] + if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] error "You cannot collect without storeconfigs being set" end @@ -192,7 +192,7 @@ collection: classref collectrhand { else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] error "You cannot collect exported resources without storeconfigs being set" end result = ast AST::Collection, args diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb index 1d93193dd..d4b7449fb 100644 --- a/lib/puppet/parser/interpreter.rb +++ b/lib/puppet/parser/interpreter.rb @@ -42,6 +42,26 @@ class Puppet::Parser::Interpreter @parsers = {} end + # Return the parser for a specific environment. + def parser(environment) + if ! @parsers[environment] or @parsers[environment].reparse? + # This will throw an exception if it does not succeed. We only + # want to get rid of the old parser if we successfully create a new + # one. + begin + tmp = create_parser(environment) + @parsers[environment].clear if @parsers[environment] + @parsers[environment] = tmp + rescue => detail + # If a parser already exists, than assume that we logged the + # exception elsewhere and reuse the parser. If one doesn't + # exist, then reraise. + raise detail unless @parsers[environment] + end + end + @parsers[environment] + end + private # Create a new parser object and pre-parse the configuration. @@ -67,24 +87,4 @@ class Puppet::Parser::Interpreter raise error end end - - # Return the parser for a specific environment. - def parser(environment) - if ! @parsers[environment] or @parsers[environment].reparse? - # This will throw an exception if it does not succeed. We only - # want to get rid of the old parser if we successfully create a new - # one. - begin - tmp = create_parser(environment) - @parsers[environment].clear if @parsers[environment] - @parsers[environment] = tmp - rescue => detail - # If a parser already exists, than assume that we logged the - # exception elsewhere and reuse the parser. If one doesn't - # exist, then reraise. - raise detail unless @parsers[environment] - end - end - @parsers[environment] - end end diff --git a/lib/puppet/parser/lexer.rb b/lib/puppet/parser/lexer.rb index 6661650ba..51026ea1b 100644 --- a/lib/puppet/parser/lexer.rb +++ b/lib/puppet/parser/lexer.rb @@ -33,7 +33,11 @@ class Puppet::Parser::Lexer end def to_s - "Lexer token %s" % @name.to_s + if self.string + @string + else + @name.to_s + end end end diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb index c3279d4e7..e27a209fc 100644 --- a/lib/puppet/parser/parser.rb +++ b/lib/puppet/parser/parser.rb @@ -29,7 +29,7 @@ module Puppet class Parser < Racc::Parser -module_eval <<'..end grammar.ra modeval..id9134b179f4', 'grammar.ra', 638 +module_eval <<'..end grammar.ra modeval..idfef5d70c9f', 'grammar.ra', 638 # It got too annoying having code in a file that needs to be compiled. require 'puppet/parser/parser_support' @@ -39,8 +39,9 @@ require 'puppet/parser/parser_support' # mode: ruby # End: +# $Id$ -..end grammar.ra modeval..id9134b179f4 +..end grammar.ra modeval..idfef5d70c9f ##### racc 1.4.5 generates ### @@ -956,7 +957,7 @@ module_eval <<'.,.,', 'grammar.ra', 174 def _reduce_38( val, _values, result ) type = val[0] - if type == :exported and ! Puppet[:storeconfigs] + if (type == :exported and ! Puppet[:storeconfigs]) and ! Puppet[:parseonly] error "You cannot collect without storeconfigs being set" end @@ -1009,7 +1010,7 @@ module_eval <<'.,.,', 'grammar.ra', 199 else args[:form] = val[1] end - if args[:form] == :exported and ! Puppet[:storeconfigs] + if args[:form] == :exported and ! Puppet[:storeconfigs] and ! Puppet[:parseonly] error "You cannot collect exported resources without storeconfigs being set" end result = ast AST::Collection, args diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb index 71547802e..3bcc2ced0 100644 --- a/lib/puppet/pgraph.rb +++ b/lib/puppet/pgraph.rb @@ -19,23 +19,6 @@ class Puppet::PGraph < Puppet::SimpleGraph super end - # Make sure whichever edge has a label keeps the label - def copy_label(source, target, label) - # 'require' relationships will not have a label, - # and all 'subscribe' relationships have the same - # label, at least for now. - - # Labels default to {}, so we can't just test for nil. - newlabel = label || {} - oldlabel = edge_label(source, target) || {} - if ! newlabel.empty? and oldlabel.empty? - edge_label_set(source, target, label) - # We should probably check to see if the labels both exist - # and don't match, but we'd just throw an error which the user - # couldn't do anyting about. - end - end - # Which resources a given resource depends upon. def dependents(resource) tree_from_vertex(resource).keys @@ -115,23 +98,11 @@ class Puppet::PGraph < Puppet::SimpleGraph t = edge.target end - # We don't want to add multiple copies of the - # same edge, but we *do* want to make sure we - # keep labels around. - # XXX This will *not* work when we support multiple - # types of labels, and only works now because - # you can only do simple subscriptions. - if edge?(s, t) - copy_label(s, t, edge.label) - next - end add_edge(s, t, edge.label) end # Now get rid of the edge, so remove_vertex! works correctly. remove_edge!(edge) - Puppet.debug "%s: %s => %s: %s" % [container, - edge.source, edge.target, edge?(edge.source, edge.target)] end end remove_vertex!(container) diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index b2ccfbd4e..e2e68b2ca 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -139,10 +139,12 @@ class DirectoryService < Puppet::Provider::NameService dscl_output.split("\n").each do |line| # JJM: Split the attribute name and the list of values. ds_attribute, ds_values_string = line.split(':') + + # Split sets the values to nil if there's nothing after the : + ds_values_string ||= "" # JJM: skip this attribute line if the Puppet::Type doesn't care about it. - next unless (@@ds_to_ns_attribute_map.keys.include?(ds_attribute) \ - and type_properties.include? @@ds_to_ns_attribute_map[ds_attribute]) + next unless (@@ds_to_ns_attribute_map.keys.include?(ds_attribute) and type_properties.include? @@ds_to_ns_attribute_map[ds_attribute]) # JJM: We asked dscl to output url encoded values so we're able # to machine parse on whitespace. We need to urldecode: @@ -178,11 +180,8 @@ class DirectoryService < Puppet::Provider::NameService # This method spits out proper DSCL commands for us. # We EXPECT name to be @resource[:name] when called from an instance object. - # JJM: With dscl, the domain "/" is always the default local domain. - # The domain /Search will search all domains, and you may - # get at specific domains with /LDAPv3/server1.foobar.com, - # /LDAPv3/server2.foobar.com, etc... - command_vector = [ command(:dscl), "-url", "/" ] + # There are two ways to specify paths in 10.5. See man dscl. + command_vector = [ command(:dscl), "-url", "." ] # JJM: The actual action to perform. See "man dscl" # Common actiosn: -create, -delete, -merge, -append, -passwd command_vector << ds_action diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb index 6e777a735..f73694779 100755 --- a/lib/puppet/provider/package/gem.rb +++ b/lib/puppet/provider/package/gem.rb @@ -23,14 +23,14 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d end begin - list = execute(command).split("\n\n").collect do |set| + list = execute(command).split("\n").collect do |set| if gemhash = gemsplit(set) gemhash[:provider] = :gem gemhash else nil end - end.reject { |p| p.nil? } + end.compact rescue Puppet::ExecutionFailure => detail raise Puppet::Error, "Could not list gems: %s" % detail end @@ -44,8 +44,8 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d def self.gemsplit(desc) case desc - when /^\*\*\*/: return nil - when /^(\S+)\s+\((.+)\)\n/ + when /^\*\*\*/, /^\s*$/, /^\s+/; return nil + when /^(\S+)\s+\((.+)\)/ name = $1 version = $2.split(/,\s*/)[0] return { diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb index 03274a78d..dccfeaf56 100644 --- a/lib/puppet/provider/package/portage.rb +++ b/lib/puppet/provider/package/portage.rb @@ -39,7 +39,7 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa return packages rescue Puppet::ExecutionFailure => detail - raise Puppet::PackageError.new(detail) + raise Puppet::Error.new(detail) end end @@ -99,14 +99,14 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa case packages.size when 0 not_found_value = "%s/%s" % [@resource[:category] ? @resource[:category] : "<unspecified category>", @resource[:name]] - raise Puppet::PackageError.new("No package found with the specified name [#{not_found_value}]") + raise Puppet::Error.new("No package found with the specified name [#{not_found_value}]") when 1 return packages[0] else - raise Puppet::PackageError.new("More than one package with the specified name [#{search_value}], please use the category parameter to disambiguate") + raise Puppet::Error.new("More than one package with the specified name [#{search_value}], please use the category parameter to disambiguate") end rescue Puppet::ExecutionFailure => detail - raise Puppet::PackageError.new(detail) + raise Puppet::Error.new(detail) end end diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb index 233242a1c..e54fb13df 100755 --- a/lib/puppet/provider/service/debian.rb +++ b/lib/puppet/provider/service/debian.rb @@ -14,6 +14,7 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do # Remove the symlinks def disable update "-f", @resource[:name], "remove" + update @resource[:name], "stop 1 2 3 4 5 6 ." end def enabled? @@ -29,6 +30,7 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do end def enable + update "-f", @resource[:name], "remove" update @resource[:name], "defaults" end end diff --git a/lib/puppet/provider/service/gentoo.rb b/lib/puppet/provider/service/gentoo.rb index 2dcc3e9c1..adbee6970 100644 --- a/lib/puppet/provider/service/gentoo.rb +++ b/lib/puppet/provider/service/gentoo.rb @@ -8,6 +8,10 @@ Puppet::Type.type(:service).provide :gentoo, :parent => :init do defaultfor :operatingsystem => :gentoo + def self.defpath + superclass.defpath + end + def disable begin output = update :del, @resource[:name], :default diff --git a/lib/puppet/reference/node_source.rb b/lib/puppet/reference/node_source.rb deleted file mode 100644 index 29a01f850..000000000 --- a/lib/puppet/reference/node_source.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'puppet/node' - -noderef = Puppet::Util::Reference.newreference :node_source, :doc => "Sources of node configuration information" do - Puppet::Network::Handler.node.docs -end - -noderef.header = " -Nodes can be searched for in different locations. This document describes those different locations. -" diff --git a/lib/puppet/reference/report.rb b/lib/puppet/reference/report.rb deleted file mode 100644 index a8086f8bc..000000000 --- a/lib/puppet/reference/report.rb +++ /dev/null @@ -1,21 +0,0 @@ -report = Puppet::Util::Reference.newreference :report, :doc => "All available transaction reports" do - Puppet::Network::Handler.report.reportdocs -end - -report.header = " -Puppet clients can report back to the server after each transaction. This -transaction report is sent as a YAML dump of the -``Puppet::Transaction::Report`` class and includes every log message that was -generated during the transaction along with as many metrics as Puppet knows how -to collect. See `ReportsAndReporting Reports and Reporting`:trac: -for more information on how to use reports. - -Currently, clients default to not sending in reports; you can enable reporting -by setting the ``report`` parameter to true. - -To use a report, set the ``reports`` parameter on the server; multiple -reports must be comma-separated. You can also specify ``none`` to disable -reports entirely. - -Puppet provides multiple report handlers that will process client reports: -" diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb index 503e4814c..48f393f77 100644 --- a/lib/puppet/simple_graph.rb +++ b/lib/puppet/simple_graph.rb @@ -51,10 +51,12 @@ class Puppet::SimpleGraph # Create methods for returning the degree and edges. [:in, :out].each do |direction| - define_method("%s_degree" % direction) do - @adjacencies[direction].length - end - + # LAK:NOTE If you decide to create methods for directly + # testing the degree, you'll have to get the values and flatten + # the results -- you might have duplicate edges, which can give + # a false impression of what the degree is. That's just + # as expensive as just getting the edge list, so I've decided + # to only add this method. define_method("%s_edges" % direction) do @adjacencies[direction].values.flatten end @@ -126,8 +128,9 @@ class Puppet::SimpleGraph # Collect each of our vertices, with the number of in-edges each has. @vertices.each do |name, wrapper| - zeros << wrapper if wrapper.in_degree == 0 - degree[wrapper.vertex] = wrapper.in_edges + edges = wrapper.in_edges + zeros << wrapper if edges.length == 0 + degree[wrapper.vertex] = edges end # Iterate over each 0-degree vertex, decrementing the degree of diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index def9e44e4..c4e154d47 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -423,8 +423,8 @@ end require 'puppet/propertychange' require 'puppet/provider' require 'puppet/type/component' -require 'puppet/type/pfile' -require 'puppet/type/pfilebucket' +require 'puppet/type/file' +require 'puppet/type/filebucket' require 'puppet/type/tidy' diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 7d3b1abe1..f8049236f 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -288,7 +288,7 @@ module Puppet # Rebuild the database, but only when the file changes exec { newaliases: path => [\"/usr/bin\", \"/usr/sbin\"], - subscribe => file[\"/etc/aliases\"], + subscribe => File[\"/etc/aliases\"], refreshonly => true } diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/file.rb index c32a4d474..65ee7e72e 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/file.rb @@ -1159,13 +1159,13 @@ module Puppet # We put all of the properties in separate files, because there are so many # of them. The order these are loaded is important, because it determines # the order they are in the property lit. - require 'puppet/type/pfile/checksum' - require 'puppet/type/pfile/content' # can create the file - require 'puppet/type/pfile/source' # can create the file - require 'puppet/type/pfile/target' # creates a different type of file - require 'puppet/type/pfile/ensure' # can create the file - require 'puppet/type/pfile/owner' - require 'puppet/type/pfile/group' - require 'puppet/type/pfile/mode' - require 'puppet/type/pfile/type' + require 'puppet/type/file/checksum' + require 'puppet/type/file/content' # can create the file + require 'puppet/type/file/source' # can create the file + require 'puppet/type/file/target' # creates a different type of file + require 'puppet/type/file/ensure' # can create the file + require 'puppet/type/file/owner' + require 'puppet/type/file/group' + require 'puppet/type/file/mode' + require 'puppet/type/file/type' end diff --git a/lib/puppet/type/pfile/checksum.rb b/lib/puppet/type/file/checksum.rb index 08f48ea21..08f48ea21 100755 --- a/lib/puppet/type/pfile/checksum.rb +++ b/lib/puppet/type/file/checksum.rb diff --git a/lib/puppet/type/pfile/content.rb b/lib/puppet/type/file/content.rb index 6dcda0aa6..6dcda0aa6 100755 --- a/lib/puppet/type/pfile/content.rb +++ b/lib/puppet/type/file/content.rb diff --git a/lib/puppet/type/pfile/ensure.rb b/lib/puppet/type/file/ensure.rb index 3aa918f65..3aa918f65 100755 --- a/lib/puppet/type/pfile/ensure.rb +++ b/lib/puppet/type/file/ensure.rb diff --git a/lib/puppet/type/pfile/group.rb b/lib/puppet/type/file/group.rb index 5f7caf342..5f7caf342 100755 --- a/lib/puppet/type/pfile/group.rb +++ b/lib/puppet/type/file/group.rb diff --git a/lib/puppet/type/pfile/mode.rb b/lib/puppet/type/file/mode.rb index 8674e0a88..8674e0a88 100755 --- a/lib/puppet/type/pfile/mode.rb +++ b/lib/puppet/type/file/mode.rb diff --git a/lib/puppet/type/pfile/owner.rb b/lib/puppet/type/file/owner.rb index 6f9bbd6a2..6f9bbd6a2 100755 --- a/lib/puppet/type/pfile/owner.rb +++ b/lib/puppet/type/file/owner.rb diff --git a/lib/puppet/type/pfile/source.rb b/lib/puppet/type/file/source.rb index 3dfb5cccd..3dfb5cccd 100755 --- a/lib/puppet/type/pfile/source.rb +++ b/lib/puppet/type/file/source.rb diff --git a/lib/puppet/type/pfile/target.rb b/lib/puppet/type/file/target.rb index a0e5dc401..a0e5dc401 100644 --- a/lib/puppet/type/pfile/target.rb +++ b/lib/puppet/type/file/target.rb diff --git a/lib/puppet/type/pfile/type.rb b/lib/puppet/type/file/type.rb index 65539795b..65539795b 100755 --- a/lib/puppet/type/pfile/type.rb +++ b/lib/puppet/type/file/type.rb diff --git a/lib/puppet/type/pfilebucket.rb b/lib/puppet/type/filebucket.rb index b268610e9..b268610e9 100755 --- a/lib/puppet/type/pfilebucket.rb +++ b/lib/puppet/type/filebucket.rb diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index a52575522..535d9ef2e 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -1,6 +1,9 @@ +require 'puppet/util/warnings' + # Autoload paths, either based on names or all at once. class Puppet::Util::Autoload include Puppet::Util + include Puppet::Util::Warnings @autoloaders = {} @loaded = [] @@ -109,9 +112,8 @@ class Puppet::Util::Autoload Dir.glob("#{dir}/*.rb").each do |file| name = File.basename(file).sub(".rb", '').intern next if loaded?(name) - rubypath = File.join(@path, name.to_s) begin - Kernel.require rubypath + Kernel.require file loaded(name, file) rescue => detail if Puppet[:trace] @@ -123,8 +125,6 @@ class Puppet::Util::Autoload end end - private - # Yield each subdir in turn. def eachdir searchpath.each do |dir| @@ -137,7 +137,7 @@ class Puppet::Util::Autoload def searchpath # JJM: Search for optional lib directories in each module bundle. module_lib_dirs = Puppet[:modulepath].split(":").collect do |d| - Dir.glob("%s/*/lib" % d).select do |f| + Dir.glob("%s/*/{plugins,lib}" % d).select do |f| FileTest.directory?(f) end end.flatten diff --git a/lib/puppet/util/checksums.rb b/lib/puppet/util/checksums.rb index 6f6ea59b5..598b3adfa 100644 --- a/lib/puppet/util/checksums.rb +++ b/lib/puppet/util/checksums.rb @@ -1,37 +1,75 @@ +# A stand-alone module for calculating checksums +# in a generic way. module Puppet::Util::Checksums + # Calculate a checksum using Digest::MD5. def md5(content) require 'digest/md5' Digest::MD5.hexdigest(content) end - def md5_file(filename) + # Calculate a checksum of the first 500 chars of the content using Digest::MD5. + def md5lite(content) + md5(content[0..511]) + end + + # Calculate a checksum of a file's content using Digest::MD5. + def md5_file(filename, lite = false) require 'digest/md5' - incr_digest = Digest::MD5.new() - File.open(filename, 'r') do |file| - file.each_line do |line| - incr_digest << line - end - end + digest = Digest::MD5.new() + return checksum_file(digest, filename, lite) + end + + # Calculate a checksum of the first 500 chars of a file's content using Digest::MD5. + def md5lite_file(filename) + md5_file(filename, true) + end - return incr_digest.hexdigest + # Return the :mtime timestamp of a file. + def mtime_file(filename) + File.stat(filename).send(:mtime) end + # Calculate a checksum using Digest::SHA1. def sha1(content) require 'digest/sha1' Digest::SHA1.hexdigest(content) end - def sha1_file(filename) + # Calculate a checksum of the first 500 chars of the content using Digest::SHA1. + def sha1lite(content) + sha1(content[0..511]) + end + + # Calculate a checksum of a file's content using Digest::SHA1. + def sha1_file(filename, lite = false) require 'digest/sha1' - incr_digest = Digest::SHA1.new() + digest = Digest::SHA1.new() + return checksum_file(digest, filename, lite) + end + + # Calculate a checksum of the first 500 chars of a file's content using Digest::SHA1. + def sha1lite_file(filename) + sha1_file(filename, true) + end + + # Return the :ctime of a file. + def timestamp_file(filename) + File.stat(filename).send(:ctime) + end + + private + + # Perform an incremental checksum on a file. + def checksum_file(digest, filename, lite = false) File.open(filename, 'r') do |file| - file.each_line do |line| - incr_digest << line + while content = file.read(512) + digest << content + break if lite end end - return incr_digest.hexdigest + return digest.hexdigest end end |
