summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom.may@betfair.com>2010-02-26 16:14:43 +0000
committerThom May <thom.may@betfair.com>2010-02-26 16:17:37 +0000
commit90f156ba97205280344df9ea32e87ad50d14ad81 (patch)
treef668bcbdd4f6867d71b8709617f942327fb680cc
parent92d7de9e9efbf5838af2f2aec6533248f37d1293 (diff)
downloadchef-90f156ba97205280344df9ea32e87ad50d14ad81.tar.gz
CHEF-986: Ensure that we don't explode just because we chose the wrong action
Update rpm install_package to check for an existing version and correctly install or upgrade Alias upgrade_package to install_package Update specs for rpm accordingly
-rw-r--r--chef/lib/chef/provider/package/rpm.rb18
-rw-r--r--chef/spec/unit/provider/package/rpm_spec.rb9
2 files changed, 19 insertions, 8 deletions
diff --git a/chef/lib/chef/provider/package/rpm.rb b/chef/lib/chef/provider/package/rpm.rb
index 2257b14592..0aebe5fbc0 100644
--- a/chef/lib/chef/provider/package/rpm.rb
+++ b/chef/lib/chef/provider/package/rpm.rb
@@ -69,16 +69,18 @@ class Chef
end
def install_package(name, version)
- run_command_with_systems_locale(
- :command => "rpm -i #{@new_resource.source}"
- )
+ unless @current_resource.version
+ run_command_with_systems_locale(
+ :command => "rpm -i #{@new_resource.source}"
+ )
+ else
+ run_command_with_systems_locale(
+ :command => "rpm -U #{@new_resource.source}"
+ )
+ end
end
- def upgrade_package(name, version)
- run_command_with_systems_locale(
- :command => "rpm -U #{@new_resource.source}"
- )
- end
+ alias_method :upgrade_package, :install_package
def remove_package(name, version)
if version
diff --git a/chef/spec/unit/provider/package/rpm_spec.rb b/chef/spec/unit/provider/package/rpm_spec.rb
index fea096033a..43b1bcc187 100644
--- a/chef/spec/unit/provider/package/rpm_spec.rb
+++ b/chef/spec/unit/provider/package/rpm_spec.rb
@@ -110,7 +110,15 @@ describe Chef::Provider::Package::Rpm, "install and upgrade" do
:updated => nil,
:source => "/tmp/emacs-21.4-20.el5.i386.rpm"
)
+ @current_resource = mock("Chef::Resource::Package",
+ :null_object => true,
+ :name => "emacs",
+ :version => nil,
+ :package_name => nil,
+ :updated => nil
+ )
@provider = Chef::Provider::Package::Rpm.new(@node, @new_resource)
+ @provider.current_resource = @current_resource
end
it "should run rpm -i with the package source to install" do
@@ -121,6 +129,7 @@ describe Chef::Provider::Package::Rpm, "install and upgrade" do
end
it "should run rpm -U with the package source to upgrade" do
+ @current_resource.stub!(:version).and_return("21.4-19.el5")
@provider.should_receive(:run_command_with_systems_locale).with({
:command => "rpm -U /tmp/emacs-21.4-20.el5.i386.rpm"
})