Skip to content

Commit

Permalink
CHEF-2716: Don't compare nil versions, use the parent logic. Add missing
Browse files Browse the repository at this point in the history
specs for the action_upgrade workaround.
  • Loading branch information
mdkent authored and btm committed Mar 16, 2012
1 parent 75981fe commit d8336f6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
8 changes: 6 additions & 2 deletions chef/lib/chef/provider/package/yum.rb
Expand Up @@ -1052,6 +1052,7 @@ def install_package(name, version)
"and release? (version-release, e.g. 1.84-10.fc6)"
end
end

if flush_cache[:after]
@yum.reload
else
Expand All @@ -1067,10 +1068,12 @@ def install_package(name, version)
#
# Hacky - better overall solution? Custom compare in Package provider?
def action_upgrade
# Could be uninstalled or have no candidate
if @current_resource.version.nil? || candidate_version.nil?
super
# Ensure the candidate is newer
if RPMVersion.parse(candidate_version) > RPMVersion.parse(@current_resource.version)
elsif RPMVersion.parse(candidate_version) > RPMVersion.parse(@current_resource.version)
super
# Candidate is older
else
Chef::Log.debug("#{@new_resource} is at the latest version - nothing to do")
end
Expand All @@ -1086,6 +1089,7 @@ def remove_package(name, version)
else
yum_command("yum -d0 -e0 -y#{expand_options(@new_resource.options)} remove #{name}#{yum_arch}")
end

if flush_cache[:after]
@yum.reload
else
Expand Down
41 changes: 41 additions & 0 deletions chef/spec/unit/provider/package/yum_spec.rb
Expand Up @@ -488,6 +488,47 @@
@provider.load_current_resource
lambda { @provider.upgrade_package("cups", "1.2.4-11.15.el5") }.should raise_error(Chef::Exceptions::Package, %r{is newer than candidate package})
end

# Test our little workaround, some crossover into Chef::Provider::Package territory
it "should call action_upgrade in the parent if the current resource version is nil" do
@yum_cache.stub!(:installed_version).and_return(nil)
@provider.load_current_resource
@current_resource = Chef::Resource::Package.new('cups')
@provider.candidate_version = '11'
@provider.should_receive(:upgrade_package).with(
"cups",
"11"
)
@provider.action_upgrade
end

it "should call action_upgrade in the parent if the candidate version is nil" do
@provider.load_current_resource
@current_resource = Chef::Resource::Package.new('cups')
@provider.candidate_version = nil
@provider.should_not_receive(:upgrade_package)
@provider.action_upgrade
end

it "should call action_upgrade in the parent if the candidate is newer" do
@provider.load_current_resource
@current_resource = Chef::Resource::Package.new('cups')
@provider.candidate_version = '11'
@provider.should_receive(:upgrade_package).with(
"cups",
"11"
)
@provider.action_upgrade
end

it "should not call action_upgrade in the parent if the candidate is older" do
@yum_cache.stub!(:installed_version).and_return("12")
@provider.load_current_resource
@current_resource = Chef::Resource::Package.new('cups')
@provider.candidate_version = '11'
@provider.should_not_receive(:upgrade_package)
@provider.action_upgrade
end
end

describe "when removing a package" do
Expand Down

0 comments on commit d8336f6

Please sign in to comment.