Adding tracing to prefetch failures, and Fixing the environment support in the cron type (#669).

git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2621 980ebf18-57e1-0310-9a29-db15c13687c0
This commit is contained in:
luke 2007-06-18 21:56:11 +00:00
Родитель fa39488560
Коммит 01420acae6
5 изменённых файлов: 77 добавлений и 10 удалений

Просмотреть файл

@ -1,3 +1,5 @@
Fixed environment handling in the crontab provider (#669).
Added patch by trombik in #572, supporting old-style Added patch by trombik in #572, supporting old-style
freebsd init scripts with '.sh' endings. freebsd init scripts with '.sh' endings.

Просмотреть файл

@ -62,7 +62,7 @@ Puppet::Type.type(:cron).provide(:crontab,
if details[:name] if details[:name]
str = "# Puppet Name: %s\n" % details[:name] str = "# Puppet Name: %s\n" % details[:name]
end end
if details[:environment] and details[:environment] != :absent if details[:environment] and details[:environment] != :absent and details[:environment] != [:absent]
details[:environment].each do |env| details[:environment].each do |env|
str += env + "\n" str += env + "\n"
end end
@ -84,10 +84,9 @@ Puppet::Type.type(:cron).provide(:crontab,
end end
# See if we can match the hash against an existing cron job. # See if we can match the hash against an existing cron job.
def self.match(hash) def self.match(hash, resources)
resource_type.find_all { |obj| resources.each do |name, obj|
obj.value(:user) == hash[:user] and obj.value(:command) == hash[:command] p hash
}.each do |obj|
# we now have a cron job whose command exactly matches # we now have a cron job whose command exactly matches
# let's see if the other fields match # let's see if the other fields match
@ -152,10 +151,7 @@ Puppet::Type.type(:cron).provide(:crontab,
record[:name] = name record[:name] = name
name = nil name = nil
end end
unless envs.empty?
record[:environment] = envs record[:environment] = envs
envs = []
end
end end
}.reject { |record| record[:skip] } }.reject { |record| record[:skip] }
end end

Просмотреть файл

@ -487,6 +487,9 @@ class Transaction
begin begin
provider.prefetch(resources) provider.prefetch(resources)
rescue => detail rescue => detail
if Puppet[:trace]
puts detail.backtrace
end
Puppet.err "Could not prefetch % provider %s: %s" % [resources[0].class.name, provider.name, detail] Puppet.err "Could not prefetch % provider %s: %s" % [resources[0].class.name, provider.name, detail]
end end
end end

Просмотреть файл

@ -287,7 +287,7 @@ Puppet::Type.newtype(:cron) do
the crontab, e.g., ``PATH=/bin:/usr/bin:/usr/sbin``." the crontab, e.g., ``PATH=/bin:/usr/bin:/usr/sbin``."
validate do |value| validate do |value|
unless value =~ /^\s*(\w+)\s*=\s*(.+)\s*$/ unless value =~ /^\s*(\w+)\s*=\s*(.+)\s*$/ or value == :absent or value == "absent"
raise ArgumentError, "Invalid environment setting %s" % raise ArgumentError, "Invalid environment setting %s" %
value.inspect value.inspect
end end
@ -301,9 +301,25 @@ Puppet::Type.newtype(:cron) do
end end
end end
def is_to_s(newvalue)
if newvalue
newvalue.join(",")
else
nil
end
end
def should def should
@should @should
end end
def should_to_s(newvalue = @should)
if newvalue
newvalue.join(",")
else
nil
end
end
end end
newparam(:name) do newparam(:name) do

Просмотреть файл

@ -342,6 +342,56 @@ class TestCronParsedProvider < Test::Unit::TestCase
@provider.clear @provider.clear
end end
end end
def test_prefetch
cron = @type.create :command => "/bin/echo yay", :name => "test", :hour => 4
assert_nothing_raised("Could not prefetch cron") do
cron.provider.class.prefetch("test" => cron)
end
end
# Testing #669.
def test_environment_settings
@provider.filetype = :ram
setme
target = @provider.target_object(@me)
# First with no env settings
cron = @type.create :command => "/bin/echo yay", :name => "test", :hour => 4
assert_apply(cron)
props = cron.retrieve.inject({}) { |hash, ary| hash[ary[0]] = ary[1]; hash }
# Now set the env
cron[:environment] = "TEST=foo"
assert_apply(cron)
props = cron.retrieve.inject({}) { |hash, ary| hash[ary[0]] = ary[1]; hash }
assert(target.read.include?("TEST=foo"), "Did not get environment setting")
#assert_equal(["TEST=foo"], props[:environment], "Did not get environment setting")
# Modify it
cron[:environment] = ["TEST=foo", "BLAH=yay"]
assert_apply(cron)
props = cron.retrieve.inject({}) { |hash, ary| hash[ary[0]] = ary[1]; hash }
assert(target.read.include?("TEST=foo"), "Did not keep environment setting")
assert(target.read.include?("BLAH=yay"), "Did not get second environment setting")
#assert_equal(["TEST=foo", "BLAH=yay"], props[:environment], "Did not modify environment setting")
# And remove it
cron[:environment] = :absent
assert_apply(cron)
props = cron.retrieve.inject({}) { |hash, ary| hash[ary[0]] = ary[1]; hash }
assert(! target.read.include?("TEST=foo"), "Did not remove environment setting")
assert(! target.read.include?("BLAH=yay"), "Did not remove second environment setting")
#assert_nil(props[:environment], "Did not modify environment setting")
end
end end
# $Id$ # $Id$