Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#23316) Updated yum package provider to support :holdable feature by #2137

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -27,6 +27,19 @@

defaultfor :operatingsystem => [:fedora, :centos, :redhat]

if command('yum')
Puppet.debug('Checking if yum supports versionlock.')
begin
yum('versionlock')
rescue Puppet::ExecutionFailure => e
Puppet.debug("Yum versionlock failed with: #{e.inspect}.")
false
else
Puppet.debug("Yum versionlock ran OK, therefore add :holdable feature.")
has_feature :holdable
end
end

def self.prefetch(packages)
raise Puppet::Error, "The yum provider can only be used as root" if Process.euid != 0
super
@@ -74,6 +87,12 @@ def install
end
end

# Unhold before installing
if self.class.declared_feature?(:holdable)
Puppet.debug('Provider supports holdable. Unholding package before installing...')
self.unhold
end

yum "-d", "0", "-e", "0", "-y", operation, wanted

is = self.query
@@ -107,4 +126,27 @@ def update
def purge
yum "-y", :erase, @resource[:name]
end

def hold
# Install before locking the version.
self.install
yum('versionlock', @resource[:name])
end

def unhold
Puppet.debug('Got to yum.unhold...')
begin
yum('versionlock', 'delete', "*#{@resource[:name]}*")
rescue Puppet::ExecutionFailure => e
# No versionlock present for this package
Puppet.debug("Yum versionlock delete failed with error: #{e.inspect}")
return true if e.inspect =~ /versionlock delete: no matches/
# If it's not a no match failure, then something else went wrong...
raise Puppet::Error, "Failed to unhold package #{@resource[:name]} due to: #{e.inspect}"
return false

This comment has been minimized.

Copy link
@zaphod42

zaphod42 Dec 11, 2013

Contributor

This line will never be reached because of the raise above it.

end
Puppet.debug("Successfully deleted versionlock for package #{@resource[:name]}")
return true
end

end
@@ -17,8 +17,8 @@
@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|
# provider should respond to the following methods
[:install, :latest, :update, :purge, :hold, :unhold].each do |method|
it "should have a(n) #{method}" do
@provider.should respond_to(method)
end
@@ -55,6 +55,12 @@
@provider.stubs(:query).returns(:ensure => '1.2').then.returns(:ensure => '1.0')
@provider.install
end

it 'should be able to hold' do
@resource.stubs(:should).with(:ensure).returns :held
@provider.expects(:yum).with('versionlock', 'mypackage')
@provider.hold
end
end

describe 'when uninstalling' do
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.