summaryrefslogtreecommitdiffstats
path: root/lib/puppet
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 /lib/puppet
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
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/type/package.rb35
-rwxr-xr-xlib/puppet/type/package/rpm.rb28
2 files changed, 36 insertions, 27 deletions
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