From 7b3b56ef7bfd32d7afb47fd71c2d9f606856d2e0 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Fri, 14 Jan 2011 18:21:57 -0600 Subject: (5977) Puppet::Applications can be loaded from multiple paths. - previously, Puppet would search $LOAD_PATH and just load applications in the first $LOAD_PATH to have the directory puppet/application. Now multiple paths can contain applications. --- lib/puppet/util/command_line.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index 3562a3dc0..4aff0a8cb 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -33,8 +33,12 @@ module Puppet end def available_subcommands - absolute_appdir = $LOAD_PATH.collect { |x| File.join(x,'puppet','application') }.detect{ |x| File.directory?(x) } - Dir[File.join(absolute_appdir, '*.rb')].map{|fn| File.basename(fn, '.rb')} + absolute_appdirs = $LOAD_PATH.collect do |x| + File.join(x,'puppet','application') + end.select{ |x| File.directory?(x) } + absolute_appdirs.inject([]) do |commands, dir| + commands + Dir[File.join(dir, '*.rb')].map{|fn| File.basename(fn, '.rb')} + end.uniq end def usage_message -- cgit From 48bc7d00ca87fa92cdde0b993529bba3827fa47e Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 11 Feb 2011 20:18:14 +0100 Subject: Fix #6280 - puppetdoc crashing on string interpolation The following manifest was crashing puppetdoc: class test { include "test::$operatingsystem" } Because the quoted string is "rendered" as a concat AST, which in turn ended being an array when entering RDoc. Signed-off-by: Brice Figureau --- lib/puppet/util/rdoc/parser.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb index f9becede1..f59af64f9 100644 --- a/lib/puppet/util/rdoc/parser.rb +++ b/lib/puppet/util/rdoc/parser.rb @@ -157,8 +157,8 @@ class Parser if stmt.is_a?(Puppet::Parser::AST::Function) and ['include','require'].include?(stmt.name) stmt.arguments.each do |included| - Puppet.debug "found #{stmt.name}: #{included.value}" - container.send("add_#{stmt.name}",Include.new(included.value, stmt.doc)) + Puppet.debug "found #{stmt.name}: #{included}" + container.send("add_#{stmt.name}",Include.new(included.to_s, stmt.doc)) end end end -- cgit From cfa0c32fc5149464af97235a7bb458950d19cc82 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 11 Feb 2011 20:34:22 +0100 Subject: Fix #6281 - Make sure puppetdoc analyzes all files It can happen that when parsing a file puppet parses other manifests if they get imported (this is at least true for site.pp, even in ignoreimport=true). Thus those files are now "watched". But puppetdoc needs to analyze all files, and since 99c101 we are now checking if the file was already parsed to not reparse it again. If that was the case, though, we weren't analyzing the produced code. Thus it was possible to not produce documentation for the site.pp content. Signed-off-by: Brice Figureau --- lib/puppet/util/rdoc/parser.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb index f59af64f9..ea7439ad7 100644 --- a/lib/puppet/util/rdoc/parser.rb +++ b/lib/puppet/util/rdoc/parser.rb @@ -41,8 +41,10 @@ class Parser @parser.file = @input_file_name @ast = @parser.parse end - scan_top_level(@top_level) + else + @ast = env.known_resource_types end + scan_top_level(@top_level) @top_level end -- cgit From 90905073a6e1136c80cd59dca1a9594f4a859126 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sat, 12 Feb 2011 13:32:24 +0100 Subject: Fix #6267 - puppetdoc embedded links to puppet entities are not hyperlinked Puppetdoc was relying on RDoc to provide the puppet entity (class, definition node, etc...) hyperlinking in comments. Unfortunately, RDoc was assuming namespaces are capitalized like Ruby namespaces and that definition would use the # or . separator. This change adds on top of RDoc puppet namespace format for classes and definition. This will make sure the comment hyperlinking will work as intented. Signed-off-by: Brice Figureau --- lib/puppet/util/rdoc/code_objects.rb | 39 ++++++++++++++++++++++ .../util/rdoc/generators/puppet_generator.rb | 18 ++++++++++ 2 files changed, 57 insertions(+) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/rdoc/code_objects.rb b/lib/puppet/util/rdoc/code_objects.rb index 3854fbc01..3c789a0c5 100644 --- a/lib/puppet/util/rdoc/code_objects.rb +++ b/lib/puppet/util/rdoc/code_objects.rb @@ -124,6 +124,45 @@ module RDoc def add_child(child) @childs << child end + + # Look up the given symbol. RDoc only looks for class1::class2.method + # or class1::class2#method. Since our definitions are mapped to RDoc methods + # but are written class1::class2::define we need to perform the lookup by + # ourselves. + def find_symbol(symbol, method=nil) + result = super + if not result and symbol =~ /::/ + modules = symbol.split(/::/) + unless modules.empty? + module_name = modules.shift + result = find_module_named(module_name) + if result + last_name = "" + previous = nil + modules.each do |module_name| + previous = result + last_name = module_name + result = result.find_module_named(module_name) + break unless result + end + unless result + result = previous + method = last_name + end + end + end + if result && method + if !result.respond_to?(:find_local_symbol) + p result.name + p method + fail + end + result = result.find_local_symbol(method) + end + end + result + end + end # PuppetNode holds a puppet node diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb index e6bbb2e1e..249c9a8ba 100644 --- a/lib/puppet/util/rdoc/generators/puppet_generator.rb +++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb @@ -31,6 +31,24 @@ module Generators NODE_DIR = "nodes" PLUGIN_DIR = "plugins" + # We're monkey patching RDoc markup to allow + # lowercase class1::class2::class3 crossref hyperlinking + module MarkUp + alias :old_markup :markup + + def new_markup(str, remove_para=false) + first = @markup.nil? + res = old_markup(str, remove_para) + if first and not @markup.nil? + @markup.add_special(/\b([a-z]\w+(::\w+)*)/,:CROSSREF) + # we need to call it again, since we added a rule + res = old_markup(str, remove_para) + end + res + end + alias :markup :new_markup + end + # This is a specialized HTMLGenerator tailored to Puppet manifests class PuppetGenerator < HTMLGenerator -- cgit From 7ef2fbf1ac217ef78181ffb41a9a226c7bb2b40f Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 14 Feb 2011 06:08:50 +1100 Subject: Updated fix for #3646 - apply / compile documentation --- lib/puppet/util/command_line/puppetd | 11 ++++++++--- lib/puppet/util/command_line/puppetmasterd | 6 +----- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/command_line/puppetd b/lib/puppet/util/command_line/puppetd index 71b28429b..d7d94ce09 100755 --- a/lib/puppet/util/command_line/puppetd +++ b/lib/puppet/util/command_line/puppetd @@ -15,6 +15,7 @@ # [-o|--onetime] [--serve ] [-t|--test] [--noop] # [--digest ] [--fingerprint] [-V|--version] # [-v|--verbose] [-w|--waitforcert ] +# [--apply catalog] # # = Description # @@ -60,7 +61,7 @@ # before signing a certificate request on the master, the certificate request the # master received is the same as the one the client sent (to prevent against # man-in-the-middle attacks when signing certificates). -# +# # # = Options # @@ -133,8 +134,8 @@ # makes sense when used in conjunction with --listen. # # onetime:: -# Run the configuration once. Runs a single (normally daemonized) Puppet run. -# Useful for interactively running puppet agent when used in conjunction with +# Run the configuration once. Runs a single (normally daemonized) Puppet run. +# Useful for interactively running puppet agent when used in conjunction with # the --no-daemonize option. # # fingerprint:: @@ -172,6 +173,10 @@ # client. You can turn off waiting for certificates by specifying a time # of 0. # +# apply:: +# Capability to apply JSON catalog (such as one generated with --compile on the Puppet master). +# You can either specify a JSON catalog file or pipe in JSON from standard input. +# # = Example # # puppet agent --server puppet.domain.com diff --git a/lib/puppet/util/command_line/puppetmasterd b/lib/puppet/util/command_line/puppetmasterd index 445169820..3b76db82b 100755 --- a/lib/puppet/util/command_line/puppetmasterd +++ b/lib/puppet/util/command_line/puppetmasterd @@ -9,7 +9,7 @@ # # puppet master [-D|--daemonize|--no-daemonize] [-d|--debug] [-h|--help] # [-l|--logdest |console|syslog] [-v|--verbose] [-V|--version] -# [--compile ] [--apply ] +# [--compile ] # # = Description # @@ -54,10 +54,6 @@ # Capability to compile a catalogue and output it in JSON from the Puppet master. Uses # facts contained in the $vardir/yaml/ directory to compile the catalog. # -# apply:: -# Capability to apply JSON catalog (such as one generated with --compile). You can either specify -# a JSON file or pipe in JSON from standard input. -# # = Example # # puppet master -- cgit From 664ef670da62f9c3dd83d047dc9e575e9ffbb8a2 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Mon, 14 Feb 2011 13:57:51 -0800 Subject: (#3646) Fix the documentation fix for `puppet apply --apply` --apply is actually off of `puppet apply`, not off of `puppet agent` (nor `puppet master`), so move the documentation accordingly. Paired-with: Jesse Wolfe --- lib/puppet/util/command_line/puppet | 6 +++++- lib/puppet/util/command_line/puppetd | 5 ----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/command_line/puppet b/lib/puppet/util/command_line/puppet index e75b92af8..ba3d57c19 100755 --- a/lib/puppet/util/command_line/puppet +++ b/lib/puppet/util/command_line/puppet @@ -7,7 +7,7 @@ # = Usage # # puppet apply [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] [-e|--execute] -# [--detailed-exitcodes] [-l|--logdest ] +# [--detailed-exitcodes] [-l|--logdest ] [--apply catalog] # # = Description # @@ -53,6 +53,10 @@ # verbose:: # Print extra information. # +# apply:: +# Capability to apply JSON catalog (such as one generated with --compile on the Puppet master). +# You can either specify a JSON catalog file or pipe in JSON from standard input. +# # = Example # # puppet -l /tmp/manifest.log manifest.pp diff --git a/lib/puppet/util/command_line/puppetd b/lib/puppet/util/command_line/puppetd index d7d94ce09..b4eafb483 100755 --- a/lib/puppet/util/command_line/puppetd +++ b/lib/puppet/util/command_line/puppetd @@ -15,7 +15,6 @@ # [-o|--onetime] [--serve ] [-t|--test] [--noop] # [--digest ] [--fingerprint] [-V|--version] # [-v|--verbose] [-w|--waitforcert ] -# [--apply catalog] # # = Description # @@ -173,10 +172,6 @@ # client. You can turn off waiting for certificates by specifying a time # of 0. # -# apply:: -# Capability to apply JSON catalog (such as one generated with --compile on the Puppet master). -# You can either specify a JSON catalog file or pipe in JSON from standard input. -# # = Example # # puppet agent --server puppet.domain.com -- cgit From 23b711954b1c1ba8deb4035503797c2f38a8ce12 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 23 Feb 2011 14:59:13 -0800 Subject: Maint: Add an assertion mechanism to Puppet This patch allows us to make C-style "assertions" in Puppet code, e.g.: assert_that { condition } assert_that(message) { condition } These methods will raise an exception if the environment variable PUPPET_ENABLE_ASSERTIONS is set to a non-empty value, and the the condition evaluates to false. If the environment variable PUPPET_ENABLE_ASSERTIONS is not set, then the condition is not even checked. Switching the assertions on with PUPPET_ENABLE_ASSERTIONS carries three advantages: 1. It makes it possible to put potentially expensive checks in assertions without degrading the performance of the code in production environments. 2. It allows strict assertions to catch Puppet bugs early in development, without increasing the risk of a crash in production environments. 3. It allows a simple command-line mechanism to run any Puppet command with assertions enabled. --- lib/puppet/util/monkey_patches.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 6b5af8350..85854a04c 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -48,3 +48,21 @@ if RUBY_VERSION == '1.8.7' end end +class Object + # The following code allows callers to make assertions that are only + # checked when the environment variable PUPPET_ENABLE_ASSERTIONS is + # set to a non-empty string. For example: + # + # assert_that { condition } + # assert_that(message) { condition } + if ENV["PUPPET_ENABLE_ASSERTIONS"].to_s != '' + def assert_that(message = nil) + unless yield + raise Exception.new("Assertion failure: #{message}") + end + end + else + def assert_that(message = nil) + end + end +end -- cgit From 439115e34c16be27549ee9aa122c418ae6992d76 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Fri, 25 Feb 2011 11:19:34 -0800 Subject: (#6499) Make puppet respond identically to -h and --help lib/puppet/util/command_line.rb had a special case for puppet --help to return generic help instead of the puppet apply help, but it would return puppet apply help when you gave it -h. --- lib/puppet/util/command_line.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb index 4aff0a8cb..7f74d266a 100644 --- a/lib/puppet/util/command_line.rb +++ b/lib/puppet/util/command_line.rb @@ -85,7 +85,7 @@ module Puppet if zero == 'puppet' case argv.first when nil; [ stdin.tty? ? nil : "apply", argv] # ttys get usage info - when "--help"; [nil, argv] # help should give you usage, not the help for `puppet apply` + when "--help", "-h"; [nil, argv] # help should give you usage, not the help for `puppet apply` when /^-|\.pp$|\.rb$/; ["apply", argv] else [ argv.first, argv[1..-1] ] end -- cgit From 8cc390caa18e3b536869f0591d529d8ade76fc49 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Mon, 28 Feb 2011 16:37:22 -0800 Subject: (#5466) Monkey patch Symbol so that you can sort them It turns out that the ability to sort symbols comes in the preinit section of application run when we load Facter and hit the code that adds the <=> method for symbols in lib/facter/util/plist/generator.rb Reviewed-by: Nick Lewis --- lib/puppet/util/monkey_patches.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/puppet/util') diff --git a/lib/puppet/util/monkey_patches.rb b/lib/puppet/util/monkey_patches.rb index 85854a04c..16384855a 100644 --- a/lib/puppet/util/monkey_patches.rb +++ b/lib/puppet/util/monkey_patches.rb @@ -21,6 +21,9 @@ class Symbol z.emit("!ruby/sym ") to_s.to_zaml(z) end + def <=> (other) + self.to_s <=> other.to_s + end end [Object, Exception, Integer, Struct, Date, Time, Range, Regexp, Hash, Array, Float, String, FalseClass, TrueClass, Symbol, NilClass, Class].each { |cls| -- cgit