Fixing #487. I know use "apt-cache policy", instead of apt-cache showpkg, because it clearly shows which version will be installed. This is basically impossible to test well, so I just added a test that verifies we always get a value back, although I cannot really test that it is the "right" value. Also, I modified the logging of packages so if there is a latest version, you will get the new version number, along with the old, in the log.

git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2310 980ebf18-57e1-0310-9a29-db15c13687c0
This commit is contained in:
luke 2007-03-19 05:21:44 +00:00
Родитель 973f9d05e8
Коммит 4dc72337ac
3 изменённых файлов: 31 добавлений и 24 удалений

Просмотреть файл

@ -76,32 +76,13 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg do
# What's the latest package version available?
def latest
output = aptcache :showpkg, @model[:name]
output = aptcache :policy, @model[:name]
if output =~ /Versions:\s*\n((\n|.)+)^$/
versions = $1
available_versions = versions.split(/\n/).collect { |version|
if version =~ /^([^\(]+)\(/
$1
else
self.warning "Could not match version '%s'" % version
nil
end
}.reject { |vers| vers.nil? }.sort { |a,b|
versioncmp(a,b)
}
if available_versions.length == 0
self.debug "No latest version"
if Puppet[:debug]
print output
end
end
# Get the latest and greatest version number
return available_versions.pop
if output =~ /\*\*\*\s+(\S+)\s/
return $1
else
self.err "Could not match string"
self.err "Could not find latest version"
return nil
end
end

Просмотреть файл

@ -163,6 +163,15 @@ module Puppet
def retrieve
@is = @parent.retrieve
end
# Provide a bit more information when logging upgrades.
def should_to_s
if @latest
@latest.to_s
else
super
end
end
end
newparam(:name) do

Просмотреть файл

@ -69,4 +69,21 @@ class AptPackageProviderTest < PuppetTest::TestCase
pkg.evaluate.each { |state| state.transaction = self; state.forward }
end
def test_latest
pkg = @type.create :name => 'ssh', :provider => :apt
assert(pkg, "did not create pkg")
status = pkg.provider.query
assert(status, "ssh is not installed")
assert(status[:ensure] != :absent, "ssh is not installed")
latest = nil
assert_nothing_raised("Could not call latest") do
latest = pkg.provider.latest
end
assert(latest, "Could not get latest value from apt")
end
end
# $Id$