diff options
-rwxr-xr-x | lib/puppet/type/package/sun.rb | 87 | ||||
-rw-r--r-- | test/types/package.rb | 68 |
2 files changed, 92 insertions, 63 deletions
diff --git a/lib/puppet/type/package/sun.rb b/lib/puppet/type/package/sun.rb index e8e17bdf4..e58980228 100755 --- a/lib/puppet/type/package/sun.rb +++ b/lib/puppet/type/package/sun.rb @@ -1,34 +1,7 @@ module Puppet Puppet.type(:package).newpkgtype(:sunpkg) do - def install - unless self[:source] - raise Puppet::Error, "Sun packages must specify a package source" - end - #cmd = "pkgadd -d %s -n %s 2>&1" % [self[:source], self[:name]] - cmd = ["pkgadd"] - - if self[:adminfile] - cmd += ["-a", self[:adminfile]] - end - - if self[:responsefile] - cmd += ["-r", self[:responsefile]] - end - - cmd += ["-d", self[:source]] - cmd += ["-n", self[:name]] - cmd << "2>&1" - cmd = cmd.join(" ") - - self.info "Executing %s" % cmd.inspect - output = %x{#{cmd} 2>&1} - - unless $? == 0 - raise Puppet::PackageError.new(output) - end - end - - def query + # Get info on a package, optionally specifying a device. + def info2hash(device = nil) names = { "PKGINST" => :name, "NAME" => nil, @@ -48,9 +21,14 @@ module Puppet } hash = {} + cmd = "pkginfo -l" + if device + cmd += " -d #{device}" + end + cmd += " #{self[:name]} 2>/dev/null" # list out all of the packages - open("| pkginfo -l %s 2>/dev/null" % self[:name]) { |process| + open("| #{cmd}") { |process| # we're using the long listing, so each line is a separate # piece of information process.each { |line| @@ -79,6 +57,39 @@ module Puppet end end + def install + unless self[:source] + raise Puppet::Error, "Sun packages must specify a package source" + end + cmd = ["pkgadd"] + + if self[:adminfile] + cmd += ["-a", self[:adminfile]] + end + + if self[:responsefile] + cmd += ["-r", self[:responsefile]] + end + + cmd += ["-d", self[:source]] + cmd += ["-n", self[:name]] + cmd << "2>&1" + cmd = cmd.join(" ") + + self.info "Executing %s" % cmd.inspect + output = %x{#{cmd} 2>&1} + + unless $? == 0 + raise Puppet::PackageError.new(output) + end + end + + # Retrieve the version from the current package file. + def latest + hash = info2hash(self[:source]) + hash[:ensure] + end + def list packages = [] hash = {} @@ -126,11 +137,9 @@ module Puppet return packages end - # we need package retrieval mechanisms before we can have package - # installation mechanisms... - #type.install = proc { |pkg| - # raise "installation not implemented yet" - #} + def query + info2hash() + end def uninstall cmd = "pkgrm -n %s 2>&1" % self[:name] @@ -139,5 +148,13 @@ module Puppet raise Puppet::Error, "Removal of %s failed: %s" % [self.name, output] end end + + # Remove the old package, and install the new one + def update + if @states[:ensure].is != :absent + self.uninstall + end + self.install + end end end diff --git a/test/types/package.rb b/test/types/package.rb index c0e997314..a0dcd9258 100644 --- a/test/types/package.rb +++ b/test/types/package.rb @@ -52,22 +52,22 @@ class TestPackages < Test::Unit::TestCase return pkgs end + def modpkg(pkg) + case $platform + when "Solaris": + pkg[:adminfile] = "/usr/local/pkg/admin_file" + end + end + def mkpkgs - tstpkgs().each { |pkg| - if pkg.is_a?(Array) - hash = {:name => pkg[0], :source => pkg[1]} - hash[:ensure] = "present" - - unless File.exists?(hash[:source]) - Puppet.info "No package file %s for %s; skipping some package tests" % - [hash[:source], Facter["operatingsystem"].value] - end - yield Puppet.type(:package).create(hash) - else - yield Puppet.type(:package).create( - :name => pkg, :ensure => "latest" - ) + tstpkgs().each { |pkg, source| + hash = {:name => pkg, :ensure => "latest"} + if source + source = source[0] if source.is_a? Array + hash[:source] = source end + obj = Puppet.type(:package).create(hash) + modpkg(obj) } end @@ -77,20 +77,28 @@ class TestPackages < Test::Unit::TestCase when "Solaris": arch = Facter["hardwareisa"].value + Facter["operatingsystemrelease"].value case arch + when "i3865.10": + retval = {"SMCrdesk" => [ + "/usr/local/pkg/rdesktop-1.3.1-sol10-intel-local", + "/usr/local/pkg/rdesktop-1.4.1-sol10-x86-local" + ]} when "sparc5.8": - retval = [["SMCarc", "/usr/local/pkg/arc-5.21e-sol8-sparc-local"]] + retval = {"SMCarc" => "/usr/local/pkg/arc-5.21e-sol8-sparc-local"} when "i3865.8": - retval = [["SMCarc", "/usr/local/pkg/arc-5.21e-sol8-intel-local"]] + retval = {"SMCarc" => "/usr/local/pkg/arc-5.21e-sol8-intel-local"} end when "OpenBSD": - retval = [["aalib", "ftp://ftp.usa.openbsd.org/pub/OpenBSD/3.8/packages/i386/aalib-1.2-no_x11.tgz"]] + retval = {"aalib" => "ftp://ftp.usa.openbsd.org/pub/OpenBSD/3.8/packages/i386/aalib-1.2-no_x11.tgz"} when "Debian": - retval = %w{zec} + retval = {"zec" => nil} #when "RedHat": type = :rpm when "Fedora": - retval = %w{wv} + retval = {"wv" => nil} when "CentOS": - retval = [%w{enhost /home/luke/rpm/RPMS/noarch/enhost-1.0.2-1.noarch.rpm}] + retval = {"enhost" => [ + "/home/luke/rpm/RPMS/noarch/enhost-1.0.1-1.noarch.rpm", + "/home/luke/rpm/RPMS/noarch/enhost-1.0.2-1.noarch.rpm" + ]} else Puppet.notice "No test packages for %s" % $platform end @@ -156,7 +164,7 @@ class TestPackages < Test::Unit::TestCase end def test_latestpkg - tstpkgs { |pkg| + mkpkgs { |pkg| assert_nothing_raised { assert(pkg.latest, "Package did not return value for 'latest'") } @@ -188,7 +196,6 @@ class TestPackages < Test::Unit::TestCase pkg[:ensure] = "absent" } - pkg.retrieve assert(! pkg.insync?, "Package is in sync") @@ -221,11 +228,12 @@ class TestPackages < Test::Unit::TestCase } end - case Facter["operatingsystem"].value - when "CentOS": - def test_upgradepkg - first = "/home/luke/rpm/RPMS/noarch/enhost-1.0.1-1.noarch.rpm" - second = "/home/luke/rpm/RPMS/noarch/enhost-1.0.2-1.noarch.rpm" + def test_upgradepkg + tstpkgs.each do |name, sources| + unless sources and sources.is_a? Array + $stderr.puts "Skipping pkg test for %s" % pkg + end + first, second = sources unless FileTest.exists?(first) and FileTest.exists?(second) $stderr.puts "Could not find upgrade test pkgs; skipping" @@ -235,12 +243,16 @@ class TestPackages < Test::Unit::TestCase pkg = nil assert_nothing_raised { pkg = Puppet.type(:package).create( - :name => "enhost", + :name => name, :ensure => :latest, :source => first ) } + modpkg(pkg) + + assert(pkg.latest, "Could not retrieve latest value") + assert_events([:package_created], pkg) assert_nothing_raised { |