diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/node/catalog.rb | 3 | ||||
-rw-r--r-- | lib/puppet/parser/functions.rb | 16 | ||||
-rw-r--r-- | lib/puppet/provider/confine/variable.rb (renamed from lib/puppet/provider/confine/facter.rb) | 25 | ||||
-rw-r--r-- | lib/puppet/provider/confine_collection.rb | 4 | ||||
-rw-r--r-- | lib/puppet/provider/group/ldap.rb | 16 | ||||
-rw-r--r-- | lib/puppet/provider/user/ldap.rb | 16 | ||||
-rw-r--r-- | lib/puppet/reference/providers.rb | 8 | ||||
-rw-r--r-- | lib/puppet/transaction.rb | 6 | ||||
-rw-r--r-- | lib/puppet/type/file/target.rb | 2 | ||||
-rw-r--r-- | lib/puppet/util/warnings.rb | 7 |
10 files changed, 73 insertions, 30 deletions
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index c5e32a032..3ac11a66d 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -483,6 +483,9 @@ class Puppet::Node::Catalog < Puppet::PGraph if resource.is_a?(Puppet::TransObject) resource = resource.dup resource.catalog = result + elsif resource.is_a?(Puppet::Parser::Resource) + resource = resource.to_transobject + resource.catalog = result end newres = resource.send(convert) diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 93991275c..8decb8227 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -188,6 +188,22 @@ module Functions result end + newfunction(:fqdn_rand, :type => :rvalue, :doc => "Generates random + numbers based on the node's fqdn. The first argument sets the range. + The second argument specifies a number to add to the seed and is + optional.") do |args| + require 'md5' + max = args[0] + if args[1] then + seed = args[1] + else + seed = 1 + end + fqdn_seed = MD5.new(lookupvar('fqdn')).to_s.hex + srand(seed+fqdn_seed) + rand(max).to_s + end + newfunction(:fail, :doc => "Fail with a parse error.") do |vals| vals = vals.collect { |s| s.to_s }.join(" ") if vals.is_a? Array raise Puppet::ParseError, vals.to_s diff --git a/lib/puppet/provider/confine/facter.rb b/lib/puppet/provider/confine/variable.rb index 9bb66c058..84d17367a 100644 --- a/lib/puppet/provider/confine/facter.rb +++ b/lib/puppet/provider/confine/variable.rb @@ -1,32 +1,27 @@ require 'puppet/provider/confine' -class Puppet::Provider::Confine::Facter < Puppet::Provider::Confine +class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine def self.summarize(confines) result = Hash.new { |hash, key| hash[key] = [] } confines.inject(result) { |total, confine| total[confine.fact] += confine.values unless confine.valid?; total } end - attr_accessor :fact - - # Are we a facter comparison? - def facter? - defined?(@facter) - end + attr_accessor :name # Retrieve the value from facter def facter_value unless defined?(@facter_value) and @facter_value - @facter_value = ::Facter.value(@fact).to_s.downcase + @facter_value = ::Facter.value(name).to_s.downcase end @facter_value end def message(value) - "facter value '%s' for '%s' not in required list '%s'" % [value, self.fact, values.join(",")] + "facter value '%s' for '%s' not in required list '%s'" % [value, self.name, values.join(",")] end def pass?(value) - facter_value == value.to_s.downcase + test_value.downcase.to_s == value.to_s.downcase end def reset @@ -34,4 +29,14 @@ class Puppet::Provider::Confine::Facter < Puppet::Provider::Confine # run, but across runs. @facter_value = nil end + + private + + def setting? + Puppet.settings.valid?(name) + end + + def test_value + setting? ? Puppet.settings[name] : facter_value + end end diff --git a/lib/puppet/provider/confine_collection.rb b/lib/puppet/provider/confine_collection.rb index 0c80086c9..35f461acb 100644 --- a/lib/puppet/provider/confine_collection.rb +++ b/lib/puppet/provider/confine_collection.rb @@ -15,8 +15,8 @@ class Puppet::Provider::ConfineCollection @confines << klass.new(values) @confines[-1].for_binary = true if for_binary else - confine = Puppet::Provider::Confine.test(:facter).new(values) - confine.fact = test + confine = Puppet::Provider::Confine.test(:variable).new(values) + confine.name = test @confines << confine end end diff --git a/lib/puppet/provider/group/ldap.rb b/lib/puppet/provider/group/ldap.rb index 632358ff1..a4870fc68 100644 --- a/lib/puppet/provider/group/ldap.rb +++ b/lib/puppet/provider/group/ldap.rb @@ -12,7 +12,7 @@ Puppet::Type.type(:group).provide :ldap, :parent => Puppet::Provider::Ldap do as it iterates across all existing groups to pick the appropriate next one." - confine :true => Puppet.features.ldap? + confine :true => Puppet.features.ldap?, :false => (Puppet[:ldapuser] == "") # We're mapping 'members' here because we want to make it # easy for the ldap user provider to manage groups. This @@ -23,12 +23,14 @@ Puppet::Type.type(:group).provide :ldap, :parent => Puppet::Provider::Ldap do # Find the next gid after the current largest gid. provider = self manager.generates(:gidNumber).with do - largest = 0 - provider.manager.search.each do |hash| - next unless value = hash[:gid] - num = value[0].to_i - if num > largest - largest = num + largest = 500 + if existing = provider.manager.search + existing.each do |hash| + next unless value = hash[:gid] + num = value[0].to_i + if num > largest + largest = num + end end end largest + 1 diff --git a/lib/puppet/provider/user/ldap.rb b/lib/puppet/provider/user/ldap.rb index ba91a871e..0d149ac9a 100644 --- a/lib/puppet/provider/user/ldap.rb +++ b/lib/puppet/provider/user/ldap.rb @@ -12,7 +12,7 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do as it iterates across all existing users to pick the appropriate next one." - confine :true => Puppet.features.ldap? + confine :feature => :ldap, :false => (Puppet[:ldapuser] == "") manages(:posixAccount, :person).at("ou=People").named_by(:uid).and.maps :name => :uid, :password => :userPassword, @@ -32,12 +32,14 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do # Find the next uid after the current largest uid. provider = self manager.generates(:uidNumber).with do - largest = 0 - provider.manager.search.each do |hash| - next unless value = hash[:uid] - num = value[0].to_i - if num > largest - largest = num + largest = 500 + if existing = provider.manager.search + existing.each do |hash| + next unless value = hash[:uid] + num = value[0].to_i + if num > largest + largest = num + end end end largest + 1 diff --git a/lib/puppet/reference/providers.rb b/lib/puppet/reference/providers.rb index 610c7550d..8fd2dbadc 100644 --- a/lib/puppet/reference/providers.rb +++ b/lib/puppet/reference/providers.rb @@ -63,9 +63,13 @@ providers = Puppet::Util::Reference.newreference :providers, :title => "Provider case test when :exists: details += " - Missing files %s\n" % values.join(", ") - when :facter: + when :variable: values.each do |name, facts| - details += " - Fact %s (currently %s) not in list %s\n" % [name, Facter.value(name).inspect, facts.join(", ")] + if Puppet.settings.valid?(name) + details += " - Setting %s (currently %s) not in list %s\n" % [name, Puppet.settings.value(name).inspect, facts.join(", ")] + else + details += " - Fact %s (currently %s) not in list %s\n" % [name, Facter.value(name).inspect, facts.join(", ")] + end end when :true: details += " - Got %s true tests that should have been false\n" % values diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index d4bc42100..fb00a592d 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -499,11 +499,13 @@ class Transaction # Prepare to evaluate the resources in a transaction. def prepare - prefetch() - # Now add any dynamically generated resources generate() + # Then prefetch. It's important that we generate and then prefetch, + # so that any generated resources also get prefetched. + prefetch() + # This will throw an error if there are cycles in the graph. @sorted_resources = relationship_graph.topsort end diff --git a/lib/puppet/type/file/target.rb b/lib/puppet/type/file/target.rb index a0e5dc401..8949c2af6 100644 --- a/lib/puppet/type/file/target.rb +++ b/lib/puppet/type/file/target.rb @@ -54,6 +54,8 @@ module Puppet def insync?(currentvalue) if [:nochange, :notlink].include?(self.should) or @resource.recurse? return true + elsif ! @resource.replace? and File.exists?(@resource[:path]) + return true else return super(currentvalue) end diff --git a/lib/puppet/util/warnings.rb b/lib/puppet/util/warnings.rb index d009c3967..97c96b74c 100644 --- a/lib/puppet/util/warnings.rb +++ b/lib/puppet/util/warnings.rb @@ -9,6 +9,13 @@ module Puppet::Util::Warnings Puppet.warning msg $stampwarnings[self.class] << msg end + + return nil + end + + def clear_warnings() + $stampwarnings = {} + return nil end end |