diff options
| author | Luke Kanies <luke@madstop.com> | 2008-03-31 23:56:09 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-03-31 23:56:09 -0500 |
| commit | 88dc49cb7b0efe757c92ce28c807b91335acb07a (patch) | |
| tree | 13fe4561f1f524f97a8bb2c1ff84c1ef981d0241 /ext | |
| parent | 4165edaeb71ee2883b1bb85ff39a52d5628b259f (diff) | |
| parent | a8592f1009040ebf30a98268610915cc33bb3f63 (diff) | |
Merge branch 'master' into master_no_global_resources
Conflicts:
lib/puppet/node/catalog.rb
lib/puppet/type/pfile.rb
lib/puppet/type/pfilebucket.rb
lib/puppet/util/filetype.rb
spec/unit/node/catalog.rb
spec/unit/other/transbucket.rb
spec/unit/ral/provider/mount/parsed.rb
spec/unit/ral/types/file.rb
spec/unit/ral/types/interface.rb
spec/unit/ral/types/mount.rb
spec/unit/ral/types/package.rb
spec/unit/ral/types/schedule.rb
spec/unit/ral/types/service.rb
test/language/compile.rb
test/language/lexer.rb
test/language/snippets.rb
test/lib/puppettest.rb
test/ral/types/basic.rb
test/ral/types/cron.rb
test/ral/types/exec.rb
test/ral/types/file.rb
test/ral/types/file/target.rb
test/ral/types/filebucket.rb
test/ral/types/fileignoresource.rb
test/ral/types/filesources.rb
test/ral/types/group.rb
test/ral/types/host.rb
test/ral/types/parameter.rb
test/ral/types/sshkey.rb
test/ral/types/tidy.rb
test/ral/types/user.rb
test/ral/types/yumrepo.rb
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/emacs/puppet-mode.el | 202 | ||||
| -rw-r--r-- | ext/ldap/puppet.schema | 7 | ||||
| -rw-r--r-- | ext/logcheck/puppet | 5 | ||||
| -rwxr-xr-x | ext/puppet-test | 76 |
4 files changed, 203 insertions, 87 deletions
diff --git a/ext/emacs/puppet-mode.el b/ext/emacs/puppet-mode.el index 2cf5dcfe9..f331474a9 100644 --- a/ext/emacs/puppet-mode.el +++ b/ext/emacs/puppet-mode.el @@ -89,46 +89,108 @@ (make-local-variable 'paragraph-ignore-fill-prefix) (setq paragraph-ignore-fill-prefix t)) +(defun puppet-comment-line-p () + "Return non-nil iff this line is a comment." + (save-excursion + (beginning-of-line) + (looking-at (format "\\s-*%s" comment-start)))) + +(defun puppet-in-array () + "If point is in an array, return the position of the opening '[' of +that array, else return nil." + (save-excursion + (save-match-data + (let ((opoint (point)) + (apoint (search-backward "[" nil t))) + (when apoint + ;; An array opens before point. If it doesn't close before + ;; point, then point must be in it. + ;; ### TODO: of course, the '[' could be in a string literal, + ;; ### in which case this whole idea is bogus. But baby + ;; ### steps, baby steps. A more robust strategy might be + ;; ### to walk backwards by sexps, until hit a wall, then + ;; ### inspect the nature of that wall. + (if (= (count-matches "\\]" apoint opoint) 0) + apoint)))))) + (defun puppet-indent-line () "Indent current line as puppet code." (interactive) (beginning-of-line) (if (bobp) (indent-line-to 0) ; First line is always non-indented - (let ((not-indented t) cur-indent) - (if (looking-at "^.*}") ; If the line we are looking at is the end of - ; a block, then decrease the indentation - (progn - (save-excursion - (forward-line -1) - - (if (looking-at "^.*}") - (progn - (setq cur-indent (- (current-indentation) 2)) - (setq not-indented nil)) - (setq cur-indent (- (current-indentation) 2)))) - (if (< cur-indent 0) ; We can't indent past the left margin - (setq cur-indent 0))) - (save-excursion - (while not-indented ; Iterate backwards until we find an - ; indentation hint - (forward-line -1) - (if (looking-at "^.*}") ; This hint indicates that we need to - ; indent at the level of the END_ token - (progn - (setq cur-indent (current-indentation)) - (setq not-indented nil)) - (if (looking-at "^.*{") ; This hint indicates that we need to - ; indent an extra level - (progn - ; Do the actual indenting - (setq cur-indent (+ (current-indentation) 2)) - (setq not-indented nil)) - (if (bobp) - (setq not-indented nil))))))) + (let ((not-indented t) + (array-start (puppet-in-array)) + cur-indent) + (cond + (array-start + ;; This line probably starts with an element from an array. + ;; Indent the line to the same indentation as the first + ;; element in that array. That is, this... + ;; + ;; exec { + ;; "add_puppetmaster_mongrel_startup_links": + ;; command => "string1", + ;; creates => [ "string2", "string3", + ;; "string4", "string5", + ;; "string6", "string7", + ;; "string3" ], + ;; refreshonly => true, + ;; } + ;; + ;; ...should instead look like this: + ;; + ;; exec { + ;; "add_puppetmaster_mongrel_startup_links": + ;; command => "string1", + ;; creates => [ "string2", "string3", + ;; "string4", "string5", + ;; "string6", "string7", + ;; "string8" ], + ;; refreshonly => true, + ;; } + (save-excursion + (goto-char array-start) + (forward-char 1) + (re-search-forward "\\S-") + (forward-char -1) + (setq cur-indent (current-column)))) + ((looking-at "^[^{\n]*}") + ;; This line contains the end of a block, but the block does + ;; not also begin on this line, so decrease the indentation. + (save-excursion + (forward-line -1) + (if (looking-at "^.*}") + (progn + (setq cur-indent (- (current-indentation) 2)) + (setq not-indented nil)) + (setq cur-indent (- (current-indentation) 2)))) + (if (< cur-indent 0) ; We can't indent past the left margin + (setq cur-indent 0))) + (t + ;; Otherwise, we did not start on a block-ending-only line. + (save-excursion + ;; Iterate backwards until we find an indentation hint + (while not-indented + (forward-line -1) + (cond + ((puppet-comment-line-p) + (if (bobp) + (setq not-indented nil) + ;; else ignore the line and continue iterating backwards + )) + ((looking-at "^.*}") ; indent at the level of the END_ token + (setq cur-indent (current-indentation)) + (setq not-indented nil)) + ((looking-at "^.*{") ; indent an extra level + (setq cur-indent (+ (current-indentation) 2)) + (setq not-indented nil)) + ((bobp) + (setq not-indented nil)) + ))))) (if cur-indent - (indent-line-to cur-indent) - (indent-line-to 0))))) + (indent-line-to cur-indent) + (indent-line-to 0))))) ;;;###autoload @@ -155,31 +217,31 @@ The variable puppet-indent-level controls the amount of indentation. (setq font-lock-variable-name-face font-lock-type-face)) (setq puppet-font-lock-syntactic-keywords - '( - ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" - (4 (7 . ?/)) - (6 (7 . ?/))) - ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) - ("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil)))) + '( + ("\\(^\\|[=(,~?:;]\\|\\(^\\|\\s \\)\\(if\\|elsif\\|unless\\|while\\|until\\|when\\|and\\|or\\|&&\\|||\\)\\|g?sub!?\\|scan\\|split!?\\)\\s *\\(/\\)[^/\n\\\\]*\\(\\\\.[^/\n\\\\]*\\)*\\(/\\)" + (4 (7 . ?/)) + (6 (7 . ?/))) + ("^\\(=\\)begin\\(\\s \\|$\\)" 1 (7 . nil)) + ("^\\(=\\)end\\(\\s \\|$\\)" 1 (7 . nil)))) (cond ((featurep 'xemacs) - (put 'puppet-mode 'font-lock-defaults - '((puppet-font-lock-keywords) - nil nil nil - beginning-of-line - (font-lock-syntactic-keywords - . puppet-font-lock-syntactic-keywords)))) - (t - (add-hook 'puppet-mode-hook - '(lambda () - (make-local-variable 'font-lock-defaults) - (make-local-variable 'font-lock-keywords) - (make-local-variable 'font-lock-syntax-table) - (make-local-variable 'font-lock-syntactic-keywords) - (setq font-lock-defaults '((puppet-font-lock-keywords) nil nil)) - (setq font-lock-keywords puppet-font-lock-keywords) - (setq font-lock-syntax-table puppet-font-lock-syntax-table) - (setq font-lock-syntactic-keywords puppet-font-lock-syntactic-keywords))))) + (put 'puppet-mode 'font-lock-defaults + '((puppet-font-lock-keywords) + nil nil nil + beginning-of-line + (font-lock-syntactic-keywords + . puppet-font-lock-syntactic-keywords)))) + (t + (add-hook 'puppet-mode-hook + '(lambda () + (make-local-variable 'font-lock-defaults) + (make-local-variable 'font-lock-keywords) + (make-local-variable 'font-lock-syntax-table) + (make-local-variable 'font-lock-syntactic-keywords) + (setq font-lock-defaults '((puppet-font-lock-keywords) nil nil)) + (setq font-lock-keywords puppet-font-lock-keywords) + (setq font-lock-syntax-table puppet-font-lock-syntax-table) + (setq font-lock-syntactic-keywords puppet-font-lock-syntactic-keywords))))) (defvar puppet-font-lock-syntax-table (let* ((tbl (copy-syntax-table puppet-mode-syntax-table))) @@ -196,23 +258,23 @@ The variable puppet-indent-level controls the amount of indentation. 1 font-lock-reference-face) ;; keywords (cons (concat - "\\b\\(\\(" - (mapconcat - 'identity - '("case" + "\\b\\(\\(" + (mapconcat + 'identity + '("case" "class" "default" "define" - "false" - "import" - "include" - "inherits" - "node" - "true" - ) - "\\|") - "\\)\\>\\)") - 1) + "false" + "import" + "include" + "inherits" + "node" + "true" + ) + "\\|") + "\\)\\>\\)") + 1) ;; variables '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\>" 2 font-lock-variable-name-face) diff --git a/ext/ldap/puppet.schema b/ext/ldap/puppet.schema index b7c715ec2..bbad23eab 100644 --- a/ext/ldap/puppet.schema +++ b/ext/ldap/puppet.schema @@ -12,6 +12,11 @@ attributetype ( 1.1.3.9 NAME 'parentnode' EQUALITY caseIgnoreIA5Match SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) +attributetype ( 1.1.3.9 NAME 'environment' + DESC 'Puppet Node Environment' + EQUALITY caseIgnoreIA5Match + SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 ) + objectclass ( 1.1.1.2 NAME 'puppetClient' SUP top AUXILIARY DESC 'Puppet Client objectclass' - MAY ( puppetclass $ parentnode )) + MAY ( puppetclass $ parentnode $ environment )) diff --git a/ext/logcheck/puppet b/ext/logcheck/puppet index 8b854dc48..449ec70f5 100644 --- a/ext/logcheck/puppet +++ b/ext/logcheck/puppet @@ -15,3 +15,8 @@ ^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Restarting with .*$ ^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Starting catalog run$ ^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Finished catalog run in [.0-9]+ seconds$ +^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Loading fact .*$ +^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Ignoring cache$ +^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Ignoring --listen on onetime run$ +^\w{3} [ :0-9]{11} [._[:alnum:]-]+ puppetd\[[0-9]+\]: Retrieving plugins$ + diff --git a/ext/puppet-test b/ext/puppet-test index 362a43996..dc0aeca92 100755 --- a/ext/puppet-test +++ b/ext/puppet-test @@ -53,6 +53,9 @@ # list:: # List all available tests. # +# pause:: +# Pause before starting test (useful for testing with dtrace). +# # repeat:: # How many times to perform the test. # @@ -88,7 +91,7 @@ # Do an initial trap, so that cancels don't get a stack trace. trap(:INT) do $stderr.puts "Cancelling startup" - exit(0) + exit(1) end require 'puppet' @@ -140,10 +143,6 @@ class Suite instance_eval(&block) end - def prepare - raise "Test %s did not override 'prepare'" % @name - end - # Define a new type of test on this suite. def newtest(name, doc, &block) @tests[name] = doc @@ -163,7 +162,14 @@ class Suite raise "Suite %s only supports tests %s; not %s" % [@name, @tests.keys.collect { |k| k.to_s }.join(","), test] end puts "Running %s %s test" % [@name, test] - prepare() + + prepare() if respond_to?(:prepare) + + if $options[:pause] + puts "Hit any key to continue" + $stdin.readline + puts "Continuing with test" + end if $options[:fork] > 0 @forking = true @@ -200,7 +206,25 @@ class Suite end end -Suite.new :catalog, "Catalog handling" do +Suite.new :parser, "Manifest parsing" do + newtest :parse, "Parsed files" do + @parser = Puppet::Parser::Parser.new(:environment => Puppet[:environment]) + @parser.file = Puppet[:manifest] + @parser.parse + end +end + +Suite.new :local_catalog, "Local catalog handling" do + def prepare + @node = Puppet::Node.find(Puppet[:certname]) + end + + newtest :compile, "Compiled catalog" do + Puppet::Node::Catalog.find(@node) + end +end + +Suite.new :remote_catalog, "Remote catalog handling" do def prepare $args[:cache] = false # Create a config client and pull the config down @@ -212,10 +236,12 @@ Suite.new :catalog, "Catalog handling" do # Use the facts from the cache, to skip the time it takes # to load them. @client.dostorage - @facts = Puppet::Util::Storage.cache(:configuration)[:facts] + @facts = Puppet::Util::Storage.cache(:configuration)[:facts] || {} if @facts.empty? - @facts = @client.master.getfacts + if tmp = Puppet::Node::Facts.find("me") + @facts = tmp.values + end end if host = $options[:fqdn] @@ -227,7 +253,7 @@ Suite.new :catalog, "Catalog handling" do @facts = YAML.dump(@facts) end - newtest :compile, "Compiled catalog" do + newtest :getconfig, "Compiled catalog" do @client.driver.getconfig(@facts, "yaml") end @@ -257,6 +283,21 @@ Suite.new :file, "File interactions" do end end +Suite.new :filebucket, "Filebucket interactions" do + def prepare + require 'tempfile' + @client = Puppet::Network::Client.dipper.new($args) + end + + newtest :backup, "Backed up file" do + Tempfile.open("bucket_testing") do |f| + f.print rand(1024) + f.close + @client.backup(f.path) + end + end +end + # Note that this uses an env variable to determine how many resources per # host to create (with a default of 10). 'repeat' determines how # many hosts to create. You probably will get mad failures if you @@ -325,12 +366,13 @@ end $cmdargs = [ [ "--compile", "-c", GetoptLong::NO_ARGUMENT ], - [ "--describe", "-D", GetoptLong::REQUIRED_ARGUMENT ], + [ "--describe", GetoptLong::REQUIRED_ARGUMENT ], [ "--retrieve", "-R", GetoptLong::REQUIRED_ARGUMENT ], [ "--fork", GetoptLong::REQUIRED_ARGUMENT ], [ "--fqdn", "-F", GetoptLong::REQUIRED_ARGUMENT ], [ "--suite", "-s", GetoptLong::REQUIRED_ARGUMENT ], [ "--test", "-t", GetoptLong::REQUIRED_ARGUMENT ], + [ "--pause", "-p", GetoptLong::NO_ARGUMENT ], [ "--repeat", "-r", GetoptLong::REQUIRED_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ], @@ -340,14 +382,14 @@ $cmdargs = [ ] # Add all of the config parameters as valid $options. -Puppet.config.addargs($cmdargs) +Puppet.settings.addargs($cmdargs) Puppet::Util::Log.newdestination(:console) result = GetoptLong.new(*$cmdargs) $args = {} -$options = {:repeat => 1, :fork => 0} +$options = {:repeat => 1, :fork => 0, :pause => false} begin explicit_waitforcert = false @@ -399,6 +441,8 @@ begin $options[:test] = arg.intern when "--file" $options[:file] = arg + when "--pause" + $options[:pause] = true when "--list" Suite.suites.sort { |a,b| a.to_s <=> b.to_s }.each do |suite_name| suite = Suite[suite_name] @@ -407,7 +451,7 @@ begin end exit(0) else - Puppet.config.handlearg(opt, arg) + Puppet.settings.handlearg(opt, arg) end } rescue GetoptLong::InvalidOption => detail @@ -422,8 +466,8 @@ Puppet.parse_config $args[:Server] = Puppet[:server] unless $options[:test] - $options[:suite] = :configuration - $options[:test] = :compile + $options[:suite] = :remote_catalog + $options[:test] = :getconfig end unless $options[:test] |
