summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorduritong <peter.meier@immerda.ch>2008-10-10 16:15:59 +0200
committerduritong <peter.meier@immerda.ch>2008-10-10 16:15:59 +0200
commit65eafb7c01e6b4c003066cf7c6dceb5910e91950 (patch)
treec87c44c8c454f9905f8349437734db51a40eecf1 /lib/puppet
parenteff6ce0b5e83ed73b8e2bbe3ddd68cf4cd77caeb (diff)
downloadpuppet-65eafb7c01e6b4c003066cf7c6dceb5910e91950.tar.gz
puppet-65eafb7c01e6b4c003066cf7c6dceb5910e91950.tar.xz
puppet-65eafb7c01e6b4c003066cf7c6dceb5910e91950.zip
lazy load latest package definitions with yumhelper 2.2
merge commit to 0.24x, original commit: I could observe that yumhelper.py can run quite some time and use quite a lot of memory (up to 100MB!) if you're using many repositories. As the yumhelper is only needed if you use latest as a ensure-keyword it makes no sense for people like me letting puppet fetch these details always, if you're never going to use latest. => lazy loading. 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.
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