From 3df0490c9dbc59e27869e09864177536400a5ae3 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Thu, 5 Aug 2010 11:09:25 -0700 Subject: [#4298] Puppet apply prints an error if the file to apply doesn't exist Also warns you it's skipping files if you pass it more than one file to apply. Reviewed-by: Nick Lewis Signed-off-by: Matt Robinson --- lib/puppet/application/apply.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index bb4186dbd..152b75442 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. -- cgit From 0c3075443c80227c1e35cfb4952d3971c1c0adeb Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 14 Aug 2010 17:31:22 -0700 Subject: Maint. Removing code at the request of the original author A contributor has requested that his changes be removed from puppet. --- lib/puppet/indirector/yaml.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index c7c053f4b..13f3c1e79 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -41,21 +41,12 @@ 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) + base = Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir] File.join(base, self.class.indirection_name.to_s, name.to_s + ".yaml") 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) } - end - private def from_yaml(text) -- cgit From 82b4f04f6b8fee7ada275fc63e519a08e1c2b0a5 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 14 Aug 2010 18:25:24 -0700 Subject: Maint. -- Fix test failures broken by previous commit This basically involved adding a search method to the yaml indirector, which I did by copying the one from ssl_file and fiddling with it until the tests passed. Since the most straight forward way to do this required extending the interface to the path method I added tests for the additional behaviour. --- lib/puppet/indirector/yaml.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb index 13f3c1e79..23997e97a 100644 --- a/lib/puppet/indirector/yaml.rb +++ b/lib/puppet/indirector/yaml.rb @@ -42,9 +42,15 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus end # Return the path to a given node's file. - def path(name) + 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 + ".yaml") + File.join(base, self.class.indirection_name.to_s, name.to_s + ext) + end + + def search(request) + Dir.glob(path(request.key,'')).collect do |file| + YAML.load_file(file) + end end private -- cgit From 20f4b903acd91074778f379631cf7545fdff9eb8 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sun, 15 Aug 2010 18:56:26 -0700 Subject: Fix for #4518 -- classes not getting added to compiler.classes The responsibility for adding classes to the compiler's classes list (for use in constructing classes.txt) moved around a bit in the 0.25 to 2.6 transition before being dropped in a merge conflict resolution. Ooops. This restores it, and adds tests to prevent regression. --- lib/puppet/resource/type.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') 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) -- cgit From d1150e0b91626e4f8843f17c413f88efd4a4ba77 Mon Sep 17 00:00:00 2001 From: Peter Meier Date: Thu, 12 Aug 2010 16:48:22 +0200 Subject: fix #4528 - treat * as absent Internally the cron type is seeing params containing only '*', as absent. However, if a user was setting a parameter explicitely as '*', we weren't munging it to be absent. Hence, we were setting this param over and over again. --- lib/puppet/type/cron.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 -- cgit From 4c280796f71fd2153ae05dfec227fb4123152088 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Tue, 17 Aug 2010 16:19:38 -0700 Subject: [#4555] puppet queue tries to call code it hasn't required puppet queue was trying to call .subscribe on Puppet::Resource::Catalog::Queue, but that object had not been loaded into the ruby interpreter. This bug was partially masked by ruby's confusing constant resolution, which was incorrectly returning the Puppet::Application::Queue class instead of throwing a NameError --- lib/puppet/application/queue.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') 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 -- cgit From 1ea4ccf44bc45ff7ccccc54720391bbe81c8a8fb Mon Sep 17 00:00:00 2001 From: Bernhard Miklautz Date: Fri, 13 Aug 2010 14:55:48 +0200 Subject: Start server before agent --- lib/puppet/daemon.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') 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 -- cgit From 302d657658db068c0c593545e92923659608c5a3 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 21 Aug 2010 14:35:05 -0700 Subject: Fix for #4501 -- reports not generated in standalone The refactors for 2.6.x stopped "puppet apply" from saving reports; this fix adds report saving back to puppet apply but leaves a number of related issues (code path consolidation, report contents, etc.) unresolved for future patches in the 2.6.x series or more significant refactoring in 2.7.x. --- lib/puppet/application/apply.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 152b75442..59a95d35a 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -126,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 -- cgit From 491c31dcbdb0977c0377cb276cfe32a4c24e0e1a Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sun, 22 Aug 2010 10:14:03 -0700 Subject: Fix for #4542 -- included classes weren't assigned proper stages This commit unifies the code paths on which classes are added, alters the default stage to respect the stage of the parent if any, and assures that the resource is notified if its stage is assigned (turning an implicit stage into an explicit one). --- lib/puppet/parser/compiler.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lib') 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 -- cgit From c3185584a0c9f22b7deaff022855b160a945486f Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sat, 21 Aug 2010 19:44:06 -0700 Subject: Fix for #4489 -- apply was using the rest terminus Basing pervasive low-level behaviour changes on the application name isn't a good idea, but if we're going to do it we need to remember to update the test when we rename the application. I am not certain that this change is globally correct; there may be other related problems that will not be fixed (and may in fact be exacerbated) by this patch. --- lib/puppet/file_serving/indirection_hooks.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') 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 -- cgit From 81a27251f9052337ae9e66962a2a1f670e803a50 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Sun, 22 Aug 2010 10:48:40 -0700 Subject: Fix for #4456 -- need to accept some mime-type aliases Rather than just creating a handler for the base mime-type (e.g. "text/yaml") we create some synonyms where appropriate (e.g. "text/x-yaml", "application/yaml", etc.) --- lib/puppet/network/format_handler.rb | 6 ++++++ lib/puppet/network/formats.rb | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lib') 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]) -- cgit