summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2010-11-23 11:18:23 -0800
committerMatt Robinson <matt@puppetlabs.com>2010-11-23 11:18:23 -0800
commite00c582c8977a02200b86f18ccc6debf30abdfed (patch)
treed22579d01f07691f61d5969554cf3549f1eed56c
parent3d2fbf604f997e6b9fd94edb96419ffa9869e709 (diff)
parent9ccd29f3aacdab03f2ea9a693b5bca928439683b (diff)
downloadpuppet-e00c582c8977a02200b86f18ccc6debf30abdfed.tar.gz
puppet-e00c582c8977a02200b86f18ccc6debf30abdfed.tar.xz
puppet-e00c582c8977a02200b86f18ccc6debf30abdfed.zip
Merge branch 'ticket/next/2866' into next
* ticket/next/2866: (#2866) yum should support downgrade. (#4711) Provide unit tests for yum package provider.
-rwxr-xr-xlib/puppet/provider/package/yum.rb9
-rw-r--r--spec/unit/provider/package/yum_spec.rb67
2 files changed, 75 insertions, 1 deletions
diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb
index fcda5ba8c..6ed966fbd 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
new file mode 100644
index 000000000..f6a99aa78
--- /dev/null
+++ b/spec/unit/provider/package/yum_spec.rb
@@ -0,0 +1,67 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider = Puppet::Type.type(:package).provider(:yum)
+
+describe provider do
+ before do
+ # Create a mock resource
+ @resource = stub 'resource'
+ @resource.stubs(:[]).with(:name).returns 'mypackage'
+ @provider = provider.new(@resource)
+ @provider.stubs(:resource).returns @resource
+ @provider.stubs(:yum).returns 'yum'
+ @provider.stubs(:rpm).returns 'rpm'
+ @provider.stubs(:get).with(:name).returns 'mypackage'
+ @provider.stubs(:get).with(:version).returns '1'
+ @provider.stubs(:get).with(:release).returns '1'
+ @provider.stubs(:get).with(:arch).returns 'i386'
+ end
+ # provider should repond to the following methods
+ [:install, :latest, :update, :purge].each do |method|
+ it "should have a(n) #{method}" do
+ @provider.should respond_to(method)
+ end
+ end
+
+ describe 'when installing' do
+ it 'should call yum install for :installed' do
+ @resource.stubs(:should).with(:ensure).returns :installed
+ @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :install, 'mypackage')
+ @provider.install
+ end
+ it 'should use :install to update' do
+ @provider.expects(:install)
+ @provider.update
+ end
+ it 'should be able to set version' do
+ @resource.stubs(:should).with(:ensure).returns '1.2'
+ @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :install, 'mypackage-1.2')
+ @provider.stubs(:query).returns :ensure => '1.2'
+ @provider.install
+ end
+ it 'should be able to downgrade' do
+ @resource.stubs(:should).with(:ensure).returns '1.0'
+ @provider.expects(:yum).with('-d', '0', '-e', '0', '-y', :downgrade, 'mypackage-1.0')
+ @provider.stubs(: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
+ @provider.expects(:yum).with('-y', :erase, 'mypackage')
+ @provider.purge
+ end
+ it 'should use rpm to uninstall' do
+ @provider.expects(:rpm).with('-e', 'mypackage-1-1.i386')
+ @provider.uninstall
+ end
+ end
+
+ it 'should be versionable' do
+ provider.should be_versionable
+ end
+end
+