Puppet: System Administration Automated

Support

Ticket #913: up2date.patch

File up2date.patch, 2.6 kB (added by jdreese, 1 year ago)

patch for up2date provider that enables prefetching

  • a/lib/puppet/provider/package/up2date.rb

    old new  
    22    desc "Support for Red Hat's proprietary ``up2date`` package update 
    33        mechanism." 
    44 
    5     commands :up2date => "/usr/sbin/up2date-nox" 
     5    commands :up2date => "/usr/sbin/up2date-nox", :python => "python" 
    66    defaultfor :operatingsystem => :redhat,  
    77               :lsbdistrelease => ["2.1", "3", "4"] 
    88    confine    :operatingsystem => :redhat 
    99 
     10    UP2DATEHELPER = File::join(File::dirname(__FILE__), "up2datehelper.py") 
     11 
     12    class << self 
     13        attr_reader :updates 
     14    end 
     15 
    1016    # Install a package using 'up2date'. 
    1117    def install 
    1218        up2date "-u", @resource[:name] 
     
    2026 
    2127    # What's the latest package version available? 
    2228    def latest 
    23         #up2date can only get a list of *all* available packages? 
    24         output = up2date "--showall" 
    25  
    26         if output =~ /^#{@resource[:name]}-(\d+.*)\.\w+/ 
    27             return $1 
     29        upd = self.class.updates[@resource[:name]] 
     30        unless upd.nil? 
     31            # FIXME: there could be more than one update for a package 
     32            # because of multiarch 
     33            upd = upd[0] 
     34            return "#{upd[:version]}-#{upd[:release]}" 
    2835        else 
    2936            # up2date didn't find updates, pretend the current 
    3037            # version is the latest 
    31             return @property_hash[:ensure] 
     38            if properties[:ensure] == :absent 
     39                raise Puppet::DevError, "Tried to get latest on a missing package" 
     40            end 
     41            return properties[:ensure] 
    3242        end 
    3343    end 
    3444 
     45 
    3546    def update 
    3647        # Install in up2date can be used for update, too 
    3748        self.install 
    3849    end 
     50 
     51    def self.prefetch(packages) 
     52        @updates = {} 
     53        if Process.euid != 0 
     54            raise Puppet::Error, "The up2date provider can only be used as root" 
     55        end 
     56        super 
     57        python(UP2DATEHELPER).each_line do |l| 
     58            l.chomp! 
     59            next if l.empty? 
     60            if l[0,4] == "_pkg" 
     61                hash = nevra_to_hash(l[5..-1]) 
     62                [hash[:name], "#{hash[:name]}.#{hash[:arch]}"].each do |n| 
     63                    @updates[n] ||= [] 
     64                    @updates[n] << hash 
     65                end 
     66            end 
     67        end 
     68    end 
     69 
    3970end 
    4071