diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-12 11:46:17 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-05-12 11:46:17 -0700 |
| commit | 1f438da968e1583d900903407c2e5b17648fa937 (patch) | |
| tree | 8d402af900458792a0cb516b2c903578fb592b7d | |
| parent | e059539a0d7bfc33f80b003894a1a2d807e85851 (diff) | |
| parent | 8f907f21c05295a4e04a55e2d0b287454eea4773 (diff) | |
| download | puppet-1f438da968e1583d900903407c2e5b17648fa937.tar.gz puppet-1f438da968e1583d900903407c2e5b17648fa937.tar.xz puppet-1f438da968e1583d900903407c2e5b17648fa937.zip | |
Merge branch '2.6.next' into 2.6.x
29 files changed, 457 insertions, 103 deletions
diff --git a/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb new file mode 100644 index 000000000..1b0b537bf --- /dev/null +++ b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb @@ -0,0 +1,39 @@ +test_name "#4655: Allow setting the default stage for parameterized classes" + +temp_file_name = "/tmp/4655-stage-in-parameterized-class.#{$$}" +test_manifest = <<HERE +stage { one: before => Stage[two] } +stage { two: before => Stage[three] } +stage { three: before => Stage[main] } + +class in_one { + exec { "echo 'in_one' > #{temp_file_name}": + path => '/usr/bin:/bin', + } +} +class { in_one: stage => "one" } + +class in_two( $stage=two ){ + exec { "echo 'in_two' >> #{temp_file_name}": + path => '/usr/bin:/bin', + } +} +class { in_two: } + +class in_three { + exec { "echo 'in_three' >> #{temp_file_name}": + path => '/usr/bin:/bin', + } +} +class { "in_three": stage => "three" } +HERE + +expected_results = "in_one +in_two +in_three +" +apply_manifest_on agents, test_manifest + +on(agents, "cat #{temp_file_name}").each do |result| + assert_equal(expected_results, "#{result.stdout}", "Unexpected result for host '#{result.host}'") +end diff --git a/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rm b/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rm new file mode 100644 index 000000000..f773ba17c --- /dev/null +++ b/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rm @@ -0,0 +1,11 @@ +test_name "#7139: Puppet resource file failes on path with leading '/'" + +step "Agents: create valid, invalid formatted manifests" +create_remote_file(agents, '/tmp/ticket-7139', %w{foo bar contents} ) + +step "Run puppet file resource on /tmp/ticket-7139" +agents.each do |host| + on(host, "puppet resource file /tmp/ticket-7139") do + assert_match(/file \{ \'\/tmp\/ticket-7139\':/, stdout, "puppet resource file failed on #{host}") + end +end diff --git a/ext/vim/README b/ext/vim/README index 776bb1eb2..7fd2934fb 100644 --- a/ext/vim/README +++ b/ext/vim/README @@ -1,2 +1,3 @@ To install these files, copy them into ~/.vim, or the relevant -system-wide location. +system-wide location. To use the ftplugin and indenting, you may need +to enable them with "filetype plugin indent on" in your vimrc. diff --git a/ext/vim/ftplugin/puppet.vim b/ext/vim/ftplugin/puppet.vim new file mode 100644 index 000000000..b6491554b --- /dev/null +++ b/ext/vim/ftplugin/puppet.vim @@ -0,0 +1,94 @@ +" Vim filetype plugin +" Language: Puppet +" Maintainer: Todd Zullinger <tmz@pobox.com> +" Last Change: 2009 Aug 19 +" vim: set sw=4 sts=4: + +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +if !exists("no_plugin_maps") && !exists("no_puppet_maps") + if !hasmapto("<Plug>AlignRange") + map <buffer> <LocalLeader>= <Plug>AlignRange + endif +endif + +noremap <buffer> <unique> <script> <Plug>AlignArrows :call <SID>AlignArrows()<CR> +noremap <buffer> <unique> <script> <Plug>AlignRange :call <SID>AlignRange()<CR> + +iabbrev => =><C-R>=<SID>AlignArrows('=>')<CR> +iabbrev +> +><C-R>=<SID>AlignArrows('+>')<CR> + +if exists('*s:AlignArrows') + finish +endif + +let s:arrow_re = '[=+]>' +let s:selector_re = '[=+]>\s*\$.*\s*?\s*{\s*$' + +function! s:AlignArrows(op) + let cursor_pos = getpos('.') + let lnum = line('.') + let line = getline(lnum) + if line !~ s:arrow_re + return + endif + let pos = stridx(line, a:op) + let start = lnum + let end = lnum + let pnum = lnum - 1 + while 1 + let pline = getline(pnum) + if pline !~ s:arrow_re || pline =~ s:selector_re + break + endif + let start = pnum + let pnum -= 1 + endwhile + let cnum = end + while 1 + let cline = getline(cnum) + if cline !~ s:arrow_re || + \ (indent(cnum) != indent(cnum+1) && getline(cnum+1) !~ '\s*}') + break + endif + let end = cnum + let cnum += 1 + endwhile + call s:AlignSection(start, end) + let cursor_pos[2] = stridx(getline('.'), a:op) + strlen(a:op) + 1 + call setpos('.', cursor_pos) + return '' +endfunction + +function! s:AlignRange() range + call s:AlignSection(a:firstline, a:lastline) +endfunction + +" AlignSection and AlignLine are from the vim wiki: +" http://vim.wikia.com/wiki/Regex-based_text_alignment +function! s:AlignSection(start, end) + let extra = 1 + let sep = s:arrow_re + let maxpos = 0 + let section = getline(a:start, a:end) + for line in section + let pos = match(line, ' *'.sep) + if maxpos < pos + let maxpos = pos + endif + endfor + call map(section, 's:AlignLine(v:val, sep, maxpos, extra)') + call setline(a:start, section) +endfunction + +function! s:AlignLine(line, sep, maxpos, extra) + let m = matchlist(a:line, '\(.\{-}\) \{-}\('.a:sep.'.*\)') + if empty(m) + return a:line + endif + let spaces = repeat(' ', a:maxpos - strlen(m[1]) + a:extra) + return m[1] . spaces . m[2] +endfunction diff --git a/ext/vim/indent/puppet.vim b/ext/vim/indent/puppet.vim new file mode 100644 index 000000000..689e06879 --- /dev/null +++ b/ext/vim/indent/puppet.vim @@ -0,0 +1,76 @@ +" Vim indent file +" Language: Puppet +" Maintainer: Todd Zullinger <tmz@pobox.com> +" Last Change: 2009 Aug 19 +" vim: set sw=4 sts=4: + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal autoindent smartindent +setlocal indentexpr=GetPuppetIndent() +setlocal indentkeys+=0],0) + +if exists("*GetPuppetIndent") + finish +endif + +" Check if a line is part of an include 'block', e.g.: +" include foo, +" bar, +" baz +function! s:PartOfInclude(lnum) + let lnum = a:lnum + while lnum + let lnum = lnum - 1 + let line = getline(lnum) + if line !~ ',$' + break + endif + if line =~ '^\s*include\s\+[^,]\+,$' + return 1 + endif + endwhile + return 0 +endfunction + +function! s:OpenBrace(lnum) + call cursor(a:lnum, 1) + return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW') +endfunction + +function! GetPuppetIndent() + let pnum = prevnonblank(v:lnum - 1) + if pnum == 0 + return 0 + endif + + let line = getline(v:lnum) + let pline = getline(pnum) + let ind = indent(pnum) + + if pline =~ '^\s*#' + return ind + endif + + if pline =~ '\({\|\[\|(\|:\)$' + let ind += &sw + elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*' + let ind -= &sw + elseif pline =~ '^\s*include\s\+.*,$' + let ind += &sw + endif + + if pline !~ ',$' && s:PartOfInclude(pnum) + let ind -= &sw + endif + + " Match } }, }; ] ]: ) + if line =~ '^\s*\(}\(,\|;\)\?$\|]:\?$\|)\)' + let ind = indent(s:OpenBrace(v:lnum)) + endif + + return ind +endfunction diff --git a/lib/puppet.rb b/lib/puppet.rb index a9ed2898c..f97d28642 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -59,8 +59,7 @@ module Puppet # configuration parameter access and stuff def self.[](param) - case param - when :debug + if param == :debug return Puppet::Util::Log.level == :debug else return @@settings[param] diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb index 9f5921de1..0d67c1a88 100644 --- a/lib/puppet/application/agent.rb +++ b/lib/puppet/application/agent.rb @@ -168,8 +168,8 @@ class Puppet::Application::Agent < Puppet::Application end def setup_listen - unless FileTest.exists?(Puppet[:authconfig]) - Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}" + unless FileTest.exists?(Puppet[:rest_authconfig]) + Puppet.err "Will not start without authorization file #{Puppet[:rest_authconfig]}" exit(14) end diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb index c020f036d..f29f70a53 100644 --- a/lib/puppet/file_serving/fileset.rb +++ b/lib/puppet/file_serving/fileset.rb @@ -59,7 +59,7 @@ class Puppet::FileServing::Fileset end def initialize(path, options = {}) - path = path.chomp(File::SEPARATOR) + path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR raise ArgumentError.new("Fileset paths must be fully qualified") unless File.expand_path(path) == path @path = path diff --git a/lib/puppet/indirector/queue.rb b/lib/puppet/indirector/queue.rb index fd089f431..85ffacacc 100644 --- a/lib/puppet/indirector/queue.rb +++ b/lib/puppet/indirector/queue.rb @@ -36,7 +36,7 @@ class Puppet::Indirector::Queue < Puppet::Indirector::Terminus def save(request) result = nil benchmark :info, "Queued #{indirection.name} for #{request.key}" do - result = client.send_message(queue, request.instance.render(:pson)) + result = client.publish_message(queue, request.instance.render(:pson)) end result rescue => detail diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 6e8e3d26b..98bf3b574 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -56,23 +56,20 @@ class Puppet::Parser::Compiler # Note that this will fail if the resource is not unique. @catalog.add_resource(resource) + if resource.type.to_s.downcase != "class" && resource[:stage] + raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage" + end - # Add our container edge. If we're a class, then we get treated specially - we can - # control the stage that the class is applied in. Otherwise, we just - # get added to our parent container. + # Stages should not be inside of classes. They are always a + # top-level container, regardless of where they appear in the + # manifest. return if resource.type.to_s.downcase == "stage" + # This adds a resource to the class it lexically appears in in the + # manifest. if resource.type.to_s.downcase != "class" - raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage" if resource[:stage] return @catalog.add_edge(scope.resource, resource) end - - unless stage = @catalog.resource(:stage, resource[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main) - raise ArgumentError, "Could not find stage #{resource[:stage] || :main} specified by #{resource}" - end - - resource[:stage] ||= stage.title unless stage.title == :main - @catalog.add_edge(stage, resource) end # Do we use nodes found in the code, vs. the external node sources? diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index c007d4dbe..e4f913013 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -62,13 +62,30 @@ class Puppet::Parser::Resource < Puppet::Resource scope.environment end + # Process the stage metaparameter for a class. A containment edge + # is drawn from the class to the stage. The stage for containment + # defaults to main, if none is specified. + def add_edge_to_stage + return unless self.type.to_s.downcase == "class" + + unless stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main) + raise ArgumentError, "Could not find stage #{self[:stage] || :main} specified by #{self}" + end + + self[:stage] ||= stage.title unless stage.title == :main + catalog.add_edge(stage, self) + end + # Retrieve the associated definition and evaluate it. def evaluate return if evaluated? @evaluated = true if klass = resource_type and ! builtin_type? finish - return klass.evaluate_code(self) + evaluated_code = klass.evaluate_code(self) + add_edge_to_stage + + return evaluated_code elsif builtin? devfail "Cannot evaluate a builtin type (#{type})" else diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 24f1d01f7..c369f129a 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -101,7 +101,7 @@ class Puppet::Parser::Scope # Remove this when rebasing def environment - compiler.environment + compiler ? compiler.environment : nil end # Are we the top scope? @@ -513,6 +513,6 @@ class Puppet::Parser::Scope def extend_with_functions_module extend Puppet::Parser::Functions.environment_module(Puppet::Node::Environment.root) - extend Puppet::Parser::Functions.environment_module(compiler ? environment : nil) + extend Puppet::Parser::Functions.environment_module(environment) end end diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb index 11c5e21a9..7c3f41bbd 100755 --- a/lib/puppet/provider/mount/parsed.rb +++ b/lib/puppet/provider/mount/parsed.rb @@ -18,7 +18,7 @@ Puppet::Type.type(:mount).provide( commands :mountcmd => "mount", :umount => "umount" - case Facter["operatingsystem"] + case Facter.value(:operatingsystem) when "Solaris" @fields = [:device, :blockdevice, :name, :fstype, :pass, :atboot, :options] else diff --git a/lib/puppet/provider/naginator.rb b/lib/puppet/provider/naginator.rb index 5c610fb31..17cc24086 100644 --- a/lib/puppet/provider/naginator.rb +++ b/lib/puppet/provider/naginator.rb @@ -30,7 +30,15 @@ class Puppet::Provider::Naginator < Puppet::Provider::ParsedFile end def self.to_file(records) - header + records.collect { |record| record.to_s }.join("\n").gsub("_naginator_name", NAME_STRING) + header + records.collect { |record| + # Remap the TYPE_name or _naginator_name params to the + # name if the record is a template (register == 0) + if record.to_s =~ /register\s+0/ + record.to_s.sub("_naginator_name", "name").sub(record.type.to_s + "_name", "name") + else + record.to_s.sub("_naginator_name", NAME_STRING) + end + }.join("\n") end def self.skip_record?(record) diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index b01880360..aab491122 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -235,11 +235,12 @@ class DirectoryService < Puppet::Provider::NameService # have a lot of choice. Ultimately this should all be done using Ruby # to access the DirectoryService APIs directly, but that's simply not # feasible for a while yet. - case self.get_macosx_version_major - when "10.4" - dscl_plist = self.parse_dscl_url_data(dscl_output) - when "10.5", "10.6" + if self.get_macosx_version_major > "10.4" dscl_plist = self.parse_dscl_plist_data(dscl_output) + elsif self.get_macosx_version_major == "10.4" + dscl_plist = self.parse_dscl_url_data(dscl_output) + else + fail("Puppet does not support OS X versions < 10.4") end self.generate_attribute_hash(dscl_plist, *type_properties) @@ -257,12 +258,14 @@ class DirectoryService < Puppet::Provider::NameService # different format for the -url output with objects with spaces in # their values. *sigh*. Use -url for 10.4 in the hope this can be # deprecated one day, and use -plist for 10.5 and higher. - case self.get_macosx_version_major - when "10.4" - command_vector = [ command(:dscl), "-url", "." ] - when "10.5", "10.6" + if self.get_macosx_version_major > "10.4" command_vector = [ command(:dscl), "-plist", "." ] + elsif self.get_macosx_version_major == "10.4" + command_vector = [ command(:dscl), "-url", "." ] + else + fail("Puppet does not support OS X versions < 10.4") end + # 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/aptitude.rb b/lib/puppet/provider/package/aptitude.rb index 8bdf984e6..2eafd3ef8 100755 --- a/lib/puppet/provider/package/aptitude.rb +++ b/lib/puppet/provider/package/aptitude.rb @@ -12,6 +12,7 @@ Puppet::Type.type(:package).provide :aptitude, :parent => :apt, :source => :dpkg args.flatten! # Apparently aptitude hasn't always supported a -q flag. args.delete("-q") if args.include?("-q") + args.delete("--force-yes") if args.include?("--force-yes") output = aptitude(*args) # Yay, stupid aptitude doesn't throw an error when the package is missing. diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index b9dea2a3d..e5360217c 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -1,3 +1,4 @@ +require 'puppet/node/environment' require 'puppet/rails' require 'puppet/rails/resource' require 'puppet/rails/fact_name' @@ -28,6 +29,12 @@ class Puppet::Rails::Host < ActiveRecord::Base host end + # Override the setter for environment to force it to be a string, lest it + # be YAML encoded. See #4487. + def environment=(value) + super value.to_s + end + # returns a hash of fact_names.name => [ fact_values ] for this host. # Note that 'fact_values' is actually a list of the value instances, not # just actual values. diff --git a/lib/puppet/util/queue.rb b/lib/puppet/util/queue.rb index 02357742a..636bdcf2e 100644 --- a/lib/puppet/util/queue.rb +++ b/lib/puppet/util/queue.rb @@ -30,7 +30,7 @@ require 'puppet/util/instance_loader' # # The client plugins are expected to implement an interface similar to that of Stomp::Client: # * <tt>new</tt> should return a connected, ready-to-go client instance. Note that no arguments are passed in. -# * <tt>send_message(queue, message)</tt> should send the _message_ to the specified _queue_. +# * <tt>publish_message(queue, message)</tt> should publish the _message_ to the specified _queue_. # * <tt>subscribe(queue)</tt> _block_ subscribes to _queue_ and executes _block_ upon receiving a message. # * _queue_ names are simple names independent of the message broker or client library. No "/queue/" prefixes like in Stomp::Client. module Puppet::Util::Queue diff --git a/lib/puppet/util/queue/stomp.rb b/lib/puppet/util/queue/stomp.rb index c18edae6a..cabc56627 100644 --- a/lib/puppet/util/queue/stomp.rb +++ b/lib/puppet/util/queue/stomp.rb @@ -28,8 +28,8 @@ class Puppet::Util::Queue::Stomp end end - def send_message(target, msg) - stomp_client.send(stompify_target(target), msg, :persistent => true) + def publish_message(target, msg) + stomp_client.publish(stompify_target(target), msg, :persistent => true) end def subscribe(target) diff --git a/spec/integration/indirector/catalog/queue_spec.rb b/spec/integration/indirector/catalog/queue_spec.rb index 4581e3062..5a4a8a4ab 100755 --- a/spec/integration/indirector/catalog/queue_spec.rb +++ b/spec/integration/indirector/catalog/queue_spec.rb @@ -20,13 +20,13 @@ describe "Puppet::Resource::Catalog::Queue", :if => Puppet.features.pson? do after { Puppet.settings.clear } - it "should render catalogs to pson and send them via the queue client when catalogs are saved" do + it "should render catalogs to pson and publish them via the queue client when catalogs are saved" do terminus = Puppet::Resource::Catalog.indirection.terminus(:queue) client = mock 'client' terminus.stubs(:client).returns client - client.expects(:send_message).with(:catalog, @catalog.to_pson) + client.expects(:publish_message).with(:catalog, @catalog.to_pson) request = Puppet::Indirector::Request.new(:catalog, :save, "foo", :instance => @catalog) diff --git a/spec/unit/application/agent_spec.rb b/spec/unit/application/agent_spec.rb index c9d9a4509..de6c7c893 100755 --- a/spec/unit/application/agent_spec.rb +++ b/spec/unit/application/agent_spec.rb @@ -411,7 +411,7 @@ describe Puppet::Application::Agent do describe "when setting up listen" do before :each do - Puppet.stubs(:[]).with(:authconfig).returns('auth') + Puppet.stubs(:[]).with(:rest_authconfig).returns('auth') FileTest.stubs(:exists?).with('auth').returns(true) File.stubs(:exist?).returns(true) @puppetd.options.stubs(:[]).with(:serve).returns([]) diff --git a/spec/unit/file_serving/fileset_spec.rb b/spec/unit/file_serving/fileset_spec.rb index 149c68c4a..6b41e8a74 100755 --- a/spec/unit/file_serving/fileset_spec.rb +++ b/spec/unit/file_serving/fileset_spec.rb @@ -21,6 +21,13 @@ describe Puppet::FileServing::Fileset, " when initializing" do fileset.path.should == path end + it "should not fail if the path is just the file separator" do + path = File::SEPARATOR + File.stubs(:lstat).with(path).returns stub('stat') + fileset = Puppet::FileServing::Fileset.new(path) + fileset.path.should == path + end + it "should fail if its path does not exist" do File.expects(:lstat).with("/some/file").returns nil proc { Puppet::FileServing::Fileset.new("/some/file") }.should raise_error(ArgumentError) diff --git a/spec/unit/indirector/queue_spec.rb b/spec/unit/indirector/queue_spec.rb index bbe00c75f..bfd7598ad 100755 --- a/spec/unit/indirector/queue_spec.rb +++ b/spec/unit/indirector/queue_spec.rb @@ -63,20 +63,20 @@ describe Puppet::Indirector::Queue, :if => Puppet.features.pson? do describe "when saving" do it 'should render the instance using pson' do @subject.expects(:render).with(:pson) - @store.client.stubs(:send_message) + @store.client.stubs(:publish_message) @store.save(@request) end - it "should send the rendered message to the appropriate queue on the client" do + it "should publish the rendered message to the appropriate queue on the client" do @subject.expects(:render).returns "mypson" - @store.client.expects(:send_message).with(:my_queue, "mypson") + @store.client.expects(:publish_message).with(:my_queue, "mypson") @store.save(@request) end it "should catch any exceptions raised" do - @store.client.expects(:send_message).raises ArgumentError + @store.client.expects(:publish_message).raises ArgumentError lambda { @store.save(@request) }.should raise_error(Puppet::Error) end diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index 261cfdec1..4cab3cb65 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -33,6 +33,14 @@ class CompilerTestResource def evaluate end + + def file + "/fake/file/goes/here" + end + + def line + "42" + end end describe Puppet::Parser::Compiler do @@ -418,52 +426,6 @@ describe Puppet::Parser::Compiler do @compiler.catalog.should be_edge(@scope.resource, resource) end - it "should add an edge to any specified stage for class resources" do - other_stage = resource(:stage, "other") - @compiler.add_resource(@scope, other_stage) - resource = resource(:class, "foo") - resource[:stage] = 'other' - - @compiler.add_resource(@scope, resource) - - @compiler.catalog.edge?(other_stage, resource).should be_true - end - - it "should fail if a non-class resource attempts to set a stage" do - other_stage = resource(:stage, "other") - @compiler.add_resource(@scope, other_stage) - resource = resource(:file, "foo") - resource[:stage] = 'other' - - lambda { @compiler.add_resource(@scope, resource) }.should raise_error(ArgumentError) - end - - it "should fail if an unknown stage is specified" do - resource = resource(:class, "foo") - resource[:stage] = 'other' - - lambda { @compiler.add_resource(@scope, resource) }.should raise_error(ArgumentError) - end - - it "should add edges from the class resources to the parent's stage if no stage is specified" do - main = @compiler.catalog.resource(:stage, :main) - foo_stage = resource(:stage, :foo_stage) - @compiler.add_resource(@scope, foo_stage) - resource = resource(:class, "foo") - @scope.stubs(:resource).returns(:stage => :foo_stage) - @compiler.add_resource(@scope, resource) - - @compiler.catalog.should be_edge(foo_stage, resource) - end - - it "should add edges from top-level class resources to the main stage if no stage is specified" do - main = @compiler.catalog.resource(:stage, :main) - resource = resource(:class, "foo") - @compiler.add_resource(@scope, resource) - - @compiler.catalog.should be_edge(main, resource) - end - it "should not add non-class resources that don't specify a stage to the 'main' stage" do main = @compiler.catalog.resource(:stage, :main) resource = resource(:file, "foo") diff --git a/spec/unit/parser/resource_spec.rb b/spec/unit/parser/resource_spec.rb index dae22fcaa..6207df36f 100755 --- a/spec/unit/parser/resource_spec.rb +++ b/spec/unit/parser/resource_spec.rb @@ -132,9 +132,19 @@ describe Puppet::Parser::Resource do end describe "when evaluating" do + before do + @node = Puppet::Node.new "test-node" + @compiler = Puppet::Parser::Compiler.new @node + @catalog = Puppet::Resource::Catalog.new + source = stub('source') + source.stubs(:module_name) + @scope = Puppet::Parser::Scope.new(:compiler => @compiler, :source => source) + @catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => @scope)) + end + it "should evaluate the associated AST definition" do definition = newdefine "mydefine" - res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source) + res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source, :catalog => @catalog) definition.expects(:evaluate_code).with(res) res.evaluate @@ -142,17 +152,65 @@ describe Puppet::Parser::Resource do it "should evaluate the associated AST class" do @class = newclass "myclass" - res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source) + res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source, :catalog => @catalog) @class.expects(:evaluate_code).with(res) res.evaluate end it "should evaluate the associated AST node" do nodedef = newnode("mynode") - res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source) + res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source, :catalog => @catalog) nodedef.expects(:evaluate_code).with(res) res.evaluate end + + it "should add an edge to any specified stage for class resources" do + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + + other_stage = Puppet::Parser::Resource.new(:stage, "other", :scope => @scope, :catalog => @catalog) + @compiler.add_resource(@scope, other_stage) + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + resource[:stage] = 'other' + @compiler.add_resource(@scope, resource) + + resource.evaluate + + @compiler.catalog.edge?(other_stage, resource).should be_true + end + + it "should fail if an unknown stage is specified" do + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + resource[:stage] = 'other' + + lambda { resource.evaluate }.should raise_error(ArgumentError, /Could not find stage other specified by/) + end + + it "should add edges from the class resources to the parent's stage if no stage is specified" do + main = @compiler.catalog.resource(:stage, :main) + foo_stage = Puppet::Parser::Resource.new(:stage, :foo_stage, :scope => @scope, :catalog => @catalog) + @compiler.add_resource(@scope, foo_stage) + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + resource[:stage] = 'foo_stage' + @compiler.add_resource(@scope, resource) + + resource.evaluate + + @compiler.catalog.should be_edge(foo_stage, resource) + end + + it "should add edges from top-level class resources to the main stage if no stage is specified" do + main = @compiler.catalog.resource(:stage, :main) + @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '') + resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog) + @compiler.add_resource(@scope, resource) + + resource.evaluate + + @compiler.catalog.should be_edge(main, resource) + end end describe "when finishing" do diff --git a/spec/unit/parser/scope_spec.rb b/spec/unit/parser/scope_spec.rb index 9895f446b..639512874 100755 --- a/spec/unit/parser/scope_spec.rb +++ b/spec/unit/parser/scope_spec.rb @@ -123,7 +123,11 @@ describe Puppet::Parser::Scope do def create_class_scope(name) klass = newclass(name) - Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate + + catalog = Puppet::Resource::Catalog.new + catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => Puppet::Parser::Scope.new)) + + Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source'), :catalog => catalog).evaluate @scope.class_scope(klass) end @@ -418,13 +422,15 @@ describe Puppet::Parser::Scope do before do @scopes = {} klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, "")) - Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source')).evaluate + @catalog = Puppet::Resource::Catalog.new + @catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => @scope)) + Puppet::Parser::Resource.new("class", :main, :scope => @scope, :source => mock('source'), :catalog => @catalog).evaluate @scopes[""] = @scope.class_scope(klass) @scopes[""].setvar("test", "value") %w{one one::two one::two::three}.each do |name| klass = @scope.known_resource_types.add(Puppet::Resource::Type.new(:hostclass, name)) - Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate + Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source'), :catalog => @catalog).evaluate @scopes[name] = @scope.class_scope(klass) @scopes[name].setvar("test", "value-#{name.sub(/.+::/,'')}") end diff --git a/spec/unit/provider/nameservice/directoryservice_spec.rb b/spec/unit/provider/nameservice/directoryservice_spec.rb index 661899db9..07f75e3f4 100755 --- a/spec/unit/provider/nameservice/directoryservice_spec.rb +++ b/spec/unit/provider/nameservice/directoryservice_spec.rb @@ -36,3 +36,63 @@ require File.dirname(__FILE__) + '/../../../spec_helper' end end end + +describe 'DirectoryService.single_report' do + it 'should fail on OS X < 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.3") + + lambda { + Puppet::Provider::NameService::DirectoryService.single_report('resource_name') + }.should raise_error(RuntimeError, "Puppet does not support OS X versions < 10.4") + end + + it 'should use url data on 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.4") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + Puppet::Provider::NameService::DirectoryService.stubs(:list_all_present).returns( + ['root', 'user1', 'user2', 'resource_name'] + ) + Puppet::Provider::NameService::DirectoryService.stubs(:generate_attribute_hash) + Puppet::Provider::NameService::DirectoryService.stubs(:execute) + Puppet::Provider::NameService::DirectoryService.expects(:parse_dscl_url_data) + + Puppet::Provider::NameService::DirectoryService.single_report('resource_name') + end + + it 'should use plist data on > 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.5") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + Puppet::Provider::NameService::DirectoryService.stubs(:list_all_present).returns( + ['root', 'user1', 'user2', 'resource_name'] + ) + Puppet::Provider::NameService::DirectoryService.stubs(:generate_attribute_hash) + Puppet::Provider::NameService::DirectoryService.stubs(:execute) + Puppet::Provider::NameService::DirectoryService.expects(:parse_dscl_plist_data) + + Puppet::Provider::NameService::DirectoryService.single_report('resource_name') + end +end + +describe 'DirectoryService.get_exec_preamble' do + it 'should fail on OS X < 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.3") + + lambda { + Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list') + }.should raise_error(RuntimeError, "Puppet does not support OS X versions < 10.4") + end + + it 'should use url data on 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.4") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + + Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list').should include("-url") + end + + it 'should use plist data on > 10.4' do + Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.5") + Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users') + + Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list').should include("-plist") + end +end diff --git a/spec/unit/rails/host_spec.rb b/spec/unit/rails/host_spec.rb index 4244f117f..b413a16b8 100755 --- a/spec/unit/rails/host_spec.rb +++ b/spec/unit/rails/host_spec.rb @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/node/environment' + describe "Puppet::Rails::Host", :if => Puppet.features.rails? do def column(name, type) ActiveRecord::ConnectionAdapters::Column.new(name, nil, type, false) @@ -43,6 +45,12 @@ describe "Puppet::Rails::Host", :if => Puppet.features.rails? do Puppet::Rails::Host.from_puppet(@node) end + it "should stringify the environment" do + host = Puppet::Rails::Host.new + host.environment = Puppet::Node::Environment.new("production") + host.environment.class.should == String + end + it "should copy the ipaddress from the Puppet instance" do Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host diff --git a/spec/unit/util/queue/stomp_spec.rb b/spec/unit/util/queue/stomp_spec.rb index c33f1a670..91036793c 100755 --- a/spec/unit/util/queue/stomp_spec.rb +++ b/spec/unit/util/queue/stomp_spec.rb @@ -64,26 +64,26 @@ describe 'Puppet::Util::Queue::Stomp', :if => Puppet.features.stomp? do end end - describe "when sending a message" do + describe "when publishing a message" do before do @client = stub 'client' Stomp::Client.stubs(:new).returns @client @queue = Puppet::Util::Queue::Stomp.new end - it "should send it to the queue client instance" do - @client.expects(:send).with { |queue, msg, options| msg == "Smite!" } - @queue.send_message('fooqueue', 'Smite!') + it "should publish it to the queue client instance" do + @client.expects(:publish).with { |queue, msg, options| msg == "Smite!" } + @queue.publish_message('fooqueue', 'Smite!') end - it "should send it to the transformed queue name" do - @client.expects(:send).with { |queue, msg, options| queue == "/queue/fooqueue" } - @queue.send_message('fooqueue', 'Smite!') + it "should publish it to the transformed queue name" do + @client.expects(:publish).with { |queue, msg, options| queue == "/queue/fooqueue" } + @queue.publish_message('fooqueue', 'Smite!') end - it "should send it as a persistent message" do - @client.expects(:send).with { |queue, msg, options| options[:persistent] == true } - @queue.send_message('fooqueue', 'Smite!') + it "should publish it as a persistent message" do + @client.expects(:publish).with { |queue, msg, options| options[:persistent] == true } + @queue.publish_message('fooqueue', 'Smite!') end end |
