puppet 0.9.2 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (213) hide show
  1. data/CHANGELOG +58 -0
  2. data/README +21 -18
  3. data/Rakefile +176 -36
  4. data/bin/puppet +34 -48
  5. data/bin/puppetca +41 -28
  6. data/bin/puppetd +87 -65
  7. data/bin/puppetdoc +99 -23
  8. data/bin/puppetmasterd +72 -91
  9. data/conf/redhat/client.init +80 -0
  10. data/conf/redhat/client.sysconfig +11 -0
  11. data/conf/redhat/fileserver.conf +12 -0
  12. data/conf/redhat/puppet.spec +130 -0
  13. data/conf/redhat/server.init +89 -0
  14. data/conf/redhat/server.sysconfig +9 -0
  15. data/examples/code/allatonce +2 -2
  16. data/examples/code/assignments +1 -1
  17. data/examples/code/classing +2 -2
  18. data/examples/code/components +2 -2
  19. data/examples/code/file.bl +5 -5
  20. data/examples/code/filedefaults +2 -2
  21. data/examples/code/fileparsing +1 -1
  22. data/examples/code/filerecursion +1 -1
  23. data/examples/code/functions +1 -1
  24. data/examples/code/groups +1 -1
  25. data/examples/code/importing +1 -1
  26. data/examples/code/nodes +1 -1
  27. data/examples/code/one +1 -1
  28. data/examples/code/relationships +2 -2
  29. data/examples/code/simpletests +5 -5
  30. data/examples/code/snippets/argumentdefaults +2 -2
  31. data/examples/code/snippets/casestatement +16 -8
  32. data/examples/code/snippets/classheirarchy.pp +4 -4
  33. data/examples/code/snippets/classincludes.pp +4 -4
  34. data/examples/code/snippets/classpathtest +2 -2
  35. data/examples/code/snippets/componentmetaparams.pp +11 -0
  36. data/examples/code/snippets/dirchmod +5 -5
  37. data/examples/code/snippets/emptyclass.pp +9 -0
  38. data/examples/code/snippets/failmissingexecpath.pp +1 -1
  39. data/examples/code/snippets/falsevalues.pp +1 -1
  40. data/examples/code/snippets/filecreate +5 -5
  41. data/examples/code/snippets/implicititeration +5 -5
  42. data/examples/code/snippets/multipleinstances +4 -4
  43. data/examples/code/snippets/namevartest +3 -3
  44. data/examples/code/snippets/scopetest +1 -1
  45. data/examples/code/snippets/selectorvalues.pp +3 -3
  46. data/examples/code/snippets/simpledefaults +2 -2
  47. data/examples/code/snippets/simpleselector +5 -5
  48. data/examples/code/snippets/singleary.pp +19 -0
  49. data/examples/root/etc/init.d/sleeper +3 -2
  50. data/ext/emacs/puppet-mode-init.el +6 -0
  51. data/ext/emacs/puppet-mode.el +189 -0
  52. data/ext/ldap/puppet.schema +17 -0
  53. data/ext/{module:puppet → module_puppet} +30 -31
  54. data/ext/vim/filetype.vim +9 -0
  55. data/ext/vim/puppet.vim +87 -0
  56. data/install.rb +63 -30
  57. data/lib/puppet.rb +216 -122
  58. data/lib/puppet/client.rb +51 -416
  59. data/lib/puppet/client/ca.rb +17 -0
  60. data/lib/puppet/client/dipper.rb +78 -0
  61. data/lib/puppet/client/file.rb +20 -0
  62. data/lib/puppet/client/log.rb +17 -0
  63. data/lib/puppet/client/master.rb +246 -0
  64. data/lib/puppet/client/proxy.rb +27 -0
  65. data/lib/puppet/client/status.rb +7 -0
  66. data/lib/puppet/config.rb +563 -13
  67. data/lib/puppet/daemon.rb +50 -22
  68. data/lib/puppet/element.rb +4 -4
  69. data/lib/puppet/event-loop.rb +1 -0
  70. data/lib/puppet/event-loop/better-definers.rb +367 -0
  71. data/lib/puppet/event-loop/event-loop.rb +355 -0
  72. data/lib/puppet/event-loop/signal-system.rb +220 -0
  73. data/lib/puppet/event.rb +9 -11
  74. data/lib/puppet/filetype.rb +195 -0
  75. data/lib/puppet/log.rb +35 -12
  76. data/lib/puppet/metric.rb +2 -2
  77. data/lib/puppet/networkclient.rb +145 -0
  78. data/lib/puppet/parameter.rb +335 -0
  79. data/lib/puppet/parser/ast.rb +42 -1453
  80. data/lib/puppet/parser/ast/astarray.rb +88 -0
  81. data/lib/puppet/parser/ast/branch.rb +47 -0
  82. data/lib/puppet/parser/ast/caseopt.rb +66 -0
  83. data/lib/puppet/parser/ast/casestatement.rb +78 -0
  84. data/lib/puppet/parser/ast/classdef.rb +78 -0
  85. data/lib/puppet/parser/ast/compdef.rb +111 -0
  86. data/lib/puppet/parser/ast/component.rb +105 -0
  87. data/lib/puppet/parser/ast/hostclass.rb +82 -0
  88. data/lib/puppet/parser/ast/leaf.rb +86 -0
  89. data/lib/puppet/parser/ast/node.rb +103 -0
  90. data/lib/puppet/parser/ast/nodedef.rb +68 -0
  91. data/lib/puppet/parser/ast/objectdef.rb +336 -0
  92. data/lib/puppet/parser/ast/objectparam.rb +30 -0
  93. data/lib/puppet/parser/ast/objectref.rb +76 -0
  94. data/lib/puppet/parser/ast/selector.rb +60 -0
  95. data/lib/puppet/parser/ast/typedefaults.rb +45 -0
  96. data/lib/puppet/parser/ast/vardef.rb +44 -0
  97. data/lib/puppet/parser/interpreter.rb +31 -14
  98. data/lib/puppet/parser/lexer.rb +2 -4
  99. data/lib/puppet/parser/parser.rb +332 -242
  100. data/lib/puppet/parser/scope.rb +55 -38
  101. data/lib/puppet/server.rb +43 -44
  102. data/lib/puppet/server/authstore.rb +3 -6
  103. data/lib/puppet/server/ca.rb +5 -2
  104. data/lib/puppet/server/filebucket.rb +2 -4
  105. data/lib/puppet/server/fileserver.rb +28 -12
  106. data/lib/puppet/server/logger.rb +15 -4
  107. data/lib/puppet/server/master.rb +62 -7
  108. data/lib/puppet/sslcertificates.rb +41 -607
  109. data/lib/puppet/sslcertificates/ca.rb +291 -0
  110. data/lib/puppet/sslcertificates/certificate.rb +283 -0
  111. data/lib/puppet/statechange.rb +6 -1
  112. data/lib/puppet/storage.rb +67 -56
  113. data/lib/puppet/transaction.rb +25 -9
  114. data/lib/puppet/transportable.rb +102 -22
  115. data/lib/puppet/type.rb +1096 -315
  116. data/lib/puppet/type/component.rb +30 -21
  117. data/lib/puppet/type/cron.rb +409 -448
  118. data/lib/puppet/type/exec.rb +234 -174
  119. data/lib/puppet/type/group.rb +65 -82
  120. data/lib/puppet/type/nameservice.rb +247 -3
  121. data/lib/puppet/type/nameservice/netinfo.rb +29 -40
  122. data/lib/puppet/type/nameservice/objectadd.rb +52 -66
  123. data/lib/puppet/type/nameservice/posix.rb +6 -194
  124. data/lib/puppet/type/package.rb +447 -295
  125. data/lib/puppet/type/package/apt.rb +51 -50
  126. data/lib/puppet/type/package/bsd.rb +82 -0
  127. data/lib/puppet/type/package/dpkg.rb +85 -88
  128. data/lib/puppet/type/package/rpm.rb +67 -63
  129. data/lib/puppet/type/package/sun.rb +119 -98
  130. data/lib/puppet/type/package/yum.rb +41 -37
  131. data/lib/puppet/type/parsedtype.rb +295 -0
  132. data/lib/puppet/type/parsedtype/host.rb +143 -0
  133. data/lib/puppet/type/parsedtype/port.rb +232 -0
  134. data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
  135. data/lib/puppet/type/pfile.rb +484 -460
  136. data/lib/puppet/type/pfile/checksum.rb +237 -181
  137. data/lib/puppet/type/pfile/content.rb +67 -0
  138. data/lib/puppet/type/pfile/ensure.rb +212 -0
  139. data/lib/puppet/type/pfile/group.rb +106 -105
  140. data/lib/puppet/type/pfile/mode.rb +98 -101
  141. data/lib/puppet/type/pfile/source.rb +228 -209
  142. data/lib/puppet/type/pfile/type.rb +18 -21
  143. data/lib/puppet/type/pfile/uid.rb +127 -130
  144. data/lib/puppet/type/pfilebucket.rb +68 -63
  145. data/lib/puppet/type/schedule.rb +341 -0
  146. data/lib/puppet/type/service.rb +351 -255
  147. data/lib/puppet/type/service/base.rb +9 -14
  148. data/lib/puppet/type/service/debian.rb +32 -38
  149. data/lib/puppet/type/service/init.rb +130 -130
  150. data/lib/puppet/type/service/smf.rb +48 -20
  151. data/lib/puppet/type/state.rb +229 -16
  152. data/lib/puppet/type/symlink.rb +51 -63
  153. data/lib/puppet/type/tidy.rb +105 -102
  154. data/lib/puppet/type/user.rb +118 -180
  155. data/lib/puppet/util.rb +100 -6
  156. data/test/certmgr/certmgr.rb +0 -1
  157. data/test/client/client.rb +4 -4
  158. data/test/executables/puppetbin.rb +7 -14
  159. data/test/executables/puppetca.rb +18 -24
  160. data/test/executables/puppetd.rb +7 -16
  161. data/test/executables/puppetmasterd.rb +7 -9
  162. data/test/executables/puppetmodule.rb +11 -16
  163. data/test/language/ast.rb +11 -7
  164. data/test/language/interpreter.rb +1 -1
  165. data/test/language/scope.rb +2 -0
  166. data/test/language/snippets.rb +30 -5
  167. data/test/language/transportable.rb +77 -0
  168. data/test/other/config.rb +316 -0
  169. data/test/other/events.rb +22 -21
  170. data/test/other/log.rb +14 -14
  171. data/test/other/metrics.rb +4 -8
  172. data/test/other/overrides.rb +5 -5
  173. data/test/other/relationships.rb +4 -2
  174. data/test/other/storage.rb +64 -3
  175. data/test/other/transactions.rb +20 -20
  176. data/test/parser/parser.rb +7 -4
  177. data/test/puppet/conffiles.rb +12 -12
  178. data/test/puppet/defaults.rb +13 -11
  179. data/test/puppet/utiltest.rb +14 -11
  180. data/test/puppettest.rb +156 -48
  181. data/test/server/bucket.rb +2 -2
  182. data/test/server/fileserver.rb +6 -6
  183. data/test/server/logger.rb +19 -11
  184. data/test/server/master.rb +33 -4
  185. data/test/server/server.rb +2 -7
  186. data/test/types/basic.rb +5 -7
  187. data/test/types/component.rb +22 -18
  188. data/test/types/cron.rb +111 -44
  189. data/test/types/exec.rb +116 -59
  190. data/test/types/file.rb +262 -137
  191. data/test/types/filebucket.rb +13 -15
  192. data/test/types/fileignoresource.rb +12 -16
  193. data/test/types/filesources.rb +73 -48
  194. data/test/types/filetype.rb +13 -15
  195. data/test/types/group.rb +15 -13
  196. data/test/types/host.rb +146 -0
  197. data/test/types/package.rb +74 -63
  198. data/test/types/port.rb +139 -0
  199. data/test/types/query.rb +8 -8
  200. data/test/types/schedule.rb +335 -0
  201. data/test/types/service.rb +137 -21
  202. data/test/types/sshkey.rb +140 -0
  203. data/test/types/symlink.rb +3 -5
  204. data/test/types/tidy.rb +5 -14
  205. data/test/types/type.rb +67 -11
  206. data/test/types/user.rb +25 -23
  207. metadata +186 -122
  208. data/lib/puppet/type/pfile/create.rb +0 -108
  209. data/lib/puppet/type/pprocess.rb +0 -97
  210. data/lib/puppet/type/typegen.rb +0 -149
  211. data/lib/puppet/type/typegen/filerecord.rb +0 -243
  212. data/lib/puppet/type/typegen/filetype.rb +0 -316
  213. data/test/other/state.rb +0 -106
@@ -3,217 +3,273 @@
3
3
  # This state never actually modifies the system, it only notices when the system
4
4
  # changes on its own.
5
5
  module Puppet
6
- class State
7
- class PFileChecksum < Puppet::State
8
- @doc = "How to check whether a file has changed. **md5**/*lite-md5*/
9
- *time*/*mtime*"
10
- @name = :checksum
11
- @event = :file_modified
12
-
13
- @unmanaged = true
14
-
15
- @validtypes = %w{md5 md5lite timestamp mtime time}
16
-
17
- def self.validtype?(type)
18
- @validtypes.include?(type)
19
- end
20
-
21
- def checktype
22
- @checktypes[0]
23
- end
24
-
25
- def getsum(checktype)
26
- sum = ""
27
- case checktype
28
- when "md5", "md5lite":
29
- unless FileTest.file?(@parent[:path])
30
- #@parent.info "Cannot MD5 sum directory %s" %
31
- # @parent[:path]
32
-
33
- # because we cannot sum directories, just delete ourselves
34
- # from the file so we won't sync
35
- @parent.delete(self.name)
36
- return
37
- else
38
- begin
39
- File.open(@parent[:path]) { |file|
40
- text = nil
41
- if checktype == "md5"
42
- text = file.read
43
- else
44
- text = file.read(512)
45
- end
46
- if text.nil?
47
- self.info "Not checksumming empty file %s" %
48
- @parent.name
49
- sum = 0
50
- else
51
- sum = Digest::MD5.hexdigest(text)
52
- end
53
- }
54
- rescue Errno::EACCES => detail
55
- self.notice "Cannot checksum %s: permission denied" %
56
- @parent.name
57
- @parent.delete(self.class.name)
58
- rescue => detail
59
- self.notice "Cannot checksum %s: %s" %
60
- detail
61
- @parent.delete(self.class.name)
62
- end
63
- end
64
- when "timestamp","mtime":
65
- sum = File.stat(@parent[:path]).mtime.to_s
66
- when "time":
67
- sum = File.stat(@parent[:path]).ctime.to_s
6
+ Puppet.type(:file).newstate(:checksum) do
7
+ desc "How to check whether a file has changed. **md5**/*lite-md5*/
8
+ *time*/*mtime*"
9
+ @event = :file_changed
10
+
11
+ @unmanaged = true
12
+
13
+ @validtypes = %w{md5 md5lite timestamp mtime time}
14
+
15
+ def self.validtype?(type)
16
+ @validtypes.include?(type)
17
+ end
18
+
19
+ def checktype
20
+ @checktypes[0]
21
+ end
22
+
23
+ # Because source and content and whomever else need to set the checksum
24
+ # and do the updating, we provide a simple mechanism for doing so.
25
+ def checksum=(value)
26
+ @is = value
27
+ @should = [value]
28
+ self.updatesum
29
+ end
30
+
31
+ # Checksums need to invert how changes are printed.
32
+ def change_to_s
33
+ begin
34
+ if @is == :absent
35
+ return "defined '%s' as '%s'" %
36
+ [self.name, self.should_to_s]
37
+ elsif self.should == :absent
38
+ return "undefined %s from '%s'" %
39
+ [self.name, self.is_to_s]
68
40
  else
69
- raise Puppet::Error, "Invalid sum type %s" % checktype
41
+ return "%s changed '%s' to '%s'" %
42
+ [self.name, self.should_to_s, self.is_to_s]
70
43
  end
44
+ rescue Puppet::Error, Puppet::DevError
45
+ raise
46
+ rescue => detail
47
+ raise Puppet::DevError, "Could not convert change %s to string: %s" %
48
+ [self.name, detail]
49
+ end
50
+ end
71
51
 
72
- return sum
52
+ # Retrieve the cached sum
53
+ def getcachedsum
54
+ hash = nil
55
+ unless hash = @parent.cached(:checksums)
56
+ hash = {}
57
+ @parent.cache(:checksums, hash)
73
58
  end
74
59
 
75
- # Convert from the sum type to the stored checksum.
76
- def shouldprocess(value)
77
- unless defined? @checktypes
78
- @checktypes = []
79
- end
80
- unless self.class.validtype?(value)
81
- raise Puppet::Error, "Invalid checksum type '%s'" % value
82
- end
60
+ sumtype = @checktypes[0]
83
61
 
84
- @checktypes << value
85
- state = Puppet::Storage.state(self)
86
- if hash = state[@parent[:path]]
87
- if hash.include?(value)
88
- return hash[value]
89
- #@parent.debug "Found checksum %s for %s" %
90
- # [self.should,@parent[:path]]
91
- else
92
- #@parent.debug "Found checksum for %s but not of type %s" %
93
- # [@parent[:path],@checktype]
94
- return :nosum
95
- end
96
- else
97
- # We can't use :notfound here, because then it'll match on
98
- # non-existent files
99
- return :nosum
100
- end
62
+ #unless state
63
+ # self.devfail "Did not get state back from Storage"
64
+ #end
65
+
66
+ if hash.include?(sumtype)
67
+ #self.notice "Found checksum %s for %s" %
68
+ # [hash[sumtype] ,@parent[:path]]
69
+ return hash[sumtype]
70
+ elsif hash.empty?
71
+ #self.notice "Could not find sum of type %s" % sumtype
72
+ return :nosum
73
+ else
74
+ #self.notice "Found checksum for %s but not of type %s" %
75
+ # [@parent[:path],sumtype]
76
+ return :nosum
101
77
  end
78
+ end
102
79
 
103
- # Even though they can specify multiple checksums, the insync?
104
- # mechanism can really only test against one, so we'll just retrieve
105
- # the first specified sum type.
106
- def retrieve
107
- unless defined? @checktypes
108
- @checktypes = ["md5"]
109
- end
80
+ # Calculate the sum from disk.
81
+ def getsum(checktype)
82
+ sum = ""
83
+ case checktype
84
+ when "md5", "md5lite":
85
+ unless FileTest.file?(@parent[:path])
86
+ @parent.info "Cannot MD5 sum directory %s" %
87
+ @parent[:path]
110
88
 
111
- unless FileTest.exists?(@parent.name)
112
- self.is = :notfound
89
+ # because we cannot sum directories, just delete ourselves
90
+ # from the file so we won't sync
91
+ @parent.delete(self.name)
113
92
  return
93
+ else
94
+ begin
95
+ File.open(@parent[:path]) { |file|
96
+ text = nil
97
+ if checktype == "md5"
98
+ text = file.read
99
+ else
100
+ text = file.read(512)
101
+ end
102
+ if text.nil?
103
+ self.info "Not checksumming empty file %s" %
104
+ @parent.name
105
+ sum = 0
106
+ else
107
+ sum = Digest::MD5.hexdigest(text)
108
+ end
109
+ }
110
+ rescue Errno::EACCES => detail
111
+ self.notice "Cannot checksum %s: permission denied" %
112
+ @parent.name
113
+ @parent.delete(self.class.name)
114
+ rescue => detail
115
+ self.notice "Cannot checksum %s: %s" %
116
+ detail
117
+ @parent.delete(self.class.name)
118
+ end
114
119
  end
120
+ when "timestamp","mtime":
121
+ sum = @parent.stat.mtime.to_s
122
+ #sum = File.stat(@parent[:path]).mtime.to_s
123
+ when "time":
124
+ sum = @parent.stat.ctime.to_s
125
+ #sum = File.stat(@parent[:path]).ctime.to_s
126
+ else
127
+ raise Puppet::Error, "Invalid sum type %s" % checktype
128
+ end
115
129
 
116
- # Just use the first allowed check type
117
- @is = getsum(@checktypes[0])
118
-
119
- # If there is no should defined, then store the current value
120
- # into the 'should' value, so that we're not marked as being
121
- # out of sync. We don't want to generate an event the first
122
- # time we get a sum.
123
- if ! defined? @should or @should == [:nosum]
124
- @should = [@is]
125
- # FIXME we should support an updatechecksums-like mechanism
126
- self.updatesum
127
- end
130
+ return sum
131
+ end
128
132
 
129
- #@parent.debug "checksum state is %s" % self.is
133
+ # Convert from the sum type to the stored checksum.
134
+ munge do |value|
135
+ unless defined? @checktypes
136
+ @checktypes = []
137
+ end
138
+ unless self.class.validtype?(value)
139
+ self.fail "Invalid checksum type '%s'" % value
130
140
  end
131
141
 
142
+ if FileTest.directory?(@parent.name)
143
+ self.info "Reverting directory sum type to timestamp"
144
+ value = "time"
145
+ end
132
146
 
133
- # At this point, we don't actually modify the system, we modify
134
- # the stored state to reflect the current state, and then kick
135
- # off an event to mark any changes.
136
- def sync
137
- if @is.nil?
138
- raise Puppet::Error, "Checksum state for %s is somehow nil" %
139
- @parent.name
140
- end
147
+ @checktypes << value
141
148
 
142
- if @is == :notfound
143
- self.retrieve
149
+ return getcachedsum()
150
+ end
144
151
 
145
- if self.insync?
146
- self.debug "Checksum is already in sync"
147
- return nil
148
- end
149
- #@parent.debug "%s(%s): after refresh, is '%s'" %
150
- # [self.class.name,@parent.name,@is]
151
-
152
- # If we still can't retrieve a checksum, it means that
153
- # the file still doesn't exist
154
- if @is == :notfound
155
- # if they're copying, then we won't worry about the file
156
- # not existing yet
157
- unless @parent.state(:source)
158
- self.warning(
159
- "File %s does not exist -- cannot checksum" %
160
- @parent.name
161
- )
162
- end
163
- return nil
164
- end
165
- end
152
+ # Even though they can specify multiple checksums, the insync?
153
+ # mechanism can really only test against one, so we'll just retrieve
154
+ # the first specified sum type.
155
+ def retrieve
156
+ unless defined? @checktypes
157
+ @checktypes = ["md5"]
158
+ end
166
159
 
167
- # If the sums are different, then return an event.
168
- if self.updatesum
169
- return :file_modified
170
- else
171
- return nil
172
- end
160
+ unless FileTest.exists?(@parent.name)
161
+ self.is = :absent
162
+ return
173
163
  end
174
164
 
175
- # Store the new sum to the state db.
176
- def updatesum
177
- result = false
178
- state = Puppet::Storage.state(self)
179
- unless state.include?(@parent.name)
180
- self.debug "Initializing state hash"
165
+ if FileTest.directory?(@parent.name) and @checktypes[0] =~ /md5/
166
+ self.info "Using timestamp on directory"
167
+ @checktypes = ["time"]
168
+ end
181
169
 
182
- state[@parent.name] = Hash.new
183
- end
170
+ # Just use the first allowed check type
171
+ @is = getsum(@checktypes[0])
172
+
173
+ # @should should always be set, so if it's not set at all, we
174
+ # know we haven't looked in the cache yet.
175
+ unless defined? @should and ! @should.nil?
176
+ @should = [getcachedsum()]
177
+ end
178
+
179
+ # If there is no should defined, then store the current value
180
+ # into the 'should' value, so that we're not marked as being
181
+ # out of sync. We don't want to generate an event the first
182
+ # time we get a sum.
183
+ if @should == [:nosum]
184
+ self.warning "updatingness from %s" % @should.inspect
185
+ @should = [@is]
186
+ # FIXME we should support an updatechecksums-like mechanism
187
+ self.updatesum
188
+ end
189
+
190
+ #@parent.debug "checksum state is %s" % self.is
191
+ end
192
+
193
+
194
+ # At this point, we don't actually modify the system, we modify
195
+ # the stored state to reflect the current state, and then kick
196
+ # off an event to mark any changes.
197
+ def sync
198
+ if @is.nil?
199
+ raise Puppet::Error, "Checksum state for %s is somehow nil" %
200
+ @parent.name
201
+ end
184
202
 
185
- if @is.is_a?(Symbol)
186
- error = Puppet::Error.new("%s has invalid checksum" %
187
- @parent.name)
188
- raise error
189
- #elsif @should == :notfound
190
- # error = Puppet::Error.new("%s has invalid 'should' checksum" %
191
- # @parent.name)
192
- # raise error
203
+ if @is == :absent
204
+ self.retrieve
205
+
206
+ if self.insync?
207
+ self.debug "Checksum is already in sync"
208
+ return nil
193
209
  end
210
+ #@parent.debug "%s(%s): after refresh, is '%s'" %
211
+ # [self.class.name,@parent.name,@is]
194
212
 
195
- # if we're replacing, vs. updating
196
- if state[@parent.name].include?(@checktypes[0])
197
- unless defined? @should
198
- raise Puppet::Error.new(
199
- ("@should is not initialized for %s, even though we " +
200
- "found a checksum") % @parent[:path]
213
+ # If we still can't retrieve a checksum, it means that
214
+ # the file still doesn't exist
215
+ if @is == :absent
216
+ # if they're copying, then we won't worry about the file
217
+ # not existing yet
218
+ unless @parent.state(:source)
219
+ self.warning(
220
+ "File %s does not exist -- cannot checksum" %
221
+ @parent.name
201
222
  )
202
223
  end
203
- self.debug "Replacing %s checksum %s with %s" %
204
- [@parent.name, state[@parent.name][@checktypes[0]],@is]
205
- #@parent.debug "@is: %s; @should: %s" % [@is,@should]
206
- result = true
207
- else
208
- @parent.debug "Creating checksum %s of type %s" %
209
- [@is,@checktypes[0]]
210
- result = false
224
+ return nil
211
225
  end
212
- state[@parent.name][@checktypes[0]] = @is
213
- return result
214
226
  end
227
+
228
+ # If the sums are different, then return an event.
229
+ if self.updatesum
230
+ return :file_changed
231
+ else
232
+ return nil
233
+ end
234
+ end
235
+
236
+ # Store the new sum to the state db.
237
+ def updatesum
238
+ result = false
239
+ state = nil
240
+ unless state = @parent.cached(:checksums)
241
+ self.debug "Initializing checksum hash for %s" % @parent.name
242
+ state = {}
243
+ @parent.cache(:checksums, state)
244
+ end
245
+
246
+ if @is.is_a?(Symbol)
247
+ error = Puppet::Error.new("%s has invalid checksum" %
248
+ @parent.name)
249
+ raise error
250
+ end
251
+
252
+ # if we're replacing, vs. updating
253
+ if state.include?(@checktypes[0])
254
+ unless defined? @should
255
+ raise Puppet::Error.new(
256
+ ("@should is not initialized for %s, even though we " +
257
+ "found a checksum") % @parent[:path]
258
+ )
259
+ end
260
+ self.debug "Replacing %s checksum %s with %s" %
261
+ [@parent.name, state[@checktypes[0]],@is]
262
+ #@parent.debug "@is: %s; @should: %s" % [@is,@should]
263
+ result = true
264
+ else
265
+ @parent.debug "Creating checksum %s of type %s" %
266
+ [@is,@checktypes[0]]
267
+ result = false
268
+ end
269
+ state[@checktypes[0]] = @is
270
+ return result
215
271
  end
216
272
  end
217
273
  end
218
274
 
219
- # $Id: checksum.rb 731 2005-10-26 04:44:25Z luke $
275
+ # $Id: checksum.rb 885 2006-02-08 17:44:44Z luke $