diff options
| author | Luke Kanies <luke@madstop.com> | 2008-05-15 23:09:58 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-05-15 23:09:58 -0500 |
| commit | a1409d73b4bb8acbf5db2f8d7a244c2bca81db14 (patch) | |
| tree | 5592eae3f085717898fc905527f2a38ebabb22e8 /lib/puppet/provider | |
| parent | 995991d8740baff52cee057752c428d0259e2be1 (diff) | |
| download | puppet-a1409d73b4bb8acbf5db2f8d7a244c2bca81db14.tar.gz puppet-a1409d73b4bb8acbf5db2f8d7a244c2bca81db14.tar.xz puppet-a1409d73b4bb8acbf5db2f8d7a244c2bca81db14.zip | |
Moving all confine code out of the Provider class, and fixing #1197.
I created a Confiner module for the Provider class methods,
and then I enhanced the interface between it and the Confine
class to make sure binary paths are searched for fresh each time.
This fixes #1197, which was a result of binary paths being
searched for at startup, rather than at execution.
Diffstat (limited to 'lib/puppet/provider')
| -rw-r--r-- | lib/puppet/provider/confine.rb | 23 | ||||
| -rw-r--r-- | lib/puppet/provider/confine_collection.rb | 48 | ||||
| -rw-r--r-- | lib/puppet/provider/confiner.rb | 43 |
3 files changed, 77 insertions, 37 deletions
diff --git a/lib/puppet/provider/confine.rb b/lib/puppet/provider/confine.rb index e55ba02ec..227c923e6 100644 --- a/lib/puppet/provider/confine.rb +++ b/lib/puppet/provider/confine.rb @@ -1,9 +1,22 @@ # The class that handles testing whether our providers # actually work or not. +require 'puppet/util' + class Puppet::Provider::Confine + include Puppet::Util + attr_reader :test, :values, :fact + # Mark that this confine is used for testing binary existence. + attr_accessor :for_binary + def for_binary? + for_binary + end + def exists?(value) + if for_binary? + return false unless value = binary(value) + end value and FileTest.exist?(value) end @@ -57,11 +70,11 @@ class Puppet::Provider::Confine values.each do |value| unless send(@method, value) msg = case test - when :false: "false value" - when :true: "true value" - when :exists: "file %s does not exist" % value - when :facter: "facter value '%s' for '%s' not in required list '%s'" % [value, @fact, values.join(",")] - end + when :false: "false value when expecting true" + when :true: "true value when expecting false" + when :exists: "file %s does not exist" % value + when :facter: "facter value '%s' for '%s' not in required list '%s'" % [value, @fact, values.join(",")] + end Puppet.debug msg return false end diff --git a/lib/puppet/provider/confine_collection.rb b/lib/puppet/provider/confine_collection.rb new file mode 100644 index 000000000..f38035521 --- /dev/null +++ b/lib/puppet/provider/confine_collection.rb @@ -0,0 +1,48 @@ +# Manage a collection of confines, returning a boolean or +# helpful information. +require 'puppet/provider/confine' + +class Puppet::Provider::ConfineCollection + def confine(hash) + if hash.include?(:for_binary) + for_binary = true + hash.delete(:for_binary) + else + for_binary = false + end + hash.each do |test, values| + @confines << Puppet::Provider::Confine.new(test, values) + @confines[-1].for_binary = true if for_binary + end + end + + def initialize + @confines = [] + end + + # Return a hash of the whole confine set, used for the Provider + # reference. + def result + defaults = { + :false => 0, + :true => 0, + :exists => [], + :facter => {} + } + missing = Hash.new { |hash, key| hash[key] = defaults[key] } + @confines.each do |confine| + case confine.test + when :false: missing[confine.test] += confine.result.find_all { |v| v == false }.length + when :true: missing[confine.test] += confine.result.find_all { |v| v == true }.length + when :exists: confine.result.zip(confine.values).each { |val, f| missing[:exists] << f unless val } + when :facter: missing[:facter][confine.fact] = confine.values if confine.result.include?(false) + end + end + + missing + end + + def valid? + ! @confines.detect { |c| ! c.valid? } + end +end diff --git a/lib/puppet/provider/confiner.rb b/lib/puppet/provider/confiner.rb index b88f1f01b..3e406873b 100644 --- a/lib/puppet/provider/confiner.rb +++ b/lib/puppet/provider/confiner.rb @@ -1,41 +1,20 @@ -# Manage a collection of confines, returning a boolean or -# helpful information. -require 'puppet/provider/confine' +require 'puppet/provider/confine_collection' -class Puppet::Provider::Confiner +module Puppet::Provider::Confiner def confine(hash) - hash.each do |test, values| - @confines << Puppet::Provider::Confine.new(test, values) - end - end - - def initialize - @confines = [] + confine_collection.confine(hash) end - # Return a hash of the whole confine set, used for the Provider - # reference. - def result - defaults = { - :false => 0, - :true => 0, - :exists => [], - :facter => {} - } - missing = Hash.new { |hash, key| hash[key] = defaults[key] } - @confines.each do |confine| - case confine.test - when :false: missing[confine.test] += confine.result.find_all { |v| v == false }.length - when :true: missing[confine.test] += confine.result.find_all { |v| v == true }.length - when :exists: confine.result.zip(confine.values).each { |val, f| missing[:exists] << f unless val } - when :facter: missing[:facter][confine.fact] = confine.values if confine.result.include?(false) - end + def confine_collection + unless defined?(@confine_collection) + @confine_collection = Puppet::Provider::ConfineCollection.new end - - missing + @confine_collection end - def valid? - ! @confines.detect { |c| ! c.valid? } + # Check whether this implementation is suitable for our platform. + def suitable?(short = true) + return confine_collection.valid? if short + return confine_collection.result end end |
