From c5a1ca0b34a57366415df60099ab0918a7579469 Mon Sep 17 00:00:00 2001 From: Derek Olsen Date: Wed, 24 Nov 2010 11:11:43 -0800 Subject: (#5391) Include additional zfs properties We added the following zfs properties to the zfs provider :recordsize, :aclmode, :aclinherit, :primarycache, :secondarycache Currently zfs users have to chain an exec to the zfs filesystem creation and the inclusion of these properties would allow puppet to set them natively. --- lib/puppet/provider/zfs/solaris.rb | 2 +- lib/puppet/type/zfs.rb | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/zfs/solaris.rb b/lib/puppet/provider/zfs/solaris.rb index 85d054f86..9aec9d801 100644 --- a/lib/puppet/provider/zfs/solaris.rb +++ b/lib/puppet/provider/zfs/solaris.rb @@ -31,7 +31,7 @@ Puppet::Type.type(:zfs).provide(:solaris) do end end - [:mountpoint, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir].each do |field| + [:mountpoint, :recordsize, :aclmode, :aclinherit, :primarycache, :secondarycache, :compression, :copies, :quota, :reservation, :sharenfs, :snapdir].each do |field| define_method(field) do zfs(:get, "-H", "-o", "value", field, @resource[:name]).strip end diff --git a/lib/puppet/type/zfs.rb b/lib/puppet/type/zfs.rb index e1a972ddf..be18ab5aa 100755 --- a/lib/puppet/type/zfs.rb +++ b/lib/puppet/type/zfs.rb @@ -12,6 +12,26 @@ module Puppet desc "The mountpoint property." end + newproperty(:recordsize) do + desc "The recordsize property." + end + + newproperty(:aclmode) do + desc "The aclmode property." + end + + newproperty(:aclinherit) do + desc "The aclinherit property." + end + + newproperty(:primarycache) do + desc "The primarycache property." + end + + newproperty(:secondarycache) do + desc "The secondarycache property." + end + newproperty(:compression) do desc "The compression property." end @@ -33,7 +53,7 @@ module Puppet end newproperty(:snapdir) do - desc "The sharenfs property." + desc "The snapdir property." end autorequire(:zpool) do @@ -48,4 +68,3 @@ module Puppet end end end - -- cgit From 0f00bf45872412605a497b3929df0bbb0fa7dd67 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 24 Nov 2010 12:22:34 -0800 Subject: Maint: Removed unused monkey patch that connected OpenSSL::PKey::RSA to indirector This file was never being required, and was inconsistent with the way SSL is used in the indirector. Paired-with: Jesse Wolfe --- lib/puppet/sslcertificates/monkey_patch.rb | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 lib/puppet/sslcertificates/monkey_patch.rb (limited to 'lib/puppet') diff --git a/lib/puppet/sslcertificates/monkey_patch.rb b/lib/puppet/sslcertificates/monkey_patch.rb deleted file mode 100644 index 663b944c1..000000000 --- a/lib/puppet/sslcertificates/monkey_patch.rb +++ /dev/null @@ -1,6 +0,0 @@ -# This is the file that we use to add indirection to all the SSL Certificate classes. - -require 'puppet/indirector' - -OpenSSL::PKey::RSA.extend Puppet::Indirector -OpenSSL::PKey::RSA.indirects :ssl_rsa, :terminus_class => :file -- cgit From 83f878e2304595f803e105abb9b5e77d7ce3272a Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 29 Nov 2010 18:37:44 +1100 Subject: Renamed Reductive to Puppet I swear I've done this before. *confused* --- lib/puppet/util/command_line/filebucket | 2 +- lib/puppet/util/command_line/pi | 2 +- lib/puppet/util/command_line/puppet | 2 +- lib/puppet/util/command_line/puppetca | 2 +- lib/puppet/util/command_line/puppetd | 2 +- lib/puppet/util/command_line/puppetdoc | 4 ++-- lib/puppet/util/command_line/puppetmasterd | 2 +- lib/puppet/util/command_line/puppetqd | 2 +- lib/puppet/util/command_line/puppetrun | 2 +- lib/puppet/util/command_line/ralsh | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/command_line/filebucket b/lib/puppet/util/command_line/filebucket index 8302d7b12..34b01508e 100755 --- a/lib/puppet/util/command_line/filebucket +++ b/lib/puppet/util/command_line/filebucket @@ -91,7 +91,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:filebucket].run diff --git a/lib/puppet/util/command_line/pi b/lib/puppet/util/command_line/pi index ae3c46e9a..3d80eea8f 100755 --- a/lib/puppet/util/command_line/pi +++ b/lib/puppet/util/command_line/pi @@ -42,7 +42,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:describe].run diff --git a/lib/puppet/util/command_line/puppet b/lib/puppet/util/command_line/puppet index 7b6c0ae7f..e75b92af8 100755 --- a/lib/puppet/util/command_line/puppet +++ b/lib/puppet/util/command_line/puppet @@ -63,7 +63,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:apply].run diff --git a/lib/puppet/util/command_line/puppetca b/lib/puppet/util/command_line/puppetca index 4f1a88da5..9aa7e907c 100755 --- a/lib/puppet/util/command_line/puppetca +++ b/lib/puppet/util/command_line/puppetca @@ -104,7 +104,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:cert].run diff --git a/lib/puppet/util/command_line/puppetd b/lib/puppet/util/command_line/puppetd index 571b15486..cb8589c5f 100755 --- a/lib/puppet/util/command_line/puppetd +++ b/lib/puppet/util/command_line/puppetd @@ -180,7 +180,7 @@ # # = Copyright # -# Copyright (c) 2005, 2006 Reductive Labs, LLC +# Copyright (c) 2005, 2006 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:agent].run diff --git a/lib/puppet/util/command_line/puppetdoc b/lib/puppet/util/command_line/puppetdoc index 0fa1830d6..8f24ea5ef 100755 --- a/lib/puppet/util/command_line/puppetdoc +++ b/lib/puppet/util/command_line/puppetdoc @@ -3,7 +3,7 @@ # # = Synopsis # -# Generate a reference for all Puppet types. Largely meant for internal Reductive +# Generate a reference for all Puppet types. Largely meant for internal Puppet # Labs use. # # = Usage @@ -61,7 +61,7 @@ # # = Copyright # -# Copyright (c) 2005-2007 Reductive Labs, LLC +# Copyright (c) 2005-2007 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:doc].run diff --git a/lib/puppet/util/command_line/puppetmasterd b/lib/puppet/util/command_line/puppetmasterd index 74efb3818..baf8a7581 100755 --- a/lib/puppet/util/command_line/puppetmasterd +++ b/lib/puppet/util/command_line/puppetmasterd @@ -59,7 +59,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:master].run diff --git a/lib/puppet/util/command_line/puppetqd b/lib/puppet/util/command_line/puppetqd index 48fc952bd..81963d537 100755 --- a/lib/puppet/util/command_line/puppetqd +++ b/lib/puppet/util/command_line/puppetqd @@ -47,7 +47,7 @@ # # = Copyright # -# Copyright (c) 2009 Reductive Labs, LLC +# Copyright (c) 2009 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:queue].run diff --git a/lib/puppet/util/command_line/puppetrun b/lib/puppet/util/command_line/puppetrun index 27cd775b9..7eba3b2c4 100755 --- a/lib/puppet/util/command_line/puppetrun +++ b/lib/puppet/util/command_line/puppetrun @@ -120,7 +120,7 @@ # # = Copyright # -# Copyright (c) 2005 Reductive Labs, LLC +# Copyright (c) 2005 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:kick].run diff --git a/lib/puppet/util/command_line/ralsh b/lib/puppet/util/command_line/ralsh index 83338fcbc..5c1f719e2 100755 --- a/lib/puppet/util/command_line/ralsh +++ b/lib/puppet/util/command_line/ralsh @@ -83,7 +83,7 @@ # # = Copyright # -# Copyright (c) 2005-2007 Reductive Labs, LLC +# Copyright (c) 2005-2007 Puppet Labs, LLC # Licensed under the GNU Public License #Puppet::Application[:resource].run -- cgit From 71ecad9904c8c48c023e90e5fbea5b26b180c9cf Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 29 Nov 2010 11:56:40 -0800 Subject: Maint: Refactor code to use .indirection. Replaced uses of the find, search, destroy, and expire methods on model classes with direct calls to the indirection objects. Also removed the old methods that delegated to the indirection object. --- lib/puppet/application/agent.rb | 7 +++-- lib/puppet/application/apply.rb | 8 +++--- lib/puppet/application/kick.rb | 4 +-- lib/puppet/application/master.rb | 4 +-- lib/puppet/application/queue.rb | 4 +-- lib/puppet/application/resource.rb | 4 +-- lib/puppet/configurer.rb | 4 +-- lib/puppet/configurer/fact_handler.rb | 2 +- lib/puppet/defaults.rb | 10 +++---- lib/puppet/file_bucket/dipper.rb | 2 +- lib/puppet/indirector.rb | 25 ------------------ lib/puppet/indirector/catalog/active_record.rb | 2 +- lib/puppet/indirector/catalog/compiler.rb | 2 +- lib/puppet/network/handler/filebucket.rb | 2 +- lib/puppet/network/handler/fileserver.rb | 2 +- lib/puppet/network/handler/master.rb | 2 +- lib/puppet/network/http/webrick.rb | 2 +- lib/puppet/node.rb | 2 +- lib/puppet/node/facts.rb | 2 +- lib/puppet/ssl/certificate_authority.rb | 22 ++++++++-------- lib/puppet/ssl/host.rb | 36 +++++++++++++------------- lib/puppet/ssl/inventory.rb | 2 +- lib/puppet/type/file.rb | 2 +- lib/puppet/type/file/source.rb | 4 +-- 24 files changed, 65 insertions(+), 91 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb index c5ad72068..96f33296f 100644 --- a/lib/puppet/application/agent.rb +++ b/lib/puppet/application/agent.rb @@ -228,9 +228,9 @@ class Puppet::Application::Agent < Puppet::Application # access to the local files and we don't need a ca. Puppet::SSL::Host.ca_location = options[:fingerprint] ? :none : :remote - Puppet::Transaction::Report.terminus_class = :rest + Puppet::Transaction::Report.indirection.terminus_class = :rest # we want the last report to be persisted locally - Puppet::Transaction::Report.cache_class = :yaml + Puppet::Transaction::Report.indirection.cache_class = :yaml # Override the default; puppetd needs this, usually. # You can still override this on the command-line with, e.g., :compiler. @@ -239,8 +239,7 @@ class Puppet::Application::Agent < Puppet::Application # Override the default. Puppet[:facts_terminus] = :facter - Puppet::Resource::Catalog.cache_class = :yaml - + Puppet::Resource::Catalog.indirection.cache_class = :yaml # We need tomake the client either way, we just don't start it # if --no-client is set. diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 8ec3fab6b..e5b4bb5b7 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -85,12 +85,12 @@ class Puppet::Application::Apply < Puppet::Application end # Collect our facts. - unless facts = Puppet::Node::Facts.find(Puppet[:certname]) + unless facts = Puppet::Node::Facts.indirection.find(Puppet[:certname]) raise "Could not find facts for #{Puppet[:certname]}" end # Find our Node - unless node = Puppet::Node.find(Puppet[:certname]) + unless node = Puppet::Node.indirection.find(Puppet[:certname]) raise "Could not find node #{Puppet[:certname]}" end @@ -112,7 +112,7 @@ class Puppet::Application::Apply < Puppet::Application begin # Compile our catalog starttime = Time.now - catalog = Puppet::Resource::Catalog.find(node.name, :use_node => node) + catalog = Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node) # Translate it to a RAL catalog catalog = catalog.to_ral @@ -149,7 +149,7 @@ class Puppet::Application::Apply < Puppet::Application end # we want the last report to be persisted locally - Puppet::Transaction::Report.cache_class = :yaml + Puppet::Transaction::Report.indirection.cache_class = :yaml if options[:debug] Puppet::Util::Log.level = :debug diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb index 37aeb1ef2..c6c6fd782 100644 --- a/lib/puppet/application/kick.rb +++ b/lib/puppet/application/kick.rb @@ -175,12 +175,12 @@ class Puppet::Application::Kick < Puppet::Application if Puppet[:node_terminus] == "ldap" and (options[:all] or @classes) if options[:all] - @hosts = Puppet::Node.search("whatever", :fqdn => options[:fqdn]).collect { |node| node.name } + @hosts = Puppet::Node.indirection.search("whatever", :fqdn => options[:fqdn]).collect { |node| node.name } puts "all: #{@hosts.join(", ")}" else @hosts = [] @classes.each do |klass| - list = Puppet::Node.search("whatever", :fqdn => options[:fqdn], :class => klass).collect { |node| node.name } + list = Puppet::Node.indirection.search("whatever", :fqdn => options[:fqdn], :class => klass).collect { |node| node.name } puts "#{klass}: #{list.join(", ")}" @hosts += list diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb index fde474907..879b66c67 100644 --- a/lib/puppet/application/master.rb +++ b/lib/puppet/application/master.rb @@ -51,7 +51,7 @@ class Puppet::Application::Master < Puppet::Application Puppet::Util::Log.newdestination :console raise ArgumentError, "Cannot render compiled catalogs without pson support" unless Puppet.features.pson? begin - unless catalog = Puppet::Resource::Catalog.find(options[:node]) + unless catalog = Puppet::Resource::Catalog.indirection.find(options[:node]) raise "Could not compile catalog for #{options[:node]}" end @@ -139,7 +139,7 @@ class Puppet::Application::Master < Puppet::Application Puppet.settings.use :main, :master, :ssl # Cache our nodes in yaml. Currently not configurable. - Puppet::Node.cache_class = :yaml + Puppet::Node.indirection.cache_class = :yaml # Configure all of the SSL stuff. if Puppet::SSL::CertificateAuthority.ca? diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb index 239f6b2ad..c7e0ce8cc 100644 --- a/lib/puppet/application/queue.rb +++ b/lib/puppet/application/queue.rb @@ -79,7 +79,7 @@ class Puppet::Application::Queue < Puppet::Application exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs? require 'puppet/resource/catalog' - Puppet::Resource::Catalog.terminus_class = :active_record + Puppet::Resource::Catalog.indirection.terminus_class = :active_record daemon.daemonize if Puppet[:daemonize] @@ -87,6 +87,6 @@ class Puppet::Application::Queue < Puppet::Application # class set up, because if storeconfigs is enabled, # we'll get a loop of continually caching the catalog # for storage again. - Puppet::Resource::Catalog.cache_class = nil + Puppet::Resource::Catalog.indirection.cache_class = nil end end diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index f55caa58a..3a7fdcc37 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -76,12 +76,12 @@ class Puppet::Application::Resource < Puppet::Application text = if name if params.empty? - [ Puppet::Resource.find( key ) ] + [ Puppet::Resource.indirection.find( key ) ] else [ Puppet::Resource.new( type, name, :parameters => params ).save( key ) ] end else - Puppet::Resource.search( key, {} ) + Puppet::Resource.indirection.search( key, {} ) end.map(&format).join("\n") if options[:edit] diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 1c0639029..77a9065df 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -224,7 +224,7 @@ class Puppet::Configurer def retrieve_catalog_from_cache(fact_options) result = nil @duration = thinmark do - result = Puppet::Resource::Catalog.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true)) + result = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true)) end Puppet.notice "Using cached catalog" result @@ -237,7 +237,7 @@ class Puppet::Configurer def retrieve_new_catalog(fact_options) result = nil @duration = thinmark do - result = Puppet::Resource::Catalog.find(Puppet[:certname], fact_options.merge(:ignore_cache => true)) + result = Puppet::Resource::Catalog.indirection.find(Puppet[:certname], fact_options.merge(:ignore_cache => true)) end result rescue SystemExit,NoMemoryError diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb index 075a59458..abe032010 100644 --- a/lib/puppet/configurer/fact_handler.rb +++ b/lib/puppet/configurer/fact_handler.rb @@ -16,7 +16,7 @@ module Puppet::Configurer::FactHandler # compile them and then "cache" them on the server. begin reload_facter - Puppet::Node::Facts.find(Puppet[:certname]) + Puppet::Node::Facts.indirection.find(Puppet[:certname]) rescue SystemExit,NoMemoryError raise rescue Exception => detail diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 8bf1cd84d..1e7229d01 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -121,7 +121,7 @@ module Puppet :hook => proc do |value| require 'puppet/node/facts' if value.to_s == "rest" - Puppet::Node::Facts.cache_class = :yaml + Puppet::Node::Facts.indirection.cache_class = :yaml end end }, @@ -152,7 +152,7 @@ module Puppet Puppet.settings[:storeconfigs] = true # But then we modify the configuration - Puppet::Resource::Catalog.cache_class = :queue + Puppet::Resource::Catalog.indirection.cache_class = :queue else raise "Cannot disable asynchronous storeconfigs in a running process" end @@ -794,9 +794,9 @@ module Puppet if value require 'puppet/rails' raise "StoreConfigs not supported without ActiveRecord 2.1 or higher" unless Puppet.features.rails? - Puppet::Resource::Catalog.cache_class = :active_record unless Puppet.settings[:async_storeconfigs] - Puppet::Node::Facts.cache_class = :active_record - Puppet::Node.cache_class = :active_record + Puppet::Resource::Catalog.indirection.cache_class = :active_record unless Puppet.settings[:async_storeconfigs] + Puppet::Node::Facts.indirection.cache_class = :active_record + Puppet::Node.indirection.cache_class = :active_record end end } diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index dbfcdcd43..8d6938930 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -47,7 +47,7 @@ class Puppet::FileBucket::Dipper # Retrieve a file by sum. def getfile(sum) source_path = "#{@rest_path}md5/#{sum}" - file_bucket_file = Puppet::FileBucket::File.find(source_path, :bucket_path => @local_path) + file_bucket_file = Puppet::FileBucket::File.indirection.find(source_path, :bucket_path => @local_path) raise Puppet::Error, "File not found" unless file_bucket_file file_bucket_file.to_s diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index 5b737578b..b0cabab8a 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -32,31 +32,6 @@ module Puppet::Indirector module ClassMethods attr_reader :indirection - - def cache_class=(klass) - indirection.cache_class = klass - end - - def terminus_class=(klass) - indirection.terminus_class = klass - end - - # Expire any cached instance. - def expire(*args) - indirection.expire(*args) - end - - def find(*args) - indirection.find(*args) - end - - def destroy(*args) - indirection.destroy(*args) - end - - def search(*args) - indirection.search(*args) - end end module InstanceMethods diff --git a/lib/puppet/indirector/catalog/active_record.rb b/lib/puppet/indirector/catalog/active_record.rb index fabb08eb9..5157fb538 100644 --- a/lib/puppet/indirector/catalog/active_record.rb +++ b/lib/puppet/indirector/catalog/active_record.rb @@ -30,7 +30,7 @@ class Puppet::Resource::Catalog::ActiveRecord < Puppet::Indirector::ActiveRecord host.merge_resources(catalog.vertices) host.last_compile = Time.now - if node = Puppet::Node.find(catalog.name) + if node = Puppet::Node.indirection.find(catalog.name) host.ip = node.parameters["ipaddress"] host.environment = node.environment end diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index 78be4caf7..b80143a4d 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -88,7 +88,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code # Turn our host name into a node object. def find_node(name) begin - return nil unless node = Puppet::Node.find(name) + return nil unless node = Puppet::Node.indirection.find(name) rescue => detail puts detail.backtrace if Puppet[:trace] raise Puppet::Error, "Failed when searching for node #{name}: #{detail}" diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb index 6aaa2df1c..ee10dbddb 100755 --- a/lib/puppet/network/handler/filebucket.rb +++ b/lib/puppet/network/handler/filebucket.rb @@ -33,7 +33,7 @@ class Puppet::Network::Handler # :nodoc: # Return the contents associated with a given md5 sum. def getfile(md5, client = nil, clientip = nil) - bucket = Puppet::FileBucket::File.find("md5:#{md5}") + bucket = Puppet::FileBucket::File.indirection.find("md5:#{md5}") contents = bucket.contents if client diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 9abc7ee1a..5b4b17a32 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -236,7 +236,7 @@ class Puppet::Network::Handler unless hostname = (client || Facter.value("hostname")) raise ArgumentError, "Could not find hostname" end - env = (node = Puppet::Node.find(hostname)) ? node.environment : nil + env = (node = Puppet::Node.indirection.find(hostname)) ? node.environment : nil # And use the environment to look up the module. (mod = Puppet::Node::Environment.new(env).module(module_name) and mod.files?) ? @mounts[MODULES].copy(mod.name, mod.file_directory) : nil diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index c21aafafc..5b9dd332a 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -49,7 +49,7 @@ class Puppet::Network::Handler # Pass the facts to the fact handler Puppet::Node::Facts.new(client, facts).save unless local? - catalog = Puppet::Resource::Catalog.find(client) + catalog = Puppet::Resource::Catalog.indirection.find(client) case format when "yaml" diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb index 8ed0b28ca..54bcf30c2 100644 --- a/lib/puppet/network/http/webrick.rb +++ b/lib/puppet/network/http/webrick.rb @@ -105,7 +105,7 @@ class Puppet::Network::HTTP::WEBrick results[:SSLStartImmediately] = true results[:SSLEnable] = true - raise Puppet::Error, "Could not find CA certificate" unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME) + raise Puppet::Error, "Could not find CA certificate" unless Puppet::SSL::Certificate.indirection.find(Puppet::SSL::CA_NAME) results[:SSLCACertificateFile] = Puppet[:localcacert] results[:SSLVerifyClient] = OpenSSL::SSL::VERIFY_PEER diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb index e8d58e6be..5b0a98615 100644 --- a/lib/puppet/node.rb +++ b/lib/puppet/node.rb @@ -57,7 +57,7 @@ class Puppet::Node # Merge the node facts with parameters from the node source. def fact_merge - if facts = Puppet::Node::Facts.find(name) + if facts = Puppet::Node::Facts.indirection.find(name) merge(facts.values) end rescue => detail diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index d84d54113..612dc3239 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -16,7 +16,7 @@ class Puppet::Node::Facts # We want to expire any cached nodes if the facts are saved. module NodeExpirer def save(key, instance) - Puppet::Node.expire(instance.name) + Puppet::Node.indirection.expire(instance.name) super end end diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb index 0c226ca6a..5725be4d5 100644 --- a/lib/puppet/ssl/certificate_authority.rb +++ b/lib/puppet/ssl/certificate_authority.rb @@ -63,7 +63,7 @@ class Puppet::SSL::CertificateAuthority store = nil store = autosign_store(auto) if auto != true - Puppet::SSL::CertificateRequest.search("*").each do |csr| + Puppet::SSL::CertificateRequest.indirection.search("*").each do |csr| sign(csr.name) if auto == true or store.allowed?(csr.name, "127.1.1.1") end end @@ -93,7 +93,7 @@ class Puppet::SSL::CertificateAuthority # Retrieve (or create, if necessary) the certificate revocation list. def crl unless defined?(@crl) - unless @crl = Puppet::SSL::CertificateRevocationList.find(Puppet::SSL::CA_NAME) + unless @crl = Puppet::SSL::CertificateRevocationList.indirection.find(Puppet::SSL::CA_NAME) @crl = Puppet::SSL::CertificateRevocationList.new(Puppet::SSL::CA_NAME) @crl.generate(host.certificate.content, host.key.content) @crl.save @@ -109,7 +109,7 @@ class Puppet::SSL::CertificateAuthority # Generate a new certificate. def generate(name) - raise ArgumentError, "A Certificate already exists for #{name}" if Puppet::SSL::Certificate.find(name) + raise ArgumentError, "A Certificate already exists for #{name}" if Puppet::SSL::Certificate.indirection.find(name) host = Puppet::SSL::Host.new(name) host.generate_certificate_request @@ -169,7 +169,7 @@ class Puppet::SSL::CertificateAuthority # List all signed certificates. def list - Puppet::SSL::Certificate.search("*").collect { |c| c.name } + Puppet::SSL::Certificate.indirection.search("*").collect { |c| c.name } end # Read the next serial from the serial file, and increment the @@ -199,14 +199,14 @@ class Puppet::SSL::CertificateAuthority # Print a given host's certificate as text. def print(name) - (cert = Puppet::SSL::Certificate.find(name)) ? cert.to_text : nil + (cert = Puppet::SSL::Certificate.indirection.find(name)) ? cert.to_text : nil end # Revoke a given certificate. def revoke(name) raise ArgumentError, "Cannot revoke certificates when the CRL is disabled" unless crl - if cert = Puppet::SSL::Certificate.find(name) + if cert = Puppet::SSL::Certificate.indirection.find(name) serial = cert.content.serial elsif ! serial = inventory.serial(name) raise ArgumentError, "Could not find a serial number for #{name}" @@ -229,7 +229,7 @@ class Puppet::SSL::CertificateAuthority csr = self_signing_csr issuer = csr.content else - unless csr = Puppet::SSL::CertificateRequest.find(hostname) + unless csr = Puppet::SSL::CertificateRequest.indirection.find(hostname) raise ArgumentError, "Could not find certificate request for #{hostname}" end issuer = host.certificate.content @@ -251,14 +251,14 @@ class Puppet::SSL::CertificateAuthority cert.save # And remove the CSR if this wasn't self signed. - Puppet::SSL::CertificateRequest.destroy(csr.name) unless self_signing_csr + Puppet::SSL::CertificateRequest.indirection.destroy(csr.name) unless self_signing_csr cert end # Verify a given host's certificate. def verify(name) - unless cert = Puppet::SSL::Certificate.find(name) + unless cert = Puppet::SSL::Certificate.indirection.find(name) raise ArgumentError, "Could not find a certificate for #{name}" end store = OpenSSL::X509::Store.new @@ -271,7 +271,7 @@ class Puppet::SSL::CertificateAuthority end def fingerprint(name, md = :MD5) - unless cert = Puppet::SSL::Certificate.find(name) || Puppet::SSL::CertificateRequest.find(name) + unless cert = Puppet::SSL::Certificate.indirection.find(name) || Puppet::SSL::CertificateRequest.indirection.find(name) raise ArgumentError, "Could not find a certificate or csr for #{name}" end cert.fingerprint(md) @@ -279,6 +279,6 @@ class Puppet::SSL::CertificateAuthority # List the waiting certificate requests. def waiting? - Puppet::SSL::CertificateRequest.search("*").collect { |r| r.name } + Puppet::SSL::CertificateRequest.indirection.search("*").collect { |r| r.name } end end diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb index 8a6f0aa6d..6539b057e 100644 --- a/lib/puppet/ssl/host.rb +++ b/lib/puppet/ssl/host.rb @@ -43,31 +43,31 @@ class Puppet::SSL::Host # Configure how our various classes interact with their various terminuses. def self.configure_indirection(terminus, cache = nil) - Certificate.terminus_class = terminus - CertificateRequest.terminus_class = terminus - CertificateRevocationList.terminus_class = terminus + Certificate.indirection.terminus_class = terminus + CertificateRequest.indirection.terminus_class = terminus + CertificateRevocationList.indirection.terminus_class = terminus if cache # This is weird; we don't actually cache our keys, we # use what would otherwise be the cache as our normal # terminus. - Key.terminus_class = cache + Key.indirection.terminus_class = cache else - Key.terminus_class = terminus + Key.indirection.terminus_class = terminus end if cache - Certificate.cache_class = cache - CertificateRequest.cache_class = cache - CertificateRevocationList.cache_class = cache + Certificate.indirection.cache_class = cache + CertificateRequest.indirection.cache_class = cache + CertificateRevocationList.indirection.cache_class = cache else # Make sure we have no cache configured. puppet master # switches the configurations around a bit, so it's important # that we specify the configs for absolutely everything, every # time. - Certificate.cache_class = nil - CertificateRequest.cache_class = nil - CertificateRevocationList.cache_class = nil + Certificate.indirection.cache_class = nil + CertificateRequest.indirection.cache_class = nil + CertificateRevocationList.indirection.cache_class = nil end end @@ -94,7 +94,7 @@ class Puppet::SSL::Host # Remove all traces of a given host def self.destroy(name) - [Key, Certificate, CertificateRequest].collect { |part| part.destroy(name) }.any? { |x| x } + [Key, Certificate, CertificateRequest].collect { |part| part.indirection.destroy(name) }.any? { |x| x } end # Search for more than one host, optionally only specifying @@ -106,7 +106,7 @@ class Puppet::SSL::Host # Collect the results from each class, flatten them, collect all of the names, make the name list unique, # then create a Host instance for each one. - classlist.collect { |klass| klass.search }.flatten.collect { |r| r.name }.uniq.collect do |name| + classlist.collect { |klass| klass.indirection.search }.flatten.collect { |r| r.name }.uniq.collect do |name| new(name) end end @@ -117,7 +117,7 @@ class Puppet::SSL::Host end def key - @key ||= Key.find(name) + @key ||= Key.indirection.find(name) end # This is the private key; we can create it from scratch @@ -135,7 +135,7 @@ class Puppet::SSL::Host end def certificate_request - @certificate_request ||= CertificateRequest.find(name) + @certificate_request ||= CertificateRequest.indirection.find(name) end # Our certificate request requires the key but that's all. @@ -159,8 +159,8 @@ class Puppet::SSL::Host # get the CA cert first, since it's required for the normal cert # to be of any use. - return nil unless Certificate.find("ca") unless ca? - return nil unless @certificate = Certificate.find(name) + return nil unless Certificate.indirection.find("ca") unless ca? + return nil unless @certificate = Certificate.indirection.find(name) unless certificate_matches_key? raise Puppet::Error, "Retrieved certificate does not match private key; please remove certificate from server and regenerate it with the current key" @@ -212,7 +212,7 @@ class Puppet::SSL::Host @ssl_store.add_file(Puppet[:localcacert]) # If there's a CRL, add it to our store. - if crl = Puppet::SSL::CertificateRevocationList.find(CA_NAME) + if crl = Puppet::SSL::CertificateRevocationList.indirection.find(CA_NAME) @ssl_store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL|OpenSSL::X509::V_FLAG_CRL_CHECK if Puppet.settings[:certificate_revocation] @ssl_store.add_crl(crl.content) end diff --git a/lib/puppet/ssl/inventory.rb b/lib/puppet/ssl/inventory.rb index b2b402a53..e094da100 100644 --- a/lib/puppet/ssl/inventory.rb +++ b/lib/puppet/ssl/inventory.rb @@ -36,7 +36,7 @@ class Puppet::SSL::Inventory f.print "# Inventory of signed certificates\n# SERIAL NOT_BEFORE NOT_AFTER SUBJECT\n" end - Puppet::SSL::Certificate.search("*").each { |cert| add(cert) } + Puppet::SSL::Certificate.indirection.search("*").each { |cert| add(cert) } end # Find the serial number for a given certificate. diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index f35a26408..0a07b6798 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -587,7 +587,7 @@ Puppet::Type.newtype(:file) do def perform_recursion(path) - Puppet::FileServing::Metadata.search( + Puppet::FileServing::Metadata.indirection.search( path, :links => self[:links], diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index 7d03de2b0..19dabbdc3 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -98,7 +98,7 @@ module Puppet cached_attr(:content) do raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source - unless tmp = Puppet::FileServing::Content.find(metadata.source) + unless tmp = Puppet::FileServing::Content.indirection.find(metadata.source) fail "Could not find any content at %s" % metadata.source end tmp.content @@ -148,7 +148,7 @@ module Puppet result = nil value.each do |source| begin - if data = Puppet::FileServing::Metadata.find(source) + if data = Puppet::FileServing::Metadata.indirection.find(source) result = data result.source = source break -- cgit From 8766efea906f57428ff175cae9355d4b03d499d9 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 30 Nov 2010 11:09:20 -0800 Subject: Maint: Make http handler code call the indirector through ".indirection" In commit 71ecad9904c8c48c023e90e5fbea5b26b180c9cf we removed the delegation from model class to indirection for the "find", "search", "destroy", and "expire" methods. When we did this we neglected to modify http handler code to call the indirector directly. This patch makes the appropriate changes to http handler code. --- lib/puppet/network/http/handler.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 82238aa0a..fbd7d195f 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -103,7 +103,7 @@ module Puppet::Network::HTTP::Handler # Execute our find. def do_find(indirection_name, key, params, request, response) - unless result = model(indirection_name).find(key, params) + unless result = model(indirection_name).indirection.find(key, params) Puppet.info("Could not find #{indirection_name} for '#{key}'") return do_exception(response, "Could not find #{indirection_name} #{key}", 404) end @@ -120,7 +120,7 @@ module Puppet::Network::HTTP::Handler # Execute our search. def do_search(indirection_name, key, params, request, response) model = self.model(indirection_name) - result = model.search(key, params) + result = model.indirection.search(key, params) if result.nil? return do_exception(response, "Could not find instances in #{indirection_name} with '#{key}'", 404) @@ -134,7 +134,7 @@ module Puppet::Network::HTTP::Handler # Execute our destroy. def do_destroy(indirection_name, key, params, request, response) - result = model(indirection_name).destroy(key, params) + result = model(indirection_name).indirection.destroy(key, params) return_yaml_response(response, result) end -- cgit From 3063000155ddc475d1703d10cfc13770f687c3b2 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 29 Nov 2010 14:52:26 -0800 Subject: Maint: Swap the order of arguments to Indirection#save The first argument was often nil, and the second was mandatory. --- lib/puppet/indirector.rb | 2 +- lib/puppet/indirector/indirection.rb | 2 +- lib/puppet/node/facts.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index b0cabab8a..d3455c014 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -36,7 +36,7 @@ module Puppet::Indirector module InstanceMethods def save(key = nil) - self.class.indirection.save key, self + self.class.indirection.save self, key end end end diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 9095e48f8..eb0aa8aee 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -247,7 +247,7 @@ class Puppet::Indirector::Indirection # Save the instance in the appropriate terminus. This method is # normally an instance method on the indirected class. - def save(key, instance = nil) + def save(instance, key = nil) request = request(:save, key, instance) terminus = prepare(request) diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index 612dc3239..fd99adc3b 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -15,7 +15,7 @@ class Puppet::Node::Facts # We want to expire any cached nodes if the facts are saved. module NodeExpirer - def save(key, instance) + def save(instance, key) Puppet::Node.indirection.expire(instance.name) super end -- cgit From beb85d65e4cced7691163add392f53ec58cb1a3d Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 29 Nov 2010 16:32:41 -0800 Subject: Maint: Moved auto-signing logic into an indirector extension Autosigning was previously accomplished by overriding CertificateRequest#save. This meant that it wouldn't work if certificate requests were saved via a direct call to Indirection#save. Changed it to use the indirector :extend mechanism, which works no matter how the save is invoked. --- lib/puppet/ssl/certificate_request.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/ssl/certificate_request.rb b/lib/puppet/ssl/certificate_request.rb index 2f6cae3f5..8c83339a1 100644 --- a/lib/puppet/ssl/certificate_request.rb +++ b/lib/puppet/ssl/certificate_request.rb @@ -5,7 +5,20 @@ class Puppet::SSL::CertificateRequest < Puppet::SSL::Base wraps OpenSSL::X509::Request extend Puppet::Indirector - indirects :certificate_request, :terminus_class => :file + + # If auto-signing is on, sign any certificate requests as they are saved. + module AutoSigner + def save(instance, key = nil) + super + + # Try to autosign the CSR. + if ca = Puppet::SSL::CertificateAuthority.instance + ca.autosign + end + end + end + + indirects :certificate_request, :terminus_class => :file, :extend => AutoSigner # Convert a string into an instance. def self.from_s(string) @@ -46,13 +59,4 @@ class Puppet::SSL::CertificateRequest < Puppet::SSL::Base Puppet.info "Certificate Request fingerprint (md5): #{fingerprint}" @content end - - def save(args = {}) - super() - - # Try to autosign the CSR. - if ca = Puppet::SSL::CertificateAuthority.instance - ca.autosign - end - end end -- cgit From 7de6af87109062a4c0b038f2f2d93191e6a93e4f Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 30 Nov 2010 11:59:45 -0800 Subject: Maint: Add a default value for key in Facts::NodeExpirer#save Changed to match the signature of the method being overridden. This will allow code to call Facts.indirection.save() without a key. --- lib/puppet/node/facts.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb index fd99adc3b..451813f7d 100755 --- a/lib/puppet/node/facts.rb +++ b/lib/puppet/node/facts.rb @@ -15,7 +15,7 @@ class Puppet::Node::Facts # We want to expire any cached nodes if the facts are saved. module NodeExpirer - def save(instance, key) + def save(instance, key = nil) Puppet::Node.indirection.expire(instance.name) super end -- cgit From 779fea867a9e23ad48cd877a88756cc5792e9e0c Mon Sep 17 00:00:00 2001 From: Nigel Kersten Date: Mon, 15 Nov 2010 12:36:34 -0800 Subject: (#5304) Use internal_name rather than real_name for maillist provider We've switched to using list_lists --bare which shows the internal_name rather than "real_name", which is the authoritative identifier. Doing this also means we have less output to scrub, so the code is simpler. Signed-off-by: Nigel Kersten --- lib/puppet/provider/maillist/mailman.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/maillist/mailman.rb b/lib/puppet/provider/maillist/mailman.rb index 4fdc20a69..633642af7 100755 --- a/lib/puppet/provider/maillist/mailman.rb +++ b/lib/puppet/provider/maillist/mailman.rb @@ -2,11 +2,11 @@ require 'puppet/provider/parsedfile' Puppet::Type.type(:maillist).provide(:mailman) do if [ "CentOS", "RedHat", "Fedora" ].any? { |os| Facter.value(:operatingsystem) == os } - commands :list_lists => "/usr/lib/mailman/bin/list_lists", :rmlist => "/usr/lib/mailman/bin/rmlist", :newlist => "/usr/lib/mailman/bin/newlist" + commands :list_lists => "/usr/lib/mailman/bin/list_lists --bare", :rmlist => "/usr/lib/mailman/bin/rmlist", :newlist => "/usr/lib/mailman/bin/newlist" commands :mailman => "/usr/lib/mailman/mail/mailman" else # This probably won't work for non-Debian installs, but this path is sure not to be in the PATH. - commands :list_lists => "list_lists", :rmlist => "rmlist", :newlist => "newlist" + commands :list_lists => "list_lists --bare", :rmlist => "rmlist", :newlist => "newlist" commands :mailman => "/var/lib/mailman/mail/mailman" end @@ -14,10 +14,9 @@ Puppet::Type.type(:maillist).provide(:mailman) do # Return a list of existing mailman instances. def self.instances - list_lists.split("\n").reject { |line| line.include?("matching mailing lists") }.collect do |line| - name, description = line.sub(/^\s+/, '').sub(/\s+$/, '').split(/\s+-\s+/) - description = :absent if description.include?("no description available") - new(:ensure => :present, :name => name, :description => description) + list_lists.split("\n").collect do |line| + name = line.strip + new(:ensure => :present, :name => name) end end -- cgit From 0747b58bfef9c6bb5f1f9ac1eb6a7b3955dac2af Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 30 Nov 2010 12:06:52 -0800 Subject: Maint: Modified uses of indirector.save to call the indirection directly. This change replaces calls to .save with calls to .indirection.save(). This makes the use of the indirector explicit rather than implicit so that it will be easier to search for all indirector call sites using grep. This is an intermediate refactor on the way towards allowing indirector calls to be explicitly routed to multiple termini. This patch affects production code. --- lib/puppet/application/kick.rb | 2 +- lib/puppet/application/queue.rb | 4 ++-- lib/puppet/application/resource.rb | 2 +- lib/puppet/configurer.rb | 2 +- lib/puppet/file_bucket/dipper.rb | 2 +- lib/puppet/indirector.rb | 7 ------- lib/puppet/indirector/catalog/compiler.rb | 2 +- lib/puppet/network/handler/filebucket.rb | 2 +- lib/puppet/network/handler/master.rb | 2 +- lib/puppet/network/http/handler.rb | 2 +- lib/puppet/ssl/certificate_authority.rb | 4 ++-- lib/puppet/ssl/certificate_revocation_list.rb | 2 +- lib/puppet/ssl/host.rb | 4 ++-- lib/puppet/transaction.rb | 2 +- 14 files changed, 16 insertions(+), 23 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb index c6c6fd782..12dad653a 100644 --- a/lib/puppet/application/kick.rb +++ b/lib/puppet/application/kick.rb @@ -120,7 +120,7 @@ class Puppet::Application::Kick < Puppet::Application :background => ! options[:foreground], :ignoreschedules => options[:ignoreschedules] } - run = Puppet::Run.new( run_options ).save( url ) + run = Puppet::Run.indirection.save(Puppet::Run.new( run_options ), url) puts "Getting status" result = run.status puts "status is #{result}" diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb index c7e0ce8cc..b9e8ca4ca 100644 --- a/lib/puppet/application/queue.rb +++ b/lib/puppet/application/queue.rb @@ -41,12 +41,12 @@ class Puppet::Application::Queue < Puppet::Application require '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 + # Once you have a Puppet::Resource::Catalog instance, passing it to save should suffice # to put it through to the database via its active_record indirector (which is determined # by the terminus_class = :active_record setting above) Puppet::Util.benchmark(:notice, "Processing queued catalog for #{catalog.name}") do begin - catalog.save + Puppet::Resource::Catalog.indirection.save(catalog) rescue => detail puts detail.backtrace if Puppet[:trace] Puppet.err "Could not save queued catalog for #{catalog.name}: #{detail}" diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb index 3a7fdcc37..c7c1c28be 100644 --- a/lib/puppet/application/resource.rb +++ b/lib/puppet/application/resource.rb @@ -78,7 +78,7 @@ class Puppet::Application::Resource < Puppet::Application if params.empty? [ Puppet::Resource.indirection.find( key ) ] else - [ Puppet::Resource.new( type, name, :parameters => params ).save( key ) ] + [ Puppet::Resource.indirection.save(Puppet::Resource.new( type, name, :parameters => params ), key) ] end else Puppet::Resource.indirection.search( key, {} ) diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 77a9065df..50aaa0d1f 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -176,7 +176,7 @@ class Puppet::Configurer puts report.summary if Puppet[:summarize] save_last_run_summary(report) if Puppet[:report] - report.save + Puppet::Transaction::Report.indirection.save(report) end rescue => detail puts detail.backtrace if Puppet[:trace] diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index 8d6938930..367d6bfbd 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -36,7 +36,7 @@ class Puppet::FileBucket::Dipper file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path, :path => absolutize_path(file) ) dest_path = "#{@rest_path}#{file_bucket_file.name}" - file_bucket_file.save(dest_path) + Puppet::FileBucket::File.indirection.save(file_bucket_file, dest_path) return file_bucket_file.checksum_data rescue => detail puts detail.backtrace if Puppet[:trace] diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index d3455c014..9effc5cdd 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -21,7 +21,6 @@ module Puppet::Indirector raise(ArgumentError, "Already handling indirection for #{@indirection.name}; cannot also handle #{indirection}") if @indirection # populate this class with the various new methods extend ClassMethods - include InstanceMethods include Puppet::Indirector::Envelope extend Puppet::Network::FormatHandler @@ -33,10 +32,4 @@ module Puppet::Indirector module ClassMethods attr_reader :indirection end - - module InstanceMethods - def save(key = nil) - self.class.indirection.save self, key - end - end end diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb index b80143a4d..f4c40812d 100644 --- a/lib/puppet/indirector/catalog/compiler.rb +++ b/lib/puppet/indirector/catalog/compiler.rb @@ -23,7 +23,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code facts = Puppet::Node::Facts.convert_from(format, text_facts) end facts.add_timestamp - facts.save + Puppet::Node::Facts.indirection.save(facts) end # Compile a node's catalog. diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb index ee10dbddb..55028ee64 100755 --- a/lib/puppet/network/handler/filebucket.rb +++ b/lib/puppet/network/handler/filebucket.rb @@ -28,7 +28,7 @@ class Puppet::Network::Handler # :nodoc: def addfile(contents, path, client = nil, clientip = nil) contents = Base64.decode64(contents) if client bucket = Puppet::FileBucket::File.new(contents) - bucket.save + Puppet::FileBucket::File.indirection.save(bucket) end # Return the contents associated with a given md5 sum. diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb index 5b9dd332a..62aab539e 100644 --- a/lib/puppet/network/handler/master.rb +++ b/lib/puppet/network/handler/master.rb @@ -47,7 +47,7 @@ class Puppet::Network::Handler client ||= facts["hostname"] # Pass the facts to the fact handler - Puppet::Node::Facts.new(client, facts).save unless local? + Puppet::Node::Facts.indirection.save(Puppet::Node::Facts.new(client, facts)) unless local? catalog = Puppet::Resource::Catalog.indirection.find(client) diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index fbd7d195f..916f02c8d 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -146,7 +146,7 @@ module Puppet::Network::HTTP::Handler format = request_format(request) obj = model(indirection_name).convert_from(format, data) - result = obj.save(key) + result = model(indirection_name).indirection.save(obj, key) return_yaml_response(response, result) end diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb index 5725be4d5..d65067c70 100644 --- a/lib/puppet/ssl/certificate_authority.rb +++ b/lib/puppet/ssl/certificate_authority.rb @@ -96,7 +96,7 @@ class Puppet::SSL::CertificateAuthority unless @crl = Puppet::SSL::CertificateRevocationList.indirection.find(Puppet::SSL::CA_NAME) @crl = Puppet::SSL::CertificateRevocationList.new(Puppet::SSL::CA_NAME) @crl.generate(host.certificate.content, host.key.content) - @crl.save + Puppet::SSL::CertificateRevocationList.indirection.save(@crl) end end @crl @@ -248,7 +248,7 @@ class Puppet::SSL::CertificateAuthority # Save the now-signed cert. This should get routed correctly depending # on the certificate type. - cert.save + Puppet::SSL::Certificate.indirection.save(cert) # And remove the CSR if this wasn't self signed. Puppet::SSL::CertificateRequest.indirection.destroy(csr.name) unless self_signing_csr diff --git a/lib/puppet/ssl/certificate_revocation_list.rb b/lib/puppet/ssl/certificate_revocation_list.rb index 44e0a9e22..293f4b8c0 100644 --- a/lib/puppet/ssl/certificate_revocation_list.rb +++ b/lib/puppet/ssl/certificate_revocation_list.rb @@ -79,6 +79,6 @@ class Puppet::SSL::CertificateRevocationList < Puppet::SSL::Base @content.sign(cakey, OpenSSL::Digest::SHA1.new) - save + Puppet::SSL::CertificateRevocationList.indirection.save(self) end end diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb index 6539b057e..7f71ced99 100644 --- a/lib/puppet/ssl/host.rb +++ b/lib/puppet/ssl/host.rb @@ -126,7 +126,7 @@ class Puppet::SSL::Host @key = Key.new(name) @key.generate begin - @key.save + Key.indirection.save(@key) rescue @key = nil raise @@ -144,7 +144,7 @@ class Puppet::SSL::Host @certificate_request = CertificateRequest.new(name) @certificate_request.generate(key.content) begin - @certificate_request.save + CertificateRequest.indirection.save(@certificate_request) rescue @certificate_request = nil raise diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index dcd9aad0a..4c0ea9ac5 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -298,7 +298,7 @@ class Puppet::Transaction if Puppet[:report] begin - report.save + Puppet::Transaction::Report.indirection.save(report) rescue => detail Puppet.err "Reporting failed: #{detail}" end -- cgit From 0ab5e0f779d7261c4a9faf890cef8df52726a82a Mon Sep 17 00:00:00 2001 From: Stefan Schulte Date: Sun, 21 Nov 2010 20:52:49 +0100 Subject: (#2495) Better value validation for sshkey As mentioned in the ticket it is not obvious that aliases do not belong in the resourcename but have to be specified with the property "host_aliases". On the puppet-user list I saw someone using this as a resource @@sshkey {"$fqdn,$hostname,$ipaddress": type => rsa, key => $sshrsakey, } Puppet will now write a correct entry to the know_hosts file, but when it rereads the file, the field $fqdn,$hostname,$ipaddress is split into name ($fqdn) and host_aliases ([$hostname,$ipaddress]). Since we dont find the resource the user specified, puppet will put the same key in the file over and over again. This patch adds a simple validation on resourcename. --- lib/puppet/type/sshkey.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/sshkey.rb b/lib/puppet/type/sshkey.rb index b7a1b8a8d..59a1a12f8 100755 --- a/lib/puppet/type/sshkey.rb +++ b/lib/puppet/type/sshkey.rb @@ -41,7 +41,7 @@ module Puppet raise Puppet::Error, "Aliases cannot include whitespace" end if value =~ /,/ - raise Puppet::Error, "Aliases cannot include whitespace" + raise Puppet::Error, "Aliases must be provided as an array, not a comma-separated list" end end end @@ -50,6 +50,11 @@ module Puppet desc "The host name that the key is associated with." isnamevar + + validate do |value| + raise Puppet::Error, "Resourcename cannot include whitespaces" if value =~ /\s/ + raise Puppet::Error, "No comma in resourcename allowed. If you want to specify aliases use the host_aliases property" if value.include?(',') + end end newproperty(:target) do -- cgit From 19f38794ecb5ce55b7850e77bdab919bb33c7ce3 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 24 Nov 2010 15:32:32 -0800 Subject: Disable remote ralsh by default Changed the default auth.conf so that accesses to "/resource" are no longer allowed. This means that to use "puppet resource -H" you will need to configure the target machine to enable access to the "/resource" URLs. --- lib/puppet/network/rest_authconfig.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/network/rest_authconfig.rb b/lib/puppet/network/rest_authconfig.rb index 82d5a9de2..7abe06956 100644 --- a/lib/puppet/network/rest_authconfig.rb +++ b/lib/puppet/network/rest_authconfig.rb @@ -17,7 +17,6 @@ module Puppet { :acl => "/certificate/", :method => :find, :authenticated => false }, { :acl => "/certificate_request", :method => [:find, :save], :authenticated => false }, { :acl => "/status", :method => [:find], :authenticated => true }, - { :acl => "/resource", :method => [:find, :save, :search], :authenticated => true }, ] def self.main -- cgit From 76890a534640e077083785ba1321e76b7c4745ca Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 2 Dec 2010 06:53:17 +1100 Subject: Revert "(#5304) Use internal_name rather than real_name for maillist provider" This reverts commit 779fea867a9e23ad48cd877a88756cc5792e9e0c. --- lib/puppet/provider/maillist/mailman.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/maillist/mailman.rb b/lib/puppet/provider/maillist/mailman.rb index 633642af7..4fdc20a69 100755 --- a/lib/puppet/provider/maillist/mailman.rb +++ b/lib/puppet/provider/maillist/mailman.rb @@ -2,11 +2,11 @@ require 'puppet/provider/parsedfile' Puppet::Type.type(:maillist).provide(:mailman) do if [ "CentOS", "RedHat", "Fedora" ].any? { |os| Facter.value(:operatingsystem) == os } - commands :list_lists => "/usr/lib/mailman/bin/list_lists --bare", :rmlist => "/usr/lib/mailman/bin/rmlist", :newlist => "/usr/lib/mailman/bin/newlist" + commands :list_lists => "/usr/lib/mailman/bin/list_lists", :rmlist => "/usr/lib/mailman/bin/rmlist", :newlist => "/usr/lib/mailman/bin/newlist" commands :mailman => "/usr/lib/mailman/mail/mailman" else # This probably won't work for non-Debian installs, but this path is sure not to be in the PATH. - commands :list_lists => "list_lists --bare", :rmlist => "rmlist", :newlist => "newlist" + commands :list_lists => "list_lists", :rmlist => "rmlist", :newlist => "newlist" commands :mailman => "/var/lib/mailman/mail/mailman" end @@ -14,9 +14,10 @@ Puppet::Type.type(:maillist).provide(:mailman) do # Return a list of existing mailman instances. def self.instances - list_lists.split("\n").collect do |line| - name = line.strip - new(:ensure => :present, :name => name) + list_lists.split("\n").reject { |line| line.include?("matching mailing lists") }.collect do |line| + name, description = line.sub(/^\s+/, '').sub(/\s+$/, '').split(/\s+-\s+/) + description = :absent if description.include?("no description available") + new(:ensure => :present, :name => name, :description => description) end end -- cgit From af6e08c0a59db951502d0cf8c0ca24f5001e92f1 Mon Sep 17 00:00:00 2001 From: Nigel Kersten Date: Mon, 15 Nov 2010 12:36:34 -0800 Subject: (#5304) Use internal_name rather than real_name for maillist provider We've switched to using list_lists --bare which shows the internal_name rather than "real_name", which is the authoritative identifier. Doing this also means we have less output to scrub, so the code is simpler. Modified by Markus as-per discussion with Nigel. Signed-off-by: Nigel Kersten --- lib/puppet/provider/maillist/mailman.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/maillist/mailman.rb b/lib/puppet/provider/maillist/mailman.rb index 4fdc20a69..e070a25dd 100755 --- a/lib/puppet/provider/maillist/mailman.rb +++ b/lib/puppet/provider/maillist/mailman.rb @@ -14,11 +14,9 @@ Puppet::Type.type(:maillist).provide(:mailman) do # Return a list of existing mailman instances. def self.instances - list_lists.split("\n").reject { |line| line.include?("matching mailing lists") }.collect do |line| - name, description = line.sub(/^\s+/, '').sub(/\s+$/, '').split(/\s+-\s+/) - description = :absent if description.include?("no description available") - new(:ensure => :present, :name => name, :description => description) - end + list_lists('--bare'). + split("\n"). + collect { |line| new(:ensure => :present, :name => line.strip) } end # Prefetch our list list, yo. -- cgit From b27e9b4bd79c30c7910a02122069695044f05477 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Wed, 1 Dec 2010 17:16:03 -0800 Subject: [#5081] Revert "Fix #4349 - Parsing with ignoreimport=true was always loading site.pp" The fix for #4349 caused --parse-only not to detect syntax errors when --ignore-import was used by adding a return statement that bypassed the initial import: commit 760e418d254a8d2198d2c6eb466d783a5930ef47 def perform_initial_import + return if Puppet.settings[:ignoreimport] The problem that #4349 fixed was more generally fixed in commit 99c1019e1d3402ec8e476dc859d5aaef82ec4f69 for ticket #4798 so the return statement is no longer needed, so reverting the commit for #4349 does not reintroduce the problem of an import loop error when running puppet doc. Paired-with: Jesse Wolfe --- lib/puppet/resource/type_collection.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb index 63d110395..6a03458b3 100644 --- a/lib/puppet/resource/type_collection.rb +++ b/lib/puppet/resource/type_collection.rb @@ -153,7 +153,6 @@ class Puppet::Resource::TypeCollection end def perform_initial_import - return if Puppet.settings[:ignoreimport] parser = Puppet::Parser::Parser.new(environment) if code = Puppet.settings.uninterpolated_value(:code, environment.to_s) and code != "" parser.string = code -- cgit From 094a5c85fc9b4b1bd00f14193abdf23839905dc7 Mon Sep 17 00:00:00 2001 From: Steve Nielson Date: Mon, 22 Nov 2010 14:58:31 -0500 Subject: (#5211) Added patch and tests for checking the size of the arrary which is returned --- lib/puppet/provider/augeas/augeas.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 7dbd06240..461968245 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -213,7 +213,12 @@ Puppet::Type.type(:augeas).provide(:augeas) do fail("Invalid command: #{cmd_array.join(" ")}") if clause_array.length != 2 comparator = clause_array.shift arg = clause_array.shift - return_value = (result.size.send(comparator, arg)) + case comparator + when "!=" + return_value = !(result.size.send(:==, arg)) + else + return_value = (result.size.send(comparator, arg)) + end when "include" arg = clause_array.shift return_value = result.include?(arg) -- cgit From c908fdb520e0fc203d49e0c14c4c7cbc193ab262 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 22 Nov 2010 15:17:51 -0800 Subject: (#5261) Fix #5261 Don't escape Unicode characters in PSON This patch removes the escaping of valid UTF-8 sequences as "\uXXXX". This code was unreliable, as it relied on Iconv's ability to convert those codepoints between UTF-8 and UTF-16, but some versions of Iconv barf on some valid codepoints. Invalid UTF-8 sequences are still passed through unchanged. We believe that this is fine; if you are concerned about complience with the JSON standard, what we are doing is equivalent to: * interpreting binary files as Latin-1 encoded character sequences * JSON-encoding those characters according to RFC 4627 * outputting the JSON as Latin-1 This allows all raw binary files to be transmitted losslessly. Paired-With: Paul Berry --- lib/puppet/external/pson/pure/generator.rb | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/external/pson/pure/generator.rb b/lib/puppet/external/pson/pure/generator.rb index 4180be57d..89a0c62e0 100644 --- a/lib/puppet/external/pson/pure/generator.rb +++ b/lib/puppet/external/pson/pure/generator.rb @@ -44,34 +44,13 @@ module PSON string << '' # XXX workaround: avoid buffer sharing string.force_encoding(Encoding::ASCII_8BIT) string.gsub!(/["\\\x0-\x1f]/) { MAP[$MATCH] } - string.gsub!(/( - (?: - [\xc2-\xdf][\x80-\xbf] | - [\xe0-\xef][\x80-\xbf]{2} | - [\xf0-\xf4][\x80-\xbf]{3} - )+ | - [\x80-\xc1\xf5-\xff] # invalid - )/nx) { |c| - c.size == 1 and raise GeneratorError, "invalid utf8 byte: '#{c}'" - s = PSON::UTF8toUTF16.iconv(c).unpack('H*')[0] - s.gsub!(/.{4}/n, '\\\\u\&') - } - string.force_encoding(Encoding::UTF_8) string rescue Iconv::Failure => e raise GeneratorError, "Caught #{e.class}: #{e}" end else def utf8_to_pson(string) # :nodoc: - string. - gsub(/["\\\x0-\x1f]/n) { MAP[$MATCH] }. - gsub(/((?: - [\xc2-\xdf][\x80-\xbf] | - [\xe0-\xef][\x80-\xbf]{2} | - [\xf0-\xf4][\x80-\xbf]{3} - )+)/nx) { |c| - PSON::UTF8toUTF16.iconv(c).unpack('H*')[0].gsub(/.{4}/n, '\\\\u\&') - } + string.gsub(/["\\\x0-\x1f]/n) { MAP[$MATCH] } end end module_function :utf8_to_pson -- cgit From 1131ad73078c3e3022b23ee8ab756b44c7de27c9 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 2 Dec 2010 10:49:13 -0800 Subject: (#4943) Add puppet inspect application "puppet inspect" will load the locally stored YAML catalog and record the current state of the audited properties in the catalog. It uses settings specified in the [agent] configuration section, and will send its inspect report to the specified server. Paired-With: Jesse Wolfe --- lib/puppet/application/inspect.rb | 80 +++++++++++++++++++++++++++++++++++++++ lib/puppet/transaction/report.rb | 5 ++- 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 lib/puppet/application/inspect.rb (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb new file mode 100644 index 000000000..c28fef326 --- /dev/null +++ b/lib/puppet/application/inspect.rb @@ -0,0 +1,80 @@ +require 'puppet/application' + +class Puppet::Application::Inspect < Puppet::Application + + should_parse_config + run_mode :agent + + option("--debug","-d") + option("--verbose","-v") + + option("--logdest LOGDEST", "-l") do |arg| + begin + Puppet::Util::Log.newdestination(arg) + options[:logset] = true + rescue => detail + $stderr.puts detail.to_s + end + end + + def setup + exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs? + + raise "Inspect requires reporting to be enabled. Set report=true in puppet.conf to enable reporting." unless Puppet[:report] + + @report = Puppet::Transaction::Report.new("inspect") + + Puppet::Util::Log.newdestination(@report) + Puppet::Util::Log.newdestination(:console) unless options[:logset] + + trap(:INT) do + $stderr.puts "Exiting" + exit(1) + end + + if options[:debug] + Puppet::Util::Log.level = :debug + elsif options[:verbose] + Puppet::Util::Log.level = :info + end + + Puppet::Transaction::Report.terminus_class = :rest + Puppet::Resource::Catalog.terminus_class = :yaml + end + + def run_command + retrieval_starttime = Time.now + + unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname]) + raise "Could not find catalog for #{Puppet[:certname]}" + end + + retrieval_time = Time.now - retrieval_starttime + @report.add_times("config_retrieval", retrieval_time) + + starttime = Time.now + + catalog.to_ral.resources.each do |ral_resource| + audited_attributes = ral_resource[:audit] + next unless audited_attributes + + audited_resource = ral_resource.to_resource + + status = Puppet::Resource::Status.new(ral_resource) + audited_attributes.each do |name| + event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}") + status.add_event(event) + end + @report.add_resource_status(status) + end + + @report.add_metric(:time, {"config_retrieval" => retrieval_time, "inspect" => Time.now - starttime}) + + begin + @report.save + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Could not send report: #{detail}" + end + end +end diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index e6d1e0528..75c08fc7a 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -10,7 +10,7 @@ class Puppet::Transaction::Report indirects :report, :terminus_class => :processor - attr_reader :resource_statuses, :logs, :metrics, :host, :time + attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind # This is necessary since Marshall doesn't know how to # dump hash with default proc (see below @records) @@ -49,13 +49,14 @@ class Puppet::Transaction::Report calculate_event_metrics end - def initialize + def initialize(kind = "apply") @metrics = {} @logs = [] @resource_statuses = {} @external_times ||= {} @host = Puppet[:certname] @time = Time.now + @kind = kind end def name -- cgit From 84bf02e9ade666c4ba1bb63476bfd4b35226e7ac Mon Sep 17 00:00:00 2001 From: Jonathan Boyett Date: Tue, 30 Nov 2010 13:06:06 -0800 Subject: Bug #5423: This moves the home directory property before the uid property, thus minimizing room for damage when usermod is in use. --- lib/puppet/type/user.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index c8110bb69..761d5d71b 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -72,6 +72,11 @@ module Puppet end end + newproperty(:home) do + desc "The home directory of the user. The directory must be created + separately and is not currently checked for existence." + end + newproperty(:uid) do desc "The user ID. Must be specified numerically. For new users being created, if no user ID is specified then one will be @@ -138,11 +143,6 @@ module Puppet desc "A description of the user. Generally is a user's full name." end - newproperty(:home) do - desc "The home directory of the user. The directory must be created - separately and is not currently checked for existence." - end - newproperty(:shell) do desc "The user's login shell. The shell must exist and be executable." -- cgit From c88afa0cb9917177502700fddffcf8a40ca75f90 Mon Sep 17 00:00:00 2001 From: Derek Olsen Date: Fri, 26 Nov 2010 13:57:10 -0800 Subject: (#5393) Add "dataset" parameter to the zone provider This patch extends the zone provider to support the inclusion of one or more datasets in a solaris zone. A dataset is an zfs filesystem that has been delegated from the global zone to the non global zone. --- lib/puppet/provider/zone/solaris.rb | 3 +++ lib/puppet/type/zone.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb index c11444993..a1df041cb 100644 --- a/lib/puppet/provider/zone/solaris.rb +++ b/lib/puppet/provider/zone/solaris.rb @@ -221,6 +221,9 @@ Puppet::Type.type(:zone).provide(:solaris) do if dir = config["inherit-pkg-dir"] result[:inherit] = dir.collect { |dirs| dirs[:dir] } end + if datasets = config["dataset"] + result[:dataset] = datasets.collect { |dataset| dataset[:name] } + end result[:iptype] = config[:"ip-type"] if net = config["net"] result[:ip] = net.collect do |params| diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb index 408d6f5dd..fc524a541 100644 --- a/lib/puppet/type/zone.rb +++ b/lib/puppet/type/zone.rb @@ -282,6 +282,33 @@ Puppet::Type.newtype(:zone) do end end + newproperty(:dataset, :parent => ZoneMultiConfigProperty) do + desc "The list of datasets delegated to the non global zone from the + global zone. All datasets must be zfs filesystem names which is + different than the mountpoint." + + validate do |value| + unless value !~ /^\// + raise ArgumentError, "Datasets must be the name of a zfs filesystem" + end + end + + # Add a zfs filesystem to our list of datasets. + def add(dataset) + "add dataset\nset name=#{dataset}\nend" + end + + # Remove a zfs filesystem from our list of datasets. + def rm(dataset) + "remove dataset name=#{dataset}" + end + + def should + @should + end + end + + newproperty(:inherit, :parent => ZoneMultiConfigProperty) do desc "The list of directories that the zone inherits from the global zone. All directories must be fully qualified." -- cgit From 3e5927773c1dc7bc6e9af922fef09149d1599ef6 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 18 Oct 2010 16:35:32 -0700 Subject: Fix #1757 Change file mode representation to octal This patch changes the internal representation of a file's mode to a string instead of an integer. This simplifies the problem of displaying the value consistently throughout all of puppet. --- lib/puppet/type/file.rb | 3 ++- lib/puppet/type/file/ensure.rb | 2 +- lib/puppet/type/file/mode.rb | 54 ++++++++---------------------------------- 3 files changed, 13 insertions(+), 46 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index f35a26408..6523c99a0 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -718,8 +718,9 @@ Puppet::Type.newtype(:file) do mode = self.should(:mode) # might be nil umask = mode ? 000 : 022 + mode_int = mode ? mode.to_i(8) : nil - content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode) { |f| write_content(f) } } + content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode_int ) { |f| write_content(f) } } # And put our new file in place if use_temporary_file # This is only not true when our file is empty. diff --git a/lib/puppet/type/file/ensure.rb b/lib/puppet/type/file/ensure.rb index 967e06aee..4a68551ee 100755 --- a/lib/puppet/type/file/ensure.rb +++ b/lib/puppet/type/file/ensure.rb @@ -66,7 +66,7 @@ module Puppet end if mode Puppet::Util.withumask(000) do - Dir.mkdir(@resource[:path],mode) + Dir.mkdir(@resource[:path], mode.to_i(8)) end else Dir.mkdir(@resource[:path]) diff --git a/lib/puppet/type/file/mode.rb b/lib/puppet/type/file/mode.rb index 1ce56c843..2acd8b359 100755 --- a/lib/puppet/type/file/mode.rb +++ b/lib/puppet/type/file/mode.rb @@ -25,60 +25,26 @@ module Puppet @event = :file_changed - # Our modes are octal, so make sure they print correctly. Other - # valid values are symbols, basically - def is_to_s(currentvalue) - case currentvalue - when Integer - return "%o" % currentvalue - when Symbol - return currentvalue - else - raise Puppet::DevError, "Invalid current value for mode: #{currentvalue.inspect}" - end - end - - def should_to_s(newvalue = @should) - case newvalue - when Integer - return "%o" % newvalue - when Symbol - return newvalue - else - raise Puppet::DevError, "Invalid 'should' value for mode: #{newvalue.inspect}" - end - end - munge do |should| - # this is pretty hackish, but i need to make sure the number is in - # octal, yet the number can only be specified as a string right now - value = should - if value.is_a?(String) - unless value =~ /^\d+$/ - raise Puppet::Error, "File modes can only be numbers, not #{value.inspect}" - end - # Make sure our number looks like octal. - unless value =~ /^0/ - value = "0#{value}" - end - old = value - begin - value = Integer(value) - rescue ArgumentError => detail - raise Puppet::DevError, "Could not convert #{old.inspect} to integer" + if should.is_a?(String) + unless should =~ /^[0-7]+$/ + raise Puppet::Error, "File modes can only be octal numbers, not #{should.inspect}" end + should.to_i(8).to_s(8) + else + should.to_s(8) end - - return value end # If we're a directory, we need to be executable for all cases # that are readable. This should probably be selectable, but eh. def dirmask(value) if FileTest.directory?(@resource[:path]) + value = value.to_i(8) value |= 0100 if value & 0400 != 0 value |= 010 if value & 040 != 0 value |= 01 if value & 04 != 0 + value = value.to_s(8) end value @@ -101,7 +67,7 @@ module Puppet unless defined?(@fixed) @should &&= @should.collect { |s| self.dirmask(s) } end - return stat.mode & 007777 + return (stat.mode & 007777).to_s(8) else return :absent end @@ -111,7 +77,7 @@ module Puppet mode = self.should begin - File.chmod(mode, @resource[:path]) + File.chmod(mode.to_i(8), @resource[:path]) rescue => detail error = Puppet::Error.new("failed to chmod #{@resource[:path]}: #{detail.message}") error.set_backtrace detail.backtrace -- cgit From 8c134b697d2c30128f51cd69e47808a051b96b72 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Fri, 10 Dec 2010 12:46:15 -0800 Subject: maint: broken test not failing due to over-eager exception catching A test was not testing what it claimed, but the failure exception was getting swallowed by an unnecessarily broad rescue match. Paired-With: Nick Lewis --- lib/puppet/configurer/plugin_handler.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/configurer/plugin_handler.rb b/lib/puppet/configurer/plugin_handler.rb index 539441e75..8192d4719 100644 --- a/lib/puppet/configurer/plugin_handler.rb +++ b/lib/puppet/configurer/plugin_handler.rb @@ -19,9 +19,7 @@ module Puppet::Configurer::PluginHandler begin Puppet.info "Loading downloaded plugin #{file}" load file - rescue SystemExit,NoMemoryError - raise - rescue Exception => detail + rescue StandardError, LoadError => detail Puppet.err "Could not load downloaded file #{file}: #{detail}" end end -- cgit From f38c36c63d6404536e075ce03c3d93e0b2f0a731 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Fri, 10 Dec 2010 14:56:19 -0800 Subject: (#5408) Attributes can be both audited and managed This patch makes it possible to both audit and manage an attribute. It introduces a new field on Event objects "historical_value", which is the value from state.yaml. The value from the RAL is written to state.yaml, and then the RAL is updated with the desired value. Paired-With: Nick Lewis Paired-With: Matt Robinson --- lib/puppet/transaction/change.rb | 74 +++++++++++++----------------- lib/puppet/transaction/event.rb | 2 +- lib/puppet/transaction/resource_harness.rb | 30 ++++++------ lib/puppet/util/log.rb | 11 +++-- 4 files changed, 54 insertions(+), 63 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index ecc3b5a5f..d57ac1917 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -4,20 +4,12 @@ require 'puppet/transaction/event' # Handle all of the work around performing an actual change, # including calling 'sync' on the properties and producing events. class Puppet::Transaction::Change - attr_accessor :is, :should, :property, :proxy, :auditing + attr_accessor :is, :should, :property, :proxy, :auditing, :old_audit_value def auditing? auditing end - # Create our event object. - def event - result = property.event - result.previous_value = is - result.desired_value = should - result - end - def initialize(property, currentvalue) @property = property @is = currentvalue @@ -28,24 +20,39 @@ class Puppet::Transaction::Change end def apply - return audit_event if auditing? - return noop_event if noop? - - property.sync - - result = event - result.message = property.change_to_s(is, should) - result.status = "success" - result.send_log - result + event = property.event + event.previous_value = is + event.desired_value = should + event.historical_value = old_audit_value + + if auditing? and old_audit_value != is + event.message = "audit change: previously recorded value #{property.is_to_s(old_audit_value)} has been changed to #{property.is_to_s(is)}" + event.status = "audit" + event.audited = true + brief_audit_message = " (previously recorded value was #{property.is_to_s(old_audit_value)})" + else + brief_audit_message = "" + end + + if property.insync?(is) + # nothing happens + elsif noop? + event.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)#{brief_audit_message}" + event.status = "noop" + else + property.sync + event.message = [ property.change_to_s(is, should), brief_audit_message ].join + event.status = "success" + end + event rescue => detail puts detail.backtrace if Puppet[:trace] - result = event - result.status = "failure" + event.status = "failure" - result.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}" - result.send_log - result + event.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}" + event + ensure + event.send_log end # Is our property noop? This is used for generating special events. @@ -65,23 +72,4 @@ class Puppet::Transaction::Change def to_s "change #{@property.change_to_s(@is, @should)}" end - - private - - def audit_event - # This needs to store the appropriate value, and then produce a new event - result = event - result.message = "audit change: previously recorded value #{property.should_to_s(should)} has been changed to #{property.is_to_s(is)}" - result.status = "audit" - result.send_log - result - end - - def noop_event - result = event - result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)" - result.status = "noop" - result.send_log - result - end end diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index e5e5793da..da5b14727 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -7,7 +7,7 @@ class Puppet::Transaction::Event include Puppet::Util::Tagging include Puppet::Util::Logging - ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :message, :node, :version, :file, :line, :source_description] + ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :node, :version, :file, :line, :source_description, :audited] attr_accessor *ATTRIBUTES attr_writer :tags attr_accessor :time diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index 29ec9a539..c978e5545 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -25,12 +25,12 @@ class Puppet::Transaction::ResourceHarness status.changed = true end - # Used mostly for scheduling at this point. + # Used mostly for scheduling and auditing at this point. def cached(resource, name) Puppet::Util::Storage.cache(resource)[name] end - # Used mostly for scheduling at this point. + # Used mostly for scheduling and auditing at this point. def cache(resource, name, value) Puppet::Util::Storage.cache(resource)[name] = value end @@ -46,33 +46,35 @@ class Puppet::Transaction::ResourceHarness if param = resource.parameter(:ensure) return [] if absent_and_not_being_created?(current, param) - return [Puppet::Transaction::Change.new(param, current[:ensure])] unless ensure_is_insync?(current, param) + unless ensure_is_insync?(current, param) + audited.keys.reject{|name| name == :ensure}.each do |name| + resource.parameter(name).notice "audit change: previously recorded value #{audited[name]} has been changed to #{current[param]}" + cache(resource, name, current[param]) + end + return [Puppet::Transaction::Change.new(param, current[:ensure])] + end return [] if ensure_should_be_absent?(current, param) end - resource.properties.reject { |p| p.name == :ensure }.reject do |param| - param.should.nil? - end.reject do |param| - param_is_insync?(current, param) + resource.properties.reject { |param| param.name == :ensure }.select do |param| + (audited.include?(param.name) && audited[param.name] != current[param.name]) || (param.should != nil && !param_is_insync?(current, param)) end.collect do |param| change = Puppet::Transaction::Change.new(param, current[param.name]) change.auditing = true if audited.include?(param.name) + change.old_audit_value = audited[param.name] change end end def copy_audited_parameters(resource, current) - return [] unless audit = resource[:audit] + return {} unless audit = resource[:audit] audit = Array(audit).collect { |p| p.to_sym } - audited = [] + audited = {} audit.find_all do |param| - next if resource[param] - if value = cached(resource, param) - resource[param] = value - audited << param + audited[param] = value else - resource.debug "Storing newly-audited value #{current[param]} for #{param}" + resource.property(param).notice "audit change: newly-recorded recorded value #{current[param]}" cache(resource, param, current[param]) end end diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 36a765c61..7764dc1d1 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -17,11 +17,12 @@ class Puppet::Util::Log # Create a new destination type. def self.newdesttype(name, options = {}, &block) - dest = genclass( - name, :parent => Puppet::Util::Log::Destination, :prefix => "Dest", - :block => block, - :hash => @desttypes, - + dest = genclass( + name, + :parent => Puppet::Util::Log::Destination, + :prefix => "Dest", + :block => block, + :hash => @desttypes, :attributes => options ) dest.match(dest.name) -- cgit From 3ac50fab81216789d6d5f7d22cb675d3264674cd Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 13 Dec 2010 13:30:24 -0800 Subject: maint: restore plugin handler safety The previous maintenance patch for this file didn't provide as strong of a guarantee of loading plugins as the code it replaced. This patch restores the extremely broad exception catching, but prevents mocha exceptions from being silently ignored. --- lib/puppet/configurer/plugin_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/configurer/plugin_handler.rb b/lib/puppet/configurer/plugin_handler.rb index 8192d4719..cfc6b5a0b 100644 --- a/lib/puppet/configurer/plugin_handler.rb +++ b/lib/puppet/configurer/plugin_handler.rb @@ -19,7 +19,7 @@ module Puppet::Configurer::PluginHandler begin Puppet.info "Loading downloaded plugin #{file}" load file - rescue StandardError, LoadError => detail + rescue Exception => detail Puppet.err "Could not load downloaded file #{file}: #{detail}" end end -- cgit From 7f4e058133a0aa6b07bd3402cf01009818066d32 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Mon, 13 Dec 2010 17:07:33 -0800 Subject: (#4487) Fix environment column in hosts table An entire environment object was being stored in a string field, causing the ZAML form of the environment to be stored. This was over-ridden to return just the ZAML serialized version of the name. Since the hosts model didn't know how to interpret a serialized value, it just returned the ZAML string as the environment. This patch stringifies the environment before putting it in the hosts table, which stores it properly. This patch also introduces a new method of testing using Tableless ActiveRecord models, which emulate their database schema. This helps to eliminate some stubbing, but it is still impossible to fully and accurately test all ActiveRecord interactions without a real database. Paired-With: Matt Robinson --- lib/puppet/indirector/catalog/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/catalog/active_record.rb b/lib/puppet/indirector/catalog/active_record.rb index fabb08eb9..f814f4aff 100644 --- a/lib/puppet/indirector/catalog/active_record.rb +++ b/lib/puppet/indirector/catalog/active_record.rb @@ -32,7 +32,7 @@ class Puppet::Resource::Catalog::ActiveRecord < Puppet::Indirector::ActiveRecord if node = Puppet::Node.find(catalog.name) host.ip = node.parameters["ipaddress"] - host.environment = node.environment + host.environment = node.environment.to_s end host.save -- cgit From b94c1b444d76a7fa1bcd63dd6ba653abf0b49826 Mon Sep 17 00:00:00 2001 From: Stefan Schulte Date: Thu, 18 Nov 2010 23:38:10 +0100 Subject: (#5427) Using Propery::OrderedList for host_alias This uses the propertyclass Puppet::Property::OrderedList to represent the list of host_aliases. This lets us remove the in_sync, should_to_s etc overrides. In the provider class the list is represented by a string (=no array) so there were a few changes necessary as well. Because Puppet::Property::List uses the specified delimiter when converting should values to strings, I changed the delimiter to a simple space instead a tab. This keeps messages produced by puppet in a nice format. The tests had to be changed to work with the new behaviour of host_aliases. There are a few additional tests as well. --- lib/puppet/provider/host/parsed.rb | 8 +++----- lib/puppet/type/host.rb | 33 +++++++++------------------------ 2 files changed, 12 insertions(+), 29 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/host/parsed.rb b/lib/puppet/provider/host/parsed.rb index a303c4bcf..2ba01a41c 100644 --- a/lib/puppet/provider/host/parsed.rb +++ b/lib/puppet/provider/host/parsed.rb @@ -22,9 +22,7 @@ Puppet::Type.type(:host).provide(:parsed,:parent => Puppet::Provider::ParsedFile # An absent comment should match "comment => ''" hash[:comment] = '' if hash[:comment].nil? or hash[:comment] == :absent unless hash[:host_aliases].nil? or hash[:host_aliases] == :absent - hash[:host_aliases] = hash[:host_aliases].split(/\s+/) - else - hash[:host_aliases] = [] + hash[:host_aliases].gsub!(/\s+/,' ') # Change delimiter end }, :to_line => proc { |hash| @@ -32,8 +30,8 @@ Puppet::Type.type(:host).provide(:parsed,:parent => Puppet::Provider::ParsedFile raise ArgumentError, "#{n} is a required attribute for hosts" unless hash[n] and hash[n] != :absent end str = "#{hash[:ip]}\t#{hash[:name]}" - if hash.include? :host_aliases and !hash[:host_aliases].empty? - str += "\t#{hash[:host_aliases].join("\t")}" + if hash.include? :host_aliases and !hash[:host_aliases].nil? and hash[:host_aliases] != :absent + str += "\t#{hash[:host_aliases]}" end if hash.include? :comment and !hash[:comment].empty? str += "\t# #{hash[:comment]}" diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index 1af74d886..867ef2ab3 100755 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -1,3 +1,5 @@ +require 'puppet/property/ordered_list' + module Puppet newtype(:host) do ensurable @@ -13,41 +15,24 @@ module Puppet end - newproperty(:host_aliases) do + # for now we use OrderedList to indicate that the order does matter. + newproperty(:host_aliases, :parent => Puppet::Property::OrderedList) do desc "Any aliases the host might have. Multiple values must be specified as an array." - def insync?(is) - is == @should + def delimiter + " " end - def is_to_s(currentvalue = @is) - currentvalue = [currentvalue] unless currentvalue.is_a? Array - currentvalue.join(" ") - end - - # We actually want to return the whole array here, not just the first - # value. - def should - if defined?(@should) - if @should == [:absent] - return :absent - else - return @should - end - else - return nil - end - end - - def should_to_s(newvalue = @should) - newvalue.join(" ") + def inclusive? + true end validate do |value| raise Puppet::Error, "Host aliases cannot include whitespace" if value =~ /\s/ raise Puppet::Error, "Host alias cannot be an empty string. Use an empty array to delete all host_aliases " if value =~ /^\s*$/ end + end newproperty(:comment) do -- cgit From 5db696b605ebb331d5af3e640e68978c4f6d604d Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Mon, 22 Nov 2010 14:56:49 -0800 Subject: maint: Fix tests that don't run on their own From the spec directory I found all the specs that fail when run on their own. for TEST in `find . -name "*.rb" -type f`; do spec $TEST > /dev/null 2>&1 if [[ $? != 0 ]]; then echo $TEST fi done All of them were cases of missing requires. Paired-with: Nick Lewis --- lib/puppet/parser/templatewrapper.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index 73a4ad8aa..6864aa1a9 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -1,6 +1,7 @@ # A simple wrapper for templates, so they don't have full access to # the scope objects. require 'puppet/parser/files' +require 'erb' class Puppet::Parser::TemplateWrapper attr_writer :scope -- cgit From e99a3ea6fc2b30ed7bcbd3c1bc011b38d92f57b2 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Thu, 16 Dec 2010 14:10:20 -0800 Subject: Fix #5566 none, mtime, and ctime checksum types can write file contents The #write method in lib/puppet/type/file/content.rb relies on the block passed to #sum_stream getting executed. "none", "mtime", and "ctime" aren't real checksums, so they violated that assumption and just returned empty results. This patch causes that block to get executed. --- lib/puppet/util/checksums.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/util/checksums.rb b/lib/puppet/util/checksums.rb index 5aebd8392..6fdf14ecf 100644 --- a/lib/puppet/util/checksums.rb +++ b/lib/puppet/util/checksums.rb @@ -1,6 +1,12 @@ # A stand-alone module for calculating checksums # in a generic way. module Puppet::Util::Checksums + class FakeChecksum + def <<(*args) + self + end + end + # Is the provided string a checksum? def checksum?(string) string =~ /^\{(\w{3,5})\}\S+/ @@ -55,7 +61,10 @@ module Puppet::Util::Checksums end # by definition this doesn't exist + # but we still need to execute the block given def mtime_stream + noop_digest = FakeChecksum.new + yield noop_digest nil end @@ -105,6 +114,8 @@ module Puppet::Util::Checksums end def none_stream + noop_digest = FakeChecksum.new + yield noop_digest "" end -- cgit From 093c45f7bffb91b869daaf5c6f97383a90e70a18 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 23 Nov 2010 11:47:36 -0800 Subject: (#5375) Rework puppet apply to use configurer.run Puppet apply used to contain code that duplicated the functionality of configurer.run. Refactored to share code. Paired-with: Jesse Wolfe --- lib/puppet/application/apply.rb | 20 ++------------------ lib/puppet/configurer.rb | 8 ++++---- 2 files changed, 6 insertions(+), 22 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb index 59a95d35a..33a70ce8a 100644 --- a/lib/puppet/application/apply.rb +++ b/lib/puppet/application/apply.rb @@ -123,25 +123,9 @@ class Puppet::Application::Apply < Puppet::Application require 'puppet/configurer' configurer = Puppet::Configurer.new - configurer.execute_prerun_command + report = configurer.run(:skip_plugin_download => true, :catalog => catalog) - # And apply it - if Puppet[:report] - report = configurer.initialize_report - Puppet::Util::Log.newdestination(report) - end - transaction = catalog.apply - - configurer.execute_postrun_command - - if Puppet[:report] - Puppet::Util::Log.close(report) - configurer.send_report(report, transaction) - else - transaction.generate_report - end - - exit( Puppet[:noop] ? 0 : options[:detailed_exitcodes] ? transaction.report.exit_status : 0 ) + exit( Puppet[:noop] ? 0 : options[:detailed_exitcodes] ? report.exit_status : 0 ) rescue => detail puts detail.backtrace if Puppet[:trace] $stderr.puts detail.message diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 31d31c2d2..2687f5fbd 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -77,12 +77,12 @@ class Puppet::Configurer end # Prepare for catalog retrieval. Downloads everything necessary, etc. - def prepare + def prepare(options) dostorage - download_plugins + download_plugins unless options[:skip_plugin_download] - download_fact_plugins + download_fact_plugins unless options[:skip_plugin_download] execute_prerun_command end @@ -126,7 +126,7 @@ class Puppet::Configurer # which accepts :tags and :ignoreschedules. def run(options = {}) begin - prepare + prepare(options) rescue SystemExit,NoMemoryError raise rescue Exception => detail -- cgit From d516f6385e0ee044603c403ecc6f96606730f8f2 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 16 Dec 2010 16:17:17 -0800 Subject: (#5493) Add report_format, puppet_version, and configuration_version to Reports Current report formats are: 0: 0.25 reports and earlier 1: 0.26.1 - 0.26.4 reports 2: 0.26.5 and beyond Paired-With: Jesse Wolfe --- lib/puppet/application/inspect.rb | 2 ++ lib/puppet/configurer.rb | 8 +++----- lib/puppet/transaction.rb | 2 +- lib/puppet/transaction/report.rb | 6 +++++- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index c28fef326..caa32a7c2 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -49,6 +49,8 @@ class Puppet::Application::Inspect < Puppet::Application raise "Could not find catalog for #{Puppet[:certname]}" end + @report.configuration_version = catalog.version + retrieval_time = Time.now - retrieval_starttime @report.add_times("config_retrieval", retrieval_time) diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 2687f5fbd..070176554 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -72,10 +72,6 @@ class Puppet::Configurer @splayed = false end - def initialize_report - Puppet::Transaction::Report.new - end - # Prepare for catalog retrieval. Downloads everything necessary, etc. def prepare(options) dostorage @@ -134,7 +130,7 @@ class Puppet::Configurer Puppet.err "Failed to prepare catalog: #{detail}" end - options[:report] ||= initialize_report + options[:report] ||= Puppet::Transaction::Report.new("apply") report = options[:report] Puppet::Util::Log.newdestination(report) @@ -145,6 +141,8 @@ class Puppet::Configurer return end + report.configuration_version = catalog.version + transaction = nil begin diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index dcd9aad0a..2d49062dd 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -238,7 +238,7 @@ class Puppet::Transaction def initialize(catalog) @catalog = catalog - @report = Report.new + @report = Report.new("apply", catalog.version) @event_manager = Puppet::Transaction::EventManager.new(self) diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 75c08fc7a..8a928454f 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -10,6 +10,7 @@ class Puppet::Transaction::Report indirects :report, :terminus_class => :processor + attr_accessor :configuration_version attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind # This is necessary since Marshall doesn't know how to @@ -49,7 +50,7 @@ class Puppet::Transaction::Report calculate_event_metrics end - def initialize(kind = "apply") + def initialize(kind, configuration_version=nil) @metrics = {} @logs = [] @resource_statuses = {} @@ -57,6 +58,9 @@ class Puppet::Transaction::Report @host = Puppet[:certname] @time = Time.now @kind = kind + @report_format = 2 + @puppet_version = Puppet.version + @configuration_version = configuration_version end def name -- cgit From 7fff7808e25491a5ea1e207b8de3ade0c4f95f4f Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 17 Dec 2010 10:59:12 -0800 Subject: (#5408) Reworked ResourceHarness so that code is clearer and all behaviors are tested This patch removes the Puppet::Transaction::Change class and replaces it with a method, Puppet::Transaction::ResourceHarness#apply_parameter. The new code is shorter, more thoroughly unit tested, and addresses known bugs in the interaction between auditing and performing changes. This code does not address drawbacks in the report output (for example a resource is still flagged as changed even if it merely contains audit information); those will be addressed in a follow-up patch. --- lib/puppet/resource/status.rb | 8 +- lib/puppet/transaction.rb | 1 - lib/puppet/transaction/change.rb | 75 --------------- lib/puppet/transaction/resource_harness.rb | 143 ++++++++++++++++++----------- 4 files changed, 97 insertions(+), 130 deletions(-) delete mode 100644 lib/puppet/transaction/change.rb (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index 2bdfbbfef..9240a06d7 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -4,13 +4,13 @@ module Puppet include Puppet::Util::Tagging include Puppet::Util::Logging - ATTRIBUTES = [:resource, :node, :version, :file, :line, :current_values, :skipped_reason, :status, :evaluation_time, :change_count] - attr_accessor *ATTRIBUTES + attr_accessor :resource, :node, :version, :file, :line, :current_values, :skipped_reason, :status, :evaluation_time STATES = [:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled] attr_accessor *STATES attr_reader :source_description, :default_log_level, :time, :resource + attr_reader :change_count # Provide a boolean method for each of the states. STATES.each do |attr| @@ -29,6 +29,9 @@ module Puppet if event.status == 'failure' self.failed = true end + @change_count += 1 + @changed = true + @out_of_sync = true end def events @@ -38,6 +41,7 @@ module Puppet def initialize(resource) @source_description = resource.path @resource = resource.to_s + @change_count = 0 [:file, :line, :version].each do |attr| send(attr.to_s + "=", resource.send(attr)) diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 2d49062dd..4db971477 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -6,7 +6,6 @@ require 'puppet/util/tagging' require 'puppet/application' class Puppet::Transaction - require 'puppet/transaction/change' require 'puppet/transaction/event' require 'puppet/transaction/event_manager' require 'puppet/transaction/resource_harness' diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb deleted file mode 100644 index d57ac1917..000000000 --- a/lib/puppet/transaction/change.rb +++ /dev/null @@ -1,75 +0,0 @@ -require 'puppet/transaction' -require 'puppet/transaction/event' - -# Handle all of the work around performing an actual change, -# including calling 'sync' on the properties and producing events. -class Puppet::Transaction::Change - attr_accessor :is, :should, :property, :proxy, :auditing, :old_audit_value - - def auditing? - auditing - end - - def initialize(property, currentvalue) - @property = property - @is = currentvalue - - @should = property.should - - @changed = false - end - - def apply - event = property.event - event.previous_value = is - event.desired_value = should - event.historical_value = old_audit_value - - if auditing? and old_audit_value != is - event.message = "audit change: previously recorded value #{property.is_to_s(old_audit_value)} has been changed to #{property.is_to_s(is)}" - event.status = "audit" - event.audited = true - brief_audit_message = " (previously recorded value was #{property.is_to_s(old_audit_value)})" - else - brief_audit_message = "" - end - - if property.insync?(is) - # nothing happens - elsif noop? - event.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)#{brief_audit_message}" - event.status = "noop" - else - property.sync - event.message = [ property.change_to_s(is, should), brief_audit_message ].join - event.status = "success" - end - event - rescue => detail - puts detail.backtrace if Puppet[:trace] - event.status = "failure" - - event.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}" - event - ensure - event.send_log - end - - # Is our property noop? This is used for generating special events. - def noop? - @property.noop - end - - # The resource that generated this change. This is used for handling events, - # and the proxy resource is used for generated resources, since we can't - # send an event to a resource we don't have a direct relationship with. If we - # have a proxy resource, then the events will be considered to be from - # that resource, rather than us, so the graph resolution will still work. - def resource - self.proxy || @property.resource - end - - def to_s - "change #{@property.change_to_s(@is, @should)}" - end -end diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index c978e5545..cb9a193b9 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -7,22 +7,15 @@ class Puppet::Transaction::ResourceHarness attr_reader :transaction def allow_changes?(resource) - return true unless resource.purging? and resource.deleting? - return true unless deps = relationship_graph.dependents(resource) and ! deps.empty? and deps.detect { |d| ! d.deleting? } - - deplabel = deps.collect { |r| r.ref }.join(",") - plurality = deps.length > 1 ? "":"s" - resource.warning "#{deplabel} still depend#{plurality} on me -- not purging" - false - end - - def apply_changes(status, changes) - changes.each do |change| - status << change.apply - - cache(change.property.resource, change.property.name, change.is) if change.auditing? + if resource.purging? and resource.deleting? and deps = relationship_graph.dependents(resource) \ + and ! deps.empty? and deps.detect { |d| ! d.deleting? } + deplabel = deps.collect { |r| r.ref }.join(",") + plurality = deps.length > 1 ? "":"s" + resource.warning "#{deplabel} still depend#{plurality} on me -- not purging" + false + else + true end - status.changed = true end # Used mostly for scheduling and auditing at this point. @@ -35,66 +28,112 @@ class Puppet::Transaction::ResourceHarness Puppet::Util::Storage.cache(resource)[name] = value end - def changes_to_perform(status, resource) + def perform_changes(resource) current = resource.retrieve_resource cache resource, :checked, Time.now return [] if ! allow_changes?(resource) - audited = copy_audited_parameters(resource, current) + current_values = current.to_hash + historical_values = Puppet::Util::Storage.cache(resource).dup + desired_values = resource.to_resource.to_hash + audited_params = (resource[:audit] || []).map { |p| p.to_sym } + synced_params = [] - if param = resource.parameter(:ensure) - return [] if absent_and_not_being_created?(current, param) - unless ensure_is_insync?(current, param) - audited.keys.reject{|name| name == :ensure}.each do |name| - resource.parameter(name).notice "audit change: previously recorded value #{audited[name]} has been changed to #{current[param]}" - cache(resource, name, current[param]) + # Record the current state in state.yml. + audited_params.each do |param| + cache(resource, param, current_values[param]) + end + + # Update the machine state & create logs/events + events = [] + ensure_param = resource.parameter(:ensure) + if desired_values[:ensure] && !ensure_param.insync?(current_values[:ensure]) + events << apply_parameter(ensure_param, current_values[:ensure], audited_params.include?(:ensure), historical_values[:ensure]) + synced_params << :ensure + elsif current_values[:ensure] != :absent + work_order = resource.properties # Note: only the resource knows what order to apply changes in + work_order.each do |param| + if !param.insync?(current_values[param.name]) + events << apply_parameter(param, current_values[param.name], audited_params.include?(param.name), historical_values[param.name]) + synced_params << param.name end - return [Puppet::Transaction::Change.new(param, current[:ensure])] end - return [] if ensure_should_be_absent?(current, param) end - resource.properties.reject { |param| param.name == :ensure }.select do |param| - (audited.include?(param.name) && audited[param.name] != current[param.name]) || (param.should != nil && !param_is_insync?(current, param)) - end.collect do |param| - change = Puppet::Transaction::Change.new(param, current[param.name]) - change.auditing = true if audited.include?(param.name) - change.old_audit_value = audited[param.name] - change + # Add more events to capture audit results + audited_params.each do |param_name| + if historical_values.include?(param_name) + if historical_values[param_name] != current_values[param_name] && !synced_params.include?(param_name) + event = create_change_event(resource.parameter(param_name), current_values[param_name], true, historical_values[param_name]) + event.send_log + events << event + end + else + resource.property(param_name).notice "audit change: newly-recorded value #{current_values[param_name]}" + end end + + events end - def copy_audited_parameters(resource, current) - return {} unless audit = resource[:audit] - audit = Array(audit).collect { |p| p.to_sym } - audited = {} - audit.find_all do |param| - if value = cached(resource, param) - audited[param] = value - else - resource.property(param).notice "audit change: newly-recorded recorded value #{current[param]}" - cache(resource, param, current[param]) - end + def create_change_event(property, current_value, do_audit, historical_value) + event = property.event + event.previous_value = current_value + event.desired_value = property.should + event.historical_value = historical_value + + if do_audit and historical_value != current_value + event.message = "audit change: previously recorded value #{property.is_to_s(historical_value)} has been changed to #{property.is_to_s(current_value)}" + event.status = "audit" + event.audited = true end - audited + event + end + + def apply_parameter(property, current_value, do_audit, historical_value) + event = create_change_event(property, current_value, do_audit, historical_value) + + if event.audited && historical_value + brief_audit_message = " (previously recorded value was #{property.is_to_s(historical_value)})" + else + brief_audit_message = "" + end + + if property.noop + event.message = "current_value #{property.is_to_s(current_value)}, should be #{property.should_to_s(property.should)} (noop)#{brief_audit_message}" + event.status = "noop" + else + property.sync + event.message = [ property.change_to_s(current_value, property.should), brief_audit_message ].join + event.status = "success" + end + event + rescue => detail + puts detail.backtrace if Puppet[:trace] + event.status = "failure" + + event.message = "change from #{property.is_to_s(current_value)} to #{property.should_to_s(property.should)} failed: #{detail}" + event + ensure + event.send_log end def evaluate(resource) start = Time.now status = Puppet::Resource::Status.new(resource) - if changes = changes_to_perform(status, resource) and ! changes.empty? - status.out_of_sync = true - status.change_count = changes.length - apply_changes(status, changes) - if ! resource.noop? - cache(resource, :synced, Time.now) - resource.flush if resource.respond_to?(:flush) - end + perform_changes(resource).each do |event| + status << event end + + if status.changed? && ! resource.noop? + cache(resource, :synced, Time.now) + resource.flush if resource.respond_to?(:flush) + end + return status rescue => detail resource.fail "Could not create resource status: #{detail}" unless status -- cgit From 4d3030c6dd67dcb1f6116e7e3d09ddcd20ee726b Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 16 Dec 2010 16:23:34 -0800 Subject: Modified the behavior of Puppet::Resource::Status as follows: - #change_count now only counts events that represent successful changes. It does not count failures, audits, or noops. - #changed is equivalent to #change_count > 0. - #out_of_sync_count (a new attribute) counts all events except audits. - #out_of_sync is equivalent to #out_of_sync_count > 0. This should hopefully make the summary statistics in reports more useful. --- lib/puppet/resource/status.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index 9240a06d7..f34edc469 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -10,7 +10,7 @@ module Puppet attr_accessor *STATES attr_reader :source_description, :default_log_level, :time, :resource - attr_reader :change_count + attr_reader :change_count, :out_of_sync_count # Provide a boolean method for each of the states. STATES.each do |attr| @@ -28,10 +28,14 @@ module Puppet @events << event if event.status == 'failure' self.failed = true + elsif event.status == 'success' + @change_count += 1 + @changed = true + end + if event.status != 'audit' + @out_of_sync_count += 1 + @out_of_sync = true end - @change_count += 1 - @changed = true - @out_of_sync = true end def events @@ -42,6 +46,7 @@ module Puppet @source_description = resource.path @resource = resource.to_s @change_count = 0 + @out_of_sync_count = 0 [:file, :line, :version].each do |attr| send(attr.to_s + "=", resource.send(attr)) -- cgit From 76fe2b3b24f6c04cd1cff7c8492d479d15258566 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 20 Dec 2010 12:17:52 -0800 Subject: Implement #5168 and #5169 ctime and mtime are properties File ctime and mtime are now implemented as read-only properties, so they can be examined with audit. --- lib/puppet/type/file.rb | 2 ++ lib/puppet/type/file/ctime.rb | 18 ++++++++++++++++++ lib/puppet/type/file/mtime.rb | 17 +++++++++++++++++ lib/puppet/type/file/type.rb | 17 +++++------------ 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 lib/puppet/type/file/ctime.rb create mode 100644 lib/puppet/type/file/mtime.rb (limited to 'lib/puppet') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 6523c99a0..eee948cd5 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -797,3 +797,5 @@ require 'puppet/type/file/group' require 'puppet/type/file/mode' require 'puppet/type/file/type' require 'puppet/type/file/selcontext' # SELinux file context +require 'puppet/type/file/ctime' +require 'puppet/type/file/mtime' diff --git a/lib/puppet/type/file/ctime.rb b/lib/puppet/type/file/ctime.rb new file mode 100644 index 000000000..24b098703 --- /dev/null +++ b/lib/puppet/type/file/ctime.rb @@ -0,0 +1,18 @@ +module Puppet + Puppet::Type.type(:file).newproperty(:ctime) do + desc "A read-only state to check the file ctime." + + def retrieve + current_value = :absent + if stat = @resource.stat(false) + current_value = stat.ctime + end + current_value + end + + validate do + fail "ctime is read-only" + end + end +end + diff --git a/lib/puppet/type/file/mtime.rb b/lib/puppet/type/file/mtime.rb new file mode 100644 index 000000000..8ca7ed0d6 --- /dev/null +++ b/lib/puppet/type/file/mtime.rb @@ -0,0 +1,17 @@ +module Puppet + Puppet::Type.type(:file).newproperty(:mtime) do + desc "A read-only state to check the file mtime." + + def retrieve + current_value = :absent + if stat = @resource.stat(false) + current_value = stat.mtime + end + current_value + end + + validate do + fail "mtime is read-only" + end + end +end diff --git a/lib/puppet/type/file/type.rb b/lib/puppet/type/file/type.rb index eb50b81f9..4da54e2cb 100755 --- a/lib/puppet/type/file/type.rb +++ b/lib/puppet/type/file/type.rb @@ -3,23 +3,16 @@ module Puppet require 'etc' desc "A read-only state to check the file type." - #munge do |value| - # raise Puppet::Error, ":type is read-only" - #end - def retrieve - currentvalue = :absent + current_value = :absent if stat = @resource.stat(false) - currentvalue = stat.ftype + current_value = stat.ftype end - # so this state is never marked out of sync - @should = [currentvalue] - currentvalue + current_value end - - def sync - raise Puppet::Error, ":type is read-only" + validate do + fail "type is read-only" end end end -- cgit From 0e39ec5bbd06dad0b59436a092c50902913d4a5a Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 11:18:35 -0800 Subject: (#5715) Removed Resource::Status#skipped_reason. It was never used. --- lib/puppet/resource/status.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index f34edc469..2bfadbd54 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -4,7 +4,7 @@ module Puppet include Puppet::Util::Tagging include Puppet::Util::Logging - attr_accessor :resource, :node, :version, :file, :line, :current_values, :skipped_reason, :status, :evaluation_time + attr_accessor :resource, :node, :version, :file, :line, :current_values, :status, :evaluation_time STATES = [:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled] attr_accessor *STATES -- cgit From 908e0e09ed94ab6b74aba3b9e4fa95318d8894ef Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 30 Dec 2010 10:45:22 -0800 Subject: (#5715) Removed the unused attribute Puppet::Transaction::Event#node --- lib/puppet/transaction/event.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index da5b14727..49c2f1a2c 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -7,7 +7,7 @@ class Puppet::Transaction::Event include Puppet::Util::Tagging include Puppet::Util::Logging - ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :node, :version, :file, :line, :source_description, :audited] + ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :version, :file, :line, :source_description, :audited] attr_accessor *ATTRIBUTES attr_writer :tags attr_accessor :time -- cgit From e596a570b2734ea27eec57a6e3a11843ccb47614 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 28 Dec 2010 17:38:57 -0800 Subject: (#5715) Removed Puppet::Util::Log#version. This attribute was only relevant in reports, and in reports it was redundant with Puppet::Transaction::Report#configuration_version and Puppet::Transaction::Report#puppet_version. --- lib/puppet/util/log.rb | 6 +++--- lib/puppet/util/log_paths.rb | 2 +- lib/puppet/util/logging.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb index 7764dc1d1..3fdac3f69 100644 --- a/lib/puppet/util/log.rb +++ b/lib/puppet/util/log.rb @@ -189,7 +189,7 @@ class Puppet::Util::Log @levels.include?(level) end - attr_accessor :time, :remote, :file, :line, :version, :source + attr_accessor :time, :remote, :file, :line, :source attr_reader :level, :message def initialize(args) @@ -203,7 +203,7 @@ class Puppet::Util::Log tags.each { |t| self.tag(t) } end - [:file, :line, :version].each do |attr| + [:file, :line].each do |attr| next unless value = args[attr] send(attr.to_s + "=", value) end @@ -234,7 +234,7 @@ class Puppet::Util::Log descriptors[:tags].each { |t| tag(t) } - [:file, :line, :version].each do |param| + [:file, :line].each do |param| next unless descriptors[param] send(param.to_s + "=", descriptors[param]) end diff --git a/lib/puppet/util/log_paths.rb b/lib/puppet/util/log_paths.rb index f59197ed1..2fefd4505 100644 --- a/lib/puppet/util/log_paths.rb +++ b/lib/puppet/util/log_paths.rb @@ -15,7 +15,7 @@ module Puppet::Util::LogPaths descriptors[:tags] = tags - [:path, :file, :line, :version].each do |param| + [:path, :file, :line].each do |param| next unless value = send(param) descriptors[param] = value end diff --git a/lib/puppet/util/logging.rb b/lib/puppet/util/logging.rb index f20444a3b..bc52b17f0 100644 --- a/lib/puppet/util/logging.rb +++ b/lib/puppet/util/logging.rb @@ -26,7 +26,7 @@ module Puppet::Util::Logging end def log_metadata - [:file, :line, :version, :tags].inject({}) do |result, attr| + [:file, :line, :tags].inject({}) do |result, attr| result[attr] = send(attr) if respond_to?(attr) result end -- cgit From 1907650515ca68e85e63c73e1a35ec30dbc81b0d Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 11:15:23 -0800 Subject: (#5715) Removed redundant attribute Resource::Status#version --- lib/puppet/resource/status.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index 2bfadbd54..43d3f1644 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -4,7 +4,7 @@ module Puppet include Puppet::Util::Tagging include Puppet::Util::Logging - attr_accessor :resource, :node, :version, :file, :line, :current_values, :status, :evaluation_time + attr_accessor :resource, :node, :file, :line, :current_values, :status, :evaluation_time STATES = [:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled] attr_accessor *STATES @@ -48,7 +48,7 @@ module Puppet @change_count = 0 @out_of_sync_count = 0 - [:file, :line, :version].each do |attr| + [:file, :line].each do |attr| send(attr.to_s + "=", resource.send(attr)) end -- cgit From 4cc42cda270cd1c04b22bf6e5452c550fb537ebf Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 11:20:46 -0800 Subject: (#5715) Removed redundant attribute Transaction::Event#version --- lib/puppet/transaction/event.rb | 2 +- lib/puppet/type.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index 49c2f1a2c..e3537bb08 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -7,7 +7,7 @@ class Puppet::Transaction::Event include Puppet::Util::Tagging include Puppet::Util::Logging - ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :version, :file, :line, :source_description, :audited] + ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :file, :line, :source_description, :audited] attr_accessor *ATTRIBUTES attr_writer :tags attr_accessor :time diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 1b6e7dcd7..ea3944b4e 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -446,7 +446,7 @@ class Type # Create a transaction event. Called by Transaction or by # a property. def event(options = {}) - Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags, :version => version}.merge(options)) + Puppet::Transaction::Event.new({:resource => self, :file => file, :line => line, :tags => tags}.merge(options)) end # Let the catalog determine whether a given cached value is -- cgit From 1550bbb218719590431575cb4c200e620680a79d Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 11:53:35 -0800 Subject: (#5715) Added total time metric to apply reports. This was a feature that was present in 0.25.x and was inadvertently dropped from 2.6.x. --- lib/puppet/transaction/report.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 8a928454f..bcdefd08d 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -149,6 +149,8 @@ class Puppet::Transaction::Report metrics[name.to_s.downcase] = value end + metrics["total"] = metrics.values.inject(0) { |a,b| a+b } + add_metric(:time, metrics) end end -- cgit From d1bcdec38e5493e1e44192eaf07da2e88b8eb850 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 12:15:26 -0800 Subject: (#5715) Removed Puppet::Transaction::Report#external_times from YAML output. This attribute was never intended to be serialized to YAML; it exists merely as temporary storage for metrics that have not yet been placed in the report's metrics attribute. --- lib/puppet/transaction/report.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index bcdefd08d..b40c856ac 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -101,6 +101,10 @@ class Puppet::Transaction::Report status end + def to_yaml_properties + (instance_variables - ["@external_times"]).sort + end + private def calculate_change_metrics -- cgit From 15dda94c7d1e117273928f094b46a81b3f842c1f Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 12:29:53 -0800 Subject: (#5715) Added total time to inspect reports and made inspect metrics more consistent. Inspect reports now contain all the metrics that apply reports do, and use the same code path for creating them. --- lib/puppet/application/inspect.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index caa32a7c2..e6c35eaeb 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -51,10 +51,8 @@ class Puppet::Application::Inspect < Puppet::Application @report.configuration_version = catalog.version - retrieval_time = Time.now - retrieval_starttime - @report.add_times("config_retrieval", retrieval_time) - - starttime = Time.now + inspect_starttime = Time.now + @report.add_times("config_retrieval", inspect_starttime - retrieval_starttime) catalog.to_ral.resources.each do |ral_resource| audited_attributes = ral_resource[:audit] @@ -70,7 +68,9 @@ class Puppet::Application::Inspect < Puppet::Application @report.add_resource_status(status) end - @report.add_metric(:time, {"config_retrieval" => retrieval_time, "inspect" => Time.now - starttime}) + finishtime = Time.now + @report.add_times("inspect", finishtime - inspect_starttime) + @report.calculate_metrics begin @report.save -- cgit From a4e40f4dd5990df4dc6b2be065e82a142a31b6fc Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 14:09:57 -0800 Subject: (#5715) Refactor in preparation for adding a status attribute to reports. Renamed Puppet::Transaction::Report#calculate_metrics to finalize_report, in preparation for adding more functionality to this method. Removed Puppet::Transaction#send_report and Puppet::Transaction#generate_report. The former was never used, and the latter was unnecessary. --- lib/puppet/application/inspect.rb | 2 +- lib/puppet/configurer.rb | 4 ++-- lib/puppet/transaction.rb | 26 -------------------------- lib/puppet/transaction/report.rb | 2 +- 4 files changed, 4 insertions(+), 30 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index e6c35eaeb..2f068a271 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -70,7 +70,7 @@ class Puppet::Application::Inspect < Puppet::Application finishtime = Time.now @report.add_times("inspect", finishtime - inspect_starttime) - @report.calculate_metrics + @report.finalize_report begin @report.save diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb index 070176554..d3c902576 100644 --- a/lib/puppet/configurer.rb +++ b/lib/puppet/configurer.rb @@ -170,8 +170,8 @@ class Puppet::Configurer send_report(report, transaction) end - def send_report(report, trans = nil) - trans.generate_report if trans + def send_report(report, trans) + report.finalize_report if trans puts report.summary if Puppet[:summarize] report.save if Puppet[:report] rescue => detail diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 4db971477..aa650eea1 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -221,12 +221,6 @@ class Puppet::Transaction end end - # Generate a transaction report. - def generate_report - @report.calculate_metrics - @report - end - # Should we ignore tags? def ignore_tags? ! (@catalog.host_config? or Puppet[:name] == "puppet") @@ -284,26 +278,6 @@ class Puppet::Transaction catalog.relationship_graph end - # Send off the transaction report. - def send_report - begin - report = generate_report - rescue => detail - Puppet.err "Could not generate report: #{detail}" - return - end - - puts report.summary if Puppet[:summarize] - - if Puppet[:report] - begin - report.save - rescue => detail - Puppet.err "Reporting failed: #{detail}" - end - end - end - def add_resource_status(status) report.add_resource_status status end diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index b40c856ac..6eac6514b 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -43,7 +43,7 @@ class Puppet::Transaction::Report @resource_statuses[status.resource] = status end - def calculate_metrics + def finalize_report calculate_resource_metrics calculate_time_metrics calculate_change_metrics -- cgit From 71db5be0ecc5ab591e01974ba109f621348fdea0 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 14:26:47 -0800 Subject: (#5715) Made the changes/total and events/total metrics always present Previously these metrics were omitted when their values were zero. --- lib/puppet/transaction/report.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 6eac6514b..16b854afc 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -46,7 +46,7 @@ class Puppet::Transaction::Report def finalize_report calculate_resource_metrics calculate_time_metrics - calculate_change_metrics + calculate_change_metric calculate_event_metrics end @@ -107,17 +107,14 @@ class Puppet::Transaction::Report private - def calculate_change_metrics - metrics = Hash.new(0) - resource_statuses.each do |name, status| - metrics[:total] += status.change_count if status.change_count - end - - add_metric(:changes, metrics) + def calculate_change_metric + total = resource_statuses.map { |name, status| status.change_count || 0 }.inject(0) { |a,b| a+b } + add_metric(:changes, {:total => total}) end def calculate_event_metrics metrics = Hash.new(0) + metrics[:total] = 0 resource_statuses.each do |name, status| metrics[:total] += status.events.length status.events.each do |event| -- cgit From e4a2e049dc9f77569a2dac042e9e847ef34f037d Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 14:35:58 -0800 Subject: (#5715) Made the report "calculate" methods strictly functional. These methods previously stored the metrics as a side effect; now they simply compute the metrics and return them. --- lib/puppet/transaction/report.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 16b854afc..f78b5aa21 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -44,10 +44,10 @@ class Puppet::Transaction::Report end def finalize_report - calculate_resource_metrics - calculate_time_metrics - calculate_change_metric - calculate_event_metrics + add_metric(:resources, calculate_resource_metrics) + add_metric(:time, calculate_time_metrics) + add_metric(:changes, {:total => calculate_change_metric}) + add_metric(:events, calculate_event_metrics) end def initialize(kind, configuration_version=nil) @@ -108,8 +108,7 @@ class Puppet::Transaction::Report private def calculate_change_metric - total = resource_statuses.map { |name, status| status.change_count || 0 }.inject(0) { |a,b| a+b } - add_metric(:changes, {:total => total}) + resource_statuses.map { |name, status| status.change_count || 0 }.inject(0) { |a,b| a+b } end def calculate_event_metrics @@ -122,7 +121,7 @@ class Puppet::Transaction::Report end end - add_metric(:events, metrics) + metrics end def calculate_resource_metrics @@ -136,7 +135,7 @@ class Puppet::Transaction::Report end end - add_metric(:resources, metrics) + metrics end def calculate_time_metrics @@ -152,6 +151,6 @@ class Puppet::Transaction::Report metrics["total"] = metrics.values.inject(0) { |a,b| a+b } - add_metric(:time, metrics) + metrics end end -- cgit From 037eac4383ed5a5e9cdde765b607a180209bad1e Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 14:49:16 -0800 Subject: (#5715) Add status attribute to reports. --- lib/puppet/transaction/report.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index f78b5aa21..6315973ba 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -11,7 +11,7 @@ class Puppet::Transaction::Report indirects :report, :terminus_class => :processor attr_accessor :configuration_version - attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind + attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind, :status # This is necessary since Marshall doesn't know how to # dump hash with default proc (see below @records) @@ -43,11 +43,23 @@ class Puppet::Transaction::Report @resource_statuses[status.resource] = status end + def compute_status(resource_metrics, change_metric) + if (resource_metrics[:failed] || 0) > 0 + 'failed' + elsif change_metric > 0 + 'changed' + else + 'unchanged' + end + end + def finalize_report - add_metric(:resources, calculate_resource_metrics) + resource_metrics = add_metric(:resources, calculate_resource_metrics) add_metric(:time, calculate_time_metrics) - add_metric(:changes, {:total => calculate_change_metric}) + change_metric = calculate_change_metric + add_metric(:changes, {:total => change_metric}) add_metric(:events, calculate_event_metrics) + @status = compute_status(resource_metrics, change_metric) end def initialize(kind, configuration_version=nil) @@ -61,6 +73,7 @@ class Puppet::Transaction::Report @report_format = 2 @puppet_version = Puppet.version @configuration_version = configuration_version + @status = 'failed' # assume failed until the report is finalized end def name -- cgit From 716ee1cd76a2b30c10e715bca3e22896d9c4e36f Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 29 Dec 2010 15:33:14 -0800 Subject: (#5715) Changed the type of metric names to always be strings. --- lib/puppet/transaction/report.rb | 16 ++++++++-------- lib/puppet/util/metric.rb | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 6315973ba..8e04759ad 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -44,7 +44,7 @@ class Puppet::Transaction::Report end def compute_status(resource_metrics, change_metric) - if (resource_metrics[:failed] || 0) > 0 + if (resource_metrics["failed"] || 0) > 0 'failed' elsif change_metric > 0 'changed' @@ -57,7 +57,7 @@ class Puppet::Transaction::Report resource_metrics = add_metric(:resources, calculate_resource_metrics) add_metric(:time, calculate_time_metrics) change_metric = calculate_change_metric - add_metric(:changes, {:total => change_metric}) + add_metric(:changes, {"total" => change_metric}) add_metric(:events, calculate_event_metrics) @status = compute_status(resource_metrics, change_metric) end @@ -109,8 +109,8 @@ class Puppet::Transaction::Report # individual bits represent the presence of different metrics. def exit_status status = 0 - status |= 2 if @metrics["changes"][:total] > 0 - status |= 4 if @metrics["resources"][:failed] > 0 + status |= 2 if @metrics["changes"]["total"] > 0 + status |= 4 if @metrics["resources"]["failed"] > 0 status end @@ -126,9 +126,9 @@ class Puppet::Transaction::Report def calculate_event_metrics metrics = Hash.new(0) - metrics[:total] = 0 + metrics["total"] = 0 resource_statuses.each do |name, status| - metrics[:total] += status.events.length + metrics["total"] += status.events.length status.events.each do |event| metrics[event.status] += 1 end @@ -139,12 +139,12 @@ class Puppet::Transaction::Report def calculate_resource_metrics metrics = Hash.new(0) - metrics[:total] = resource_statuses.length + metrics["total"] = resource_statuses.length resource_statuses.each do |name, status| Puppet::Resource::Status::STATES.each do |state| - metrics[state] += 1 if status.send(state) + metrics[state.to_s] += 1 if status.send(state) end end diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb index 8f55e7b44..09bbb6137 100644 --- a/lib/puppet/util/metric.rb +++ b/lib/puppet/util/metric.rb @@ -132,6 +132,7 @@ class Puppet::Util::Metric end def newvalue(name,value,label = nil) + raise ArgumentError.new("metric name #{name.inspect} is not a string") unless name.is_a? String label ||= labelize(name) @values.push [name,label,value] end -- cgit From bd4a8a13a85e6d64c987765cb83b1ebd4a63a341 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Wed, 29 Dec 2010 16:00:23 -0800 Subject: (#5715) Make certain report attributes always present. The attributes Puppet::Resource::Status#changed, Puppet::Resource::Status#out_of_sync, and Puppet::Transaction::Event#audited used to only appear in reports when their state was true. Now they appear always. --- lib/puppet/resource/status.rb | 2 ++ lib/puppet/transaction/event.rb | 1 + 2 files changed, 3 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index 43d3f1644..b138c6520 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -47,6 +47,8 @@ module Puppet @resource = resource.to_s @change_count = 0 @out_of_sync_count = 0 + @changed = false + @out_of_sync = false [:file, :line].each do |attr| send(attr.to_s + "=", resource.send(attr)) diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index e3537bb08..b9fa5c38b 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -16,6 +16,7 @@ class Puppet::Transaction::Event EVENT_STATUSES = %w{noop success failure audit} def initialize(*args) + @audited = false options = args.last.is_a?(Hash) ? args.pop : ATTRIBUTES.inject({}) { |hash, attr| hash[attr] = args.pop; hash } options.each { |attr, value| send(attr.to_s + "=", value) unless value.nil? } -- cgit From 98db2da4e9b35f6260bf07c641550b380b603baa Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 30 Dec 2010 11:01:23 -0800 Subject: (#5715) Removed unnecessary attributes from YAML of Puppet::Transaction::Event. The removed attributes are file, line, resource, tags, source_description, and default_log_level. These attributes were all redundant with those in Puppet::Resource::Status. --- lib/puppet/transaction/event.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index b9fa5c38b..64980f1d9 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -8,6 +8,7 @@ class Puppet::Transaction::Event include Puppet::Util::Logging ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :file, :line, :source_description, :audited] + YAML_ATTRIBUTES = %w{@audited @property @previous_value @desired_value @historical_value @message @name @status @time} attr_accessor *ATTRIBUTES attr_writer :tags attr_accessor :time @@ -47,6 +48,10 @@ class Puppet::Transaction::Event message end + def to_yaml_properties + (YAML_ATTRIBUTES & instance_variables).sort + end + private # If it's a failure, use 'err', else use either the resource's log level (if available) -- cgit From a6cd736379d37c5ca205d74d8a957a6c79f95548 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 30 Dec 2010 11:18:57 -0800 Subject: (#5715) Removed attribute source_description from the YAML representation of Puppet::Resource::Status. This attribute is only used for properly generating log messages and was never intended to appear in reports. --- lib/puppet/resource/status.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index b138c6520..1108aa611 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -12,6 +12,8 @@ module Puppet attr_reader :source_description, :default_log_level, :time, :resource attr_reader :change_count, :out_of_sync_count + YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed} + # Provide a boolean method for each of the states. STATES.each do |attr| define_method("#{attr}?") do @@ -59,6 +61,10 @@ module Puppet @events = [] end + def to_yaml_properties + (YAML_ATTRIBUTES & instance_variables).sort + end + private def log_source -- cgit From 1f72c31f9e0223e71e2729da96e0e98ebea5417e Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 30 Dec 2010 11:26:30 -0800 Subject: (#5715) Added attributes resource_type and title to Puppet::Resource::Status. These new attributes save report processors from having to parse the "resource" attribute. --- lib/puppet/resource/status.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index 1108aa611..ee83004bb 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -10,9 +10,9 @@ module Puppet attr_accessor *STATES attr_reader :source_description, :default_log_level, :time, :resource - attr_reader :change_count, :out_of_sync_count + attr_reader :change_count, :out_of_sync_count, :resource_type, :title - YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed} + YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title} # Provide a boolean method for each of the states. STATES.each do |attr| @@ -59,6 +59,8 @@ module Puppet tag(*resource.tags) @time = Time.now @events = [] + @resource_type = resource.type.to_s.capitalize + @title = resource.title end def to_yaml_properties -- cgit From 06a8d1ee8775ba8693ced002f5972bbfc346ebf8 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Tue, 28 Dec 2010 17:18:55 -0800 Subject: Fix #5698 puppet inspect shouldn't report of attributes of deleted files If a resource is absent, then reporting that its properties are all ":absent" is not particularly correct. This patch makes the `inspect` application's reports behave more like `apply` reports, and skip properties other than :ensure for absent resources. Reviewed-By: Nick Lewis --- lib/puppet/application/inspect.rb | 8 ++++++-- lib/puppet/reports/http.rb | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index caa32a7c2..342b8daae 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -64,8 +64,12 @@ class Puppet::Application::Inspect < Puppet::Application status = Puppet::Resource::Status.new(ral_resource) audited_attributes.each do |name| - event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}") - status.add_event(event) + next if audited_resource[name].nil? + # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW + if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent + event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}") + status.add_event(event) + end end @report.add_resource_status(status) end diff --git a/lib/puppet/reports/http.rb b/lib/puppet/reports/http.rb index 7ac54dfbd..101c8e0cb 100644 --- a/lib/puppet/reports/http.rb +++ b/lib/puppet/reports/http.rb @@ -15,7 +15,7 @@ Puppet::Reports.register_report(:http) do req = Net::HTTP::Post.new(url.path) req.body = self.to_yaml req.content_type = "application/x-yaml" - Net::HTTP.new(url.host, url.port).start {|http| + p Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } end -- cgit From e162da905549002d31eb9ff159406cec8b659046 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 3 Jan 2011 15:45:41 -0800 Subject: Prep work for #5758: clean up initializer for Puppet::Transaction::Event Puppet::Transaction::Event#initialize() contained unnecessary code that allowed the properties of an event to be passed in as separate arguments. This was never used. Paired-with: Matt Robinson --- lib/puppet/transaction/event.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index 64980f1d9..cd695cff8 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -16,10 +16,9 @@ class Puppet::Transaction::Event EVENT_STATUSES = %w{noop success failure audit} - def initialize(*args) + def initialize(options = {}) @audited = false - options = args.last.is_a?(Hash) ? args.pop : ATTRIBUTES.inject({}) { |hash, attr| hash[attr] = args.pop; hash } - options.each { |attr, value| send(attr.to_s + "=", value) unless value.nil? } + options.each { |attr, value| send(attr.to_s + "=", value) } @time = Time.now end -- cgit From de85f8d598606fc4fcce59228f5cb6d2715e66b5 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 3 Jan 2011 15:47:15 -0800 Subject: Prep work for #5758: set audited=true on all audit events Previously, events would only have audited=true if auditing was enabled AND there had been a change in an audited parameter. Paired-with: Matt Robinson --- lib/puppet/transaction/resource_harness.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index cb9a193b9..c259d3e05 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -84,10 +84,12 @@ class Puppet::Transaction::ResourceHarness event.desired_value = property.should event.historical_value = historical_value - if do_audit and historical_value != current_value - event.message = "audit change: previously recorded value #{property.is_to_s(historical_value)} has been changed to #{property.is_to_s(current_value)}" - event.status = "audit" + if do_audit event.audited = true + event.status = "audit" + if historical_value != current_value + event.message = "audit change: previously recorded value #{property.is_to_s(historical_value)} has been changed to #{property.is_to_s(current_value)}" + end end event @@ -96,7 +98,7 @@ class Puppet::Transaction::ResourceHarness def apply_parameter(property, current_value, do_audit, historical_value) event = create_change_event(property, current_value, do_audit, historical_value) - if event.audited && historical_value + if do_audit && historical_value && historical_value != current_value brief_audit_message = " (previously recorded value was #{property.is_to_s(historical_value)})" else brief_audit_message = "" -- cgit From 7661ba82a3c765d4bf8a400a3c770f351c541f96 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 3 Jan 2011 16:28:24 -0800 Subject: maint: Prune #inspect methods on various objects Ruby's default #inspect method can lead to printing factorial-order output for large graphs of objects. Since we have large graphs of objects, this is not optimal. This patch replaces a few well-connected objects' #inspect methods with methods that produce reduced output, and are thus much faster. Paired-With: Nick Lewis --- lib/puppet/parser/ast.rb | 4 ++++ lib/puppet/relationship.rb | 4 ++++ lib/puppet/resource.rb | 4 ++++ lib/puppet/resource/type_collection.rb | 4 ++++ lib/puppet/simple_graph.rb | 4 ++++ 5 files changed, 20 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 54e034acb..a5aaeddc4 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -19,6 +19,10 @@ class Puppet::Parser::AST attr_accessor :parent, :scope + def inspect + "( #{self.class} #{self.to_s} #{@children.inspect} )" + end + # don't fetch lexer comment by default def use_docs self.class.use_docs diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb index 7079fb44b..08d7d042b 100644 --- a/lib/puppet/relationship.rb +++ b/lib/puppet/relationship.rb @@ -71,6 +71,10 @@ class Puppet::Relationship "#{source} => #{target}" end + def inspect + "{ #{source} => #{target} }" + end + def to_pson_data_hash data = { 'source' => source.to_s, diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 4f0d50750..b0a3ecee6 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -46,6 +46,10 @@ class Puppet::Resource resource end + def inspect + "#{@type}[#{@title}]#{to_hash.inspect}" + end + def to_pson_data_hash data = ([:type, :title, :tags] + ATTRIBUTES).inject({}) do |hash, param| next hash unless value = self.send(param) diff --git a/lib/puppet/resource/type_collection.rb b/lib/puppet/resource/type_collection.rb index 6a03458b3..277d37b18 100644 --- a/lib/puppet/resource/type_collection.rb +++ b/lib/puppet/resource/type_collection.rb @@ -19,6 +19,10 @@ class Puppet::Resource::TypeCollection @watched_files = {} end + def inspect + "TypeCollection" + { :hostclasses => @hostclasses.keys, :definitions => @definitions.keys, :nodes => @nodes.keys }.inspect + end + def <<(thing) add(thing) self diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb index 55b39fadf..c5dac0f6c 100644 --- a/lib/puppet/simple_graph.rb +++ b/lib/puppet/simple_graph.rb @@ -80,6 +80,10 @@ class Puppet::SimpleGraph vertex.to_s end + def inspect + { :@adjacencies => @adjacencies, :@vertex => @vertex.to_s }.inspect + end + private # These methods exist so we don't need a Hash with a default proc. -- cgit From 7603b055d10810a901b6e0f9d9de89e00b842058 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 3 Jan 2011 17:27:14 -0800 Subject: maint: remove stray debug statement. I accidentally committed a debug statement. Now I am removing it. --- lib/puppet/reports/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/reports/http.rb b/lib/puppet/reports/http.rb index 101c8e0cb..7ac54dfbd 100644 --- a/lib/puppet/reports/http.rb +++ b/lib/puppet/reports/http.rb @@ -15,7 +15,7 @@ Puppet::Reports.register_report(:http) do req = Net::HTTP::Post.new(url.path) req.body = self.to_yaml req.content_type = "application/x-yaml" - p Net::HTTP.new(url.host, url.port).start {|http| + Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } end -- cgit From 4c9eca1cab3caae8050807fc71b24408fce85e69 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 6 Jan 2011 10:55:21 -0800 Subject: Maint: Added "skipped" to the YAML output for Puppet::Resource::Status In 2.6.4 and earlier, "skipped" appeared only when true. A recent change accidentally caused it to never appear. This change makes it always appear. --- lib/puppet/resource/status.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index ee83004bb..a9a64425e 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -12,7 +12,7 @@ module Puppet attr_reader :source_description, :default_log_level, :time, :resource attr_reader :change_count, :out_of_sync_count, :resource_type, :title - YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title} + YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title @skipped} # Provide a boolean method for each of the states. STATES.each do |attr| @@ -51,6 +51,7 @@ module Puppet @out_of_sync_count = 0 @changed = false @out_of_sync = false + @skipped = false [:file, :line].each do |attr| send(attr.to_s + "=", resource.send(attr)) -- cgit From df653045aee21ae53e0e94d47e0edbdaf308fbf5 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Thu, 6 Jan 2011 11:24:18 -0800 Subject: maint: Inspect reports should have audited = true on events Paired-with: Jesse Wolfe --- lib/puppet/application/inspect.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index c7be893c7..07ee4c317 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -65,7 +65,13 @@ class Puppet::Application::Inspect < Puppet::Application next if audited_resource[name].nil? # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent - event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}") + event = ral_resource.event( + :previous_value => audited_resource[name], + :property => name, + :status => "audit", + :audited => true, + :message => "inspected value is #{audited_resource[name].inspect}" + ) status.add_event(event) end end -- cgit From 8aa8b9dbc2437cea8109e4d272018437afe13794 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 6 Jan 2011 17:39:03 -0800 Subject: (#5799) Simplify report dir creation This report processor was unnecessarily using Puppet to create a single directory. This was causing complex failures in any spec dealing with reports. Paired-With: Paul Berry --- lib/puppet/reports/store.rb | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb index 30f24591c..99a9fc177 100644 --- a/lib/puppet/reports/store.rb +++ b/lib/puppet/reports/store.rb @@ -8,24 +8,6 @@ Puppet::Reports.register_report(:store) do to perform some maintenance on them if you use this report (it's the only default report)." - def mkclientdir(client, dir) - config = Puppet::Util::Settings.new - - config.setdefaults( - "reportclient-#{client}".to_sym, - "client-#{client}-dir" => { :default => dir, - :mode => 0750, - :desc => "Client dir for #{client}", - :owner => 'service', - :group => 'service' - }, - - :noop => [false, "Used by settings internally."] - ) - - config.use("reportclient-#{client}".to_sym) - end - def process # We don't want any tracking back in the fs. Unlikely, but there # you go. @@ -33,7 +15,7 @@ Puppet::Reports.register_report(:store) do dir = File.join(Puppet[:reportdir], client) - mkclientdir(client, dir) unless FileTest.exists?(dir) + Dir.mkdir(dir, 0750) unless FileTest.exists?(dir) # Now store the report. now = Time.now.gmtime -- cgit From 8f314f2bb14d61a2a26b67d002d90f84349b25b5 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 7 Jan 2011 15:39:52 -0800 Subject: (#5710) Removed unnecessary calls to insync? In the resource harness, we were calling insync? on all properties of a resource, even if those properties weren't being managed. This was unsafe. Changed to only call insync? on properties that are mentioned in the manifest. In addition, we discovered that the resource harness's computation of desired_values was incorrect, and was consulting the current system state rather than the desired state. Since this hash was (erroneously) only being consulted to see if it included :ensure, this didn't cause any obvious bugs. However it is now fixed. Paired-with: Jesse Wolfe --- lib/puppet/transaction/resource_harness.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index c259d3e05..c1b980632 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -37,7 +37,10 @@ class Puppet::Transaction::ResourceHarness current_values = current.to_hash historical_values = Puppet::Util::Storage.cache(resource).dup - desired_values = resource.to_resource.to_hash + desired_values = {} + resource.properties.each do |property| + desired_values[property.name] = property.should + end audited_params = (resource[:audit] || []).map { |p| p.to_sym } synced_params = [] @@ -55,7 +58,7 @@ class Puppet::Transaction::ResourceHarness elsif current_values[:ensure] != :absent work_order = resource.properties # Note: only the resource knows what order to apply changes in work_order.each do |param| - if !param.insync?(current_values[param.name]) + if desired_values[param.name] && !param.insync?(current_values[param.name]) events << apply_parameter(param, current_values[param.name], audited_params.include?(param.name), historical_values[param.name]) synced_params << param.name end -- cgit From a002231f45339da9b152162c2f48126d95e2e246 Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 10 Jan 2011 18:30:42 -0800 Subject: (#5171) Made filebucket able to perform diffs It is now possible to ask the filebucket to diff two files using a URL of the form: https://puppet/production/file_bucket_file/md5/{first file hash}?diff_with={second file hash} The returned diff is a string, the output of the "diff" command. Paired-with: Paul Berry --- lib/puppet/indirector/file_bucket_file/file.rb | 11 ++++++++++- lib/puppet/indirector/indirection.rb | 2 +- lib/puppet/network/http/handler.rb | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb index 318858aaf..9d9cee793 100644 --- a/lib/puppet/indirector/file_bucket_file/file.rb +++ b/lib/puppet/indirector/file_bucket_file/file.rb @@ -15,7 +15,16 @@ module Puppet::FileBucketFile def find( request ) checksum, path = request_to_checksum_and_path( request ) - find_by_checksum( checksum, request.options ) + file = find_by_checksum( checksum, request.options ) + + if file && request.options[:diff_with] + hash_protocol = sumtype(checksum) + file2 = find_by_checksum( "{#{hash_protocol}}#{request.options[:diff_with]}", request.options ) + raise "could not find diff_with #{request.options[:diff_with]}" unless file2 + return `diff #{path_for(file).inspect}/contents #{path_for(file2).inspect}/contents` + end + + file end def save( request ) diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 309eed7b6..a010c4e40 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -191,7 +191,7 @@ class Puppet::Indirector::Indirection # Otherwise, return the result from the terminus, caching if appropriate. if ! request.ignore_terminus? and result = terminus.find(request) - result.expiration ||= self.expiration + result.expiration ||= self.expiration if result.respond_to?(:expiration) if cache? and request.use_cache? Puppet.info "Caching #{self.name} for #{request.key}" cache.save request(:save, result, *args) diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index 61ae2d2fc..f22498b70 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -109,7 +109,11 @@ module Puppet::Network::HTTP::Handler format = format_to_use(request) set_content_type(response, format) - set_response(response, result.render(format)) + if result.respond_to?(:render) + set_response(response, result.render(format)) + else + set_response(response, result) + end end # Execute our search. -- cgit From 87c5c30fe8d2bbc31dabeb7383f5e5703a732bc5 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Tue, 11 Jan 2011 20:00:32 -0600 Subject: (#5910) Improved logging when declared classes cannot be found: Previously, when a class could not be found, it was displaying the same error message as when a resource type could not be found. This resulted in confusing error message: Invalid resource type class, when really it should display the name of the class that could not be found. My patch changes the error message to: Could not find declared class #{title} --- lib/puppet/resource.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb index 4f0d50750..6821e0e06 100644 --- a/lib/puppet/resource.rb +++ b/lib/puppet/resource.rb @@ -201,8 +201,13 @@ class Puppet::Resource tag(self.title) if valid_tag?(self.title) @reference = Reference.new(@type,@title) # for serialization compatibility with 0.25.x - - raise ArgumentError, "Invalid resource type #{type}" if strict? and ! resource_type + if strict? and ! resource_type + if @type == 'Class' + raise ArgumentError, "Could not find declared class #{title}" + else + raise ArgumentError, "Invalid resource type #{type}" + end + end end def ref -- cgit From 08561b22920aa5eaa76addd8b0da8feb189e0d18 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 11 Jan 2011 14:56:14 -0800 Subject: (#5838) Refactored Puppet::Network::Rights#fail_on_deny Changed into a method that returns the exception to raised rather than raising it. Paired-with: Jesse Wolfe --- lib/puppet/network/rest_authconfig.rb | 18 ++++++++++-------- lib/puppet/network/rights.rb | 20 +++++--------------- 2 files changed, 15 insertions(+), 23 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/network/rest_authconfig.rb b/lib/puppet/network/rest_authconfig.rb index 7abe06956..1704ea0c1 100644 --- a/lib/puppet/network/rest_authconfig.rb +++ b/lib/puppet/network/rest_authconfig.rb @@ -38,14 +38,16 @@ module Puppet # fail_on_deny could as well be called in the XMLRPC context # with a ClientRequest. - @rights.fail_on_deny( - build_uri(request), - - :node => request.node, - :ip => request.ip, - :method => request.method, - :environment => request.environment, - :authenticated => request.authenticated) + if authorization_failure_exception = @rights.is_forbidden_and_why?( + build_uri(request), + :node => request.node, + :ip => request.ip, + :method => request.method, + :environment => request.environment, + :authenticated => request.authenticated) + Puppet.warning("Denying access: #{authorization_failure_exception}") + raise authorization_failure_exception + end end def initialize(file = nil, parsenow = true) diff --git a/lib/puppet/network/rights.rb b/lib/puppet/network/rights.rb index e3cd3179a..b2146494c 100755 --- a/lib/puppet/network/rights.rb +++ b/lib/puppet/network/rights.rb @@ -26,19 +26,10 @@ class Rights # Check that name is allowed or not def allowed?(name, *args) - begin - fail_on_deny(name, :node => args[0], :ip => args[1]) - rescue AuthorizationError - return false - rescue ArgumentError - # the namespace contract says we should raise this error - # if we didn't find the right acl - raise - end - true + !is_forbidden_and_why?(name, :node => args[0], :ip => args[1]) end - def fail_on_deny(name, args = {}) + def is_forbidden_and_why?(name, args = {}) res = :nomatch right = @rights.find do |acl| found = false @@ -49,7 +40,7 @@ class Rights args[:match] = match if (res = acl.allowed?(args[:node], args[:ip], args)) != :dunno # return early if we're allowed - return if res + return nil if res # we matched, select this acl found = true end @@ -70,13 +61,12 @@ class Rights error.file = right.file error.line = right.line end - Puppet.warning("Denying access: #{error}") else # there were no rights allowing/denying name # if name is not a path, let's throw - error = ArgumentError.new "Unknown namespace right '#{name}'" + raise ArgumentError.new "Unknown namespace right '#{name}'" end - raise error + error end def initialize -- cgit From 2b9b7a5f7fe4b673f0d1fba9fb523cc0e2e34fa5 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 10 Jan 2011 14:17:14 -0800 Subject: (#5838) Refactored error handling logic into find_in_cache. Moved the error handling logic surrounding the call to Puppet::Indirector::Indirection#find_in_cache() into the find_in_cache() method itself, so that won't need to be duplicated when find_in_cache() is called from elsewhere. Paired-with: Jesse Wolfe --- lib/puppet/indirector/indirection.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index a010c4e40..4341f7cb2 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -180,13 +180,8 @@ class Puppet::Indirector::Indirection request = request(:find, key, *args) terminus = prepare(request) - begin - if result = find_in_cache(request) - return result - end - rescue => detail - puts detail.backtrace if Puppet[:trace] - Puppet.err "Cached #{self.name} for #{request.key} failed: #{detail}" + if result = find_in_cache(request) + return result end # Otherwise, return the result from the terminus, caching if appropriate. @@ -213,6 +208,10 @@ class Puppet::Indirector::Indirection Puppet.debug "Using cached #{self.name} for #{request.key}" cached + rescue => detail + puts detail.backtrace if Puppet[:trace] + Puppet.err "Cached #{self.name} for #{request.key} failed: #{detail}" + nil end # Remove something via the terminus. -- cgit From c514c641d0c0090be29252dcc773385248d3fe93 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Mon, 10 Jan 2011 17:05:38 -0800 Subject: (#5838) Added support for HEAD requests to the indirector. Added the ability for the indirector to handle REST HEAD requests. These are done using a new indirector method, head(), which should return true if find() would return a result and false if find() would return nil. Access control for the head method is the union of that for the find and save methods. That is, if either find or save is allowed, then head is allowed. This is necessary so that users will not have to change their authconfig to take advantage of the new feature. Paired-with: Jesse Wolfe --- lib/puppet/indirector.rb | 4 ++++ lib/puppet/indirector/indirection.rb | 11 +++++++++++ lib/puppet/indirector/rest.rb | 21 +++++++++++++++++++-- lib/puppet/network/http/api/v1.rb | 3 +++ lib/puppet/network/http/handler.rb | 11 +++++++++++ lib/puppet/network/rest_authconfig.rb | 12 +----------- lib/puppet/network/rights.rb | 24 ++++++++++++++++++++++++ 7 files changed, 73 insertions(+), 13 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb index 5b737578b..e6472f4d9 100644 --- a/lib/puppet/indirector.rb +++ b/lib/puppet/indirector.rb @@ -50,6 +50,10 @@ module Puppet::Indirector indirection.find(*args) end + def head(*args) + indirection.head(*args) + end + def destroy(*args) indirection.destroy(*args) end diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 4341f7cb2..ec147ec69 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -198,6 +198,17 @@ class Puppet::Indirector::Indirection nil end + # Search for an instance in the appropriate terminus, and return a + # boolean indicating whether the instance was found. + def head(key, *args) + request = request(:head, key, *args) + terminus = prepare(request) + + # Look in the cache first, then in the terminus. Force the result + # to be a boolean. + !!(find_in_cache(request) || terminus.head(request)) + end + def find_in_cache(request) # See if our instance is in the cache and up to date. return nil unless cache? and ! request.ignore_cache? and cached = cache.find(request) diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb index eb41ff3b1..e50dc68ae 100644 --- a/lib/puppet/indirector/rest.rb +++ b/lib/puppet/indirector/rest.rb @@ -53,11 +53,15 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus end else # Raise the http error if we didn't get a 'success' of some kind. - message = "Error #{response.code} on SERVER: #{(response.body||'').empty? ? response.message : uncompress_body(response)}" - raise Net::HTTPError.new(message, response) + raise convert_to_http_error(response) end end + def convert_to_http_error(response) + message = "Error #{response.code} on SERVER: #{(response.body||'').empty? ? response.message : uncompress_body(response)}" + Net::HTTPError.new(message, response) + end + # Provide appropriate headers. def headers add_accept_encoding({"Accept" => model.supported_formats.join(", ")}) @@ -73,6 +77,19 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus result end + def head(request) + response = network(request).head(indirection2uri(request), headers) + case response.code + when "404" + return false + when /^2/ + return true + else + # Raise the http error if we didn't get a 'success' of some kind. + raise convert_to_http_error(response) + end + end + def search(request) unless result = deserialize(network(request).get(indirection2uri(request), headers), true) return [] diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb index dd4612a14..8aa1f0ee1 100644 --- a/lib/puppet/network/http/api/v1.rb +++ b/lib/puppet/network/http/api/v1.rb @@ -13,6 +13,9 @@ module Puppet::Network::HTTP::API::V1 }, "DELETE" => { :singular => :destroy + }, + "HEAD" => { + :singular => :head } } diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index f22498b70..9e9356b2f 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -116,6 +116,17 @@ module Puppet::Network::HTTP::Handler end end + # Execute our head. + def do_head(indirection_request, request, response) + unless indirection_request.model.head(indirection_request.key, indirection_request.to_hash) + Puppet.info("Could not find #{indirection_request.indirection_name} for '#{indirection_request.key}'") + return do_exception(response, "Could not find #{indirection_request.indirection_name} #{indirection_request.key}", 404) + end + + # No need to set a response because no response is expected from a + # HEAD request. All we need to do is not die. + end + # Execute our search. def do_search(indirection_request, request, response) result = indirection_request.model.search(indirection_request.key, indirection_request.to_hash) diff --git a/lib/puppet/network/rest_authconfig.rb b/lib/puppet/network/rest_authconfig.rb index 1704ea0c1..7a6147a82 100644 --- a/lib/puppet/network/rest_authconfig.rb +++ b/lib/puppet/network/rest_authconfig.rb @@ -38,13 +38,7 @@ module Puppet # fail_on_deny could as well be called in the XMLRPC context # with a ClientRequest. - if authorization_failure_exception = @rights.is_forbidden_and_why?( - build_uri(request), - :node => request.node, - :ip => request.ip, - :method => request.method, - :environment => request.environment, - :authenticated => request.authenticated) + if authorization_failure_exception = @rights.is_request_forbidden_and_why?(request) Puppet.warning("Denying access: #{authorization_failure_exception}") raise authorization_failure_exception end @@ -90,9 +84,5 @@ module Puppet end @rights.restrict_authenticated(acl[:acl], acl[:authenticated]) unless acl[:authenticated].nil? end - - def build_uri(request) - "/#{request.indirection_name}/#{request.key}" - end end end diff --git a/lib/puppet/network/rights.rb b/lib/puppet/network/rights.rb index b2146494c..00ee04f8d 100755 --- a/lib/puppet/network/rights.rb +++ b/lib/puppet/network/rights.rb @@ -29,6 +29,30 @@ class Rights !is_forbidden_and_why?(name, :node => args[0], :ip => args[1]) end + def is_request_forbidden_and_why?(request) + methods_to_check = if request.method == :head + # :head is ok if either :find or :save is ok. + [:find, :save] + else + [request.method] + end + authorization_failure_exceptions = methods_to_check.map do |method| + is_forbidden_and_why?("/#{request.indirection_name}/#{request.key}", + :node => request.node, + :ip => request.ip, + :method => method, + :environment => request.environment, + :authenticated => request.authenticated) + end + if authorization_failure_exceptions.include? nil + # One of the methods we checked is ok, therefore this request is ok. + nil + else + # Just need to return any of the failure exceptions. + authorization_failure_exceptions.first + end + end + def is_forbidden_and_why?(name, args = {}) res = :nomatch right = @rights.find do |acl| -- cgit From 89f56920f26544f7c5aa97785567b193034db151 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 11 Jan 2011 15:24:10 -0800 Subject: (#5838) Implemented the "head" method for FileBucketFile::File terminus. In order to do this it was necessary to refactor FileBucketFile to untangle responsibilities for computing paths, reading files, etc. In the process, removed speculative generalizations and unused functionality. Paired-with: Jesse Wolfe --- lib/puppet/file_bucket/dipper.rb | 2 +- lib/puppet/file_bucket/file.rb | 108 +++------------------- lib/puppet/indirector/file_bucket_file/file.rb | 121 ++++++++----------------- 3 files changed, 51 insertions(+), 180 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index dbfcdcd43..b012a8681 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -33,7 +33,7 @@ class Puppet::FileBucket::Dipper raise(ArgumentError, "File #{file} does not exist") unless ::File.exist?(file) contents = ::File.read(file) begin - file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path, :path => absolutize_path(file) ) + file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path) dest_path = "#{@rest_path}#{file_bucket_file.name}" file_bucket_file.save(dest_path) diff --git a/lib/puppet/file_bucket/file.rb b/lib/puppet/file_bucket/file.rb index 96fd8e225..08c0329f1 100644 --- a/lib/puppet/file_bucket/file.rb +++ b/lib/puppet/file_bucket/file.rb @@ -1,10 +1,9 @@ require 'puppet/file_bucket' require 'puppet/indirector' require 'puppet/util/checksums' +require 'digest/md5' class Puppet::FileBucket::File - include Puppet::Util::Checksums - # This class handles the abstract notion of a file in a filebucket. # There are mechanisms to save and load this file locally and remotely in puppet/indirector/filebucketfile/* # There is a compatibility class that emulates pre-indirector filebuckets in Puppet::FileBucket::Dipper @@ -12,71 +11,27 @@ class Puppet::FileBucket::File require 'puppet/file_bucket/file/indirection_hooks' indirects :file_bucket_file, :terminus_class => :file, :extend => Puppet::FileBucket::File::IndirectionHooks - attr :path, true - attr :paths, true - attr :contents, true - attr :checksum_type - attr :bucket_path, true - - def self.default_checksum_type - "md5" - end + attr :contents + attr :bucket_path def initialize( contents, options = {} ) - @bucket_path = options[:bucket_path] - @path = options[:path] - @paths = options[:paths] || [] - - @checksum = options[:checksum] - @checksum_type = options[:checksum_type] - - self.contents = contents - - yield(self) if block_given? - - validate! - end + raise ArgumentError if !contents.is_a?(String) + @contents = contents - def validate! - validate_checksum_type!(checksum_type) - validate_checksum!(checksum) if checksum + @bucket_path = options.delete(:bucket_path) + raise ArgumentError if options != {} end - def contents=(str) - raise "You may not change the contents of a FileBucket File" if @contents - validate_content!(str) - @contents = str + def checksum_type + 'md5' end def checksum - return @checksum if @checksum - @checksum = calculate_checksum if contents - @checksum - end - - def checksum=(checksum) - validate_checksum!(checksum) - @checksum = checksum - end - - def checksum_type=( new_checksum_type ) - @checksum = nil - @checksum_type = new_checksum_type - end - - def checksum_type - unless @checksum_type - if @checksum - @checksum_type = sumtype(checksum) - else - @checksum_type = self.class.default_checksum_type - end - end - @checksum_type + "{#{checksum_type}}#{checksum_data}" end def checksum_data - sumdata(checksum) + @checksum_data ||= Digest::MD5.hexdigest(contents) end def to_s @@ -84,18 +39,7 @@ class Puppet::FileBucket::File end def name - [checksum_type, checksum_data, path].compact.join('/') - end - - def name=(name) - data = name.split('/',3) - self.path = data.pop - @checksum_type = nil - self.checksum = "{#{data[0]}}#{data[1]}" - end - - def conflict_check? - true + "#{checksum_type}/#{checksum_data}" end def self.from_s( contents ) @@ -103,34 +47,10 @@ class Puppet::FileBucket::File end def to_pson - hash = { "contents" => contents } - hash["path"] = @path if @path - hash.to_pson + { "contents" => contents }.to_pson end def self.from_pson( pson ) - self.new( pson["contents"], :path => pson["path"] ) - end - - private - - def calculate_checksum - "{#{checksum_type}}" + send(checksum_type, contents) - end - - def validate_content!(content) - raise ArgumentError, "Contents must be a string" if content and ! content.is_a?(String) - end - - def validate_checksum!(new_checksum) - newtype = sumtype(new_checksum) - - unless sumdata(new_checksum) == (calc_sum = send(newtype, contents)) - raise Puppet::Error, "Checksum #{new_checksum} does not match contents #{calc_sum}" - end - end - - def validate_checksum_type!(type) - raise ArgumentError, "Invalid checksum type #{type}" unless respond_to?(type) + self.new( pson["contents"] ) end end diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb index 9d9cee793..38e0be6e9 100644 --- a/lib/puppet/indirector/file_bucket_file/file.rb +++ b/lib/puppet/indirector/file_bucket_file/file.rb @@ -14,25 +14,31 @@ module Puppet::FileBucketFile end def find( request ) - checksum, path = request_to_checksum_and_path( request ) - file = find_by_checksum( checksum, request.options ) + checksum = request_to_checksum( request ) + file_path = path_for(request.options[:bucket_path], checksum, 'contents') - if file && request.options[:diff_with] + return nil unless ::File.exists?(file_path) + + if request.options[:diff_with] hash_protocol = sumtype(checksum) - file2 = find_by_checksum( "{#{hash_protocol}}#{request.options[:diff_with]}", request.options ) - raise "could not find diff_with #{request.options[:diff_with]}" unless file2 - return `diff #{path_for(file).inspect}/contents #{path_for(file2).inspect}/contents` + file2_path = path_for(request.options[:bucket_path], request.options[:diff_with], 'contents') + raise "could not find diff_with #{request.options[:diff_with]}" unless ::File.exists?(file2_path) + return `diff #{file_path.inspect} #{file2_path.inspect}` + else + contents = ::File.read file_path + Puppet.info "FileBucket read #{checksum}" + model.new(contents) end + end - file + def head(request) + checksum = request_to_checksum(request) + file_path = path_for(request.options[:bucket_path], checksum, 'contents') + ::File.exists?(file_path) end def save( request ) - checksum, path = request_to_checksum_and_path( request ) - instance = request.instance - instance.checksum = checksum if checksum - instance.path = path if path save_to_disk(instance) instance.to_s @@ -40,66 +46,41 @@ module Puppet::FileBucketFile private - def find_by_checksum( checksum, options ) - model.new( nil, :checksum => checksum ) do |bucket_file| - bucket_file.bucket_path = options[:bucket_path] - filename = contents_path_for( bucket_file ) - - return nil if ! ::File.exist? filename - - begin - contents = ::File.read filename - Puppet.info "FileBucket read #{bucket_file.checksum}" - rescue RuntimeError => e - raise Puppet::Error, "file could not be read: #{e.message}" - end - - if ::File.exist?(paths_path_for( bucket_file) ) - ::File.open(paths_path_for( bucket_file) ) do |f| - bucket_file.paths = f.readlines.map { |l| l.chomp } - end - end - - bucket_file.contents = contents - end - end - def save_to_disk( bucket_file ) - # If the file already exists, just return the md5 sum. - if ::File.exist?(contents_path_for( bucket_file) ) + filename = path_for(bucket_file.bucket_path, bucket_file.checksum_data, 'contents') + dirname = path_for(bucket_file.bucket_path, bucket_file.checksum_data) + + # If the file already exists, do nothing. + if ::File.exist?(filename) verify_identical_file!(bucket_file) else # Make the directories if necessary. - unless ::File.directory?( path_for( bucket_file) ) + unless ::File.directory?(dirname) Puppet::Util.withumask(0007) do - ::FileUtils.mkdir_p( path_for( bucket_file) ) + ::FileUtils.mkdir_p(dirname) end end - Puppet.info "FileBucket adding #{bucket_file.path} as #{bucket_file.checksum}" + Puppet.info "FileBucket adding #{bucket_file.checksum}" # Write the file to disk. Puppet::Util.withumask(0007) do - ::File.open(contents_path_for(bucket_file), ::File::WRONLY|::File::CREAT, 0440) do |of| + ::File.open(filename, ::File::WRONLY|::File::CREAT, 0440) do |of| of.print bucket_file.contents end end end - - save_path_to_paths_file(bucket_file) - bucket_file.checksum_data end - def request_to_checksum_and_path( request ) - return [request.key, nil] if checksum?(request.key) - - checksum_type, checksum, path = request.key.split(/\//, 3) - return(checksum_type.to_s == "" ? nil : [ "{#{checksum_type}}#{checksum}", path ]) + def request_to_checksum( request ) + checksum_type, checksum = request.key.split(/\//, 2) + raise "Unsupported checksum type #{checksum_type.inspect}" if checksum_type != 'md5' + raise "Invalid checksum #{checksum.inspect}" if checksum !~ /^[0-9a-f]{32}$/ + checksum end - def path_for(bucket_file, subfile = nil) - bucket_path = bucket_file.bucket_path || Puppet[:bucketdir] - digest = bucket_file.checksum_data + def path_for(bucket_path, digest, subfile = nil) + bucket_path ||= Puppet[:bucketdir] dir = ::File.join(digest[0..7].split("")) basedir = ::File.join(bucket_path, dir, digest) @@ -108,48 +89,18 @@ module Puppet::FileBucketFile ::File.join(basedir, subfile) end - def contents_path_for(bucket_file) - path_for(bucket_file, "contents") - end - - def paths_path_for(bucket_file) - path_for(bucket_file, "paths") - end - - def content_check? - true - end - # If conflict_check is enabled, verify that the passed text is # the same as the text in our file. def verify_identical_file!(bucket_file) - return unless content_check? - disk_contents = ::File.read(contents_path_for(bucket_file)) + disk_contents = ::File.read(path_for(bucket_file.bucket_path, bucket_file.checksum_data, 'contents')) # If the contents don't match, then we've found a conflict. # Unlikely, but quite bad. if disk_contents != bucket_file.contents - raise Puppet::FileBucket::BucketError, "Got passed new contents for sum #{bucket_file.checksum}", caller + raise Puppet::FileBucket::BucketError, "Got passed new contents for sum #{bucket_file.checksum}" else - Puppet.info "FileBucket got a duplicate file #{bucket_file.path} (#{bucket_file.checksum})" + Puppet.info "FileBucket got a duplicate file #{bucket_file.checksum}" end end - - def save_path_to_paths_file(bucket_file) - return unless bucket_file.path - - # check for dupes - if ::File.exist?(paths_path_for( bucket_file) ) - ::File.open(paths_path_for( bucket_file) ) do |f| - return if f.readlines.collect { |l| l.chomp }.include?(bucket_file.path) - end - end - - # if it's a new file, or if our path isn't in the file yet, add it - ::File.open(paths_path_for(bucket_file), ::File::WRONLY|::File::CREAT|::File::APPEND) do |of| - of.puts bucket_file.path - end - end - end end -- cgit From 94d71799f1ee196186bc3a8a5a1b06ef2ae0806e Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 11 Jan 2011 13:45:55 -0800 Subject: (#5838) Make file bucket dipper efficient when saving a file that already exists Before saving to the file bucket, the file bucket dipper now checks to make sure that no file with the given checksum is already present. Paired-with: Jesse Wolfe --- lib/puppet/file_bucket/dipper.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb index b012a8681..f4bef28a8 100644 --- a/lib/puppet/file_bucket/dipper.rb +++ b/lib/puppet/file_bucket/dipper.rb @@ -36,7 +36,12 @@ class Puppet::FileBucket::Dipper file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path) dest_path = "#{@rest_path}#{file_bucket_file.name}" - file_bucket_file.save(dest_path) + # Make a HEAD request for the file so that we don't waste time + # uploading it if it already exists in the bucket. + unless Puppet::FileBucket::File.head("#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}") + file_bucket_file.save(dest_path) + end + return file_bucket_file.checksum_data rescue => detail puts detail.backtrace if Puppet[:trace] -- cgit From abc62560f78fa227d6ffd3263a095665609a15b5 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Wed, 12 Jan 2011 15:41:39 -0800 Subject: (#5838) Support paths as part of file bucket requests. In versions of Puppet 2.6.0-2.6.4, file bucket requests are of the form md5//. The path functionality has been removed, however we still need to support requests coming from older clients. Paired-with: Jesse Wolfe --- lib/puppet/indirector/file_bucket_file/file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb index 38e0be6e9..8bea2d767 100644 --- a/lib/puppet/indirector/file_bucket_file/file.rb +++ b/lib/puppet/indirector/file_bucket_file/file.rb @@ -73,7 +73,7 @@ module Puppet::FileBucketFile end def request_to_checksum( request ) - checksum_type, checksum = request.key.split(/\//, 2) + checksum_type, checksum, path = request.key.split(/\//, 3) # Note: we ignore path if present. raise "Unsupported checksum type #{checksum_type.inspect}" if checksum_type != 'md5' raise "Invalid checksum #{checksum.inspect}" if checksum !~ /^[0-9a-f]{32}$/ checksum -- cgit From a7cd1856f3347b6a00a260d1001252b56f54f7de Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 13 Jan 2011 14:31:51 -0800 Subject: Prep for #5171: Added a missing require to inspect application. Paired-with: Nick Lewis --- lib/puppet/application/inspect.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index 07ee4c317..f2e03b589 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -1,3 +1,4 @@ +require 'puppet' require 'puppet/application' class Puppet::Application::Inspect < Puppet::Application -- cgit From 1a6fab2aacbc1499a00a9451654073181435afa1 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 13 Jan 2011 12:18:37 -0800 Subject: (#5171) Made "puppet inspect" upload audited files to a file bucket This only occurs if the new setting :archive_files is set. Another new setting, :archive_file_server, can be used to specify the server that files should be uploaded to. Paired-with: Nick Lewis --- lib/puppet/application/inspect.rb | 11 +++++++++++ lib/puppet/defaults.rb | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index f2e03b589..b4d263545 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -1,5 +1,6 @@ require 'puppet' require 'puppet/application' +require 'puppet/file_bucket/dipper' class Puppet::Application::Inspect < Puppet::Application @@ -55,6 +56,10 @@ class Puppet::Application::Inspect < Puppet::Application inspect_starttime = Time.now @report.add_times("config_retrieval", inspect_starttime - retrieval_starttime) + if Puppet[:archive_files] + dipper = Puppet::FileBucket::Dipper.new(:Server => Puppet[:archive_file_server]) + end + catalog.to_ral.resources.each do |ral_resource| audited_attributes = ral_resource[:audit] next unless audited_attributes @@ -77,6 +82,12 @@ class Puppet::Application::Inspect < Puppet::Application end end @report.add_resource_status(status) + if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content) + path = ral_resource[:path] + if File.readable?(path) + dipper.backup(path) + end + end end finishtime = Time.now diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 4521a5901..400d59f15 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -598,6 +598,11 @@ module Puppet compression, but if it supports it, this setting might reduce performance on high-speed LANs."] ) + setdefaults(:inspect, + :archive_files => [false, "During an inspect run, whether to archive files whose contents are audited to a file bucket."], + :archive_file_server => ["$server", "During an inspect run, the file bucket server to archive files to if archive_files is set."] + ) + # Plugin information. setdefaults( -- cgit From 17843d5e86a8841728a77c77d5f2ea4661c0f417 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 13 Jan 2011 16:03:41 -0800 Subject: (#5882) Added error-handling to puppet inspect when auditing If auditing a resource fails, the report will contain failure events for every audited property of the resource. The report itself will also be marked as "failed". Paired-With: Paul Berry --- lib/puppet/application/inspect.rb | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index b4d263545..5254afbd0 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -64,30 +64,45 @@ class Puppet::Application::Inspect < Puppet::Application audited_attributes = ral_resource[:audit] next unless audited_attributes - audited_resource = ral_resource.to_resource - status = Puppet::Resource::Status.new(ral_resource) - audited_attributes.each do |name| - next if audited_resource[name].nil? - # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW - if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent + + begin + audited_resource = ral_resource.to_resource + rescue StandardError => detail + puts detail.backtrace if Puppet[:trace] + ral_resource.err "Could not inspect #{ral_resource}; skipping: #{detail}" + audited_attributes.each do |name| event = ral_resource.event( - :previous_value => audited_resource[name], - :property => name, - :status => "audit", - :audited => true, - :message => "inspected value is #{audited_resource[name].inspect}" + :property => name, + :status => "failure", + :audited => true, + :message => "failed to inspect #{name}" ) status.add_event(event) end + else + audited_attributes.each do |name| + next if audited_resource[name].nil? + # Skip :absent properties of :absent resources. Really, it would be nicer if the RAL returned nil for those, but it doesn't. ~JW + if name == :ensure or audited_resource[:ensure] != :absent or audited_resource[name] != :absent + event = ral_resource.event( + :previous_value => audited_resource[name], + :property => name, + :status => "audit", + :audited => true, + :message => "inspected value is #{audited_resource[name].inspect}" + ) + status.add_event(event) + end + end end - @report.add_resource_status(status) if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content) path = ral_resource[:path] if File.readable?(path) dipper.backup(path) end end + @report.add_resource_status(status) end finishtime = Time.now -- cgit From 79b633220376bf0503f926b9371283cece17a9e6 Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Thu, 13 Jan 2011 16:57:01 -0800 Subject: (#5882) Added error-handling for bucketing files in puppet inspect Paired-With: Paul Berry --- lib/puppet/application/inspect.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/inspect.rb b/lib/puppet/application/inspect.rb index 5254afbd0..77e8476a2 100644 --- a/lib/puppet/application/inspect.rb +++ b/lib/puppet/application/inspect.rb @@ -99,7 +99,11 @@ class Puppet::Application::Inspect < Puppet::Application if Puppet[:archive_files] and ral_resource.type == :file and audited_attributes.include?(:content) path = ral_resource[:path] if File.readable?(path) - dipper.backup(path) + begin + dipper.backup(path) + rescue StandardError => detail + Puppet.warning detail + end end end @report.add_resource_status(status) -- cgit From f9bfb968fac70eca9fe29bbd8afbcabfa1c27b9e Mon Sep 17 00:00:00 2001 From: Nick Lewis Date: Fri, 14 Jan 2011 10:55:05 -0800 Subject: (#5900) Include ResourceStatus#failed in serialized reports This property was excluded from serialization because it was believed that its value could be determined by looking at the events of a ResourceStatus. However, if a resource can't be retrieved, it will have no events created, and will have no other way of determining its status. Reviewed-By: Paul Berry --- lib/puppet/resource/status.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/status.rb b/lib/puppet/resource/status.rb index a9a64425e..dea8c105d 100644 --- a/lib/puppet/resource/status.rb +++ b/lib/puppet/resource/status.rb @@ -12,7 +12,7 @@ module Puppet attr_reader :source_description, :default_log_level, :time, :resource attr_reader :change_count, :out_of_sync_count, :resource_type, :title - YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title @skipped} + YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title @skipped @failed} # Provide a boolean method for each of the states. STATES.each do |attr| @@ -52,6 +52,7 @@ module Puppet @changed = false @out_of_sync = false @skipped = false + @failed = false [:file, :line].each do |attr| send(attr.to_s + "=", resource.send(attr)) -- cgit From c1b5c7f515a0add663fb532859d91e28ef37a971 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 16 Jan 2011 14:27:24 -0800 Subject: (#5913) Fix Puppet::Application.find constant lookup behavior Puppet::Application.find now only looks in the Puppet::Application namespace for the given constant. --- lib/puppet/application.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index f0159a65d..17ad69cee 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -212,10 +212,17 @@ class Application end def find(name) - self.const_get(name.to_s.capitalize) - rescue + klass = name.to_s.capitalize + + # const_defined? is used before const_get since const_defined? will only + # check within our namespace, whereas const_get will check ancestor + # trees as well, resulting in unexpected behaviour. + if !self.const_defined?(klass) puts "Unable to find application '#{name.to_s}'." Kernel::exit(1) + end + + self.const_get(klass) end def [](name) -- cgit From 4d1b51fbcd7d7e285e7e56242951fcc821972e11 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 17 Jan 2011 10:38:03 +1100 Subject: Fixed #5167 - misleading documentation in the defaults of [main] --- lib/puppet/defaults.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 4521a5901..df359a7b4 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -2,8 +2,8 @@ module Puppet setdefaults(:main, :confdir => [Puppet.run_mode.conf_dir, "The main Puppet configuration directory. The default for this parameter is calculated based on the user. If the process - is running as root or the user that `puppet master` is supposed to run as, it defaults to a system directory, but if it's running as any other user, - it defaults to being in `~`."], + is running as root or the user that Puppet is supposed to run as, it defaults to a system directory, but if it's running as any other user, + it defaults to being in the user's home directory."], :vardir => [Puppet.run_mode.var_dir, "Where Puppet stores dynamic and growing data. The default for this parameter is calculated specially, like `confdir`_."], :name => [Puppet.application_name.to_s, "The name of the application, if we are running as one. The default is essentially $0 without the path or `.rb`."], -- cgit From e58f5dc724c060d08e0ec4abdab6908442bcc0bc Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 17 Jan 2011 10:44:57 +1100 Subject: Fixed #5742 - Removed legacy fqdn option from documentation Patch from: Nick Fagerlund --- lib/puppet/util/command_line/puppetd | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/command_line/puppetd b/lib/puppet/util/command_line/puppetd index cb8589c5f..f26131f30 100755 --- a/lib/puppet/util/command_line/puppetd +++ b/lib/puppet/util/command_line/puppetd @@ -11,7 +11,7 @@ # # puppet agent [-D|--daemonize|--no-daemonize] [-d|--debug] # [--detailed-exitcodes] [--disable] [--enable] -# [-h|--help] [--fqdn ] [-l|--logdest syslog||console] +# [-h|--help] [--certname ] [-l|--logdest syslog||console] # [-o|--onetime] [--serve ] [-t|--test] [--noop] # [--digest ] [--fingerprint] [-V|--version] # [-v|--verbose] [-w|--waitforcert ] @@ -113,10 +113,11 @@ # # +puppet agent+ exits after executing this. # -# fqdn:: -# Set the fully-qualified domain name of the client. This is only used for -# certificate purposes, but can be used to override the discovered hostname. -# If you need to use this flag, it is generally an indication of a setup problem. +# certname:: +# Set the certname (unique ID) of the client. The master reads this unique +# identifying string, which is usually set to the node's fully-qualified domain +# name, to determine which configurations the node will receive. Use this option +# to debug setup problems or implement unusual node identification schemes. # # help:: # Print this help message -- cgit From 9b74968a42d9a6e53bc61f7e8e17822316d557e8 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Thu, 30 Dec 2010 16:37:46 -0800 Subject: Modified rubydoc in lib/puppet/util/command_line/puppetca to fix inaccurate description of --clean. --- lib/puppet/util/command_line/puppetca | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/command_line/puppetca b/lib/puppet/util/command_line/puppetca index 9aa7e907c..317d99881 100755 --- a/lib/puppet/util/command_line/puppetca +++ b/lib/puppet/util/command_line/puppetca @@ -27,7 +27,7 @@ # parameter, so you can specify '--ssldir ' as an argument. # # See the configuration file documentation at -# http://reductivelabs.com/projects/puppet/reference/configref.html for +# http://docs.puppetlabs.com/references/stable/configuration.html for # the full list of acceptable parameters. A commented list of all # configuration options can also be generated by running puppet cert with # '--genconfig'. @@ -45,7 +45,7 @@ # Remove all files related to a host from puppet cert's storage. This is # useful when rebuilding hosts, since new certificate signing requests # will only be honored if puppet cert does not have a copy of a signed -# certificate for that host. The certificate of the host remains valid. +# certificate for that host. The certificate of the host is also revoked. # If '--all' is specified then all host certificates, both signed and # unsigned, will be removed. # -- cgit From 66b442b723f1e74b934381227955cc30d64f3636 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 17 Jan 2011 11:45:55 +1100 Subject: Fixes #5916 - Cleanup of unused doc methods and documentation --- lib/puppet/application/doc.rb | 5 +---- lib/puppet/util/command_line/puppetdoc | 4 ++-- lib/puppet/util/reference.rb | 11 +---------- 3 files changed, 4 insertions(+), 16 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb index 1f6c63286..aaefd6e75 100644 --- a/lib/puppet/application/doc.rb +++ b/lib/puppet/application/doc.rb @@ -8,7 +8,7 @@ class Puppet::Application::Doc < Puppet::Application attr_accessor :unknown_args, :manifest def preinit - {:references => [], :mode => :text, :format => :to_rest }.each do |name,value| + {:references => [], :mode => :text, :format => :to_markdown }.each do |name,value| options[name] = value end @unknown_args = [] @@ -113,9 +113,6 @@ class Puppet::Application::Doc < Puppet::Application text += Puppet::Util::Reference.footer unless with_contents # We've only got one reference - # Replace the trac links, since they're invalid everywhere else - text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 } - if options[:mode] == :pdf Puppet::Util::Reference.pdf(text) else diff --git a/lib/puppet/util/command_line/puppetdoc b/lib/puppet/util/command_line/puppetdoc index 8f24ea5ef..45a9c6518 100755 --- a/lib/puppet/util/command_line/puppetdoc +++ b/lib/puppet/util/command_line/puppetdoc @@ -37,7 +37,7 @@ # Specifies the directory where to output the rdoc documentation in 'rdoc' mode. # # mode:: -# Determine the output mode. Valid modes are 'text', 'trac', 'pdf' and 'rdoc'. The 'pdf' mode creates PDF formatted files in the /tmp directory. The default mode is 'text'. In 'rdoc' mode you must provide 'manifests-path' +# Determine the output mode. Valid modes are 'text', 'pdf' and 'rdoc'. The 'pdf' mode creates PDF formatted files in the /tmp directory. The default mode is 'text'. In 'rdoc' mode you must provide 'manifests-path' # # reference:: # Build a particular reference. Get a list of references by running +puppet doc --list+. @@ -47,7 +47,7 @@ # # = Example # -# $ puppet doc -r type > /tmp/type_reference.rst +# $ puppet doc -r type > /tmp/type_reference.markdown # or # $ puppet doc --outputdir /tmp/rdoc --mode rdoc /path/to/manifests # or diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb index 95efeb1c1..a4921ed2a 100644 --- a/lib/puppet/util/reference.rb +++ b/lib/puppet/util/reference.rb @@ -120,16 +120,11 @@ class Puppet::Util::Reference str += "\n\n" end - # Remove all trac links. - def strip_trac(text) - text.gsub(/`\w+\s+([^`]+)`:trac:/) { |m| $1 } - end - def text puts output end - def to_rest(withcontents = true) + def to_markdown(withcontents = true) # First the header text = h(@title, 1) text += "\n\n**This page is autogenerated; any changes will get overwritten** *(last generated on #{Time.now.to_s})*\n\n" @@ -142,8 +137,4 @@ class Puppet::Util::Reference text end - - def to_text(withcontents = true) - strip_trac(to_rest(withcontents)) - end end -- cgit From 069f29bf2b348e540c63c12bc203838b02d8a0bf Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 17 Jan 2011 12:01:13 +1100 Subject: Fixed #2096 - clarified option modification and tested it is working --- lib/puppet/reference/configuration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/reference/configuration.rb b/lib/puppet/reference/configuration.rb index e6a8dc20f..c8ff145ba 100644 --- a/lib/puppet/reference/configuration.rb +++ b/lib/puppet/reference/configuration.rb @@ -94,11 +94,11 @@ The file follows INI-style formatting. Here is an example of a very simple Note that boolean parameters must be explicitly specified as `true` or `false` as seen above. -If you need to change file parameters (e.g., reset the mode or owner), do +If you need to change file or directory parameters (e.g., reset the mode or owner), do so within curly braces on the same line: [main] - myfile = /tmp/whatever {owner = root, mode = 644} + vardir = /new/vardir {owner = root, mode = 644} If you're starting out with a fresh configuration, you may wish to let the executable generate a template configuration file for you by invoking -- cgit From 7e7f34237f67ad27534855d1df328c96e30285bf Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 17 Jan 2011 12:23:29 +1100 Subject: Fixed #1657 - Added note about target file --- lib/puppet/type/host.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/host.rb b/lib/puppet/type/host.rb index 8ab750459..2666e50ae 100755 --- a/lib/puppet/type/host.rb +++ b/lib/puppet/type/host.rb @@ -66,7 +66,7 @@ module Puppet newproperty(:target) do desc "The file in which to store service information. Only used by - those providers that write to disk." + those providers that write to disk. On most systems this defaults to `/etc/hosts`." defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) @resource.class.defaultprovider.default_target -- cgit From ae48634cec08bbb590110a38e4538a984186f1b7 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 20 Jan 2011 13:55:37 +1100 Subject: Fixed #5914 Removed genconfig = true from genconfig output --- lib/puppet/util/settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb index ca4ecda35..626ed20eb 100644 --- a/lib/puppet/util/settings.rb +++ b/lib/puppet/util/settings.rb @@ -593,7 +593,7 @@ if @config.include?(:run_mode) end eachsection do |section| persection(section) do |obj| - str += obj.to_config + "\n" unless ReadOnly.include? obj.name + str += obj.to_config + "\n" unless ReadOnly.include? obj.name or obj.name == :genconfig end end -- cgit From 1fd3600458b8561d33d34369d349ecefee04996b Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 21 Jan 2011 04:04:45 +1100 Subject: Fixed #3646 - Added documentation for compile and apply to man page --- lib/puppet/util/command_line/puppetmasterd | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/util/command_line/puppetmasterd b/lib/puppet/util/command_line/puppetmasterd index baf8a7581..445169820 100755 --- a/lib/puppet/util/command_line/puppetmasterd +++ b/lib/puppet/util/command_line/puppetmasterd @@ -9,6 +9,7 @@ # # puppet master [-D|--daemonize|--no-daemonize] [-d|--debug] [-h|--help] # [-l|--logdest |console|syslog] [-v|--verbose] [-V|--version] +# [--compile ] [--apply ] # # = Description # @@ -49,6 +50,14 @@ # version:: # Print the puppet version number and exit. # +# compile:: +# 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 70630b903b747db0148cd972b64e5162b8f459cc Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Mon, 18 Oct 2010 15:24:37 -0700 Subject: Fix #3165 Ralsh (bin/puppet resource) can't manage files This is based on the patch submitted by Owen Smith. File management was being blocked by two problems: an obsolete, broken `instances` method for the file type, and a bug in the way resource/ral handled slashes in resource names. This patch makes two changes to Owen's version: 1) our unit tests caught an unexpected ruby quirk: "text/".split("/") and "text/".split("/", 2) do not return the same values. 2) File.instances now reproduces the old behavior of listing files in the root directory. This is now implemented in terms of the existing file recursion feature. --- lib/puppet/indirector/resource/ral.rb | 9 +++++++-- lib/puppet/type/file.rb | 21 ++------------------- 2 files changed, 9 insertions(+), 21 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/indirector/resource/ral.rb b/lib/puppet/indirector/resource/ral.rb index 1c2ab14ae..bc41d14ae 100644 --- a/lib/puppet/indirector/resource/ral.rb +++ b/lib/puppet/indirector/resource/ral.rb @@ -34,12 +34,17 @@ class Puppet::Resource::Ral < Puppet::Indirector::Code private + # {type,resource}_name: the resource name may contain slashes: + # File["/etc/hosts"]. To handle, assume the type name does + # _not_ have any slashes in it, and split only on the first. + def type_name( request ) - request.key.split('/')[0] + request.key.split('/', 2)[0] end def resource_name( request ) - request.key.split('/')[1] + name = request.key.split('/', 2)[1] + name unless name == "" end def type( request ) diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index eee948cd5..dc0fe7b24 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -290,25 +290,8 @@ Puppet::Type.newtype(:file) do super(path.gsub(/\/+/, '/').sub(/\/$/, '')) end - # List files, but only one level deep. - def self.instances(base = "/") - return [] unless FileTest.directory?(base) - - files = [] - Dir.entries(base).reject { |e| - e == "." or e == ".." - }.each do |name| - path = File.join(base, name) - if obj = self[path] - obj[:audit] = :all - files << obj - else - files << self.new( - :name => path, :audit => :all - ) - end - end - files + def self.instances(base = '/') + return self.new(:name => base, :recurse => true, :recurselimit => 1, :audit => :all).recurse_local.values end @depthfirst = false -- cgit From 18ca97b0d16fae149a1eab04c520421b5eb38969 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Sat, 8 Jan 2011 17:18:25 -0600 Subject: (#5045) Adds support to resource/type to also accept a param hash The params are added as attributes when the resource is created. Also, even if the class already exists, if params are passed, we still try to create it. Reviewed-by: Matt Robinson --- lib/puppet/resource/type.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index d40adc145..a31795a1b 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -143,18 +143,26 @@ class Puppet::Resource::Type # classes and nodes. No parameters are be supplied--if this is a # parameterized class, then all parameters take on their default # values. - def ensure_in_catalog(scope) + def ensure_in_catalog(scope, attributes=nil) type == :definition and raise ArgumentError, "Cannot create resources for defined resource types" resource_type = type == :hostclass ? :class : :node # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the # singleton nature of classes. - if resource = scope.catalog.resource(resource_type, name) + # we should not do this for classes with attributes + # if attributes are passed, we should still try to create the resource + # even if it exists so that we can fail + # this prevents us from being able to combine param classes with include + if resource = scope.catalog.resource(resource_type, name) and !attributes return resource end - resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self) + if attributes + attributes.each do |k,v| + resource.set_parameter(k,v) + end + end instantiate_resource(scope, resource) scope.compiler.add_resource(scope, resource) resource -- cgit From a2036ea693996cb6ba5eb9f8f52fefa843a320a6 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Sat, 8 Jan 2011 17:34:19 -0600 Subject: (#5045) External node classifiers should be able to specify params for classes It facilitates the support for param classes from the ENC. It adds support for classes to be passed as a hash to the evaluate_classes method. If a hash of classes is specified, it also evaluates duplicates. I also had to convert the hash to an array for tags to be applied correctly. Reviewed-by: Matt Robinson --- lib/puppet/parser/compiler.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index c60e1d4fb..3134e03d9 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -139,12 +139,23 @@ class Puppet::Parser::Compiler def evaluate_classes(classes, scope, lazy_evaluate = true) raise Puppet::DevError, "No source for scope passed to evaluate_classes" unless scope.source found = [] + param_classes = nil + # if we are a param class, save the classes hash + # and transform classes to be the keys + if classes.class == Hash + param_classes = classes + classes = classes.keys + end classes.each do |name| # If we can find the class, then make a resource that will evaluate it. if klass = scope.find_hostclass(name) - found << name and next if scope.class_scope(klass) - resource = klass.ensure_in_catalog(scope) + if param_classes + resource = klass.ensure_in_catalog(scope, param_classes[name] || {}) + else + found << name and next if scope.class_scope(klass) and !param_classes + resource = klass.ensure_in_catalog(scope) + end # If they've disabled lazy evaluation (which the :include function does), # then evaluate our resource immediately. @@ -432,7 +443,11 @@ class Puppet::Parser::Compiler @resources = [] # Make sure any external node classes are in our class list - @catalog.add_class(*@node.classes) + if @node.classes.class == Hash + @catalog.add_class(*@node.classes.keys) + else + @catalog.add_class(*@node.classes) + end end # Set the node's parameters into the top-scope as variables. -- cgit From 3cfbd0722c5f64a3ef39a65f53fa4195135e90b4 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Fri, 21 Jan 2011 14:07:32 -0800 Subject: (#5045) Cleaning up some tests and code Renamed some variables to be clearer, made tests use less stubbing, added some additional tests and got rid of some unecessary logic. Paired-with: Dan Bode --- lib/puppet/parser/compiler.rb | 2 +- lib/puppet/resource/type.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index 3134e03d9..fdabd05c9 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -153,7 +153,7 @@ class Puppet::Parser::Compiler if param_classes resource = klass.ensure_in_catalog(scope, param_classes[name] || {}) else - found << name and next if scope.class_scope(klass) and !param_classes + found << name and next if scope.class_scope(klass) resource = klass.ensure_in_catalog(scope) end diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index a31795a1b..92e1ef719 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -143,23 +143,23 @@ class Puppet::Resource::Type # classes and nodes. No parameters are be supplied--if this is a # parameterized class, then all parameters take on their default # values. - def ensure_in_catalog(scope, attributes=nil) + def ensure_in_catalog(scope, parameters=nil) type == :definition and raise ArgumentError, "Cannot create resources for defined resource types" resource_type = type == :hostclass ? :class : :node # Do nothing if the resource already exists; this makes sure we don't # get multiple copies of the class resource, which helps provide the # singleton nature of classes. - # we should not do this for classes with attributes - # if attributes are passed, we should still try to create the resource + # we should not do this for classes with parameters + # if parameters are passed, we should still try to create the resource # even if it exists so that we can fail # this prevents us from being able to combine param classes with include - if resource = scope.catalog.resource(resource_type, name) and !attributes + if resource = scope.catalog.resource(resource_type, name) and !parameters return resource end resource = Puppet::Parser::Resource.new(resource_type, name, :scope => scope, :source => self) - if attributes - attributes.each do |k,v| + if parameters + parameters.each do |k,v| resource.set_parameter(k,v) end end -- cgit From dd332f6e87dcd997a19060c94749740d31fcff24 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 25 Jan 2011 21:44:25 +1100 Subject: Fixed #6002 - Added note about function execution --- lib/puppet/reference/function.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/reference/function.rb b/lib/puppet/reference/function.rb index 1333e0d26..7d39bebd5 100644 --- a/lib/puppet/reference/function.rb +++ b/lib/puppet/reference/function.rb @@ -8,6 +8,10 @@ performing stand-alone work like importing. Rvalues return values and can only be used in a statement requiring a value, such as an assignment or a case statement. +Functions execute on the Puppet master. They do not execute on the Puppet agent. +Hence they only have access to the commands and data available on the Puppet master +host. + Here are the functions available in Puppet: " -- cgit From 0084b082df016ad87752ef570cfe50bce0f6048e Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Mon, 24 Jan 2011 13:47:53 -0800 Subject: (#5548) Specify return values of manual status commands in service type description. Reviewed by Matt Robinson. --- lib/puppet/type/service.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index c00f02789..2801f3a78 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -144,10 +144,16 @@ module Puppet specified." end newparam(:status) do - desc "Specify a *status* command manually. If left - unspecified, the status method will be determined - automatically, usually by looking for the service in the - process table." + desc "Specify a *status* command manually. This command must + return 0 if the service is running and a nonzero value otherwise. + Ideally, these return codes should conform to + [the LSB's specification for init script status actions](http://refspecs.freestandards.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html), + but puppet only considers the difference between 0 and nonzero + to be relevant. + + If left unspecified, the status method will be determined + automatically, usually by looking for the service in the process + table." end newparam(:stop) do -- cgit From 0765afbd2459a60f5ded89a4c34a3bcb3c560399 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 25 Jan 2011 14:03:14 -0800 Subject: Maint: Rename misleading insync? method in file provider This method actually checks whether the file owner is in sync. Renamed to is_owner_insync? Paired-with: Jesse Wolfe --- lib/puppet/provider/file/posix.rb | 2 +- lib/puppet/provider/file/win32.rb | 2 +- lib/puppet/type/file/owner.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/file/posix.rb b/lib/puppet/provider/file/posix.rb index 6cbf98e9a..415a5af40 100644 --- a/lib/puppet/provider/file/posix.rb +++ b/lib/puppet/provider/file/posix.rb @@ -27,7 +27,7 @@ Puppet::Type.type(:file).provide :posix do end end - def insync?(current, should) + def is_owner_insync?(current, should) return true unless should should.each do |value| diff --git a/lib/puppet/provider/file/win32.rb b/lib/puppet/provider/file/win32.rb index 8ead69a89..23aa491dc 100644 --- a/lib/puppet/provider/file/win32.rb +++ b/lib/puppet/provider/file/win32.rb @@ -14,7 +14,7 @@ Puppet::Type.type(:file).provide :microsoft_windows do id end - def insync?(current, should) + def is_owner_insync?(current, should) return true unless should should.each do |value| diff --git a/lib/puppet/type/file/owner.rb b/lib/puppet/type/file/owner.rb index d473da20e..483cc7fce 100755 --- a/lib/puppet/type/file/owner.rb +++ b/lib/puppet/type/file/owner.rb @@ -6,7 +6,7 @@ module Puppet @event = :file_changed def insync?(current) - provider.insync?(current, @should) + provider.is_owner_insync?(current, @should) end # We want to print names, not numbers -- cgit From 0f9d23617e4115166d6b9e004332dcdf5eccc924 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 25 Jan 2011 14:05:47 -0800 Subject: Maint: Removed dead code from resource harness. Paired-with: Jesse Wolfe --- lib/puppet/transaction/resource_harness.rb | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index c1b980632..0abab10a5 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -175,22 +175,4 @@ class Puppet::Transaction::ResourceHarness return nil unless name = resource[:schedule] resource.catalog.resource(:schedule, name) || resource.fail("Could not find schedule #{name}") end - - private - - def absent_and_not_being_created?(current, param) - current[:ensure] == :absent and param.should.nil? - end - - def ensure_is_insync?(current, param) - param.insync?(current[:ensure]) - end - - def ensure_should_be_absent?(current, param) - param.should == :absent - end - - def param_is_insync?(current, param) - param.insync?(current[param.name]) - end end -- cgit From 67e1bba154accd900b9690d96cec8b050f8082e7 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 25 Jan 2011 14:34:28 -0800 Subject: (#5931) Prevent errors when calling insync? on audited properties Created a method safe_insync? which first checks whether the property has a "should" value of nil, and if so returns true. Most insync? methods were already doing this, but a few were not, leading to bugs if a property was being audited but not set. Types should continue to override the insync? method, but callers of insync? should call safe_insync? instead. Paired-with: Jesse Wolfe --- lib/puppet/property.rb | 17 ++++++++++++++++- lib/puppet/property/keyvalue.rb | 2 -- lib/puppet/property/list.rb | 2 -- lib/puppet/provider/file/posix.rb | 2 -- lib/puppet/provider/file/win32.rb | 2 -- lib/puppet/provider/zone/solaris.rb | 2 +- lib/puppet/transaction/resource_harness.rb | 4 ++-- lib/puppet/type.rb | 4 ++-- lib/puppet/type/cron.rb | 6 +----- lib/puppet/type/file.rb | 2 +- lib/puppet/type/file/content.rb | 1 - lib/puppet/type/file/target.rb | 2 +- lib/puppet/type/mount.rb | 2 +- lib/puppet/type/package.rb | 2 -- lib/puppet/type/service.rb | 2 +- lib/puppet/type/user.rb | 2 -- lib/puppet/type/yumrepo.rb | 4 ++-- lib/puppet/type/zpool.rb | 4 ---- 18 files changed, 28 insertions(+), 34 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb index 84e1a0360..12f496a6e 100644 --- a/lib/puppet/property.rb +++ b/lib/puppet/property.rb @@ -152,9 +152,24 @@ class Puppet::Property < Puppet::Parameter # since we cannot fix it. Otherwise, we expect our should value # to be an array, and if @is matches any of those values, then # we consider it to be in-sync. - def insync?(is) + # + # Don't override this method. + def safe_insync?(is) + # If there is no @should value, consider the property to be in sync. return true unless @should + # Otherwise delegate to the (possibly derived) insync? method. + insync?(is) + end + + def self.method_added(sym) + raise "Puppet::Property#safe_insync? shouldn't be overridden; please override insync? instead" if sym == :safe_insync? + end + + # This method should be overridden by derived classes if necessary + # to provide extra logic to determine whether the property is in + # sync. + def insync?(is) self.devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array) # an empty array is analogous to no should values diff --git a/lib/puppet/property/keyvalue.rb b/lib/puppet/property/keyvalue.rb index 0181708f9..57d0ea2d9 100644 --- a/lib/puppet/property/keyvalue.rb +++ b/lib/puppet/property/keyvalue.rb @@ -77,8 +77,6 @@ module Puppet end def insync?(is) - return true unless @should - return true unless is (is == self.should) diff --git a/lib/puppet/property/list.rb b/lib/puppet/property/list.rb index dcee85db7..b86dc87f2 100644 --- a/lib/puppet/property/list.rb +++ b/lib/puppet/property/list.rb @@ -66,8 +66,6 @@ module Puppet end def insync?(is) - return true unless @should - return true unless is (prepare_is_for_comparison(is) == self.should) diff --git a/lib/puppet/provider/file/posix.rb b/lib/puppet/provider/file/posix.rb index 415a5af40..f7b8c9797 100644 --- a/lib/puppet/provider/file/posix.rb +++ b/lib/puppet/provider/file/posix.rb @@ -28,8 +28,6 @@ Puppet::Type.type(:file).provide :posix do end def is_owner_insync?(current, should) - return true unless should - should.each do |value| if value =~ /^\d+$/ uid = Integer(value) diff --git a/lib/puppet/provider/file/win32.rb b/lib/puppet/provider/file/win32.rb index 23aa491dc..21e7ca974 100644 --- a/lib/puppet/provider/file/win32.rb +++ b/lib/puppet/provider/file/win32.rb @@ -15,8 +15,6 @@ Puppet::Type.type(:file).provide :microsoft_windows do end def is_owner_insync?(current, should) - return true unless should - should.each do |value| if value =~ /^\d+$/ uid = Integer(value) diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb index c11444993..f46337b14 100644 --- a/lib/puppet/provider/zone/solaris.rb +++ b/lib/puppet/provider/zone/solaris.rb @@ -40,7 +40,7 @@ Puppet::Type.type(:zone).provide(:solaris) do # Then perform all of our configuration steps. It's annoying # that we need this much internal info on the resource. @resource.send(:properties).each do |property| - str += property.configtext + "\n" if property.is_a? ZoneConfigProperty and ! property.insync?(properties[property.name]) + str += property.configtext + "\n" if property.is_a? ZoneConfigProperty and ! property.safe_insync?(properties[property.name]) end str += "commit\n" diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index 0abab10a5..4a3d35e0d 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -52,13 +52,13 @@ class Puppet::Transaction::ResourceHarness # Update the machine state & create logs/events events = [] ensure_param = resource.parameter(:ensure) - if desired_values[:ensure] && !ensure_param.insync?(current_values[:ensure]) + if desired_values[:ensure] && !ensure_param.safe_insync?(current_values[:ensure]) events << apply_parameter(ensure_param, current_values[:ensure], audited_params.include?(:ensure), historical_values[:ensure]) synced_params << :ensure elsif current_values[:ensure] != :absent work_order = resource.properties # Note: only the resource knows what order to apply changes in work_order.each do |param| - if desired_values[param.name] && !param.insync?(current_values[param.name]) + if desired_values[param.name] && !param.safe_insync?(current_values[param.name]) events << apply_parameter(param, current_values[param.name], audited_params.include?(param.name), historical_values[param.name]) synced_params << param.name end diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index ea3944b4e..e03650b54 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -648,7 +648,7 @@ class Type "The is value is not in the is array for '#{property.name}'" end ensureis = is[property] - if property.insync?(ensureis) and property.should == :absent + if property.safe_insync?(ensureis) and property.should == :absent return true end end @@ -660,7 +660,7 @@ class Type end propis = is[property] - unless property.insync?(propis) + unless property.safe_insync?(propis) property.debug("Not in sync: #{propis.inspect} vs #{property.should.inspect}") insync = false #else diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb index 76399d693..4b18e71f9 100755 --- a/lib/puppet/type/cron.rb +++ b/lib/puppet/type/cron.rb @@ -54,11 +54,7 @@ Puppet::Type.newtype(:cron) do # We have to override the parent method, because we consume the entire # "should" array def insync?(is) - if @should - self.is_to_s(is) == self.should_to_s - else - true - end + self.is_to_s(is) == self.should_to_s end # A method used to do parameter input handling. Converts integers diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index eee948cd5..0d69446b4 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -779,7 +779,7 @@ Puppet::Type.newtype(:file) do # Make sure we get a new stat objct expire currentvalue = thing.retrieve - thing.sync unless thing.insync?(currentvalue) + thing.sync unless thing.safe_insync?(currentvalue) end end end diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb index b8f30a9c7..04b917a7e 100755 --- a/lib/puppet/type/file/content.rb +++ b/lib/puppet/type/file/content.rb @@ -96,7 +96,6 @@ module Puppet end return true if ! @resource.replace? - return true unless self.should result = super diff --git a/lib/puppet/type/file/target.rb b/lib/puppet/type/file/target.rb index 9e7229dda..b9fe9213b 100644 --- a/lib/puppet/type/file/target.rb +++ b/lib/puppet/type/file/target.rb @@ -14,7 +14,7 @@ module Puppet # Only call mklink if ensure didn't call us in the first place. currentensure = @resource.property(:ensure).retrieve - mklink if @resource.property(:ensure).insync?(currentensure) + mklink if @resource.property(:ensure).safe_insync?(currentensure) end # Create our link. diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index d048c90f1..36fb553f5 100755 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -89,7 +89,7 @@ module Puppet if prop.name == :ensure false else - ! prop.insync?(currentvalues[prop]) + ! prop.safe_insync?(currentvalues[prop]) end end.each { |prop| prop.sync }.length @resource.flush if oos > 0 diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb index 51a866332..d73d90dff 100644 --- a/lib/puppet/type/package.rb +++ b/lib/puppet/type/package.rb @@ -109,8 +109,6 @@ module Puppet # Override the parent method, because we've got all kinds of # funky definitions of 'in sync'. def insync?(is) - @should ||= [] - @latest ||= nil @lateststamp ||= (Time.now.to_i - 1000) # Iterate across all of the should values, and see how they diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index c00f02789..973a76c2d 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -73,7 +73,7 @@ module Puppet if property = @resource.property(:enable) val = property.retrieve - property.sync unless property.insync?(val) + property.sync unless property.safe_insync?(val) end event diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index 761d5d71b..5de73e3dd 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -112,8 +112,6 @@ module Puppet end def insync?(is) - return true unless self.should - # We know the 'is' is a number, so we need to convert the 'should' to a number, # too. @should.each do |value| diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb index 160b2164d..9b4c79428 100644 --- a/lib/puppet/type/yumrepo.rb +++ b/lib/puppet/type/yumrepo.rb @@ -7,14 +7,14 @@ module Puppet class IniProperty < Puppet::Property def insync?(is) # A should property of :absent is the same as nil - if is.nil? && (should.nil? || should == :absent) + if is.nil? && should == :absent return true end super(is) end def sync - if insync?(retrieve) + if safe_insync?(retrieve) result = nil else result = set(self.should) diff --git a/lib/puppet/type/zpool.rb b/lib/puppet/type/zpool.rb index 49cce552a..df06522e8 100755 --- a/lib/puppet/type/zpool.rb +++ b/lib/puppet/type/zpool.rb @@ -8,8 +8,6 @@ module Puppet end def insync?(is) - return true unless self.should - return @should == [:absent] if is == :absent flatten_and_sort(is) == flatten_and_sort(@should) @@ -18,8 +16,6 @@ module Puppet class MultiVDev < VDev def insync?(is) - return true unless self.should - return @should == [:absent] if is == :absent return false unless is.length == @should.length -- cgit From 7d38ab24fa3740ef53510db143f34ac271aced2d Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Wed, 19 Jan 2011 16:59:53 -0800 Subject: (#5594) Update documentation of exec resource type. The exec resource doc referred to duplicate names being allowed, which stopped being true in 0.24.2. Reviewed by Matt Robinson. --- lib/puppet/type/exec.rb | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 606888c75..8019af67e 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -9,41 +9,11 @@ module Puppet commands is to use the checks like `creates` to avoid running the command unless some condition is met. - Note also that you can restrict an `exec` to only run when it receives + Note that you can restrict an `exec` to only run when it receives events by using the `refreshonly` parameter; this is a useful way to have your configuration respond to events with arbitrary commands. - It is worth noting that `exec` is special, in that it is not - currently considered an error to have multiple `exec` instances - with the same name. This was done purely because it had to be this - way in order to get certain functionality, but it complicates things. - In particular, you will not be able to use `exec` instances that - share their commands with other instances as a dependency, since - Puppet has no way of knowing which instance you mean. - - For example: - - # defined in the production class - exec { \"make\": - cwd => \"/prod/build/dir\", - path => \"/usr/bin:/usr/sbin:/bin\" - } - - . etc. . - - # defined in the test class - exec { \"make\": - cwd => \"/test/build/dir\", - path => \"/usr/bin:/usr/sbin:/bin\" - } - - Any other type would throw an error, complaining that you had - the same instance being managed in multiple places, but these are - obviously different images, so `exec` had to be treated specially. - - It is recommended to avoid duplicate names whenever possible. - - Note that if an `exec` receives an event from another resource, + Note also that if an `exec` receives an event from another resource, it will get executed again (or execute the command specified in `refresh`, if there is one). There is a strong tendency to use `exec` to do whatever work Puppet -- cgit From 5d108e8007b76ce62f13c99ed1caedcc0f69c37c Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Fri, 21 Jan 2011 17:21:03 -0800 Subject: (#5944) Improve documentation of defined() function The differences in the way defined() handles different types of entities weren't well-explained. Documentation was also added for the behavior of defined(Node["somenode.domain.com"]). --- lib/puppet/parser/functions/defined.rb | 47 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/functions/defined.rb b/lib/puppet/parser/functions/defined.rb index 90632af2f..c3efc5f76 100644 --- a/lib/puppet/parser/functions/defined.rb +++ b/lib/puppet/parser/functions/defined.rb @@ -1,10 +1,45 @@ # Test whether a given class or definition is defined -Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given - type is defined, either as a native type or a defined type, or whether a class is defined. - This is useful for checking whether a class is defined and only including it if it is. - This function can also test whether a resource has been defined, using resource references - (e.g., `if defined(File['/tmp/myfile']) { ... }`). This function is unfortunately - dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals| +Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether + a given type, class, resource, or node is defined, and return + true or false. Accepts class names, type names, resource references, and node + references. + + The `defined` function checks both native and defined types, including types + provided as plugins via modules. Types are checked using their names: + + defined(\"file\") + defined(\"customtype\") + + Classes are also checked using their names: + + defined(\"foo\") + defined(\"foo::bar\") + + Unlike classes and types, resource definitions are checked using resource + references, e.g. `defined( File['/tmp/myfile'] )`. Checking whether a given + resource defined is, unfortunately, dependent on the parse order of the + configuration, and the following code will not work: + + if defined(File['/tmp/foo']) { + notify(\"This configuration includes the /tmp/foo file.\") + } + file {\"/tmp/foo\": + ensure => present, + } + + However, this order requirement refers to parse order only, and ordering of + resources in the configuration graph (e.g. with `begin` or `require`) does not + affect the behavior of `defined`. + + You can also use `defined` to check whether a node is defined using syntax + resembling a resource reference, like `Node[\"testnode.domain.com\"]`. This usage + is not necessarily recommended, and is included here only in the spirit of + completeness. Checking for node definitions behaves differently from the other + uses of `defined`: it will only return true if a definition for the specified + node (the name of which must match exactly) exists in the manifest **AND** the + specified node matches the node whose configuration is being compiled (either + directly or through node inheritance). The `define` function cannot be used to + introspect information returned by an external node classifier. ") do |vals| result = false vals = [vals] unless vals.is_a?(Array) vals.each do |val| -- cgit From 2b9f6535d46eecd60d8997e93dd2b7533b9e5e71 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Tue, 25 Jan 2011 17:09:25 -0800 Subject: (#5944) Further edits of inline defined() documentation. Fixing use of define/declare; editing for clarity. --- lib/puppet/parser/functions/defined.rb | 55 ++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/functions/defined.rb b/lib/puppet/parser/functions/defined.rb index c3efc5f76..deb57a616 100644 --- a/lib/puppet/parser/functions/defined.rb +++ b/lib/puppet/parser/functions/defined.rb @@ -1,45 +1,50 @@ # Test whether a given class or definition is defined Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether - a given type, class, resource, or node is defined, and return - true or false. Accepts class names, type names, resource references, and node - references. - + a given type or class is defined. This function can also determine whether a + specific resource has been declared. Returns true or false. Accepts class names, + type names, resource references, and node references. + The `defined` function checks both native and defined types, including types - provided as plugins via modules. Types are checked using their names: - + provided as plugins via modules. Types and classes are both checked using their names: + defined(\"file\") defined(\"customtype\") - - Classes are also checked using their names: - defined(\"foo\") defined(\"foo::bar\") - - Unlike classes and types, resource definitions are checked using resource - references, e.g. `defined( File['/tmp/myfile'] )`. Checking whether a given - resource defined is, unfortunately, dependent on the parse order of the - configuration, and the following code will not work: - + + Resource declarations are checked using resource references, e.g. + `defined( File['/tmp/myfile'] )`. Checking whether a given resource + has been declared is, unfortunately, dependent on the parse order of + the configuration, and the following code will not work: + if defined(File['/tmp/foo']) { notify(\"This configuration includes the /tmp/foo file.\") } file {\"/tmp/foo\": ensure => present, } - + However, this order requirement refers to parse order only, and ordering of - resources in the configuration graph (e.g. with `begin` or `require`) does not + resources in the configuration graph (e.g. with `before` or `require`) does not affect the behavior of `defined`. - - You can also use `defined` to check whether a node is defined using syntax + + You can also use `defined` to check whether a node is declared using syntax resembling a resource reference, like `Node[\"testnode.domain.com\"]`. This usage is not necessarily recommended, and is included here only in the spirit of - completeness. Checking for node definitions behaves differently from the other - uses of `defined`: it will only return true if a definition for the specified - node (the name of which must match exactly) exists in the manifest **AND** the - specified node matches the node whose configuration is being compiled (either - directly or through node inheritance). The `define` function cannot be used to - introspect information returned by an external node classifier. ") do |vals| + completeness. Note that: + + * Only the node whose configuration is being compiled is considered declared; + the `define` function will not return information about definitions not currently + being used. + * Node definitions inherited by the current node are considered declared; + however, the default node is never considered declared. + * A node is not considered declared simply by virtue of receiving a + configuration; it must have matched a node definition in the manifest. + * The name used in the node reference must match the name used in the node + definition, even if this is not the node's actual certname. + * Regular expression node definitions cannot be checked for declaration using + `define`, nor can `define` be used to introspect information returned by an + external node classifier.") do |vals| result = false vals = [vals] unless vals.is_a?(Array) vals.each do |val| -- cgit From 86a2a0031fdad032003d053244a3baa04c8f2b81 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Tue, 25 Jan 2011 17:50:17 -0800 Subject: (#5944) Remove documentation of define() when used on nodes, as it is not a supported use of this function. Final patch in this series reviewed by Dan Bode. --- lib/puppet/parser/functions/defined.rb | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/functions/defined.rb b/lib/puppet/parser/functions/defined.rb index deb57a616..2aeaa9ba0 100644 --- a/lib/puppet/parser/functions/defined.rb +++ b/lib/puppet/parser/functions/defined.rb @@ -1,8 +1,8 @@ # Test whether a given class or definition is defined Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether - a given type or class is defined. This function can also determine whether a + a given class or resource type is defined. This function can also determine whether a specific resource has been declared. Returns true or false. Accepts class names, - type names, resource references, and node references. + type names, and resource references. The `defined` function checks both native and defined types, including types provided as plugins via modules. Types and classes are both checked using their names: @@ -26,25 +26,7 @@ Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Dete However, this order requirement refers to parse order only, and ordering of resources in the configuration graph (e.g. with `before` or `require`) does not - affect the behavior of `defined`. - - You can also use `defined` to check whether a node is declared using syntax - resembling a resource reference, like `Node[\"testnode.domain.com\"]`. This usage - is not necessarily recommended, and is included here only in the spirit of - completeness. Note that: - - * Only the node whose configuration is being compiled is considered declared; - the `define` function will not return information about definitions not currently - being used. - * Node definitions inherited by the current node are considered declared; - however, the default node is never considered declared. - * A node is not considered declared simply by virtue of receiving a - configuration; it must have matched a node definition in the manifest. - * The name used in the node reference must match the name used in the node - definition, even if this is not the node's actual certname. - * Regular expression node definitions cannot be checked for declaration using - `define`, nor can `define` be used to introspect information returned by an - external node classifier.") do |vals| + affect the behavior of `defined`.") do |vals| result = false vals = [vals] unless vals.is_a?(Array) vals.each do |val| -- cgit From f1ab58839b5fc2d311b2c2656e480fb563acd03f Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 26 Jan 2011 08:54:55 +1100 Subject: Fixed #6009 - nested member list vs directory service group provider The Directory Service group (and user) provider behaves erratically if members is a nested list; this happens with the following manifest: $r = ["root"] $a = ["daemon", "crc"] $n = ["nobody"] group { "testgroup": ensure => present, members => [$r, $a, $n] } This resolves the issue by flattening the list at the time we are using it; while a more general solution might be desirable this resolves the specific issue cleanly enough. Original patch from Clay Caviness. Tests by Daniel Pittman Signed-off-by: Daniel Pittman Signed-off-by: James Turnbull --- lib/puppet/provider/nameservice/directoryservice.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index 965a2aa60..b01880360 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -442,7 +442,7 @@ class DirectoryService < Puppet::Provider::NameService def remove_unwanted_members(current_members, new_members) current_members.each do |member| - if not new_members.include?(member) + if not new_members.flatten.include?(member) cmd = [:dseditgroup, "-o", "edit", "-n", ".", "-d", member, @resource[:name]] begin execute(cmd) @@ -454,7 +454,7 @@ class DirectoryService < Puppet::Provider::NameService end def add_members(current_members, new_members) - new_members.each do |new_member| + new_members.flatten.each do |new_member| if current_members.nil? or not current_members.include?(new_member) cmd = [:dseditgroup, "-o", "edit", "-n", ".", "-a", new_member, @resource[:name]] begin -- cgit From af1c1febd6ae4accf840279539855592705878bf Mon Sep 17 00:00:00 2001 From: fredrik-eriksson Date: Tue, 25 Jan 2011 09:27:54 +0100 Subject: Feature #5855 -- fix withenv call in freebsd package provider Qualify 'withenv' in the provider, since it is part of an entirely different part of puppet, not a method on this provider. This closes #5855. Signed-off-by: fredrik-eriksson Signed-off-by: Daniel Pittman --- lib/puppet/provider/package/freebsd.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/package/freebsd.rb b/lib/puppet/provider/package/freebsd.rb index 2f012a4ed..e10a20b04 100755 --- a/lib/puppet/provider/package/freebsd.rb +++ b/lib/puppet/provider/package/freebsd.rb @@ -20,11 +20,11 @@ Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do if @resource[:source] =~ /\/$/ if @resource[:source] =~ /^(ftp|https?):/ - withenv :PACKAGESITE => @resource[:source] do + Puppet::Util::Execution::withenv :PACKAGESITE => @resource[:source] do pkgadd "-r", @resource[:name] end else - withenv :PKG_PATH => @resource[:source] do + Puppet::Util::Execution::withenv :PKG_PATH => @resource[:source] do pkgadd @resource[:name] end end -- cgit From c50a48edb19e80d48019b19d852665411d6222e7 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 29 Jan 2011 04:03:21 +1100 Subject: Fixed #6061 - Allowed -1 as password min/max age This allows setting disabling password aging on Linux and Solaris Signed-off-by: James Turnbull --- lib/puppet/type/user.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb index 5de73e3dd..e7389a0d1 100755 --- a/lib/puppet/type/user.rb +++ b/lib/puppet/type/user.rb @@ -175,7 +175,7 @@ module Puppet end validate do |value| - if value.to_s !~ /^\d+$/ + if value.to_s !~ /^-?\d+$/ raise ArgumentError, "Password minimum age must be provided as a number" end end @@ -194,7 +194,7 @@ module Puppet end validate do |value| - if value.to_s !~ /^\d+$/ + if value.to_s !~ /^-?\d+$/ raise ArgumentError, "Password maximum age must be provided as a number" end end -- cgit From 1bfc9a0314c3b6247a3a1e4689c80997d343b2dc Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sun, 30 Jan 2011 03:32:49 +1100 Subject: Fixed #6071 - Fixed typo and improved exec path error message --- lib/puppet/type/exec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 606888c75..723a8ca5f 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -335,7 +335,7 @@ module Puppet # Pull down the main aliases file file { \"/etc/aliases\": source => \"puppet://server/module/aliases\" - } + } # Rebuild the database, but only when the file changes exec { newaliases: @@ -664,7 +664,7 @@ module Puppet def validatecmd(cmd) exe = extractexe(cmd) # if we're not fully qualified, require a path - self.fail "'#{cmd}' is both unqualifed and specified no search path" if File.expand_path(exe) != exe and self[:path].nil? + self.fail "'#{cmd}' is not qualified and no path was specified. Please qualify the command or specify a path." if File.expand_path(exe) != exe and self[:path].nil? end def extractexe(cmd) -- cgit From 878f266fbf8979bcfeab9faef308816fd4a54c50 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 1 Feb 2011 04:55:26 +1100 Subject: Fixed #6091 - Changed POSIX path matching to allow multiple leading slashes According to http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_266: "Multiple successive slashes are considered to be the same as one slash.", so '//tmp/xxx' is a valid POSIX pathname. Thomas Bellman adds: You should probably read section 3.2 then as well: 3.2 Absolute Pathname A pathname beginning with a single or more than two slashes; see also Pathname. Note that a pathname starting with exactly two slashes is *not* an absolute pathname according to Posix. And 4.11 (Pathname Resolution) says: A pathname that begins with two successive slashes may be interpreted in an implementation-defined manner, although more than two leading slashes shall be treated as a single slash. Posix has this rule to accomodate DomainOS, which was a Unix- like OS from Apollo, where paths on the form "//foo/bar/gazonk" meant the file "/bar/gazonk" on the machine named "foo". You may recognize this format from URLs, or MS Windows SMB paths (with backslashes instead of forward slashes). This ignores that complication, since none of our supported platforms treat the '//' form as significant. Signed-off-by: James Turnbull Signed-off-by: Daniel Pittman Signed-off-by: Rick Bradley --- lib/puppet/type/file.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 0d69446b4..a91e7a504 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -34,7 +34,7 @@ Puppet::Type.newtype(:file) do validate do |value| # accept various path syntaxes: lone slash, posix, win32, unc - unless (Puppet.features.posix? and (value =~ /^\/$/ or value =~ /^\/[^\/]/)) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)) + unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)) fail Puppet::Error, "File paths must be fully qualified, not '#{value}'" end end -- cgit From 139760bfa7d79464d5ee092ff4e952138a29b760 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 31 Jan 2011 14:00:33 -0800 Subject: Bug #5681 -- parse AIX mount command output. - Modified the Puppet::Provider::Mount (lib/puppet/provider/mount.rb) to parse AIX mount command output - Modified lib/puppet/type/mount.rb to set remount to false by default in AIX and fix small typo --- lib/puppet/provider/mount.rb | 2 ++ lib/puppet/type/mount.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb index 8c7b24bd4..6a7c72cdc 100644 --- a/lib/puppet/provider/mount.rb +++ b/lib/puppet/provider/mount.rb @@ -43,6 +43,8 @@ module Puppet::Provider::Mount line =~ / on #{name} / or line =~ %r{ on /private/var/automount#{name}} when "Solaris", "HP-UX" line =~ /^#{name} on / + when "AIX" + line =~ /^[^\s]*\s+[^\s]+\s+#{name}\s/ else line =~ / on #{name} / end diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index 36fb553f5..da9a70bdf 100755 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -200,7 +200,7 @@ module Puppet newvalues(:true, :false) defaultto do case Facter.value(:operatingsystem) - when "FreeBSD", "Darwin" + when "FreeBSD", "Darwin", "AIX" false else true -- cgit From 50c12e55b6f8462f6904ae061e661d1d10c7590a Mon Sep 17 00:00:00 2001 From: Rick Bradley Date: Mon, 31 Jan 2011 14:03:16 -0800 Subject: bug #5681 -- code fix to handle AIX mount output Making a simplified fix to find mount name in AIX mount command output. --- lib/puppet/provider/mount.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb index 6a7c72cdc..c979f742f 100644 --- a/lib/puppet/provider/mount.rb +++ b/lib/puppet/provider/mount.rb @@ -44,7 +44,7 @@ module Puppet::Provider::Mount when "Solaris", "HP-UX" line =~ /^#{name} on / when "AIX" - line =~ /^[^\s]*\s+[^\s]+\s+#{name}\s/ + line.split(/\s+/)[1] == name else line =~ / on #{name} / end -- cgit From 3a125d486ba4555796840a93a01ca5055eb9e157 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Mon, 31 Jan 2011 16:00:37 -0800 Subject: Bug #5755 -- ZAML generates extra newline in some hash backreferences. This data structure generates YAML with an extra newline that violates the syntax rules and all: list = [1] { :a => list, :b => list }.to_yaml This breaks real client use of the YAML catalogs, not to mention our own use of cached catalogs... --- lib/puppet/util/zaml.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb index 9fda5ae3b..6ac956565 100644 --- a/lib/puppet/util/zaml.rb +++ b/lib/puppet/util/zaml.rb @@ -59,13 +59,12 @@ class ZAML @@previously_emitted_object = {} @@next_free_label_number = 0 end - def initialize(obj,indent) - @indent = indent + def initialize(obj) @this_label_number = nil @@previously_emitted_object[obj.object_id] = self end def to_s - @this_label_number ? ('&id%03d%s' % [@this_label_number, @indent]) : '' + @this_label_number ? ('&id%03d ' % @this_label_number) : '' end def reference @this_label_number ||= (@@next_free_label_number += 1) @@ -76,7 +75,7 @@ class ZAML end end def new_label_for(obj) - Label.new(obj,(Hash === obj || Array === obj) ? "#{@indent || "\n"} " : ' ') + Label.new(obj) end def first_time_only(obj) if label = Label.for(obj) -- cgit From 6c93eb2c142e346077c49ef78a5fcf675eeb2698 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Tue, 1 Feb 2011 14:37:34 -0800 Subject: Remove order dependency when specifying source and checksum on File type If source was specified after setting the checksum, it would cause the checksum to be set back to :md5. This was completely unnecessary, because the checksum has its own default of :md5. Paired-with: Jesse Wolfe --- lib/puppet/type/file/source.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index 7d03de2b0..bc464e1c3 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -169,7 +169,6 @@ module Puppet checks.delete(:checksum) resource[:audit] = checks - resource[:checksum] = :md5 unless resource.property(:checksum) end def local? -- cgit From 3398139f29d26c337476ee36c63d07080c442058 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Tue, 1 Feb 2011 14:40:21 -0800 Subject: Remove invalid "timestamp" and "time", and add missing "ctime" File checksum types. 'timestamp', and 'time' have been invalid since well before 2.6.0, so do not add them to the list of valid checksum types. 'ctime' was missing from the list of valid checksum types, so add it. Paired-with: Jesse Wolfe --- lib/puppet/type/file/checksum.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index 732460738..5586b1383 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -9,7 +9,7 @@ Puppet::Type.type(:file).newparam(:checksum) do The default checksum parameter, if checksums are enabled, is md5." - newvalues "md5", "md5lite", "timestamp", "mtime", "time", "none" + newvalues "md5", "md5lite", "mtime", "ctime", "none" defaultto :md5 -- cgit From d6572921832cc0df22e13d55c3bc090b74155b91 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Tue, 1 Feb 2011 14:55:25 -0800 Subject: Rename variable used in File type validation to be more clear The 'count' variable is used to keep track of how many 'creator' parameters are set on the Type in order to raise an exception if this is greater than one. Be explicit about this. Paired-with: Jesse Wolfe --- lib/puppet/type/file.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index a91e7a504..7c4280bee 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -273,12 +273,12 @@ Puppet::Type.newtype(:file) do CREATORS = [:content, :source, :target] validate do - count = 0 + creator_count = 0 CREATORS.each do |param| - count += 1 if self.should(param) + creator_count += 1 if self.should(param) end - count += 1 if @parameters.include?(:source) - self.fail "You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}" if count > 1 + creator_count += 1 if @parameters.include?(:source) + self.fail "You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}" if creator_count > 1 self.fail "You cannot specify a remote recursion without a source" if !self[:source] and self[:recurse] == :remote -- cgit From 76788f80aab15e5ef6487788132b87ecc6ddd9ac Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Tue, 1 Feb 2011 14:43:47 -0800 Subject: (#5566) Treat source only File checksums as syntax errors when used with content Certain checksum types (ctime, mtime) only make sense when used with the 'source' File parameter, since there is no way to check them on raw strings. Given the limitations of the current checksumming implementations, it is likely to introduce unexpected behavior when using the 'none' checksum type and either one of the 'source', and 'content' File parameters. Because of this, it is now a syntax error to use a checksum of 'none' with either parameter. Paired-with: Jesse Wolfe --- lib/puppet/type/file.rb | 7 +++++++ lib/puppet/util/checksums.rb | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index 7c4280bee..c66a53c5e 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -271,6 +271,7 @@ Puppet::Type.newtype(:file) do end CREATORS = [:content, :source, :target] + SOURCE_ONLY_CHECKSUMS = [:none, :ctime, :mtime] validate do creator_count = 0 @@ -282,6 +283,12 @@ Puppet::Type.newtype(:file) do self.fail "You cannot specify a remote recursion without a source" if !self[:source] and self[:recurse] == :remote + self.fail "You cannot specify source when using checksum 'none'" if self[:checksum] == :none && !self[:source].nil? + + SOURCE_ONLY_CHECKSUMS.each do |checksum_type| + self.fail "You cannot specify content when using checksum '#{checksum_type}'" if self[:checksum] == checksum_type && !self[:content].nil? + end + self.warning "Possible error: recurselimit is set but not recurse, no recursion will happen" if !self[:recurse] and self[:recurselimit] end diff --git a/lib/puppet/util/checksums.rb b/lib/puppet/util/checksums.rb index 6fdf14ecf..e129301e6 100644 --- a/lib/puppet/util/checksums.rb +++ b/lib/puppet/util/checksums.rb @@ -68,7 +68,9 @@ module Puppet::Util::Checksums nil end - alias :ctime_stream :mtime_stream + def mtime(content) + "" + end # Calculate a checksum using Digest::SHA1. def sha1(content) @@ -108,6 +110,12 @@ module Puppet::Util::Checksums File.stat(filename).send(:ctime) end + alias :ctime_stream :mtime_stream + + def ctime(content) + "" + end + # Return a "no checksum" def none_file(filename) "" @@ -119,6 +127,10 @@ module Puppet::Util::Checksums "" end + def none(content) + "" + end + private # Perform an incremental checksum on a file. -- cgit From fd73874147a1aaa3a047f904a0bc1ae67780a2e4 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 1 Feb 2011 15:30:28 -0800 Subject: (#6107) Fix an error when auditing a file with empty content The manifest: file { "/tmp/foo" : ensure => present, audit => content, } produced the error: err: /Stage[main]//File[/tmp/foo]/ensure: change from absent to present failed: Could not retrieve content for from filebucket: private method `sub' called for nil:NilClass at /Users/matthewrobinson/work/puppet/test.pp:4 This was due to logic in content assuming that if you didn't specify content while you were auditing it you must have specified a source. The code paths in the file type badly need a cleanup so that these sorts of errors aren't so difficult to track down and things are easier to test. Paired-with: Daniel Pittman --- lib/puppet/type/file/content.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/puppet') diff --git a/lib/puppet/type/file/content.rb b/lib/puppet/type/file/content.rb index 04b917a7e..cf924f371 100755 --- a/lib/puppet/type/file/content.rb +++ b/lib/puppet/type/file/content.rb @@ -167,6 +167,8 @@ module Puppet def each_chunk_from(source_or_content) if source_or_content.is_a?(String) yield source_or_content + elsif source_or_content.nil? && resource.parameter(:ensure) && [:present, :file].include?(resource.parameter(:ensure).value) + yield '' elsif source_or_content.nil? yield read_file_from_filebucket elsif self.class.standalone? -- cgit From ce5a2bf3ba66d5ce723a6887580b008e8ba4104b Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Sun, 24 Oct 2010 00:49:03 -0500 Subject: (#5061) - allow special hostclass/define variables to be evaluated as defaults. I have always been annoyed that special variables for defines and hostclasses can not be evaluated as param defaults. Special variables are: $name, $title, $module_name. Code example: class x ( foo = $name ) { notice($foo)} should print x, and with my patch, it does. Reviewed-by: Paul Berry --- lib/puppet/resource/type.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index d40adc145..c19a28c35 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -222,6 +222,19 @@ class Puppet::Resource::Type set[param] = true end + if @type == :hostclass + scope.setvar("title", resource.title.to_s.downcase) unless set.include? :title + scope.setvar("name", resource.name.to_s.downcase ) unless set.include? :name + else + scope.setvar("title", resource.title ) unless set.include? :title + scope.setvar("name", resource.name ) unless set.include? :name + end + scope.setvar("module_name", module_name) if module_name and ! set.include? :module_name + + if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name) + scope.setvar("caller_module_name", caller_name) + end + scope.class_set(self.name,scope) if hostclass? or node? # Verify that all required arguments are either present or # have been provided with defaults. arguments.each do |param, default| @@ -238,19 +251,6 @@ class Puppet::Resource::Type resource[param] = value end - if @type == :hostclass - scope.setvar("title", resource.title.to_s.downcase) unless set.include? :title - scope.setvar("name", resource.name.to_s.downcase ) unless set.include? :name - else - scope.setvar("title", resource.title ) unless set.include? :title - scope.setvar("name", resource.name ) unless set.include? :name - end - scope.setvar("module_name", module_name) if module_name and ! set.include? :module_name - - if caller_name = scope.parent_module_name and ! set.include?(:caller_module_name) - scope.setvar("caller_module_name", caller_name) - end - scope.class_set(self.name,scope) if hostclass? or node? end # Create a new subscope in which to evaluate our code. -- cgit From f279f2c24ad1c87940eca3592f4c6e2f5676c694 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 17 Jan 2011 11:21:02 +1100 Subject: Fixed #4968 - Updated list of options turned on by --test in documentation Reviewed-by: Jacob Helwig Reviewed-by: Jesse Wolfe --- lib/puppet/util/command_line/puppetd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/command_line/puppetd b/lib/puppet/util/command_line/puppetd index cb8589c5f..7d78ce90f 100755 --- a/lib/puppet/util/command_line/puppetd +++ b/lib/puppet/util/command_line/puppetd @@ -150,7 +150,8 @@ # # test:: # Enable the most common options used for testing. These are +onetime+, -# +verbose+, +ignorecache, +no-daemonize+, and +no-usecacheonfailure+. +# +verbose+, +ignorecache, +no-daemonize+, +no-usecacheonfailure+, +# +detailed-exit-codes+, +no-splay+, and +show_diff+. # # noop:: # Use +noop+ mode where the daemon runs in a no-op or dry-run mode. This is useful -- cgit From a732a15a0fd43ce983474cae4c298a9bbd86329f Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 15 Dec 2010 23:39:12 +1100 Subject: Fixed #5564 - Added some more fqdn_rand documentation Reviewed-by: Paul Berry --- lib/puppet/parser/functions/fqdn_rand.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functions/fqdn_rand.rb index 3e7018ac4..52946f2c1 100644 --- a/lib/puppet/parser/functions/fqdn_rand.rb +++ b/lib/puppet/parser/functions/fqdn_rand.rb @@ -1,7 +1,10 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc => - "Generates random numbers based on the node's fqdn. The first argument - sets the range. Additional (optional) arguments may be used to further - distinguish the seed.") do |args| + "Generates random numbers based on the node's fqdn. Generated random values + will be a range from 0 up to and excluding n, where n is the first parameter. + The second argument specifies a number to add to the seed and is optional, for example: + + $random_number = fqdn_rand(30) + $random_number_seed = fqdn_rand(30,30)") do |args| require 'md5' max = args.shift srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex -- cgit From 392504a1eb49820711fe605e795fff897b5f5fcf Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Tue, 1 Feb 2011 16:48:09 -0800 Subject: Fix to fix for #5755 -- backref serialization issues in zaml This commit addresses the original issue that the change reverted in the previous commit for #5755 was intended to fix by removing the special case on labels in emit (lables, even if they are never generated, are not "new lines" and thus @recent_nl should always be set to false when one is emitted). It also partially addresses a related issue wherein temporary strings generated when field names are constructed recycle their object_id (they are temporary) and thus cause incorrect back references. This commit "fixes" the problem by never generating backrefs to strings (treating them as immutable). It does not address other suspected issues such as thread safety durring serialization due to the use of class variables to store the seen-object hash or the use of object ids as "permanently unique" identifiers. Paired with: Daniel Pittman Advice & Commiseration: Jesse Wolfe --- lib/puppet/util/zaml.rb | 52 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/util/zaml.rb b/lib/puppet/util/zaml.rb index 6ac956565..14aa90e5f 100644 --- a/lib/puppet/util/zaml.rb +++ b/lib/puppet/util/zaml.rb @@ -91,7 +91,7 @@ class ZAML end def emit(s) @result << s - @recent_nl = false unless s.kind_of?(Label) + @recent_nl = false end def nl(s='') emit(@indent || "\n") unless @recent_nl @@ -223,32 +223,30 @@ class String gsub( /([\x80-\xFF])/ ) { |x| "\\x#{x.unpack("C")[0].to_s(16)}" } end def to_zaml(z) - z.first_time_only(self) { - num = '[-+]?(0x)?\d+\.?\d*' - case - when self == '' - z.emit('""') - # when self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/ - # z.emit("!binary |\n") - # z.emit([self].pack("m*")) - when ( - (self =~ /\A(true|false|yes|no|on|null|off|#{num}(:#{num})*|!|=|~)$/i) or - (self =~ /\A\n* /) or - (self =~ /[\s:]$/) or - (self =~ /^[>|][-+\d]*\s/i) or - (self[-1..-1] =~ /\s/) or - (self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/) or - (self =~ /[,\[\]\{\}\r\t]|:\s|\s#/) or - (self =~ /\A([-:?!#&*'"]|<<|%.+:.)/) - ) - z.emit("\"#{escaped_for_zaml}\"") - when self =~ /\n/ - if self[-1..-1] == "\n" then z.emit('|+') else z.emit('|-') end - z.nested { split("\n",-1).each { |line| z.nl; z.emit(line.chomp("\n")) } } - else - z.emit(self) - end - } + num = '[-+]?(0x)?\d+\.?\d*' + case + when self == '' + z.emit('""') + # when self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/ + # z.emit("!binary |\n") + # z.emit([self].pack("m*")) + when ( + (self =~ /\A(true|false|yes|no|on|null|off|#{num}(:#{num})*|!|=|~)$/i) or + (self =~ /\A\n* /) or + (self =~ /[\s:]$/) or + (self =~ /^[>|][-+\d]*\s/i) or + (self[-1..-1] =~ /\s/) or + (self =~ /[\x00-\x08\x0B\x0C\x0E-\x1F\x80-\xFF]/) or + (self =~ /[,\[\]\{\}\r\t]|:\s|\s#/) or + (self =~ /\A([-:?!#&*'"]|<<|%.+:.)/) + ) + z.emit("\"#{escaped_for_zaml}\"") + when self =~ /\n/ + if self[-1..-1] == "\n" then z.emit('|+') else z.emit('|-') end + z.nested { split("\n",-1).each { |line| z.nl; z.emit(line.chomp("\n")) } } + else + z.emit(self) + end end end -- cgit