From 25a3f59be4a514629db6825ce4b5abb99371ae3e Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 20 Feb 2009 09:45:42 -0600 Subject: Fixing #558 - File checksums no longer refer to 'nosum' It was only used in a method that apparently was not in use any more. Signed-off-by: Luke Kanies --- lib/puppet/type/file/checksum.rb | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index 785ed0fee..f681a8ebe 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -37,11 +37,6 @@ Puppet::Type.type(:file).newproperty(:checksum) do handlesum() end - newvalue(:nosum) do - # nothing - :nochange - end - # If they pass us a sum type, behave normally, but if they pass # us a sum type + sum, stick the sum in the cache. munge do |value| @@ -129,35 +124,6 @@ Puppet::Type.type(:file).newproperty(:checksum) do cache(checktype()) end - # Retrieve the cached sum - def getcachedsum - hash = nil - unless hash = @resource.cached(:checksums) - hash = {} - @resource.cache(:checksums, hash) - end - - sumtype = self.should - - if hash.include?(sumtype) - #self.notice "Found checksum %s for %s" % - # [hash[sumtype] ,@resource[:path]] - sum = hash[sumtype] - - unless sum =~ /^\{\w+\}/ - sum = "{%s}%s" % [sumtype, sum] - end - return sum - elsif hash.empty? - #self.notice "Could not find sum of type %s" % sumtype - return :nosum - else - #self.notice "Found checksum for %s but not of type %s" % - # [@resource[:path],sumtype] - return :nosum - end - end - # Calculate the sum from disk. def getsum(checktype, file = nil) sum = "" -- cgit From f07d9283d70378066987017d436db6deb1adae9d Mon Sep 17 00:00:00 2001 From: Peter Meier Date: Sun, 22 Feb 2009 00:11:34 +0100 Subject: Use Puppet.debug instead of own debug flag It's better to use puppet's logging environment than an own. Especially if the default is quite verbose and can't be set by config flag. --- lib/puppet/rails/host.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index a429cbfb1..b60b0689d 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -3,8 +3,6 @@ require 'puppet/rails/fact_name' require 'puppet/rails/source_file' require 'puppet/util/rails/collection_merger' -Puppet::TIME_DEBUG = true - class Puppet::Rails::Host < ActiveRecord::Base include Puppet::Util include Puppet::Util::CollectionMerger @@ -36,7 +34,7 @@ class Puppet::Rails::Host < ActiveRecord::Base host = new(:name => node.name) end } - Puppet.notice("Searched for host in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) + Puppet.debug("Searched for host in %0.2f seconds" % seconds) if ip = node.parameters["ipaddress"] host.ip = ip end @@ -51,7 +49,7 @@ class Puppet::Rails::Host < ActiveRecord::Base seconds = Benchmark.realtime { host.setresources(resources) } - Puppet.notice("Handled resources in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) + Puppet.debug("Handled resources in %0.2f seconds" % seconds) host.last_compile = Time.now @@ -119,17 +117,17 @@ class Puppet::Rails::Host < ActiveRecord::Base seconds = Benchmark.realtime { existing = find_resources() } - Puppet.notice("Searched for resources in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) + Puppet.debug("Searched for resources in %0.2f seconds" % seconds) seconds = Benchmark.realtime { find_resources_parameters_tags(existing) } if id - Puppet.notice("Searched for resource params and tags in %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) + Puppet.debug("Searched for resource params and tags in %0.2f seconds" % seconds) seconds = Benchmark.realtime { compare_to_catalog(existing, list) } - Puppet.notice("Resource comparison took %0.2f seconds" % seconds) if defined?(Puppet::TIME_DEBUG) + Puppet.debug("Resource comparison took %0.2f seconds" % seconds) end def find_resources -- cgit From 7504b0499170aa81a143f74065507410424e5e17 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 25 Feb 2009 02:25:09 +1100 Subject: Updated useradd.rb managehome confine to include other RH-like distributions --- lib/puppet/provider/user/useradd.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb index 6996dd69a..15b3b1379 100644 --- a/lib/puppet/provider/user/useradd.rb +++ b/lib/puppet/provider/user/useradd.rb @@ -31,7 +31,7 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ cmd = [] if @resource.managehome? cmd << "-m" - elsif %w{Fedora RedHat}.include?(Facter.value("operatingsystem")) + elsif %w{Fedora RedHat CentOS OEL OVS}.include?(Facter.value("operatingsystem")) cmd << "-M" end cmd -- cgit From 417023835fb5d175fef3b6a06591a8170a5f81a4 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Fri, 27 Feb 2009 08:00:27 +1100 Subject: Fixed #2025 - gentoo service provider handle only default init level --- lib/puppet/provider/service/gentoo.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/provider/service/gentoo.rb b/lib/puppet/provider/service/gentoo.rb index 4067dee5e..d62df1a38 100644 --- a/lib/puppet/provider/service/gentoo.rb +++ b/lib/puppet/provider/service/gentoo.rb @@ -38,7 +38,7 @@ Puppet::Type.type(:service).provide :gentoo, :parent => :init do return :false unless line # If it's enabled then it will print output showing service | runlevel - if output =~ /#{@resource[:name]}\s*\|\s*default/ + if output =~ /#{@resource[:name]}\s*\|\s*(boot|default)/ return :true else return :false -- cgit From 0e467869f4d427a8c42e1c2ff6a0bb215f288b09 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 28 Feb 2009 03:05:23 +1100 Subject: Fixed #1963 - Failing to read /proc/mounts for selinux kills file downloads --- lib/puppet/util/selinux.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 70f244507..cd3b2ac1a 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -153,7 +153,9 @@ module Puppet::Util::SELinux # Internal helper function to read and parse /proc/mounts def read_mounts begin - mounts = File.read("/proc/mounts") + mountfh = File.open("/proc/mounts", NONBLOCK) + mounts = mountfh.read + mountfh.close rescue return nil end -- cgit From 373d505c381696f880c305a9357a6e50342079b8 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 12 Feb 2009 23:42:31 -0600 Subject: Adding a FileCollection and a lookup module for it. Signed-off-by: Luke Kanies --- lib/puppet/file_collection.rb | 20 ++++++++++++++++++++ lib/puppet/file_collection/lookup.rb | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 lib/puppet/file_collection.rb create mode 100644 lib/puppet/file_collection/lookup.rb (limited to 'lib') diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb new file mode 100644 index 000000000..451b496a1 --- /dev/null +++ b/lib/puppet/file_collection.rb @@ -0,0 +1,20 @@ +# A simple way to turn file names into singletons, +# so we don't have tons of copies of each file path around. +class Puppet::FileCollection + def initialize + @paths = [] + end + + def index(path) + if @paths.include?(path) + return @paths.index(path) + else + @paths << path + return @paths.length - 1 + end + end + + def path(index) + @paths[index] + end +end diff --git a/lib/puppet/file_collection/lookup.rb b/lib/puppet/file_collection/lookup.rb new file mode 100644 index 000000000..8f69c6681 --- /dev/null +++ b/lib/puppet/file_collection/lookup.rb @@ -0,0 +1,16 @@ +require 'puppet/file_collection' + +# A simple module for looking up file paths and indexes +# in a file collection. +module Puppet::FileCollection::Lookup + attr_accessor :line, :file_index + + def file=(path) + @file_index = file_collection.index(path) + end + + def file + return nil unless file_index + file_collection.path(file_index) + end +end -- cgit From fa6494b69ad1b01a9c587c86aa1731f4702f5509 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 13 Feb 2009 00:29:07 -0600 Subject: Using the FileCollection where appropriate. This commit just replaces the :file and :line accessors with the use of the new FileCollection Lookup module. This should mean that we've normalized all file names in a given process, which *might* have drastic RAM improvements. For initial simplicity, I've gone with a single global collection of file names, but it's built so it's easy to use individual file collections instead. Signed-off-by: Luke Kanies --- lib/puppet/file_collection.rb | 8 ++++++++ lib/puppet/file_collection/lookup.rb | 4 ++++ lib/puppet/parser/ast.rb | 7 ++++--- lib/puppet/parser/ast/leaf.rb | 2 +- lib/puppet/parser/ast/resource_override.rb | 4 ++-- lib/puppet/parser/resource.rb | 6 +++++- lib/puppet/parser/resource/param.rb | 6 +++++- lib/puppet/parser/resource/reference.rb | 2 ++ lib/puppet/type.rb | 4 ++-- 9 files changed, 33 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb index 451b496a1..69f59ffdf 100644 --- a/lib/puppet/file_collection.rb +++ b/lib/puppet/file_collection.rb @@ -1,6 +1,12 @@ # A simple way to turn file names into singletons, # so we don't have tons of copies of each file path around. class Puppet::FileCollection + require 'puppet/file_collection/lookup' + + def self.collection + @collection + end + def initialize @paths = [] end @@ -17,4 +23,6 @@ class Puppet::FileCollection def path(index) @paths[index] end + + @collection = self.new end diff --git a/lib/puppet/file_collection/lookup.rb b/lib/puppet/file_collection/lookup.rb index 8f69c6681..ddb0c8431 100644 --- a/lib/puppet/file_collection/lookup.rb +++ b/lib/puppet/file_collection/lookup.rb @@ -5,6 +5,10 @@ require 'puppet/file_collection' module Puppet::FileCollection::Lookup attr_accessor :line, :file_index + def file_collection + Puppet::FileCollection.collection + end + def file=(path) @file_index = file_collection.index(path) end diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 303d75bac..ab23dd1f8 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -2,6 +2,7 @@ require 'puppet' require 'puppet/util/autoload' +require 'puppet/file_collection/lookup' # The base class for all of the objects that make up the parse trees. # Handles things like file name, line #, and also does the initialization @@ -10,11 +11,13 @@ class Puppet::Parser::AST # Do this so I don't have to type the full path in all of the subclasses AST = Puppet::Parser::AST + include Puppet::FileCollection::Lookup + include Puppet::Util::Errors include Puppet::Util::MethodHelper include Puppet::Util::Docs - attr_accessor :line, :file, :parent, :scope + attr_accessor :parent, :scope # don't fetch lexer comment by default def use_docs @@ -82,8 +85,6 @@ class Puppet::Parser::AST # method for them. This is probably pretty inefficient and should # likely be changed at some point. def initialize(args) - @file = nil - @line = nil set_options(args) end end diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index c545c1e47..dba9812a7 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -36,7 +36,7 @@ class Puppet::Parser::AST # Interpolate the string looking for variables, and then return # the result. def evaluate(scope) - return scope.strinterp(@value, @file, @line) + return scope.strinterp(@value, file, line) end end diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index 5c4a2410f..f8cf3a81e 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -40,8 +40,8 @@ class Puppet::Parser::AST :type => r.type, :title => r.title, :params => params, - :file => @file, - :line => @line, + :file => file, + :line => line, :source => scope.source, :scope => scope ) diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 2fdd78ddf..7f0e33359 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -4,13 +4,17 @@ class Puppet::Parser::Resource require 'puppet/parser/resource/param' require 'puppet/parser/resource/reference' require 'puppet/util/tagging' + require 'puppet/file_collection/lookup' + + include Puppet::FileCollection::Lookup + include Puppet::Util include Puppet::Util::MethodHelper include Puppet::Util::Errors include Puppet::Util::Logging include Puppet::Util::Tagging - attr_accessor :source, :line, :file, :scope, :rails_id + attr_accessor :source, :scope, :rails_id attr_accessor :virtual, :override, :translated attr_reader :exported, :evaluated, :params diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb index 1a5cfe8fb..7ce58f4c4 100644 --- a/lib/puppet/parser/resource/param.rb +++ b/lib/puppet/parser/resource/param.rb @@ -1,10 +1,14 @@ +require 'puppet/file_collection/lookup' + # The parameters we stick in Resources. class Puppet::Parser::Resource::Param - attr_accessor :name, :value, :source, :line, :file, :add + attr_accessor :name, :value, :source, :add include Puppet::Util include Puppet::Util::Errors include Puppet::Util::MethodHelper + include Puppet::FileCollection::Lookup + def initialize(hash) set_options(hash) requiredopts(:name, :value, :source) diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb index cb505d606..bffc03788 100644 --- a/lib/puppet/parser/resource/reference.rb +++ b/lib/puppet/parser/resource/reference.rb @@ -1,7 +1,9 @@ require 'puppet/resource_reference' +require 'puppet/file_collection/lookup' # A reference to a resource. Mostly just the type and title. class Puppet::Parser::Resource::Reference < Puppet::ResourceReference + include Puppet::FileCollection::Lookup include Puppet::Util::MethodHelper include Puppet::Util::Errors diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index b57c74b95..5cb4ce13d 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -10,6 +10,7 @@ require 'puppet/util/errors' require 'puppet/util/log_paths' require 'puppet/util/logging' require 'puppet/resource_reference' +require 'puppet/file_collection/lookup' # see the bottom of the file for the rest of the inclusions @@ -19,6 +20,7 @@ class Type include Puppet::Util::Errors include Puppet::Util::LogPaths include Puppet::Util::Logging + include Puppet::FileCollection::Lookup ############################### # Code related to resource type attributes. @@ -2135,8 +2137,6 @@ class Type # In naming methods, I have tried to consistently name the method so # that it is clear whether it operates on all attributes (thus has 'attr' in # the method name, or whether it operates on a specific type of attributes. - attr_accessor :file, :line - attr_writer :title attr_writer :noop -- cgit From e2b406239eaa255c41acb31942169296bea71948 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 13 Feb 2009 00:46:45 -0600 Subject: Adding a performance optimization to the FileCollection. I saw about a 7x speed increase when adding this simple hash to speed up the file index lookup. Signed-off-by: Luke Kanies --- lib/puppet/file_collection.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb index 69f59ffdf..7db2600c0 100644 --- a/lib/puppet/file_collection.rb +++ b/lib/puppet/file_collection.rb @@ -9,14 +9,16 @@ class Puppet::FileCollection def initialize @paths = [] + @inverse = {} end def index(path) - if @paths.include?(path) - return @paths.index(path) + if i = @inverse[path] + return i else @paths << path - return @paths.length - 1 + i = @inverse[path] = @paths.length - 1 + return i end end -- cgit From c052ff881e4a0cf6edfe4c1974597cd3abb378cf Mon Sep 17 00:00:00 2001 From: Paul Lathrop Date: Fri, 27 Feb 2009 12:25:28 -0800 Subject: Make puppetd --waitforcert option behave as documented: "You can turn off waiting for certificates by specifying a time of 0." Also add a test to ensure we catch any future regression of this behavior. Signed-off-by: Paul Lathrop --- lib/puppet/executables/client/certhandler.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/executables/client/certhandler.rb b/lib/puppet/executables/client/certhandler.rb index b041397ae..bf3ea167d 100644 --- a/lib/puppet/executables/client/certhandler.rb +++ b/lib/puppet/executables/client/certhandler.rb @@ -49,7 +49,12 @@ module Puppet exit(23) if @one_time end - sleep @wait_for_cert + if @wait_for_cert > 0 + sleep @wait_for_cert + else + Puppet.notice "waitforcert disabled; exiting with no certificate" + exit(1) + end end end -- cgit From ac87600bfc63ab589f3f691fd649f496467cc048 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 3 Mar 2009 12:35:37 +1100 Subject: Fixed report reference page --- lib/puppet/reference/report.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/puppet/reference/report.rb b/lib/puppet/reference/report.rb index be8e64751..2ea00b6d6 100644 --- a/lib/puppet/reference/report.rb +++ b/lib/puppet/reference/report.rb @@ -20,4 +20,5 @@ reports must be comma-separated. You can also specify ``none`` to disable reports entirely. Puppet provides multiple report handlers that will process client reports: + " -- cgit From 9577d3af929727ac1e7b5e7e54e4491990d55995 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 3 Mar 2009 23:20:29 -0600 Subject: Fixing #2013 - prefetching had a mismatch between type and title The ParsedFile types seem to be the main one that suffers from this, but the transactions were using the resource titles, not names, so resources were often not getting prefetched correctly. Signed-off-by: Luke Kanies --- lib/puppet/transaction.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index f3defb7a2..43ba8582c 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -480,7 +480,7 @@ class Transaction @catalog.vertices.each do |resource| if provider = resource.provider and provider.class.respond_to?(:prefetch) prefetchers[provider.class] ||= {} - prefetchers[provider.class][resource.title] = resource + prefetchers[provider.class][resource.name] = resource end end -- cgit From c55ac3f2c2335de0beacd2cb3396b550c8f1402f Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Mon, 23 Feb 2009 20:33:16 +0100 Subject: Fix #2010 - add protection code for some storeconfig corruption This patch adds a more robust and self-healing storedconfig in case of logically corrupted database as the one in #2010 (where multiple resources of same references are present in the database for the same host). The problem is that the resources are stored in a hash with the resource ref as the key, so we collapse resource of different id but same reference. The patch fixed this by using a hash by resource id, and maintaining a list of old extraneous resource in the db that are removved after the storeconfig pass. Signed-off-by: Brice Figureau --- lib/puppet/rails/host.rb | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/puppet/rails/host.rb b/lib/puppet/rails/host.rb index b60b0689d..851cc21d9 100644 --- a/lib/puppet/rails/host.rb +++ b/lib/puppet/rails/host.rb @@ -113,26 +113,26 @@ class Puppet::Rails::Host < ActiveRecord::Base # Set our resources. def setresources(list) - existing = nil + resource_by_id = nil seconds = Benchmark.realtime { - existing = find_resources() + resource_by_id = find_resources() } Puppet.debug("Searched for resources in %0.2f seconds" % seconds) seconds = Benchmark.realtime { - find_resources_parameters_tags(existing) + find_resources_parameters_tags(resource_by_id) } if id Puppet.debug("Searched for resource params and tags in %0.2f seconds" % seconds) seconds = Benchmark.realtime { - compare_to_catalog(existing, list) + compare_to_catalog(resource_by_id, list) } Puppet.debug("Resource comparison took %0.2f seconds" % seconds) end def find_resources resources.find(:all, :include => :source_file).inject({}) do | hash, resource | - hash[resource.ref] = resource + hash[resource.id] = resource hash end end @@ -143,20 +143,29 @@ class Puppet::Rails::Host < ActiveRecord::Base resource.params_hash = [] end - resources_by_id = resources.inject({}) do |hash, res| - hash[res[1]['id']] = res[1] + find_resources_parameters(resources) + find_resources_tags(resources) + end + + # it seems that it can happen (see bug #2010) some resources are duplicated in the + # database (ie logically corrupted database), in which case we remove the extraneous + # entries. + def compare_to_catalog(existing, list) + extra_db_resources = [] + resources = existing.inject({}) do |hash, res| + resource = res[1] + if hash.include?(resource.ref) + extra_db_resources << hash[resource.ref] + end + hash[resource.ref] = resource hash end - find_resources_parameters(resources_by_id) - find_resources_tags(resources_by_id) - end - - def compare_to_catalog(resources, list) compiled = list.inject({}) do |hash, resource| hash[resource.ref] = resource hash end + ar_hash_merge(resources, compiled, :create => Proc.new { |ref, resource| resource.to_rails(self) @@ -165,6 +174,11 @@ class Puppet::Rails::Host < ActiveRecord::Base }, :modify => Proc.new { |db, mem| mem.modify_rails(db) }) + + # fix-up extraneous resources + extra_db_resources.each do |resource| + self.resources.delete(resource) + end end def find_resources_parameters(resources) @@ -172,7 +186,7 @@ class Puppet::Rails::Host < ActiveRecord::Base # assign each loaded parameters/tags to the resource it belongs to params.each do |param| - resources[param['resource_id']].add_param_to_hash(param) + resources[param['resource_id']].add_param_to_hash(param) if resources.include?(param['resource_id']) end end @@ -180,7 +194,7 @@ class Puppet::Rails::Host < ActiveRecord::Base tags = Puppet::Rails::ResourceTag.find_all_tags_from_host(self) tags.each do |tag| - resources[tag['resource_id']].add_tag_to_hash(tag) + resources[tag['resource_id']].add_tag_to_hash(tag) if resources.include?(tag['resource_id']) end end -- cgit From d5850dc40f20b6ea9429588c476eb0dca2d205b7 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 3 Mar 2009 21:18:37 -0600 Subject: Refactored a method: extracted about five other methods Signed-off-by: Luke Kanies --- lib/puppet/indirector/node/ldap.rb | 89 +++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 39 deletions(-) (limited to 'lib') diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 01010a2af..759db3a5c 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -81,45 +81,10 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap def entry2hash(entry) result = {} result[:name] = entry.dn.split(',')[0].split("=")[1] - if pattr = parent_attribute - if values = entry.vals(pattr) - if values.length > 1 - raise Puppet::Error, - "Node entry %s specifies more than one parent: %s" % [entry.dn, values.inspect] - end - unless values.empty? - result[:parent] = values.shift - end - end - end - - result[:classes] = [] - class_attributes.each { |attr| - if values = entry.vals(attr) - values.each do |v| result[:classes] << v end - end - } - result[:classes].uniq! - - result[:stacked] = [] - stacked_params = stacked_attributes - stacked_params.each { |attr| - if values = entry.vals(attr) - result[:stacked] = result[:stacked] + values - end - } - - - result[:parameters] = entry.to_hash.inject({}) do |hash, ary| - unless stacked_params.include?(ary[0]) # don't add our stacked parameters to the main param list - if ary[1].length == 1 - hash[ary[0]] = ary[1].shift - else - hash[ary[0]] = ary[1] - end - end - hash - end + result[:parent] = get_parent_from_entry(entry) if parent_attribute + result[:classes] = get_classes_from_entry(entry) + result[:stacked] = get_stacked_values_from_entry(entry) + result[:parameters] = get_parameters_from_entry(entry) result[:environment] = result[:parameters]["environment"] if result[:parameters]["environment"] @@ -224,4 +189,50 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap return info end + + def get_classes_from_entry(entry) + result = class_attributes.inject([]) do |array, attr| + if values = entry.vals(attr) + values.each do |v| array << v end + end + array + end + result.uniq + end + + def get_parameters_from_entry(entry) + stacked_params = stacked_attributes + entry.to_hash.inject({}) do |hash, ary| + unless stacked_params.include?(ary[0]) # don't add our stacked parameters to the main param list + if ary[1].length == 1 + hash[ary[0]] = ary[1].shift + else + hash[ary[0]] = ary[1] + end + end + hash + end + end + + def get_parent_from_entry(entry) + pattr = parent_attribute + + return nil unless values = entry.vals(pattr) + + if values.length > 1 + raise Puppet::Error, + "Node entry %s specifies more than one parent: %s" % [entry.dn, values.inspect] + end + return nil if values.empty? + return values.shift + end + + def get_stacked_values_from_entry(entry) + stacked_attributes.inject([]) do |result, attr| + if values = entry.vals(attr) + result += values + end + result + end + end end -- cgit From 61661b1c46fafeabf1bdbc4778762831d7178d91 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Tue, 3 Mar 2009 21:36:56 -0600 Subject: Fixing #1991 - ldap booleans get converted to booleans Signed-off-by: Luke Kanies --- lib/puppet/indirector/node/ldap.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib') diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb index 759db3a5c..ab5d47b1c 100644 --- a/lib/puppet/indirector/node/ldap.rb +++ b/lib/puppet/indirector/node/ldap.rb @@ -103,6 +103,8 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap end end + result[:parameters] = convert_parameters(result[:parameters]) + result end @@ -143,6 +145,29 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap node.environment = information[:environment] if information[:environment] end + def convert_parameters(parameters) + result = {} + parameters.each do |param, value| + if value.is_a?(Array) + result[param] = value.collect { |v| convert(v) } + else + result[param] = convert(value) + end + end + result + end + + # Convert any values if necessary. + def convert(value) + case value + when Integer, Fixnum, Bignum; value + when "true"; true + when "false"; false + else + value + end + end + # Find information for our parent and merge it into the current info. def find_and_merge_parent(parent, information) unless parent_info = name2hash(parent) -- cgit From 9d36b5833ceef954181d5d281aba08d414fcdb65 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Thu, 12 Feb 2009 09:32:01 -0500 Subject: Bug 1948: Added patch by jab to support the correct ins syntax. Updated the test cases as well --- lib/puppet/provider/augeas/augeas.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 8d4f6d55a..f70654438 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -178,14 +178,12 @@ Puppet::Type.type(:augeas).provide(:augeas) do debug("sending command '#{command}' with params #{cmd_array.inspect}") aug.clear(cmd_array[0]) when "insert", "ins" - - ext_array = cmd_array[1].split(" ") ; - if cmd_array.size < 2 or ext_array.size < 2 + if cmd_array.size < 3 fail("ins requires 3 parameters") end label = cmd_array[0] - where = ext_array[0] - path = File.join(context, ext_array[1]) + where = cmd_array[1] + path = File.join(context, cmd_array[2]) case where when "before": before = true when "after": before = false -- cgit From cf48ec0aba120e6e83e48b3499df9029b5302767 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Wed, 18 Feb 2009 12:34:17 -0500 Subject: First cut at the not running if augeas does not change any of the underlieing files --- lib/puppet/provider/augeas/augeas.rb | 101 ++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index f70654438..5fa5ab409 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -20,13 +20,17 @@ require 'augeas' if Puppet.features.augeas? Puppet::Type.type(:augeas).provide(:augeas) do -#class Puppet::Provider::Augeas < Puppet::Provider include Puppet::Util confine :true => Puppet.features.augeas? has_features :parse_commands, :need_to_run?,:execute_changes + SAVE_NOOP = "noop" + SAVE_OVERWRITE = "overwrite" + + attr_accessor :aug + # Extracts an 2 dimensional array of commands which are in the # form of command path value. # The input can be @@ -56,12 +60,19 @@ Puppet::Type.type(:augeas).provide(:augeas) do end def open_augeas - flags = 0 - (flags = 1 << 2 ) if self.resource[:type_check] == :true - root = self.resource[:root] - load_path = self.resource[:load_path] - debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}") - Augeas.open(root, load_path,flags) + if (@aug.nil?) + flags = 0 + (flags = 1 << 2 ) if self.resource[:type_check] == :true + root = self.resource[:root] + load_path = self.resource[:load_path] + debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}") + @aug = Augeas.open(root, load_path,flags) + + if (self.get_augeas_version() >= "0.3.6") + debug("Augeas version #{self.get_augeas_version()} is installed") + end + end + @aug end # Used by the need_to_run? method to process get filters. Returns @@ -78,8 +89,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do arg = cmd_array.join(" ") #check the value in augeas - aug = open_augeas() - result = aug.get(path) || '' + result = @aug.get(path) || '' unless result.nil? case comparator when "!=": @@ -107,8 +117,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do verb = cmd_array.shift() #Get the values from augeas - aug = open_augeas() - result = aug.match(path) || '' + result = @aug.match(path) || '' # Now do the work if (!result.nil?) case verb @@ -131,10 +140,24 @@ Puppet::Type.type(:augeas).provide(:augeas) do end end return_value - end + end + + def get_augeas_version + return @aug.get("/augeas/version") || "" + end + + def set_augeas_save_mode(mode) + return @aug.set("/augeas/save", mode) + end + + def files_changed? + saved_files = @aug.match("/augeas/events/saved") + return saved_files.size() > 0 + end # Determines if augeas acutally needs to run. def need_to_run? + self.open_augeas() return_value = true filter = resource[:onlyif] unless (filter == "") @@ -151,12 +174,46 @@ Puppet::Type.type(:augeas).provide(:augeas) do fail("Error sending command '#{command}' with params #{cmd_array[1..-1].inspect}/#{e.message}") end end - return_value + + # If we have a verison of augeas which is at least 0.3.6 then we + # can make the changes now, see if changes were made, and + # actually do the save. + if ((return_value) and (self.get_augeas_version() >= "0.3.6")) + debug("Will attempt to save and only run if files changed") + self.set_augeas_save_mode(SAVE_NOOP) + self.do_execute_changes() + save_result = @aug.save() + saved_files = @aug.match("/augeas/events/saved") + if ((save_result) and (not files_changed?)) + debug("Skipping becuase no files were changed") + return_value = false + else + debug("Files changed, should execute") + end + end + + return return_value end + + def execute_changes + # if we have version 0.3.6 or greater we have already executed + # the changes. We just need to save them. If not, do the changes + if (self.get_augeas_version() >= "0.3.6") + self.set_augeas_save_mode(SAVE_OVERWRITE) + else + self.do_execute_changes() + end + + success = @aug.save() + if (success != true) + fail("Save failed with return code #{success}") + end + + return :executed + end # Actually execute the augeas changes. - def execute_changes - aug = open_augeas + def do_execute_changes commands = resource[:changes] context = resource[:context] commands.each do |cmd_array| @@ -168,15 +225,15 @@ Puppet::Type.type(:augeas).provide(:augeas) do when "set": cmd_array[0]=File.join(context, cmd_array[0]) debug("sending command '#{command}' with params #{cmd_array.inspect}") - aug.set(cmd_array[0], cmd_array[1]) + @aug.set(cmd_array[0], cmd_array[1]) when "rm", "remove": cmd_array[0]=File.join(context, cmd_array[0]) debug("sending command '#{command}' with params #{cmd_array.inspect}") - aug.rm(cmd_array[0]) + @aug.rm(cmd_array[0]) when "clear": cmd_array[0]=File.join(context, cmd_array[0]) debug("sending command '#{command}' with params #{cmd_array.inspect}") - aug.clear(cmd_array[0]) + @aug.clear(cmd_array[0]) when "insert", "ins" if cmd_array.size < 3 fail("ins requires 3 parameters") @@ -190,19 +247,13 @@ Puppet::Type.type(:augeas).provide(:augeas) do else fail("Invalid value '#{where}' for where param") end debug("sending command '#{command}' with params #{[label, where, path].inspect()}") - aug.insert(path, label, before) + @aug.insert(path, label, before) else fail("Command '#{command}' is not supported") end rescue Exception => e fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") end end - success = aug.save() - if (success != true) - fail("Save failed with return code #{success}") - end - - return :executed end end -- cgit From cedeb7982b051e00173822c8d14a794e4fb10ae7 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Wed, 18 Feb 2009 12:46:17 -0500 Subject: Backport the fix for #1835 --- lib/puppet/provider/augeas/augeas.rb | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 5fa5ab409..e9471b1be 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -42,10 +42,27 @@ Puppet::Type.type(:augeas).provide(:augeas) do if data.is_a?(String) data.each_line do |line| cmd_array = Array.new() - tokens = line.split(" ") - cmd = tokens.shift() - file = tokens.shift() - other = tokens.join(" ") + single = line.index("'") + double = line.index('"') + tokens = nil + delim = " " + if ((single != nil) or (double != nil)) + single = 99999 if single == nil + double = 99999 if double == nil + delim = '"' if double < single + delim = "'" if single < double + end + tokens = line.split(delim) + # If the length of tokens is 2, thn that means the pattern was + # command file "some text", therefore we need to re-split + # the first line + if tokens.length == 2 + tokens = (tokens[0].split(" ")) << tokens[1] + end + cmd = tokens.shift().strip() + delim = "" if delim == " " + file = tokens.shift().strip() + other = tokens.join(" ").strip() cmd_array << cmd if !cmd.nil? cmd_array << file if !file.nil? cmd_array << other if other != "" @@ -59,6 +76,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do return commands end + def open_augeas if (@aug.nil?) flags = 0 -- cgit From 01bc88c7e2a3d5a71aec8f0727631cbf41680720 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Mon, 23 Feb 2009 11:21:59 -0500 Subject: Added a force option to ensure the change is always applied, and call augeas twice to reduce the chance that data is lost --- lib/puppet/provider/augeas/augeas.rb | 102 ++++++++++++++++++++--------------- lib/puppet/type/augeas.rb | 29 ++++++---- 2 files changed, 76 insertions(+), 55 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index e9471b1be..56e217a54 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -21,9 +21,9 @@ require 'augeas' if Puppet.features.augeas? Puppet::Type.type(:augeas).provide(:augeas) do include Puppet::Util - - confine :true => Puppet.features.augeas? - + + confine :true => Puppet.features.augeas? + has_features :parse_commands, :need_to_run?,:execute_changes SAVE_NOOP = "noop" @@ -85,14 +85,22 @@ Puppet::Type.type(:augeas).provide(:augeas) do load_path = self.resource[:load_path] debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}") @aug = Augeas.open(root, load_path,flags) - + if (self.get_augeas_version() >= "0.3.6") debug("Augeas version #{self.get_augeas_version()} is installed") end end @aug end - + + def close_augeas + if (!@aug.nil?) + @aug.close() + debug("Closed the augeas connection") + @aug = nil; + end + end + # Used by the need_to_run? method to process get filters. Returns # true if there is a match, false if otherwise # Assumes a syntax of get /files/path [COMPARATOR] value @@ -121,8 +129,8 @@ Puppet::Type.type(:augeas).provide(:augeas) do end end return_value - end - + end + # Used by the need_to_run? method to process match filters. Returns # true if there is a match, false if otherwise def process_match(cmd_array) @@ -137,7 +145,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do #Get the values from augeas result = @aug.match(path) || '' # Now do the work - if (!result.nil?) + unless (result.nil?) case verb when "size": fail("Invalid command: #{cmd_array.join(" ")}") if cmd_array.length != 2 @@ -170,13 +178,14 @@ Puppet::Type.type(:augeas).provide(:augeas) do def files_changed? saved_files = @aug.match("/augeas/events/saved") - return saved_files.size() > 0 + return saved_files.size() > 0 end - + # Determines if augeas acutally needs to run. def need_to_run? - self.open_augeas() + force = resource[:force] return_value = true + self.open_augeas() filter = resource[:onlyif] unless (filter == "") cmd_array = filter.split @@ -193,48 +202,52 @@ Puppet::Type.type(:augeas).provide(:augeas) do end end - # If we have a verison of augeas which is at least 0.3.6 then we - # can make the changes now, see if changes were made, and - # actually do the save. - if ((return_value) and (self.get_augeas_version() >= "0.3.6")) - debug("Will attempt to save and only run if files changed") - self.set_augeas_save_mode(SAVE_NOOP) - self.do_execute_changes() - save_result = @aug.save() - saved_files = @aug.match("/augeas/events/saved") - if ((save_result) and (not files_changed?)) - debug("Skipping becuase no files were changed") - return_value = false - else - debug("Files changed, should execute") + unless (force) + # If we have a verison of augeas which is at least 0.3.6 then we + # can make the changes now, see if changes were made, and + # actually do the save. + if ((return_value) and (self.get_augeas_version() >= "0.3.6")) + debug("Will attempt to save and only run if files changed") + self.set_augeas_save_mode(SAVE_NOOP) + self.do_execute_changes() + save_result = @aug.save() + saved_files = @aug.match("/augeas/events/saved") + if ((save_result) and (not files_changed?)) + debug("Skipping becuase no files were changed") + return_value = false + else + debug("Files changed, should execute") + end end end - + self.close_augeas() return return_value - end + end def execute_changes - # if we have version 0.3.6 or greater we have already executed - # the changes. We just need to save them. If not, do the changes + # Re-connect to augeas, and re-execute the changes + self.open_augeas() if (self.get_augeas_version() >= "0.3.6") self.set_augeas_save_mode(SAVE_OVERWRITE) - else - self.do_execute_changes() end - + + self.do_execute_changes() + success = @aug.save() if (success != true) fail("Save failed with return code #{success}") end + self.close_augeas() - return :executed + return :executed end - + # Actually execute the augeas changes. def do_execute_changes - commands = resource[:changes] + commands = resource[:changes].clone() context = resource[:context] commands.each do |cmd_array| + cmd_array = cmd_array.clone() fail("invalid command #{cmd_array.join[" "]}") if cmd_array.length < 2 command = cmd_array[0] cmd_array.shift() @@ -246,32 +259,33 @@ Puppet::Type.type(:augeas).provide(:augeas) do @aug.set(cmd_array[0], cmd_array[1]) when "rm", "remove": cmd_array[0]=File.join(context, cmd_array[0]) - debug("sending command '#{command}' with params #{cmd_array.inspect}") + debug("sending command '#{command}' with params #{cmd_array.inspect}") @aug.rm(cmd_array[0]) when "clear": cmd_array[0]=File.join(context, cmd_array[0]) - debug("sending command '#{command}' with params #{cmd_array.inspect}") + debug("sending command '#{command}' with params #{cmd_array.inspect}") @aug.clear(cmd_array[0]) when "insert", "ins" - if cmd_array.size < 3 + ext_array = cmd_array[1].split(" ") ; + if cmd_array.size < 2 or ext_array.size < 2 fail("ins requires 3 parameters") end label = cmd_array[0] - where = cmd_array[1] - path = File.join(context, cmd_array[2]) + where = ext_array[0] + path = File.join(context, ext_array[1]) case where when "before": before = true when "after": before = false else fail("Invalid value '#{where}' for where param") end - debug("sending command '#{command}' with params #{[label, where, path].inspect()}") - @aug.insert(path, label, before) + debug("sending command '#{command}' with params #{[label, where, path].inspect()}") + aug.insert(path, label, before) else fail("Command '#{command}' is not supported") end rescue Exception => e fail("Error sending command '#{command}' with params #{cmd_array.inspect}/#{e.message}") end end - end - + end + end diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb index c89400b5e..e0d5e10b7 100644 --- a/lib/puppet/type/augeas.rb +++ b/lib/puppet/type/augeas.rb @@ -19,10 +19,10 @@ Puppet::Type.newtype(:augeas) do include Puppet::Util - + feature :parse_commands, "Parse the command string" feature :need_to_run?, "If the command should run" - feature :execute_changes, "Actually make the changes" + feature :execute_changes, "Actually make the changes" @doc = "Apply the changes (single or array of changes) to the filesystem via the augeas tool. @@ -59,7 +59,7 @@ Puppet::Type.newtype(:augeas) do newparam (:context) do desc "Optional context path. This value is pre-pended to the paths of all changes" - defaultto "" + defaultto "" end newparam (:onlyif) do @@ -81,7 +81,7 @@ Puppet::Type.newtype(:augeas) do AN_ARRAY is in the form ['a string', 'another']" defaultto "" end - + newparam(:changes) do desc "The changes which should be applied to the filesystem. This @@ -99,7 +99,7 @@ Puppet::Type.newtype(:augeas) do If the parameter 'context' is set that value is prepended to PATH" - munge do |value| + munge do |value| provider.parse_commands(value) end end @@ -115,6 +115,13 @@ Puppet::Type.newtype(:augeas) do defaultto "" end + newparam(:force) do + desc "Optional command to force the augeas type to execute even if it thinks changes + will not be made. This does not overide the only setting. If onlyif is set, then the + foce setting will not override that result" + + defaultto false + end newparam(:type_check) do desc "Set to true if augeas should perform typechecking. Optional, defaults to false" @@ -122,7 +129,7 @@ Puppet::Type.newtype(:augeas) do defaultto :false end - + # This is the acutal meat of the code. It forces # augeas to be run and fails or not based on the augeas return # code. @@ -131,12 +138,12 @@ Puppet::Type.newtype(:augeas) do desc "The expected return code from the augeas command. Should not be set" defaultto 0 - + # Make output a bit prettier def change_to_s(currentvalue, newvalue) return "executed successfully" - end - + end + # if the onlyif resource is provided, then the value is parsed. # a return value of 0 will stop exection becuase it matches the # default value. @@ -146,12 +153,12 @@ Puppet::Type.newtype(:augeas) do else 0 end - end + end # Actually execute the command. def sync @resource.provider.execute_changes() end - end + end end -- cgit From cf64827970d8725cea93fee57ec03ea70d63a142 Mon Sep 17 00:00:00 2001 From: Bryan Kearney Date: Fri, 27 Feb 2009 10:36:38 -0500 Subject: Bring in the documentation changes from the master branch --- lib/puppet/type/augeas.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb index e0d5e10b7..da9cff369 100644 --- a/lib/puppet/type/augeas.rb +++ b/lib/puppet/type/augeas.rb @@ -92,11 +92,10 @@ Puppet::Type.newtype(:augeas) do rm [PATH] Removes the node at location PATH remove [PATH] Synonym for rm clear [PATH] Keeps the node at PATH, but removes the value. - ins [LABEL] [WHERE] [PATH] + ins [LABEL] [WHERE] [PATH] Inserts an empty node LABEL either [WHERE={before|after}] PATH. - insert [LABEL] [WHERE] [PATH] + insert [LABEL] [WHERE] [PATH] Synonym for ins - If the parameter 'context' is set that value is prepended to PATH" munge do |value| -- cgit From 67fc394d9ffaed89328c00678559f57418a1511d Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sat, 7 Mar 2009 11:14:14 +1100 Subject: Fixed #2026 - Red Hat ignoring stop method --- lib/puppet/provider/service/redhat.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb index 031db46c1..f31903e84 100755 --- a/lib/puppet/provider/service/redhat.rb +++ b/lib/puppet/provider/service/redhat.rb @@ -73,12 +73,12 @@ Puppet::Type.type(:service).provide :redhat, :parent => :init do end end - def start - service(@resource[:name], "start") + def startcmd + [command(:service), @resource[:name], "start"] end - def stop - service(@resource[:name], "stop") + def stopcmd + [command(:service), @resource[:name], "stop"] end end -- cgit From a3bb201bd4c964ab4f68e00895b692d9d9585407 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Fri, 6 Mar 2009 18:11:33 -0600 Subject: Fixing change printing when list properties are absent They were throwing an exception when the 'is' value was 'absent'. Signed-off-by: Luke Kanies --- lib/puppet/property/list.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/property/list.rb b/lib/puppet/property/list.rb index 0c933f164..b7db8b42a 100644 --- a/lib/puppet/property/list.rb +++ b/lib/puppet/property/list.rb @@ -10,7 +10,11 @@ module Puppet end def is_to_s(currentvalue) - currentvalue.join(delimiter) + if currentvalue == :absent + return "absent" + else + return currentvalue.join(delimiter) + end end def membership -- cgit From 84d6637cfc47a14114493254ec8e68f2887a93d8 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 9 Mar 2009 14:46:46 +1100 Subject: Fixed #2000 - No default specified for checksum --- lib/puppet/type/file/checksum.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet/type/file/checksum.rb b/lib/puppet/type/file/checksum.rb index f681a8ebe..095c62f37 100755 --- a/lib/puppet/type/file/checksum.rb +++ b/lib/puppet/type/file/checksum.rb @@ -11,7 +11,13 @@ Puppet::Type.type(:file).newproperty(:checksum) do like Tripwire without managing the file contents in any way. You can specify that a file's checksum should be monitored and then subscribe to the file from another object and receive events to signify - checksum changes, for instance." + checksum changes, for instance. + + There are a number of checksum types available including MD5 hashing (and + an md5lite variation that only hashes the first 500 characters of the + file. + + The default checksum parameter, if checksums are enabled, is md5." @event = :file_changed -- cgit From 73a0757b559d7e4fbd1da43bbcf4e60fd9155896 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 15:05:29 +0100 Subject: Fix #1828 - Scope.number? wasn't strict enough and could produce wrong results Some invalid numbers were treated as numbers and conversion to Integer was failing returning 0 (for instance 0.24.7). Signed-off-by: Brice Figureau --- lib/puppet/parser/scope.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 4acdf41c9..77e7b0cfd 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -52,11 +52,11 @@ class Puppet::Parser::Scope if value.is_a?(String) if value =~ /^-?\d+(:?\.\d+|(:?\.\d+)?e\d+)$/ return value.to_f - elsif value =~ /^0x\d+/i + elsif value =~ /^0x[0-9a-f]+$/i return value.to_i(16) - elsif value =~ /^0\d+/i + elsif value =~ /^0[0-7]+$/ return value.to_i(8) - elsif value =~ /^-?\d+/ + elsif value =~ /^-?\d+$/ return value.to_i else return nil -- cgit From 2c7e1897eaaa7d2dd8d8d993df8a9a217d1c46c6 Mon Sep 17 00:00:00 2001 From: Nigel Kersten Date: Mon, 16 Mar 2009 07:30:16 -0700 Subject: Fixes incorrect detail variable in OS X version check, re-patches ralsh to work with Facter values and adds error check for missing password hash files. --- lib/puppet/provider/nameservice/directoryservice.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb index 42c52f0a7..0e06bb089 100644 --- a/lib/puppet/provider/nameservice/directoryservice.rb +++ b/lib/puppet/provider/nameservice/directoryservice.rb @@ -118,7 +118,7 @@ class DirectoryService < Puppet::Provider::NameService begin product_version = Facter.value(:macosx_productversion) if product_version.nil? - raise Puppet::Error, "Could not determine OS X version: %s" % detail + raise Puppet::Error, "Could not determine OS X version" end product_version_major = product_version.scan(/(\d+)\.(\d+)./).join(".") if %w{10.0 10.1 10.2 10.3}.include?(product_version_major) @@ -320,14 +320,14 @@ class DirectoryService < Puppet::Provider::NameService def self.get_password(guid) password_hash = nil password_hash_file = "#{@@password_hash_dir}/#{guid}" - if File.exists?(password_hash_file) + if File.exists?(password_hash_file) and File.file?(password_hash_file) if not File.readable?(password_hash_file) raise Puppet::Error("Could not read password hash file at #{password_hash_file} for #{@resource[:name]}") end f = File.new(password_hash_file) password_hash = f.read f.close - end + end password_hash end -- cgit From 081021af4dda0d19e7de7debb580196219bb7c36 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 17:38:50 +0100 Subject: Fix #1829 - Add puppet function versioncmp to compare versions Signed-off-by: Brice Figureau --- lib/puppet/parser/functions/versioncmp.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/puppet/parser/functions/versioncmp.rb (limited to 'lib') diff --git a/lib/puppet/parser/functions/versioncmp.rb b/lib/puppet/parser/functions/versioncmp.rb new file mode 100644 index 000000000..62df38ffc --- /dev/null +++ b/lib/puppet/parser/functions/versioncmp.rb @@ -0,0 +1,10 @@ +require 'puppet/util/package' + +Puppet::Parser::Functions::newfunction(:versioncmp, :doc => "Compares two versions.") do |args| + + unless args.length == 2 + raise Puppet::ParseError, "versioncmp should have 2 arguments" + end + + return Puppet::Util::Package.versioncmp(args[0], args[1]) +end -- cgit From 69a0f7dc8d3ba1c64e5acdf99628f10b41ab8e30 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 19 Dec 2008 17:35:08 +0100 Subject: Fix #1807 - make Puppet::Util::Package.versioncmp a module function Signed-off-by: Brice Figureau --- lib/puppet/util/package.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib') diff --git a/lib/puppet/util/package.rb b/lib/puppet/util/package.rb index 00e04f64a..613aa6b1e 100644 --- a/lib/puppet/util/package.rb +++ b/lib/puppet/util/package.rb @@ -28,4 +28,6 @@ module Puppet::Util::Package end return version_a <=> version_b; end + + module_function :versioncmp end -- cgit From bbcda1d5bcab492dc68d331e6f78fb0473e9f046 Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Fri, 28 Nov 2008 15:12:30 +0100 Subject: Fix Bug #1629 A refactoring of ssh_authorized_key parsed provider was needed and tests were improved. flush method has been split for clarity. --- lib/puppet/provider/ssh_authorized_key/parsed.rb | 64 +++++++++++++++++++----- 1 file changed, 52 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb index 77af58ef5..5604ba32a 100644 --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb @@ -40,25 +40,55 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, # This was done in the type class but path expansion was failing for # not yet existing users, the only workaround I found was to move that # in the provider. - if user = @resource.should(:user) - target = File.expand_path("~%s/.ssh/authorized_keys" % user) - @property_hash[:target] = target - @resource[:target] = target - end + @resource[:target] = target super end + def target + if user + File.expand_path("~%s/.ssh/authorized_keys" % user) + elsif target = @resource.should(:target) + target + end + end + + def user + @resource.should(:user) + end + + def dir_perm + # Determine correct permission for created directory and file + # we can afford more restrictive permissions when the user is known + if target + if user + 0700 + else + 0755 + end + end + end + + def file_perm + if target + if user + 0600 + else + 0644 + end + end + end + def flush # As path expansion had to be moved in the provider, we cannot generate new file # resources and thus have to chown and chmod here. It smells hackish. - + # Create target's parent directory if nonexistant - if target = @property_hash[:target] - dir = File.dirname(@property_hash[:target]) + if target + dir = File.dirname(target) if not File.exist? dir Puppet.debug("Creating directory %s which did not exist" % dir) - Dir.mkdir(dir, 0700) + Dir.mkdir(dir, dir_perm) end end @@ -66,9 +96,19 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, super # Ensure correct permissions - if target and user = @property_hash[:user] - File.chown(Puppet::Util.uid(user), nil, dir) - File.chown(Puppet::Util.uid(user), nil, @property_hash[:target]) + if target and user + uid = Puppet::Util.uid(user) + + if uid + File.chown(uid, nil, dir) + File.chown(uid, nil, target) + else + raise Puppet::Error, "Specified user does not exist" + end + end + + if target + File.chmod(file_perm, target) end end -- cgit From 39deaf373c46c20d14a04391ad4b7c70ad43e266 Mon Sep 17 00:00:00 2001 From: Francois Deppierraz Date: Sat, 21 Mar 2009 23:32:02 +0100 Subject: Fixed #2004 - ssh_authorized_key fails if no target is defined This commit depends on 7f291afdacf59f762c3b78481f5420ec8919e46d (fixing #1629) which was cherry-picked from master. Signed-off-by: Francois Deppierraz --- lib/puppet/provider/ssh_authorized_key/parsed.rb | 15 +-------------- lib/puppet/type/ssh_authorized_key.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb index 5604ba32a..051fb63ef 100644 --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb @@ -36,21 +36,8 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, :rts => /^\s+/, :match => /^(?:(.+) )?(\d+) (\d+) (\d+)(?: (.+))?$/ - def prefetch - # This was done in the type class but path expansion was failing for - # not yet existing users, the only workaround I found was to move that - # in the provider. - @resource[:target] = target - - super - end - def target - if user - File.expand_path("~%s/.ssh/authorized_keys" % user) - elsif target = @resource.should(:target) - target - end + @resource.should(:target) end def user diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index 66cf3e733..997afb81e 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -31,6 +31,20 @@ module Puppet newproperty(:target) do desc "The file in which to store the SSH key." + + defaultto :absent + + def should + if defined? @should and @should[0] != :absent + return super + end + + if user = resource[:user] + return File.expand_path("~%s/.ssh/authorized_keys" % user) + end + + return nil + end end newproperty(:options, :array_matching => :all) do -- cgit From aa00bdedefcf4dce9c55968e33123a73b78fb6d6 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 22 Mar 2009 22:00:41 -0500 Subject: Fixing #1631 - adding /sbin and /usr/sbin to PATH This is a trivial fix but seems to crop up more often than it should. Signed-off-by: Luke Kanies --- lib/puppet/defaults.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index e1b6dc423..e36dd7068 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -95,8 +95,17 @@ module Puppet :path => {:default => "none", :desc => "The shell search path. Defaults to whatever is inherited from the parent process.", + :call_on_define => true, # Call our hook with the default value, so we always get the libdir set. :hook => proc do |value| ENV["PATH"] = value unless value == "none" + + paths = ENV["PATH"].split(File::PATH_SEPARATOR) + %w{/usr/sbin /sbin}.each do |path| + unless paths.include?(path) + ENV["PATH"] += File::PATH_SEPARATOR + path + end + end + value end }, :libdir => {:default => "$vardir/lib", -- cgit From c62c19370bfba881819c1a3d9da2f8e6fb52e5d9 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 23 Mar 2009 03:41:25 +0000 Subject: Updated to version 0.24.8 --- lib/puppet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/puppet.rb b/lib/puppet.rb index 4b0091cd0..c7e28b7cf 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -25,7 +25,7 @@ require 'puppet/util/suidmanager' # it's also a place to find top-level commands like 'debug' module Puppet - PUPPETVERSION = '0.24.7' + PUPPETVERSION = '0.24.8' def Puppet.version return PUPPETVERSION -- cgit From a677e26eb1452c08d7724047a18e50f4a654d2cd Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 2 Apr 2009 19:41:17 -0500 Subject: Fixing all tests that were apparently broken in the 0.24.x merge. Signed-off-by: Luke Kanies --- lib/puppet/parser/resource/reference.rb | 2 +- lib/puppet/util/selinux.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb index cf7e997d8..0c28cf0df 100644 --- a/lib/puppet/parser/resource/reference.rb +++ b/lib/puppet/parser/resource/reference.rb @@ -1,5 +1,5 @@ # A reference to a resource. Mostly just the type and title. -require 'puppet/resource_reference' +require 'puppet/resource/reference' require 'puppet/file_collection/lookup' # A reference to a resource. Mostly just the type and title. diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index cd3b2ac1a..f13600680 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -153,7 +153,7 @@ module Puppet::Util::SELinux # Internal helper function to read and parse /proc/mounts def read_mounts begin - mountfh = File.open("/proc/mounts", NONBLOCK) + mountfh = File.open("/proc/mounts", File::NONBLOCK) mounts = mountfh.read mountfh.close rescue -- cgit