+1 On Tue, Oct 5, 2010 at 3:28 PM, Matt Robinson <[email protected]> wrote: > From: Dan Bode <[email protected]> > > patch originally from Grzegorz Nosek with contributions on > the test from Oliver Hookins. > > checks if the current version is greater than the should > version, if so, calls yum downgrade. > > Reviewed-by: Matt Robinson > > Signed-off-by: Matt Robinson <[email protected]> > --- > lib/puppet/provider/package/yum.rb | 9 ++++++++- > spec/unit/provider/package/yum_spec.rb | 20 +++++++++++++------- > 2 files changed, 21 insertions(+), 8 deletions(-) > > diff --git a/lib/puppet/provider/package/yum.rb > b/lib/puppet/provider/package/yum.rb > index fcda5ba..6ed966f 100755 > --- a/lib/puppet/provider/package/yum.rb > +++ b/lib/puppet/provider/package/yum.rb > @@ -1,3 +1,4 @@ > +require 'puppet/util/package' > Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do > desc "Support via `yum`." > > @@ -52,6 +53,7 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, > :source => :rpm do > should = @resource.should(:ensure) > self.debug "Ensuring => #{should}" > wanted = @resource[:name] > + operation = :install > > # XXX: We don't actually deal with epochs here. > case should > @@ -61,9 +63,14 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, > :source => :rpm do > else > # Add the package version > wanted += "-#{should}" > + is = self.query > + if is && Puppet::Util::Package.versioncmp(should, is[:ensure]) < 0 > + self.debug "Downgrading package #...@resource[:name]} from version > #{is[:ensure]} to #{should}" > + operation = :downgrade > + end > end > > - output = yum "-d", "0", "-e", "0", "-y", :install, wanted > + output = yum "-d", "0", "-e", "0", "-y", operation, wanted > > is = self.query > raise Puppet::Error, "Could not find package #{self.name}" unless is > diff --git a/spec/unit/provider/package/yum_spec.rb > b/spec/unit/provider/package/yum_spec.rb > index 09c81f7..f6a99aa 100644 > --- a/spec/unit/provider/package/yum_spec.rb > +++ b/spec/unit/provider/package/yum_spec.rb > @@ -31,21 +31,27 @@ describe provider do > @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :install, > 'mypackage') > @provider.install > end > - it "should use :install to update" do > + it 'should use :install to update' do > @provider.expects(:install) > @provider.update > end > - it "should be able to set version" do > - �[email protected](:should).with(:ensure).returns "1.2" > + it 'should be able to set version' do > + �[email protected](:should).with(:ensure).returns '1.2' > @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :install, > 'mypackage-1.2') > - �[email protected](:query).returns :ensure => '1.2' > + �[email protected](:query).returns :ensure => '1.2' > + �[email protected] > + end > + it 'should be able to downgrade' do > + �[email protected](:should).with(:ensure).returns '1.0' > + �[email protected](:yum).with('-d', '0', '-e', '0', '-y', > :downgrade, 'mypackage-1.0') > + �[email protected](:query).returns(:ensure => > '1.2').then.returns(:ensure => '1.0') > @provider.install > end > end > > describe 'when uninstalling' do > - it "should use erase to purge" do > - �[email protected](:yum).with("-y", :erase, 'mypackage') > + it 'should use erase to purge' do > + �[email protected](:yum).with('-y', :erase, 'mypackage') > @provider.purge > end > it 'should use rpm to uninstall' do > @@ -54,7 +60,7 @@ describe provider do > end > end > > - it "should be versionable" do > + it 'should be versionable' do > provider.should be_versionable > end > end > -- > 1.7.1 > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Developers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/puppet-dev?hl=en. > >
-- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
