summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-12 00:58:45 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-03-12 00:58:45 +0000
commitc6230dd265ec2de32471e6b38c6234be65f71f69 (patch)
tree0580d1e8a7b61cecedef48f5062369ef06b0b478
parentcaa3d4350e7118ec4589cb23f6c918746431d010 (diff)
downloadpuppet-c6230dd265ec2de32471e6b38c6234be65f71f69.tar.gz
puppet-c6230dd265ec2de32471e6b38c6234be65f71f69.tar.xz
puppet-c6230dd265ec2de32471e6b38c6234be65f71f69.zip
Fixing rpms so they will automatically upgrade when you point Puppet to a new package file
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1007 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--CHANGELOG7
-rw-r--r--lib/puppet/type/package.rb35
-rwxr-xr-xlib/puppet/type/package/rpm.rb28
-rw-r--r--test/types/package.rb50
4 files changed, 93 insertions, 27 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b35d47c40..9599e3a9a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+0.14.2
+ Unset variables no longer throw an error, they just return an empty string
+ You can now specify tags to restrict which objects run.
+ RPMs can now install, as long as they specify a package location, and they'll
+ automatically upgrade if you point them to a new file with an upgrade.
+ Multiple bug fixes.
+
0.14.1
Fixed a couple of small logging bugs
Fixed a bug with handling group ownership of links
diff --git a/lib/puppet/type/package.rb b/lib/puppet/type/package.rb
index e23732c70..ee978e11f 100644
--- a/lib/puppet/type/package.rb
+++ b/lib/puppet/type/package.rb
@@ -78,28 +78,7 @@ module Puppet
those packaging formats that can retrieve new packages on
their own."
- #munge do |value|
- # # possible values are: true, false, and a version number
- # case value
- # when "latest":
- # unless @parent.respond_to?(:latest)
- # self.err @parent.inspect
- # raise Puppet::Error,
- # "Package type %s cannot install later versions" %
- # @parent[:type].name
- # end
- # return :latest
- # when true, :present:
- # return :present
- # when false, :absent:
- # return :absent
- # else
- # # We allow them to set a should value however they want,
- # # but only specific package types will be able to use this
- # # value
- # return value
- # end
- #end
+ attr_accessor :latest
newvalue(:present) do
@parent.install
@@ -175,10 +154,13 @@ module Puppet
when :present:
if @parent[:version] == @latest
return true
+ else
+ self.debug "our version is %s and latest is %s" %
+ [@parent[:version], @latest]
end
else
- #self.debug "@is is %s, latest %s is %s" %
- # [@is, @parent.name, latest]
+ self.debug "@is is %s, latest %s is %s" %
+ [@is, @parent.name, @latest]
end
when :absent
if @is == :absent
@@ -482,6 +464,11 @@ module Puppet
end
end
+ # This only exists for testing.
+ def clear
+ @states[:ensure].latest = nil
+ end
+
# The 'query' method returns a hash of info if the package
# exists and returns nil if it does not.
def exists?
diff --git a/lib/puppet/type/package/rpm.rb b/lib/puppet/type/package/rpm.rb
index e0fa9d467..2bcb41fbd 100755
--- a/lib/puppet/type/package/rpm.rb
+++ b/lib/puppet/type/package/rpm.rb
@@ -1,5 +1,6 @@
module Puppet
Puppet.type(:package).newpkgtype(:rpm) do
+ VERSIONSTRING = "%{VERSION}-%{RELEASE}"
def query
fields = {
:name => "NAME",
@@ -8,7 +9,7 @@ module Puppet
}
cmd = "rpm -q #{self[:name]} --qf '%s\n'" %
- "%{NAME} %{VERSION}-%{RELEASE}"
+ "%{NAME} #{VERSIONSTRING}"
self.debug "Executing %s" % cmd.inspect
# list out all of the packages
@@ -40,11 +41,24 @@ module Puppet
return hash
end
+ # Here we just retrieve the version from the file specified in the source.
+ def latest
+ unless source = self[:source]
+ self.fail "RPMs must specify a package source"
+ end
+
+ cmd = "rpm -p -q --qf '#{VERSIONSTRING}' #{self[:source]}"
+ self.debug "Executing %s" % cmd.inspect
+ version = %x{#{cmd}}
+
+ return version
+ end
+
def list
packages = []
# list out all of the packages
- open("| rpm -q -a --qf '%{NAME} %{VERSION}\n'") { |process|
+ open("| rpm -q -a --qf '%{NAME} #{VERSIONSTRING}\n'") { |process|
# our regex for matching dpkg output
regex = %r{^(\S+)\s+(\S+)}
fields = [:name, :ensure]
@@ -74,7 +88,11 @@ module Puppet
self.fail "RPMs must specify a package source"
end
- output = %x{rpm -i #{source} 2>&1}
+ flag = "-i"
+ if @states[:ensure].is != :absent
+ flag = "-U"
+ end
+ output = %x{rpm #{flag} #{source} 2>&1}
unless $? == 0
raise Puppet::PackageError.new(output)
@@ -88,5 +106,9 @@ module Puppet
raise output
end
end
+
+ def update
+ self.install
+ end
end
end
diff --git a/test/types/package.rb b/test/types/package.rb
index 2d309b0f3..c0e997314 100644
--- a/test/types/package.rb
+++ b/test/types/package.rb
@@ -89,6 +89,8 @@ class TestPackages < Test::Unit::TestCase
#when "RedHat": type = :rpm
when "Fedora":
retval = %w{wv}
+ when "CentOS":
+ retval = [%w{enhost /home/luke/rpm/RPMS/noarch/enhost-1.0.2-1.noarch.rpm}]
else
Puppet.notice "No test packages for %s" % $platform
end
@@ -218,6 +220,54 @@ class TestPackages < Test::Unit::TestCase
end
}
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"
+
+ unless FileTest.exists?(first) and FileTest.exists?(second)
+ $stderr.puts "Could not find upgrade test pkgs; skipping"
+ return
+ end
+
+ pkg = nil
+ assert_nothing_raised {
+ pkg = Puppet.type(:package).create(
+ :name => "enhost",
+ :ensure => :latest,
+ :source => first
+ )
+ }
+
+ assert_events([:package_created], pkg)
+
+ assert_nothing_raised {
+ pkg.retrieve
+ }
+ assert(pkg.insync?, "Package is not in sync")
+ pkg.clear
+ assert_nothing_raised {
+ pkg[:source] = second
+ }
+ assert_events([:package_changed], pkg)
+
+ assert_nothing_raised {
+ pkg.retrieve
+ }
+ assert(pkg.insync?, "Package is not in sync")
+ assert_nothing_raised {
+ pkg[:ensure] = :absent
+ }
+ assert_events([:package_removed], pkg)
+
+ assert_nothing_raised {
+ pkg.retrieve
+ }
+ assert(pkg.insync?, "Package is not in sync")
+ end
+ end
end
end
end