summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-10-21 06:39:00 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2005-10-21 06:39:00 +0000
commitf036778df725e1b328ac6f11b784f8e72ee34261 (patch)
treeb2a9284caedec7888817c3dc6a43f7f833314e8d
parenta232e5c6ef359b600cdbc618a9791f8eda8eb081 (diff)
downloadpuppet-f036778df725e1b328ac6f11b784f8e72ee34261.tar.gz
puppet-f036778df725e1b328ac6f11b784f8e72ee34261.tar.xz
puppet-f036778df725e1b328ac6f11b784f8e72ee34261.zip
Apt-cache was showing more information that I thought, so I had to redo how I was collecting the most recent package version
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@721 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/type/package.rb2
-rwxr-xr-xlib/puppet/type/package/apt.rb28
-rw-r--r--test/types/tc_package.rb64
3 files changed, 56 insertions, 38 deletions
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index 296e8af54..690e2d000 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -37,7 +37,7 @@ module Puppet
if @is == latest
return true
else
- Puppet.debug "latest is %s" % latest
+ Puppet.debug "latest %s is %s" % [@parent.name, latest]
end
when :notinstalled
if @is == :notinstalled
diff --git a/lib/puppet/type/package/apt.rb b/lib/puppet/type/package/apt.rb
index 47887ec8a..9267fbcd8 100755
--- a/lib/puppet/type/package/apt.rb
+++ b/lib/puppet/type/package/apt.rb
@@ -31,22 +31,34 @@ module Puppet
# What's the latest package version available?
def latest
- cmd = "apt-cache show %s" % self.name
+ cmd = "apt-cache showpkg %s" % self.name
output = %x{#{cmd} 2>&1}
unless $? == 0
raise Puppet::PackageError.new(output)
end
- if output =~ /Version: (.+)\n/
- return $1
- else
- Puppet.debug "No version"
- if Puppet[:debug]
- print output
+ if output =~ /Versions:\s*\n((\n|.)+)^$/
+ versions = $1
+ version = versions.split(/\n/).collect { |version|
+ if version =~ /(.+)\(/
+ $1
+ else
+ Puppet.warning "Could not match version '%s'" % version
+ nil
+ end
+ }.reject { |vers| vers.nil? }.sort[-1]
+
+ unless version
+ Puppet.debug "No latest version"
+ if Puppet[:debug]
+ print output
+ end
end
- return nil
+ return version
+ else
+ Puppet.err "Could not match string"
end
end
diff --git a/test/types/tc_package.rb b/test/types/tc_package.rb
index a1eaefa52..1936c8bbc 100644
--- a/test/types/tc_package.rb
+++ b/test/types/tc_package.rb
@@ -35,6 +35,29 @@ class TestPackages < Test::Unit::TestCase
super
end
+ # These are packages that we're sure will be installed
+ def installedpkgs
+ pkgs = nil
+ case $platform
+ when "SunOS"
+ pkgs = %w{SMCossh}
+ when "Linux"
+ case Facter["distro"].value
+ when "Debian": pkgs = %w{ssh openssl}
+ when "Fedora": pkgs = %w{openssh}
+ #when "RedHat": type = :rpm
+ else
+ Puppet.notice "No test package for %s" % $platform
+ return []
+ end
+ else
+ Puppet.notice "No test package for %s" % $platform
+ return []
+ end
+
+ return pkgs
+ end
+
def tstpkg
case $platform
#when "SunOS"
@@ -70,39 +93,22 @@ class TestPackages < Test::Unit::TestCase
end
def test_retrievepkg
- pkg = nil
-
- case $platform
- when "SunOS"
- pkg = "SMCossh"
- when "Linux"
- case Facter["distro"].value
- when "Debian": pkg = "ssh"
- when "Fedora": pkg = "openssh"
- #when "RedHat": type = :rpm
- else
- Puppet.notice "No test package for %s" % $platform
- return
- end
- else
- Puppet.notice "No test package for %s" % $platform
- return
- end
+ installedpkgs().each { |pkg|
+ obj = nil
+ assert_nothing_raised {
+ obj = Puppet::Type::Package.create(
+ :name => pkg
+ )
+ }
- obj = nil
- assert_nothing_raised {
- obj = Puppet::Type::Package.create(
- :name => pkg
- )
- }
+ assert(obj, "could not create package")
- assert(obj, "could not create package")
+ assert_nothing_raised {
+ obj.retrieve
+ }
- assert_nothing_raised {
- obj.retrieve
+ assert(obj.is(:install), "Could not retrieve package version")
}
-
- assert(obj.is(:install), "Could not retrieve package version")
end
def test_nosuchpkg