diff options
-rw-r--r-- | CHANGELOG | 18 | ||||
-rwxr-xr-x | ext/puppetlast | 16 | ||||
-rw-r--r-- | ext/rack/files/config.ru | 3 | ||||
-rw-r--r-- | lib/puppet/application/apply.rb | 20 | ||||
-rw-r--r-- | lib/puppet/application/queue.rb | 1 | ||||
-rwxr-xr-x | lib/puppet/daemon.rb | 2 | ||||
-rw-r--r-- | lib/puppet/file_serving/indirection_hooks.rb | 4 | ||||
-rw-r--r-- | lib/puppet/indirector/yaml.rb | 15 | ||||
-rw-r--r-- | lib/puppet/network/format_handler.rb | 6 | ||||
-rw-r--r-- | lib/puppet/network/formats.rb | 8 | ||||
-rw-r--r-- | lib/puppet/parser/compiler.rb | 19 | ||||
-rw-r--r-- | lib/puppet/resource/type.rb | 1 | ||||
-rwxr-xr-x | lib/puppet/type/cron.rb | 2 | ||||
-rw-r--r-- | spec/shared_behaviours/file_serving.rb | 13 | ||||
-rwxr-xr-x | spec/unit/application/apply_spec.rb | 24 | ||||
-rwxr-xr-x | spec/unit/application/doc_spec.rb | 19 | ||||
-rwxr-xr-x | spec/unit/indirector/yaml_spec.rb | 24 | ||||
-rwxr-xr-x | spec/unit/parser/compiler_spec.rb | 13 | ||||
-rwxr-xr-x | spec/unit/resource/type_spec.rb | 17 |
19 files changed, 141 insertions, 84 deletions
@@ -1,5 +1,23 @@ +2.6.1rc3 +======== +81a2725 Fix for #4456 -- need to accept some mime-type aliases +c318558 Fix for #4489 -- apply was using the rest terminus +491c31d Fix for #4542 -- included classes weren't assigned proper stages +302d657 Fix for #4501 -- reports not generated in standalone +1ea4ccf Start server before agent +4c28079 [#4555] puppet queue tries to call code it hasn't required +d1150e0 fix #4528 - treat * as absent +20f4b90 Fix for #4518 -- classes not getting added to compiler.classes +57bb06b [#4545] Remove obsolete 'trac' specs +82b4f04 Maint. -- Fix test failures broken by previous commit +0c30754 Maint. Removing code at the request of the original author +3df0490 [#4298] Puppet apply prints an error if the file to apply doesn't exist +5d4f222 Fixed #4527 correctly for 2.6.1 +1b3d782 Updated config.ru example for 2.6.1 + 2.6.1rc2 ======== +0aa27b5 Updated for 2.6.1rc2 252c9b8 Further RST to Markdown fixes for types, values, tests 1157e8d Updated all types to Markdown output fef8800 Updated reference output to generate valid Markdown diff --git a/ext/puppetlast b/ext/puppetlast deleted file mode 100755 index 7434368a3..000000000 --- a/ext/puppetlast +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ruby -# Puppetlast, a script to output the last check-in time of nodes. Also outputs the cached configuration state, if expired or not. -# -# AJ "Fujin" Christensen <aj@junglist.gen.nz> -# -require 'puppet' -require 'time' - -Puppet[:config] = "/etc/puppet/puppet.conf" -Puppet.parse_config -Puppet[:name] = "puppetmasterd" -Puppet::Node::Facts.terminus_class = :yaml - -Puppet::Node::Facts.search("*").sort { |a,b| a.name <=> b.name }.each do |node| - puts "#{node.name} checked in #{((Time.now - Time.parse(node.values[:_timestamp].to_s)) / 60).floor} minutes ago. Version #{node.values['puppetversion']}#{node.expired? ? ' Cache expired.' : ''}" -end diff --git a/ext/rack/files/config.ru b/ext/rack/files/config.ru index 995a9f8c5..f9c492dd7 100644 --- a/ext/rack/files/config.ru +++ b/ext/rack/files/config.ru @@ -4,8 +4,7 @@ # if puppet is not in your RUBYLIB: # $:.unshift('/opt/puppet/lib') -$0 = "puppetmasterd" -require 'puppet' +$0 = "master" # if you want debugging: # ARGV << "--debug" diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index bb4186dbd..59a95d35a 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -78,7 +78,10 @@ class Puppet::Application::Apply < Puppet::Application if options[:code] or command_line.args.length == 0 Puppet[:code] = options[:code] || STDIN.read else - Puppet[:manifest] = command_line.args.shift + manifest = command_line.args.shift + raise "Could not find file #{manifest}" unless File.exist?(manifest) + Puppet.warning("Only one file can be applied per run. Skipping #{command_line.args.join(', ')}") if command_line.args.size > 0 + Puppet[:manifest] = manifest end # Collect our facts. @@ -123,17 +126,22 @@ class Puppet::Application::Apply < Puppet::Application configurer.execute_prerun_command # And apply it + if Puppet[:report] + report = configurer.initialize_report + Puppet::Util::Log.newdestination(report) + end transaction = catalog.apply configurer.execute_postrun_command - status = 0 - if not Puppet[:noop] and options[:detailed_exitcodes] - transaction.generate_report - exit(transaction.report.exit_status) + if Puppet[:report] + Puppet::Util::Log.close(report) + configurer.send_report(report, transaction) else - exit(0) + transaction.generate_report end + + exit( Puppet[:noop] ? 0 : options[:detailed_exitcodes] ? transaction.report.exit_status : 0 ) rescue => detail puts detail.backtrace if Puppet[:trace] $stderr.puts detail.message diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb index 6df825dd1..6c90ca0a1 100644 --- a/lib/puppet/application/queue.rb +++ b/lib/puppet/application/queue.rb @@ -38,6 +38,7 @@ class Puppet::Application::Queue < Puppet::Application option("--verbose","-v") def main + require 'lib/puppet/indirector/catalog/queue' # provides Puppet::Indirector::Queue.subscribe Puppet.notice "Starting puppetqd #{Puppet.version}" Puppet::Resource::Catalog::Queue.subscribe do |catalog| # Once you have a Puppet::Resource::Catalog instance, calling save on it should suffice diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb index aa4a12bfa..ad0edd3b9 100755 --- a/lib/puppet/daemon.rb +++ b/lib/puppet/daemon.rb @@ -121,8 +121,8 @@ class Puppet::Daemon create_pidfile raise Puppet::DevError, "Daemons must have an agent, server, or both" unless agent or server - agent.start if agent server.start if server + agent.start if agent EventLoop.current.run end diff --git a/lib/puppet/file_serving/indirection_hooks.rb b/lib/puppet/file_serving/indirection_hooks.rb index 7e0c17916..a85e90ef1 100644 --- a/lib/puppet/file_serving/indirection_hooks.rb +++ b/lib/puppet/file_serving/indirection_hooks.rb @@ -19,8 +19,8 @@ module Puppet::FileServing::IndirectionHooks return PROTOCOL_MAP["file"] if request.key =~ /^#{::File::SEPARATOR}/ return PROTOCOL_MAP["file"] if request.protocol == "file" - # We're heading over the wire the protocol is 'puppet' and we've got a server name or we're not named 'puppet' - if request.protocol == "puppet" and (request.server or Puppet.settings[:name] != "puppet") + # We're heading over the wire the protocol is 'puppet' and we've got a server name or we're not named 'apply' or 'puppet' + if request.protocol == "puppet" and (request.server or !["puppet","apply"].include?(Puppet.settings[:name])) return PROTOCOL_MAP["puppet"] end diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index c7c053f4b..23997e97a 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -41,19 +41,16 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus end end - # Get the yaml directory - def base - Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir] - end - # Return the path to a given node's file. - def path(name) - File.join(base, self.class.indirection_name.to_s, name.to_s + ".yaml") + def path(name,ext='.yaml') + base = Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir] + File.join(base, self.class.indirection_name.to_s, name.to_s + ext) end - # Do a glob on the yaml directory, loading each file found def search(request) - Dir.glob(File.join(base, self.class.indirection_name.to_s, request.key)).collect { |f| YAML.load_file(f) } + Dir.glob(path(request.key,'')).collect do |file| + YAML.load_file(file) + end end private diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb index d378ad6a1..b94a4f902 100644 --- a/lib/puppet/network/format_handler.rb +++ b/lib/puppet/network/format_handler.rb @@ -37,6 +37,12 @@ module Puppet::Network::FormatHandler instance end + def self.create_serialized_formats(name,options = {},&block) + ["application/x-#{name}", "application/#{name}", "text/x-#{name}", "text/#{name}"].each { |mime_type| + create name, {:mime => mime_type}.update(options), &block + } + end + def self.extended(klass) klass.extend(ClassMethods) diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb index 8a61ee62a..4ca3240d4 100644 --- a/lib/puppet/network/formats.rb +++ b/lib/puppet/network/formats.rb @@ -1,6 +1,6 @@ require 'puppet/network/format_handler' -Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml") do +Puppet::Network::FormatHandler.create_serialized_formats(:yaml) do # Yaml doesn't need the class name; it's serialized. def intern(klass, text) YAML.load(text) @@ -29,7 +29,7 @@ end # This is a "special" format which is used for the moment only when sending facts # as REST GET parameters (see Puppet::Configurer::FactHandler). # This format combines a yaml serialization, then zlib compression and base64 encoding. -Puppet::Network::FormatHandler.create(:b64_zlib_yaml, :mime => "text/b64_zlib_yaml") do +Puppet::Network::FormatHandler.create_serialized_formats(:b64_zlib_yaml) do require 'base64' def use_zlib? @@ -127,7 +127,7 @@ Puppet::Network::FormatHandler.create(:raw, :mime => "application/x-raw", :weigh end end -Puppet::Network::FormatHandler.create(:pson, :mime => "text/pson", :weight => 10, :required_methods => [:render_method, :intern_method]) do +Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, :required_methods => [:render_method, :intern_method]) do confine :true => Puppet.features.pson? def intern(klass, text) @@ -159,4 +159,4 @@ Puppet::Network::FormatHandler.create(:pson, :mime => "text/pson", :weight => 10 end # This is really only ever going to be used for Catalogs. -Puppet::Network::FormatHandler.create(:dot, :mime => "text/dot", :required_methods => [:render_method]) +Puppet::Network::FormatHandler.create_serialized_formats(:dot, :required_methods => [:render_method]) diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 98cad952c..7504b276b 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -56,13 +56,10 @@ class Puppet::Parser::Compiler # Note that this will fail if the resource is not unique. @catalog.add_resource(resource) - set_container_resource(scope, resource) - 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. - def set_container_resource(scope, resource) + # 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. return if resource.type.to_s.downcase == "stage" if resource.type.to_s.downcase != "class" @@ -70,15 +67,14 @@ class Puppet::Parser::Compiler return @catalog.add_edge(scope.resource, resource) end - unless stage = @catalog.resource(:stage, resource[:stage] || :main) + 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 @catalog.add_edge(stage, resource) end - private :set_container_resource - # Do we use nodes found in the code, vs. the external node sources? def ast_nodes? known_resource_types.nodes? @@ -289,10 +285,7 @@ class Puppet::Parser::Compiler @main_resource = Puppet::Parser::Resource.new("class", :main, :scope => @topscope, :source => @main) @topscope.resource = @main_resource - @resources << @main_resource - @catalog.add_resource(@main_resource) - - set_container_resource(@topscope, @main_resource) + add_resource(@topscope, @main_resource) @main_resource.evaluate end diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 6296d26e5..f6d378512 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -69,6 +69,7 @@ class Puppet::Resource::Type end scope = subscope(scope, resource) unless resource.title == :main + scope.compiler.add_class(name) unless definition? set_resource_parameters(resource, scope) diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 9d827df78..c42f0df55 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -169,7 +169,7 @@ Puppet::Type.newtype(:cron) do end if value == "*" - return value + return :absent end return value unless self.class.boundaries diff --git a/spec/shared_behaviours/file_serving.rb b/spec/shared_behaviours/file_serving.rb index c86453a03..5f5b2b0af 100644 --- a/spec/shared_behaviours/file_serving.rb +++ b/spec/shared_behaviours/file_serving.rb @@ -15,7 +15,7 @@ describe "Puppet::FileServing::Files", :shared => true do @test_class.find(uri) end - it "should use the rest terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is not 'puppet'" do + it "should use the rest terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is not 'puppet' or 'apply'" do uri = "puppet:///fakemod/my/file" Puppet.settings.stubs(:value).returns "foo" Puppet.settings.stubs(:value).with(:name).returns("puppetd") @@ -35,6 +35,17 @@ describe "Puppet::FileServing::Files", :shared => true do @test_class.find(uri) end + it "should use the file_server terminus when the 'puppet' URI scheme is used, no host name is present, and the process name is 'apply'" do + uri = "puppet:///fakemod/my/file" + Puppet::Node::Environment.stubs(:new).returns(stub("env", :name => "testing", :module => nil, :modulepath => [])) + Puppet.settings.stubs(:value).returns "" + Puppet.settings.stubs(:value).with(:name).returns("apply") + Puppet.settings.stubs(:value).with(:fileserverconfig).returns("/whatever") + @indirection.terminus(:file_server).expects(:find) + @indirection.terminus(:file_server).stubs(:authorized?).returns(true) + @test_class.find(uri) + end + it "should use the file terminus when the 'file' URI scheme is used" do uri = "file:///fakemod/my/file" @indirection.terminus(:file).expects(:find) diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb index 0b00d1a2e..8c53136d0 100755 --- a/spec/unit/application/apply_spec.rb +++ b/spec/unit/application/apply_spec.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/application/apply' +require 'puppet/file_bucket/dipper' describe Puppet::Application::Apply do before :each do @@ -53,7 +54,6 @@ describe Puppet::Application::Apply do Puppet.stubs(:trap) Puppet::Log.stubs(:level=) Puppet.stubs(:parse_config) - require 'lib/puppet/file_bucket/dipper' Puppet::FileBucket::Dipper.stubs(:new) STDIN.stubs(:read) @@ -212,7 +212,8 @@ describe Puppet::Application::Apply do @apply.main end - it "should set the manifest if some files are passed on command line" do + it "should set the manifest if a file is passed on command line and the file exists" do + File.stubs(:exist?).with('site.pp').returns true @apply.command_line.stubs(:args).returns(['site.pp']) Puppet.expects(:[]=).with(:manifest,"site.pp") @@ -220,6 +221,23 @@ describe Puppet::Application::Apply do @apply.main end + it "should raise an error if a file is passed on command line and the file does not exist" do + File.stubs(:exist?).with('noexist.pp').returns false + @apply.command_line.stubs(:args).returns(['noexist.pp']) + lambda { @apply.main }.should raise_error(RuntimeError, 'Could not find file noexist.pp') + end + + it "should set the manifest to the first file and warn other files will be skipped" do + File.stubs(:exist?).with('starwarsIV').returns true + File.expects(:exist?).with('starwarsI').never + @apply.command_line.stubs(:args).returns(['starwarsIV', 'starwarsI', 'starwarsII']) + + Puppet.expects(:[]=).with(:manifest,"starwarsIV") + Puppet.expects(:warning).with('Only one file can be applied per run. Skipping starwarsI, starwarsII') + + @apply.main + end + it "should collect the node facts" do Puppet::Node::Facts.expects(:find).returns(@facts) @@ -232,7 +250,7 @@ describe Puppet::Application::Apply do lambda { @apply.main }.should raise_error end - it "should find the node" do + it "should look for the node" do Puppet::Node.expects(:find).returns(@node) @apply.main diff --git a/spec/unit/application/doc_spec.rb b/spec/unit/application/doc_spec.rb index 7a22f5b2e..55da5e39a 100755 --- a/spec/unit/application/doc_spec.rb +++ b/spec/unit/application/doc_spec.rb @@ -27,10 +27,6 @@ describe Puppet::Application::Doc do @doc.should respond_to(:rdoc) end - it "should declare a trac command" do - @doc.should respond_to(:trac) - end - it "should declare a fallback for unknown options" do @doc.should respond_to(:handle_unknown) end @@ -270,21 +266,6 @@ describe Puppet::Application::Doc do end describe "when running" do - before :each do - end - - describe "in trac mode" do - it "should call trac for each reference" do - ref = stub 'ref' - Puppet::Util::Reference.stubs(:reference).with(:ref).returns(ref) - @doc.options.stubs(:[]).with(:references).returns([:ref]) - @doc.options.stubs(:[]).with(:mode).returns(:trac) - - ref.expects(:trac) - - @doc.trac - end - end describe "in rdoc mode" do before :each do diff --git a/spec/unit/indirector/yaml_spec.rb b/spec/unit/indirector/yaml_spec.rb index 134d476ba..86c13c5a0 100755 --- a/spec/unit/indirector/yaml_spec.rb +++ b/spec/unit/indirector/yaml_spec.rb @@ -40,6 +40,18 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do @store.path(:me).should =~ %r{^/client/yaml/dir} end + it "should use the extension if one is specified" do + Puppet.run_mode.expects(:master?).returns true + Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" + @store.path(:me,'.farfignewton').should =~ %r{\.farfignewton$} + end + + it "should assume an extension of .yaml if none is specified" do + Puppet.run_mode.expects(:master?).returns true + Puppet.settings.expects(:value).with(:yamldir).returns "/server/yaml/dir" + @store.path(:me).should =~ %r{\.yaml$} + end + it "should store all files in a single file root set in the Puppet defaults" do @store.path(:me).should =~ %r{^#{@dir}} end @@ -120,8 +132,8 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do @request = stub 'request', :key => "*", :instance => @subject @one = mock 'one' @two = mock 'two' - @store.expects(:base).returns "/my/yaml/dir" - Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml two.yaml}) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns(%w{one.yaml two.yaml}) YAML.expects(:load_file).with("one.yaml").returns @one; YAML.expects(:load_file).with("two.yaml").returns @two; @store.search(@request).should == [@one, @two] @@ -130,16 +142,16 @@ describe Puppet::Indirector::Yaml, " when choosing file location" do it "should return an array containing a single instance of fact when globbing 'one*'" do @request = stub 'request', :key => "one*", :instance => @subject @one = mock 'one' - @store.expects(:base).returns "/my/yaml/dir" - Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns(%w{one.yaml}) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns(%w{one.yaml}) YAML.expects(:load_file).with("one.yaml").returns @one; @store.search(@request).should == [@one] end it "should return an empty array when the glob doesn't match anything" do @request = stub 'request', :key => "f*ilglobcanfail*", :instance => @subject - @store.expects(:base).returns "/my/yaml/dir" - Dir.expects(:glob).with(File.join("/my/yaml/dir", @store.class.indirection_name.to_s, @request.key)).returns([]) + @store.expects(:path).with(@request.key,'').returns :glob + Dir.expects(:glob).with(:glob).returns [] @store.search(@request).should == [] end end diff --git a/spec/unit/parser/compiler_spec.rb b/spec/unit/parser/compiler_spec.rb index e8c06dd0b..22d52f257 100755 --- a/spec/unit/parser/compiler_spec.rb +++ b/spec/unit/parser/compiler_spec.rb @@ -430,7 +430,18 @@ describe Puppet::Parser::Compiler do lambda { @compiler.add_resource(@scope, resource) }.should raise_error(ArgumentError) end - it "should add edges from the class resources to the main stage if no stage is specified" do + 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) diff --git a/spec/unit/resource/type_spec.rb b/spec/unit/resource/type_spec.rb index 4d3942c5c..f58092ec5 100755 --- a/spec/unit/resource/type_spec.rb +++ b/spec/unit/resource/type_spec.rb @@ -412,6 +412,23 @@ describe Puppet::Resource::Type do @type = Puppet::Resource::Type.new(:hostclass, "foo") end + it "should add hostclass names to the classes list" do + @type.evaluate_code(@resource) + @compiler.catalog.classes.should be_include("foo") + end + + it "should add node names to the classes list" do + @type = Puppet::Resource::Type.new(:node, "foo") + @type.evaluate_code(@resource) + @compiler.catalog.classes.should be_include("foo") + end + + it "should not add defined resource names to the classes list" do + @type = Puppet::Resource::Type.new(:definition, "foo") + @type.evaluate_code(@resource) + @compiler.catalog.classes.should_not be_include("foo") + end + it "should set all of its parameters in a subscope" do subscope = stub 'subscope', :compiler => @compiler @type.expects(:subscope).with(@scope, @resource).returns subscope |