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 | |
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')
-rw-r--r-- | lib/puppet/provider.rb | 43 | ||||
-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 |
4 files changed, 84 insertions, 73 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb index e0de9d61d..c02e15029 100644 --- a/lib/puppet/provider.rb +++ b/lib/puppet/provider.rb @@ -7,6 +7,8 @@ class Puppet::Provider require 'puppet/provider/confiner' + extend Puppet::Provider::Confiner + Puppet::Util.logmethods(self, true) class << self @@ -42,31 +44,16 @@ class Puppet::Provider [name, self.name] end - if command == :missing - return nil - end - - command + return binary(command) end # Define commands that are not optional. def self.commands(hash) optional_commands(hash) do |name, path| - confine :exists => path + confine :exists => path, :for_binary => true end end - def self.confine(hash) - confiner.confine(hash) - end - - def self.confiner - unless defined?(@confiner) - @confiner = Puppet::Provider::Confiner.new - end - @confiner - end - # Is the provided feature a declared feature? def self.declared_feature?(name) defined?(@declared_features) and @declared_features.include?(name) @@ -111,7 +98,6 @@ class Puppet::Provider def self.initvars @defaults = {} @commands = {} - @origcommands = {} end # The method for returning a list of provider instances. Note that it returns providers, preferably with values already @@ -180,16 +166,7 @@ class Puppet::Provider def self.optional_commands(hash) hash.each do |name, path| name = symbolize(name) - @origcommands[name] = path - - # Try to find the full path (or verify already-full paths); otherwise - # store that the command is missing so we know it's defined but absent. - if tmp = binary(path) - path = tmp - @commands[name] = path - else - @commands[name] = :missing - end + @commands[name] = path if block_given? yield(name, path) @@ -208,12 +185,6 @@ class Puppet::Provider @source end - # Check whether this implementation is suitable for our platform. - def self.suitable?(short = true) - return confiner.valid? if short - return confiner.result - end - # Does this provider support the specified parameter? def self.supports_parameter?(param) if param.is_a?(Class) @@ -252,8 +223,8 @@ class Puppet::Provider end dochook(:commands) do - if @origcommands.length > 0 - return " Required binaries: " + @origcommands.collect do |n, c| + if @commands.length > 0 + return " Required binaries: " + @commands.collect do |n, c| "``#{c}``" end.join(", ") + "." end 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 |