diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-07-21 16:43:16 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-07-22 13:29:32 -0700 |
commit | 532c4f37e4f8289cf4a9871ebc0cb5086c2ba26a (patch) | |
tree | b8e682f621a8974874d79c60a9562611bd6e21b0 /lib/puppet/interface | |
parent | 2cd3bc47993fbd32a77ca9dfdd51353f2dfbcb58 (diff) | |
download | puppet-532c4f37e4f8289cf4a9871ebc0cb5086c2ba26a.tar.gz puppet-532c4f37e4f8289cf4a9871ebc0cb5086c2ba26a.tar.xz puppet-532c4f37e4f8289cf4a9871ebc0cb5086c2ba26a.zip |
(#7184) Load the core of obsolete versions of Faces.
When we define an action on an older version of a Face, we must be sure to
directly load the core of that version, not just define it with the external
Action(s) that it had.
Otherwise we break our contract, which is that any core Actions for a specific
version will be available to your external Action for as long as we support
that core version.
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'lib/puppet/interface')
-rw-r--r-- | lib/puppet/interface/face_collection.rb | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/puppet/interface/face_collection.rb b/lib/puppet/interface/face_collection.rb index 868997b67..b1f6ba398 100644 --- a/lib/puppet/interface/face_collection.rb +++ b/lib/puppet/interface/face_collection.rb @@ -56,9 +56,7 @@ module Puppet::Interface::FaceCollection # # We use require to avoid executing the code multiple times, like any # other Ruby library that we might want to use. --daniel 2011-04-06 - begin - require "puppet/face/#{name}" - + if safely_require name then # If we wanted :current, we need to index to find that; direct version # requests just work™ as they go. --daniel 2011-04-06 if version == :current then @@ -90,18 +88,32 @@ module Puppet::Interface::FaceCollection latest_ver = @faces[name].keys.sort.last @faces[name][:current] = @faces[name][latest_ver] end - rescue LoadError => e - raise unless e.message =~ %r{-- puppet/face/#{name}$} - # ...guess we didn't find the file; return a much better problem. - rescue SyntaxError => e - raise unless e.message =~ %r{puppet/face/#{name}\.rb:\d+: } - Puppet.err "Failed to load face #{name}:\n#{e}" - # ...but we just carry on after complaining. + end + + unless version == :current or get_face(name, version) + # Try an obsolete version of the face, if needed, to see if that helps? + safely_require name, version end return get_face(name, version) end + def self.safely_require(name, version = nil) + path = File.join 'puppet' ,'face', version.to_s, name.to_s + require path + true + + rescue LoadError => e + raise unless e.message =~ %r{-- #{path}$} + # ...guess we didn't find the file; return a much better problem. + nil + rescue SyntaxError => e + raise unless e.message =~ %r{#{path}\.rb:\d+: } + Puppet.err "Failed to load face #{name}:\n#{e}" + # ...but we just carry on after complaining. + nil + end + def self.register(face) @faces[underscorize(face.name)][face.version] = face end |