[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

duritong peter.meier at immerda.ch
Fri Jan 23 14:21:25 UTC 2009


The following commit has been merged in the master branch:
commit 65eafb7c01e6b4c003066cf7c6dceb5910e91950
Author: duritong <peter.meier at immerda.ch>
Date:   Fri Oct 10 16:15:59 2008 +0200

    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.

diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb
index 7998b92..56fad1a 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

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list