From c5ce953462f424138f0009ce978eb9620aff84a7 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 6 Sep 2006 00:49:14 +0000 Subject: Adding aptitude support, including a new util::package module that provides a method for package version sorting, and a couple of smaller bug fixes. This fixes #237. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1570 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/provider/package/apt.rb | 15 +++++++-- lib/puppet/provider/package/aptitude.rb | 14 ++++++++ lib/puppet/type.rb | 1 - lib/puppet/type/pfile.rb | 3 +- lib/puppet/util.rb | 1 + test/other/loadedfile.rb | 58 +++++++++++++++++++++++++++++++++ test/other/parsedfile.rb | 58 --------------------------------- test/other/puppet.rb | 1 - test/types/service.rb | 1 - test/util/classgen.rb | 2 +- test/util/package.rb | 30 +++++++++++++++++ 11 files changed, 118 insertions(+), 66 deletions(-) create mode 100755 lib/puppet/provider/package/aptitude.rb create mode 100755 test/other/loadedfile.rb delete mode 100755 test/other/parsedfile.rb create mode 100755 test/util/package.rb diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb index c0fa0f3a5..a31fbda2b 100755 --- a/lib/puppet/provider/package/apt.rb +++ b/lib/puppet/provider/package/apt.rb @@ -1,4 +1,7 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg do + # Provide sorting functionality + include Puppet::Util::Package + desc "Package management via ``apt-get``." commands :aptget => "/usr/bin/apt-get" @@ -12,6 +15,10 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg do # Debian boxes, and the only thing that differs is that it can # install packages from remote sites. + def apt + command(:aptget) + end + def checkforcdrom unless defined? @@checkedforcdrom if FileTest.exists? "/etc/apt/sources.list" @@ -48,7 +55,7 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg do # Add the package version str += "=%s" % should end - cmd = "#{command(:aptget)} -q -y install %s" % str + cmd = "#{apt()} -q -y install %s" % str begin output = execute(cmd) @@ -75,7 +82,9 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg do self.warning "Could not match version '%s'" % version nil end - }.reject { |vers| vers.nil? }.sort[-1] + }.reject { |vers| vers.nil? }.sort { |a,b| + versioncmp(a,b) + } unless version self.debug "No latest version" @@ -95,7 +104,7 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg do end def uninstall - cmd = "#{command(:aptget)} -y -q remove %s" % @model[:name] + cmd = "#{apt()} -y -q remove %s" % @model[:name] begin output = execute(cmd) rescue Puppet::ExecutionFailure diff --git a/lib/puppet/provider/package/aptitude.rb b/lib/puppet/provider/package/aptitude.rb new file mode 100755 index 000000000..ca5acaf62 --- /dev/null +++ b/lib/puppet/provider/package/aptitude.rb @@ -0,0 +1,14 @@ +Puppet::Type.type(:package).provide :aptitude, :parent => :apt do + desc "Package management via ``aptitude``." + + commands :aptitude => "/usr/bin/aptitude" + commands :aptcache => "/usr/bin/apt-cache" + + ENV['DEBIAN_FRONTEND'] = "noninteractive" + + def apt + command(:aptitude) + end +end + +# $Id$ diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index d87cbcbd3..07510faa7 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -791,7 +791,6 @@ class Type < Puppet::Element when @@metaparamhash.include?(attr): :meta when @paramhash.include?(attr): :param else - Puppet.err "raising a warning, yo: %s" % attr raise Puppet::DevError, "Invalid attribute '%s' for class '%s'" % [attr, self.name] diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index ec666497d..a8d5fbe33 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -691,7 +691,8 @@ module Puppet if child = self.newchild(file, true, options) # Mark any unmanaged files for removal if purge is set. - if self[:purge] == :true and child.implicit? + # Use the array rather than [] because tidy uses this method, too. + if @parameters.include?(:purge) and self[:purge] == :true and child.implicit? child[:ensure] = :absent end diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb index f42eddef0..502a47abf 100644 --- a/lib/puppet/util.rb +++ b/lib/puppet/util.rb @@ -521,5 +521,6 @@ require 'puppet/util/metaid' require 'puppet/util/classgen' require 'puppet/util/docs' require 'puppet/util/execution' +require 'puppet/util/package' # $Id$ diff --git a/test/other/loadedfile.rb b/test/other/loadedfile.rb new file mode 100755 index 000000000..efb17a1e5 --- /dev/null +++ b/test/other/loadedfile.rb @@ -0,0 +1,58 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/loadedfile' +require 'puppettest' +require 'test/unit' + +class TestLoadedFile < Test::Unit::TestCase + include TestPuppet + def test_file + Puppet[:filetimeout] = 0 + file = nil + path = tempfile() + File.open(path, "w") { |f| f.puts "yayness" } + assert_nothing_raised { + file = Puppet::LoadedFile.new(path) + } + + assert(!file.changed?, "File incorrectly returned changed") + + #sleep(1) + File.open(path, "w") { |f| f.puts "booness" } + file.send("tstamp=".intern, File.stat(path).ctime - 5) + + assert(file.changed?, "File did not catch change") + end + + def test_timeout + Puppet[:filetimeout] = 50 + path = tempfile() + + File.open(path, "w") { |f| f.puts "yay" } + file = nil + assert_nothing_raised { + file = Puppet::LoadedFile.new(path) + } + + assert_nothing_raised { file.changed? } + + File.open(path, "w") { |f| f.puts "yay" } + file.send("tstamp=".intern, File.stat(path).ctime - 5) + + assert(!file.changed?, + "File was marked as changed too soon") + + Puppet[:filetimeout] = 0 + assert(file.changed?, + "File was not marked as changed soon enough") + + + end +end + +# $Id$ diff --git a/test/other/parsedfile.rb b/test/other/parsedfile.rb deleted file mode 100755 index 2f87308ab..000000000 --- a/test/other/parsedfile.rb +++ /dev/null @@ -1,58 +0,0 @@ -if __FILE__ == $0 - $:.unshift '..' - $:.unshift '../../lib' - $puppetbase = "../.." -end - -require 'puppet' -require 'puppet/parsedfile' -require 'puppettest' -require 'test/unit' - -class TestParsedFile < Test::Unit::TestCase - include TestPuppet - def test_file - Puppet[:filetimeout] = 0 - file = nil - path = tempfile() - File.open(path, "w") { |f| f.puts "yayness" } - assert_nothing_raised { - file = Puppet::ParsedFile.new(path) - } - - assert(!file.changed?, "File incorrectly returned changed") - - #sleep(1) - File.open(path, "w") { |f| f.puts "booness" } - file.send("tstamp=".intern, File.stat(path).ctime - 5) - - assert(file.changed?, "File did not catch change") - end - - def test_timeout - Puppet[:filetimeout] = 50 - path = tempfile() - - File.open(path, "w") { |f| f.puts "yay" } - file = nil - assert_nothing_raised { - file = Puppet::ParsedFile.new(path) - } - - assert_nothing_raised { file.changed? } - - File.open(path, "w") { |f| f.puts "yay" } - file.send("tstamp=".intern, File.stat(path).ctime - 5) - - assert(!file.changed?, - "File was marked as changed too soon") - - Puppet[:filetimeout] = 0 - assert(file.changed?, - "File was not marked as changed soon enough") - - - end -end - -# $Id$ diff --git a/test/other/puppet.rb b/test/other/puppet.rb index b9ddb07b0..18600f7a0 100755 --- a/test/other/puppet.rb +++ b/test/other/puppet.rb @@ -5,7 +5,6 @@ if __FILE__ == $0 end require 'puppet' -require 'puppet/parsedfile' require 'puppettest' require 'test/unit' diff --git a/test/types/service.rb b/test/types/service.rb index c6f530dc7..e936e8f84 100644 --- a/test/types/service.rb +++ b/test/types/service.rb @@ -16,7 +16,6 @@ end if $skipsvcs puts "Skipping service testing on %s" % Facter["operatingsystem"].value else - puts "wtf?" #class TestInitService < Test::Unit::TestCase class TestInitService include TestPuppet diff --git a/test/util/classgen.rb b/test/util/classgen.rb index 825a98f3c..7b1b4731c 100755 --- a/test/util/classgen.rb +++ b/test/util/classgen.rb @@ -58,7 +58,7 @@ class TestPuppetUtilClassGen < Test::Unit::TestCase klass = nil assert_nothing_raised { - klass = GenTest.genclass(:yayness, :parent => newclass) + klass = GenTest.genclass(:funtest, :parent => newclass) } assert(klass.preinited, "prehook did not get called") diff --git a/test/util/package.rb b/test/util/package.rb new file mode 100755 index 000000000..2d7f633de --- /dev/null +++ b/test/util/package.rb @@ -0,0 +1,30 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = ".." +end + +require 'puppet' +require 'puppet/util/package' +require 'puppettest' +require 'test/unit' + +class TestPuppetUtilPackage < Test::Unit::TestCase + include TestPuppet + include Puppet::Util::Package + + def test_versioncmp + ary = %w{ 1.1.6 2.3 1.1a 3.0 1.5 1 2.4 1.1-4 + 2.3.1 1.2 2.3.0 1.1-3 2.4b 2.4 2.40.2 2.3a.1 3.1 0002 1.1-5 1.1.a 1.06} + + newary = nil + assert_nothing_raised do + newary = ary.sort { |a, b| + versioncmp(a,b) + } + end + assert_equal(["0002", "1", "1.06", "1.1-3", "1.1-4", "1.1-5", "1.1.6", "1.1.a", "1.1a", "1.2", "1.5", "2.3", "2.3.0", "2.3.1", "2.3a.1", "2.4", "2.4", "2.4b", "2.40.2", "3.0", "3.1"], newary) + end +end + +# $Id$ -- cgit