summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorMarcel Haerry <haerry@puzzle.ch>2008-07-28 16:02:10 +0200
committerJames Turnbull <james@lovedthanlost.net>2008-08-01 08:49:47 +1000
commit818599db7dc6210cc015d8888d119726eb6c3323 (patch)
tree6c1171e427ab175a6e157c0f19a6e77d15855fcd /lib/puppet
parent8457856c0abb58e0521532148b368be1a8b4790e (diff)
downloadpuppet-818599db7dc6210cc015d8888d119726eb6c3323.tar.gz
puppet-818599db7dc6210cc015d8888d119726eb6c3323.tar.xz
puppet-818599db7dc6210cc015d8888d119726eb6c3323.zip
lazy load latest package definitions with yumhelper 2.2
I have to admit that the version 2.1 one of this patch was not good tested from my side and it simply didn't work. I'm very sorry for that. However I did now extensive (manual) testing and it works the way it should for me. I can confirm that yumhelper isn't called if there is no latest ensure and it is called if there is at least one. So correct commit message: After discussion on the list, this is the new version for lazy loading yum latest package versions. It is implemented mainly in the way that Luke proposed. However it stores the latest informations in the variable latest_info so the latest method didn't get too hackish and could nearly be left like it was before. + fixed copy&paste regression, so :latest_info is not anymore on the class side + fixed package iteration and ensure usage.
Diffstat (limited to 'lib/puppet')
-rwxr-xr-xlib/puppet/provider/package/yum.rb41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb
index 7998b92c0..56fad1af9 100755
--- a/lib/puppet/provider/package/yum.rb
+++ b/lib/puppet/provider/package/yum.rb
@@ -7,9 +7,7 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
YUMHELPER = File::join(File::dirname(__FILE__), "yumhelper.py")
- class << self
- attr_reader :updates
- end
+ attr_accessor :latest_info
if command('rpm')
confine :true => begin
@@ -24,22 +22,32 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
defaultfor :operatingsystem => [:fedora, :centos, :redhat]
def self.prefetch(packages)
- @updates = {}
if Process.euid != 0
raise Puppet::Error, "The yum provider can only be used as root"
end
super
- python(YUMHELPER).each_line do |l|
- l.chomp!
- next if l.empty?
- if l[0,4] == "_pkg"
- hash = nevra_to_hash(l[5..-1])
- [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n|
- @updates[n] ||= []
- @updates[n] << hash
- end
- end
- end
+ return unless packages.detect { |name, package| package.should(:ensure) == :latest }
+
+ # collect our 'latest' info
+ updates = {}
+ python(YUMHELPER).each_line do |l|
+ l.chomp!
+ next if l.empty?
+ if l[0,4] == "_pkg"
+ hash = nevra_to_hash(l[5..-1])
+ [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n|
+ updates[n] ||= []
+ updates[n] << hash
+ end
+ end
+ end
+
+ # Add our 'latest' info to the providers.
+ packages.each do |name, package|
+ if info = updates[package[:name]]
+ package.provider.latest_info = info[0]
+ end
+ end
end
def install
@@ -73,11 +81,10 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
# What's the latest package version available?
def latest
- upd = self.class.updates[@resource[:name]]
+ upd = latest_info
unless upd.nil?
# FIXME: there could be more than one update for a package
# because of multiarch
- upd = upd[0]
return "#{upd[:version]}-#{upd[:release]}"
else
# Yum didn't find updates, pretend the current