puppet 0.24.1 → 0.24.2

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 (266) hide show
  1. data/CHANGELOG +94 -0
  2. data/Rakefile +0 -4
  3. data/bin/puppet +18 -10
  4. data/bin/puppetd +1 -1
  5. data/bin/puppetdoc +14 -4
  6. data/bin/puppetmasterd +1 -1
  7. data/bin/puppetrun +3 -8
  8. data/bin/ralsh +12 -11
  9. data/conf/freebsd/puppetd +1 -1
  10. data/conf/freebsd/puppetmasterd +1 -1
  11. data/conf/gentoo/puppet/puppet.conf +29 -0
  12. data/conf/namespaceauth.conf +20 -0
  13. data/conf/redhat/puppet.spec +4 -1
  14. data/conf/solaris/smf/puppetd.xml +1 -1
  15. data/conf/solaris/smf/puppetmasterd.xml +1 -1
  16. data/conf/suse/puppet.spec +10 -8
  17. data/examples/root/etc/puppet/{puppetmasterd.conf → puppet.conf} +6 -3
  18. data/ext/logcheck/puppet +7 -0
  19. data/ext/puppet-test +28 -5
  20. data/lib/puppet.rb +2 -1
  21. data/lib/puppet/defaults.rb +12 -5
  22. data/lib/puppet/dsl.rb +43 -45
  23. data/lib/puppet/external/{gratr/rdot.rb → dot.rb} +0 -0
  24. data/lib/puppet/external/nagios.rb +50 -0
  25. data/lib/puppet/external/nagios/base.rb +421 -0
  26. data/lib/puppet/external/nagios/parser.rb +816 -0
  27. data/lib/puppet/file_serving/file_base.rb +16 -3
  28. data/lib/puppet/file_serving/metadata.rb +29 -11
  29. data/lib/puppet/indirector/terminus.rb +1 -0
  30. data/lib/puppet/metatype/closure.rb +4 -0
  31. data/lib/puppet/metatype/evaluation.rb +2 -17
  32. data/lib/puppet/metatype/metaparams.rb +1 -1
  33. data/lib/puppet/network.rb +3 -0
  34. data/lib/puppet/network/client.rb +4 -5
  35. data/lib/puppet/network/client/master.rb +10 -7
  36. data/lib/puppet/network/handler/fileserver.rb +22 -45
  37. data/lib/puppet/network/http_pool.rb +3 -0
  38. data/lib/puppet/network/http_server/mongrel.rb +7 -1
  39. data/lib/puppet/network/http_server/webrick.rb +4 -3
  40. data/lib/puppet/network/xmlrpc/client.rb +12 -1
  41. data/lib/puppet/node/catalog.rb +51 -40
  42. data/lib/puppet/parser/ast.rb +27 -49
  43. data/lib/puppet/parser/ast/astarray.rb +5 -24
  44. data/lib/puppet/parser/ast/caseopt.rb +4 -4
  45. data/lib/puppet/parser/ast/casestatement.rb +4 -5
  46. data/lib/puppet/parser/ast/collection.rb +3 -5
  47. data/lib/puppet/parser/ast/collexpr.rb +3 -5
  48. data/lib/puppet/parser/ast/definition.rb +148 -159
  49. data/lib/puppet/parser/ast/else.rb +2 -3
  50. data/lib/puppet/parser/ast/function.rb +3 -10
  51. data/lib/puppet/parser/ast/hostclass.rb +66 -59
  52. data/lib/puppet/parser/ast/ifstatement.rb +4 -5
  53. data/lib/puppet/parser/ast/leaf.rb +6 -6
  54. data/lib/puppet/parser/ast/node.rb +26 -58
  55. data/lib/puppet/parser/ast/resource.rb +5 -7
  56. data/lib/puppet/parser/ast/resource_defaults.rb +2 -4
  57. data/lib/puppet/parser/ast/resource_override.rb +4 -6
  58. data/lib/puppet/parser/ast/resource_reference.rb +2 -4
  59. data/lib/puppet/parser/ast/resourceparam.rb +2 -4
  60. data/lib/puppet/parser/ast/selector.rb +5 -6
  61. data/lib/puppet/parser/ast/tag.rb +2 -4
  62. data/lib/puppet/parser/ast/vardef.rb +3 -4
  63. data/lib/puppet/parser/collector.rb +5 -5
  64. data/lib/puppet/parser/{compile.rb → compiler.rb} +69 -107
  65. data/lib/puppet/parser/functions.rb +3 -3
  66. data/lib/puppet/parser/interpreter.rb +32 -23
  67. data/lib/puppet/parser/lexer.rb +391 -282
  68. data/lib/puppet/parser/parser.rb +5 -4
  69. data/lib/puppet/parser/parser_support.rb +3 -6
  70. data/lib/puppet/parser/resource.rb +24 -36
  71. data/lib/puppet/parser/resource/param.rb +1 -1
  72. data/lib/puppet/parser/resource/reference.rb +7 -3
  73. data/lib/puppet/parser/scope.rb +12 -7
  74. data/lib/puppet/parser/templatewrapper.rb +1 -1
  75. data/lib/puppet/pgraph.rb +9 -98
  76. data/lib/puppet/provider/interface/redhat.rb +65 -65
  77. data/lib/puppet/provider/mount/parsed.rb +1 -1
  78. data/lib/puppet/provider/naginator.rb +55 -0
  79. data/lib/puppet/provider/nameservice/directoryservice.rb +6 -7
  80. data/lib/puppet/provider/package/fink.rb +0 -2
  81. data/lib/puppet/provider/package/gem.rb +9 -5
  82. data/lib/puppet/provider/package/openbsd.rb +1 -1
  83. data/lib/puppet/provider/package/pkgdmg.rb +3 -8
  84. data/lib/puppet/provider/package/portage.rb +4 -4
  85. data/lib/puppet/provider/package/yumhelper.py +8 -6
  86. data/lib/puppet/provider/parsedfile.rb +7 -1
  87. data/lib/puppet/provider/service/debian.rb +2 -0
  88. data/lib/puppet/provider/service/gentoo.rb +4 -0
  89. data/lib/puppet/provider/service/init.rb +1 -1
  90. data/lib/puppet/provider/sshkey/parsed.rb +2 -0
  91. data/lib/puppet/provider/user/useradd.rb +1 -1
  92. data/lib/puppet/rails.rb +4 -0
  93. data/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb +17 -0
  94. data/lib/puppet/rails/fact_value.rb +4 -0
  95. data/lib/puppet/rails/host.rb +1 -2
  96. data/lib/puppet/rails/param_value.rb +4 -0
  97. data/lib/puppet/rails/resource_tag.rb +4 -0
  98. data/lib/puppet/rails/source_file.rb +4 -1
  99. data/lib/puppet/relationship.rb +5 -1
  100. data/lib/puppet/reports/tagmail.rb +12 -1
  101. data/lib/puppet/resource_reference.rb +1 -1
  102. data/lib/puppet/simple_graph.rb +78 -11
  103. data/lib/puppet/sslcertificates.rb +1 -1
  104. data/lib/puppet/sslcertificates/ca.rb +3 -3
  105. data/lib/puppet/transaction.rb +7 -4
  106. data/lib/puppet/transportable.rb +1 -1
  107. data/lib/puppet/type.rb +3 -10
  108. data/lib/puppet/type/cron.rb +18 -0
  109. data/lib/puppet/type/exec.rb +18 -12
  110. data/lib/puppet/type/{pfile.rb → file.rb} +66 -84
  111. data/lib/puppet/type/file/checksum.rb +271 -0
  112. data/lib/puppet/type/{pfile → file}/content.rb +10 -15
  113. data/lib/puppet/type/{pfile → file}/ensure.rb +15 -8
  114. data/lib/puppet/type/{pfile → file}/group.rb +0 -0
  115. data/lib/puppet/type/{pfile → file}/mode.rb +0 -0
  116. data/lib/puppet/type/{pfile → file}/owner.rb +0 -0
  117. data/lib/puppet/type/{pfile → file}/source.rb +34 -48
  118. data/lib/puppet/type/{pfile → file}/target.rb +0 -0
  119. data/lib/puppet/type/{pfile → file}/type.rb +0 -0
  120. data/lib/puppet/type/{pfilebucket.rb → filebucket.rb} +0 -0
  121. data/lib/puppet/type/host.rb +13 -0
  122. data/lib/puppet/type/mailalias.rb +1 -1
  123. data/lib/puppet/type/nagios_command.rb +3 -0
  124. data/lib/puppet/type/nagios_contact.rb +3 -0
  125. data/lib/puppet/type/nagios_contactgroup.rb +3 -0
  126. data/lib/puppet/type/nagios_host.rb +3 -0
  127. data/lib/puppet/type/nagios_hostextinfo.rb +3 -0
  128. data/lib/puppet/type/nagios_hostgroup.rb +3 -0
  129. data/lib/puppet/type/nagios_hostgroupescalation.rb +3 -0
  130. data/lib/puppet/type/nagios_service.rb +3 -0
  131. data/lib/puppet/type/nagios_servicedependency.rb +3 -0
  132. data/lib/puppet/type/nagios_serviceescalation.rb +3 -0
  133. data/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
  134. data/lib/puppet/type/nagios_timeperiod.rb +3 -0
  135. data/lib/puppet/type/package.rb +4 -12
  136. data/lib/puppet/type/service.rb +9 -0
  137. data/lib/puppet/type/sshkey.rb +3 -3
  138. data/lib/puppet/util/autoload.rb +5 -5
  139. data/lib/puppet/util/checksums.rb +51 -13
  140. data/lib/puppet/util/constant_inflector.rb +14 -0
  141. data/lib/puppet/util/filetype.rb +1 -1
  142. data/lib/puppet/util/graph.rb +3 -9
  143. data/lib/puppet/util/nagios_maker.rb +57 -0
  144. data/lib/puppet/util/settings.rb +19 -16
  145. data/lib/puppet/util/tagging.rb +39 -0
  146. data/test/executables/puppetbin.rb +17 -0
  147. data/test/language/ast.rb +8 -58
  148. data/test/language/ast/casestatement.rb +3 -3
  149. data/test/language/ast/resource.rb +6 -7
  150. data/test/language/ast/resource_reference.rb +12 -12
  151. data/test/language/ast/selector.rb +2 -2
  152. data/test/language/ast/variable.rb +2 -2
  153. data/test/language/functions.rb +24 -24
  154. data/test/language/parser.rb +20 -8
  155. data/test/language/resource.rb +5 -42
  156. data/test/language/scope.rb +21 -37
  157. data/test/language/snippets.rb +7 -0
  158. data/test/lib/puppettest.rb +28 -14
  159. data/test/lib/puppettest/parsertesting.rb +10 -10
  160. data/test/lib/puppettest/support/resources.rb +1 -1
  161. data/test/network/client/master.rb +10 -0
  162. data/test/network/handler/fileserver.rb +51 -49
  163. data/test/network/server/webrick.rb +1 -1
  164. data/test/other/dsl.rb +3 -4
  165. data/test/other/transactions.rb +6 -4
  166. data/test/rails/ast.rb +2 -2
  167. data/test/rails/configuration.rb +1 -1
  168. data/test/rails/railsparameter.rb +2 -0
  169. data/test/rails/railsresource.rb +1 -0
  170. data/test/ral/manager/type.rb +4 -4
  171. data/test/ral/providers/cron/crontab.rb +3 -1
  172. data/test/ral/providers/package.rb +1 -1
  173. data/test/ral/{types → type}/basic.rb +2 -2
  174. data/test/ral/{types → type}/cron.rb +0 -0
  175. data/test/ral/{types → type}/exec.rb +42 -2
  176. data/test/ral/{types → type}/file.rb +34 -79
  177. data/test/ral/{types → type}/file/target.rb +0 -0
  178. data/test/ral/{types → type}/filebucket.rb +0 -0
  179. data/test/ral/{types → type}/fileignoresource.rb +0 -0
  180. data/test/ral/{types → type}/filesources.rb +8 -27
  181. data/test/ral/{types → type}/group.rb +0 -0
  182. data/test/ral/{types → type}/host.rb +16 -0
  183. data/test/ral/{types → type}/mailalias.rb +0 -0
  184. data/test/ral/{types → type}/parameter.rb +0 -0
  185. data/test/ral/{types → type}/port.rb +0 -0
  186. data/test/ral/{types → type}/property.rb +0 -0
  187. data/test/ral/{types → type}/resources.rb +0 -0
  188. data/test/ral/{types → type}/service.rb +0 -0
  189. data/test/ral/{types → type}/sshkey.rb +0 -0
  190. data/test/ral/{types → type}/tidy.rb +1 -0
  191. data/test/ral/{types → type}/user.rb +0 -0
  192. data/test/ral/{types → type}/yumrepo.rb +0 -0
  193. data/test/ral/{types → type}/zone.rb +0 -0
  194. data/test/util/autoload.rb +24 -5
  195. metadata +60 -107
  196. data/conf/gentoo/puppet/puppetca.conf +0 -29
  197. data/conf/gentoo/puppet/puppetd.conf +0 -29
  198. data/conf/gentoo/puppet/puppetmasterd.conf +0 -29
  199. data/examples/root/etc/puppet/puppetd.conf +0 -4
  200. data/lib/puppet/external/gratr.rb +0 -33
  201. data/lib/puppet/external/gratr/adjacency_graph.rb +0 -257
  202. data/lib/puppet/external/gratr/base.rb +0 -34
  203. data/lib/puppet/external/gratr/biconnected.rb +0 -116
  204. data/lib/puppet/external/gratr/chinese_postman.rb +0 -123
  205. data/lib/puppet/external/gratr/common.rb +0 -73
  206. data/lib/puppet/external/gratr/comparability.rb +0 -92
  207. data/lib/puppet/external/gratr/digraph.rb +0 -116
  208. data/lib/puppet/external/gratr/digraph_distance.rb +0 -185
  209. data/lib/puppet/external/gratr/dot.rb +0 -90
  210. data/lib/puppet/external/gratr/edge.rb +0 -145
  211. data/lib/puppet/external/gratr/graph.rb +0 -303
  212. data/lib/puppet/external/gratr/graph_api.rb +0 -83
  213. data/lib/puppet/external/gratr/import.rb +0 -44
  214. data/lib/puppet/external/gratr/labels.rb +0 -90
  215. data/lib/puppet/external/gratr/maximum_flow.rb +0 -64
  216. data/lib/puppet/external/gratr/search.rb +0 -409
  217. data/lib/puppet/external/gratr/strong_components.rb +0 -127
  218. data/lib/puppet/external/gratr/undirected_graph.rb +0 -153
  219. data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +0 -62
  220. data/lib/puppet/rails/external/tagging/init.rb +0 -5
  221. data/lib/puppet/rails/external/tagging/tag.rb +0 -50
  222. data/lib/puppet/rails/external/tagging/tagging.rb +0 -12
  223. data/lib/puppet/rails/puppet_class.rb +0 -6
  224. data/lib/puppet/reference/node_source.rb +0 -9
  225. data/lib/puppet/reference/report.rb +0 -21
  226. data/lib/puppet/type/pfile/checksum.rb +0 -326
  227. data/test/language/ast/definition.rb +0 -166
  228. data/test/language/ast/hostclass.rb +0 -184
  229. data/test/language/compile.rb +0 -569
  230. data/test/language/lexer.rb +0 -276
  231. data/test/lib/mocha.rb +0 -19
  232. data/test/lib/mocha/any_instance_method.rb +0 -35
  233. data/test/lib/mocha/auto_verify.rb +0 -113
  234. data/test/lib/mocha/central.rb +0 -35
  235. data/test/lib/mocha/class_method.rb +0 -62
  236. data/test/lib/mocha/deprecation.rb +0 -22
  237. data/test/lib/mocha/exception_raiser.rb +0 -17
  238. data/test/lib/mocha/expectation.rb +0 -378
  239. data/test/lib/mocha/expectation_error.rb +0 -6
  240. data/test/lib/mocha/infinite_range.rb +0 -25
  241. data/test/lib/mocha/inspect.rb +0 -39
  242. data/test/lib/mocha/instance_method.rb +0 -8
  243. data/test/lib/mocha/is_a.rb +0 -9
  244. data/test/lib/mocha/metaclass.rb +0 -7
  245. data/test/lib/mocha/missing_expectation.rb +0 -27
  246. data/test/lib/mocha/mock.rb +0 -207
  247. data/test/lib/mocha/multiple_yields.rb +0 -20
  248. data/test/lib/mocha/no_yields.rb +0 -11
  249. data/test/lib/mocha/object.rb +0 -110
  250. data/test/lib/mocha/parameter_matchers.rb +0 -9
  251. data/test/lib/mocha/parameter_matchers/all_of.rb +0 -39
  252. data/test/lib/mocha/parameter_matchers/any_of.rb +0 -44
  253. data/test/lib/mocha/parameter_matchers/anything.rb +0 -30
  254. data/test/lib/mocha/parameter_matchers/has_entry.rb +0 -39
  255. data/test/lib/mocha/parameter_matchers/has_key.rb +0 -39
  256. data/test/lib/mocha/parameter_matchers/has_value.rb +0 -39
  257. data/test/lib/mocha/parameter_matchers/includes.rb +0 -37
  258. data/test/lib/mocha/pretty_parameters.rb +0 -28
  259. data/test/lib/mocha/return_values.rb +0 -31
  260. data/test/lib/mocha/setup_and_teardown.rb +0 -23
  261. data/test/lib/mocha/single_return_value.rb +0 -24
  262. data/test/lib/mocha/single_yield.rb +0 -18
  263. data/test/lib/mocha/standalone.rb +0 -32
  264. data/test/lib/mocha/stub.rb +0 -18
  265. data/test/lib/mocha/test_case_adapter.rb +0 -49
  266. data/test/lib/mocha/yield_parameters.rb +0 -31
@@ -1,326 +0,0 @@
1
- # Keep a copy of the file checksums, and notify when they change.
2
-
3
- # This state never actually modifies the system, it only notices when the system
4
- # changes on its own.
5
- module Puppet
6
- Puppet.type(:file).newproperty(:checksum) do
7
- desc "How to check whether a file has changed. This state is used internally
8
- for file copying, but it can also be used to monitor files somewhat
9
- like Tripwire without managing the file contents in any way. You can
10
- specify that a file's checksum should be monitored and then subscribe to
11
- the file from another object and receive events to signify
12
- checksum changes, for instance."
13
-
14
- @event = :file_changed
15
-
16
- @unmanaged = true
17
-
18
- @validtypes = %w{md5 md5lite timestamp mtime time}
19
-
20
- def self.validtype?(type)
21
- @validtypes.include?(type)
22
- end
23
-
24
- @validtypes.each do |ctype|
25
- newvalue(ctype) do
26
- handlesum()
27
- end
28
- end
29
-
30
- str = @validtypes.join("|")
31
-
32
- # This is here because Puppet sets this internally, using
33
- # {md5}......
34
- newvalue(/^\{#{str}\}/) do
35
- handlesum()
36
- end
37
-
38
- newvalue(:nosum) do
39
- # nothing
40
- :nochange
41
- end
42
-
43
- # If they pass us a sum type, behave normally, but if they pass
44
- # us a sum type + sum, stick the sum in the cache.
45
- munge do |value|
46
- if value =~ /^\{(\w+)\}(.+)$/
47
- type = symbolize($1)
48
- sum = $2
49
- cache(type, sum)
50
- return type
51
- else
52
- if FileTest.directory?(@resource[:path])
53
- return :time
54
- else
55
- return symbolize(value)
56
- end
57
- end
58
- end
59
-
60
- # Store the checksum in the data cache, or retrieve it if only the
61
- # sum type is provided.
62
- def cache(type, sum = nil)
63
- unless type
64
- raise ArgumentError, "A type must be specified to cache a checksum"
65
- end
66
- type = symbolize(type)
67
- unless state = @resource.cached(:checksums)
68
- self.debug "Initializing checksum hash"
69
- state = {}
70
- @resource.cache(:checksums, state)
71
- end
72
-
73
- if sum
74
- unless sum =~ /\{\w+\}/
75
- sum = "{%s}%s" % [type, sum]
76
- end
77
- state[type] = sum
78
- else
79
- return state[type]
80
- end
81
- end
82
-
83
- # Because source and content and whomever else need to set the checksum
84
- # and do the updating, we provide a simple mechanism for doing so.
85
- def checksum=(value)
86
- munge(@should)
87
- self.updatesum(value)
88
- end
89
-
90
- def checktype
91
- self.should || :md5
92
- end
93
-
94
- # Checksums need to invert how changes are printed.
95
- def change_to_s(currentvalue, newvalue)
96
- begin
97
- if currentvalue == :absent
98
- return "defined '%s' as '%s'" %
99
- [self.name, self.currentsum]
100
- elsif newvalue == :absent
101
- return "undefined %s from '%s'" %
102
- [self.name, self.is_to_s(currentvalue)]
103
- else
104
- if defined? @cached and @cached
105
- return "%s changed '%s' to '%s'" %
106
- [self.name, @cached, self.is_to_s(currentvalue)]
107
- else
108
- return "%s changed '%s' to '%s'" %
109
- [self.name, self.currentsum, self.is_to_s(currentvalue)]
110
- end
111
- end
112
- rescue Puppet::Error, Puppet::DevError
113
- raise
114
- rescue => detail
115
- raise Puppet::DevError, "Could not convert change %s to string: %s" %
116
- [self.name, detail]
117
- end
118
- end
119
-
120
- def currentsum
121
- #"{%s}%s" % [self.should, cache(self.should)]
122
- cache(checktype())
123
- end
124
-
125
- # Retrieve the cached sum
126
- def getcachedsum
127
- hash = nil
128
- unless hash = @resource.cached(:checksums)
129
- hash = {}
130
- @resource.cache(:checksums, hash)
131
- end
132
-
133
- sumtype = self.should
134
-
135
- if hash.include?(sumtype)
136
- #self.notice "Found checksum %s for %s" %
137
- # [hash[sumtype] ,@resource[:path]]
138
- sum = hash[sumtype]
139
-
140
- unless sum =~ /^\{\w+\}/
141
- sum = "{%s}%s" % [sumtype, sum]
142
- end
143
- return sum
144
- elsif hash.empty?
145
- #self.notice "Could not find sum of type %s" % sumtype
146
- return :nosum
147
- else
148
- #self.notice "Found checksum for %s but not of type %s" %
149
- # [@resource[:path],sumtype]
150
- return :nosum
151
- end
152
- end
153
-
154
- # Calculate the sum from disk.
155
- def getsum(checktype)
156
- sum = ""
157
-
158
- checktype = checktype.intern if checktype.is_a? String
159
- case checktype
160
- when :md5, :md5lite:
161
- if ! FileTest.file?(@resource[:path])
162
- @resource.debug "Cannot MD5 sum %s; using mtime" %
163
- [@resource.stat.ftype]
164
- sum = @resource.stat.mtime.to_s
165
- else
166
- begin
167
- File.open(@resource[:path]) { |file|
168
- hashfunc = Digest::MD5.new
169
- while (!file.eof)
170
- readBuf = file.read(512)
171
- hashfunc.update(readBuf)
172
- if checktype == :md5lite then
173
- break
174
- end
175
- end
176
- sum = hashfunc.hexdigest
177
- }
178
- rescue Errno::EACCES => detail
179
- self.notice "Cannot checksum %s: permission denied" %
180
- @resource[:path]
181
- @resource.delete(self.class.name)
182
- rescue => detail
183
- self.notice "Cannot checksum: %s" %
184
- detail
185
- @resource.delete(self.class.name)
186
- end
187
- end
188
- when :timestamp, :mtime:
189
- sum = @resource.stat.mtime.to_s
190
- #sum = File.stat(@resource[:path]).mtime.to_s
191
- when :time:
192
- sum = @resource.stat.ctime.to_s
193
- #sum = File.stat(@resource[:path]).ctime.to_s
194
- else
195
- raise Puppet::Error, "Invalid sum type %s" % checktype
196
- end
197
-
198
- return "{#{checktype}}" + sum.to_s
199
- end
200
-
201
- # At this point, we don't actually modify the system, we modify
202
- # the stored state to reflect the current state, and then kick
203
- # off an event to mark any changes.
204
- def handlesum
205
- currentvalue = self.retrieve
206
- if currentvalue.nil?
207
- raise Puppet::Error, "Checksum state for %s is somehow nil" %
208
- @resource.title
209
- end
210
-
211
- if self.insync?(currentvalue)
212
- self.debug "Checksum is already in sync"
213
- return nil
214
- end
215
- # @resource.debug "%s(%s): after refresh, is '%s'" %
216
- # [self.class.name,@resource.name,@is]
217
-
218
- # If we still can't retrieve a checksum, it means that
219
- # the file still doesn't exist
220
- if currentvalue == :absent
221
- # if they're copying, then we won't worry about the file
222
- # not existing yet
223
- unless @resource.property(:source)
224
- self.warning("File %s does not exist -- cannot checksum" %
225
- @resource[:path]
226
- )
227
- end
228
- return nil
229
- end
230
-
231
- # If the sums are different, then return an event.
232
- if self.updatesum(currentvalue)
233
- return :file_changed
234
- else
235
- return nil
236
- end
237
- end
238
-
239
- def insync?(currentvalue)
240
- @should = [checktype()]
241
- if cache(checktype())
242
- return currentvalue == currentsum()
243
- else
244
- # If there's no cached sum, then we don't want to generate
245
- # an event.
246
- return true
247
- end
248
- end
249
-
250
- # Even though they can specify multiple checksums, the insync?
251
- # mechanism can really only test against one, so we'll just retrieve
252
- # the first specified sum type.
253
- def retrieve(usecache = false)
254
- # When the 'source' is retrieving, it passes "true" here so
255
- # that we aren't reading the file twice in quick succession, yo.
256
- currentvalue = currentsum()
257
- if usecache and currentvalue
258
- return currentvalue
259
- end
260
-
261
- stat = nil
262
- unless stat = @resource.stat
263
- return :absent
264
- end
265
-
266
- if stat.ftype == "link" and @resource[:links] != :follow
267
- self.debug "Not checksumming symlink"
268
- # @resource.delete(:checksum)
269
- return currentvalue
270
- end
271
-
272
- # Just use the first allowed check type
273
- currentvalue = getsum(checktype())
274
-
275
- # If there is no sum defined, then store the current value
276
- # into the cache, so that we're not marked as being
277
- # out of sync. We don't want to generate an event the first
278
- # time we get a sum.
279
- unless cache(checktype())
280
- # FIXME we should support an updatechecksums-like mechanism
281
- self.updatesum(currentvalue)
282
- end
283
-
284
- # @resource.debug "checksum state is %s" % self.is
285
- return currentvalue
286
- end
287
-
288
- # Store the new sum to the state db.
289
- def updatesum(newvalue)
290
- result = false
291
-
292
- if newvalue.is_a?(Symbol)
293
- raise Puppet::Error, "%s has invalid checksum" % @resource.title
294
- end
295
-
296
- # if we're replacing, vs. updating
297
- if sum = cache(checktype())
298
- # unless defined? @should
299
- # raise Puppet::Error.new(
300
- # ("@should is not initialized for %s, even though we " +
301
- # "found a checksum") % @resource[:path]
302
- # )
303
- # end
304
-
305
- if newvalue == sum
306
- return false
307
- end
308
-
309
- self.debug "Replacing %s checksum %s with %s" %
310
- [@resource.title, sum, newvalue]
311
- # @resource.debug "currentvalue: %s; @should: %s" %
312
- # [newvalue,@should]
313
- result = true
314
- else
315
- @resource.debug "Creating checksum %s" % newvalue
316
- result = false
317
- end
318
-
319
- # Cache the sum so the log message can be right if possible.
320
- @cached = sum
321
- cache(checktype(), newvalue)
322
- return result
323
- end
324
- end
325
- end
326
-
@@ -1,166 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Created by Luke A. Kanies on 2006-02-20.
4
- # Copyright (c) 2006. All rights reserved.
5
-
6
- require File.dirname(__FILE__) + '/../../lib/puppettest'
7
-
8
- require 'puppettest'
9
- require 'mocha'
10
- require 'puppettest/parsertesting'
11
- require 'puppettest/resourcetesting'
12
-
13
- class TestASTDefinition < Test::Unit::TestCase
14
- include PuppetTest
15
- include PuppetTest::ParserTesting
16
- include PuppetTest::ResourceTesting
17
- AST = Puppet::Parser::AST
18
-
19
- def test_initialize
20
- parser = mkparser
21
-
22
- # Create a new definition
23
- klass = parser.newdefine "yayness",
24
- :arguments => [["owner", stringobj("nobody")], %w{mode}],
25
- :code => AST::ASTArray.new(
26
- :children => [resourcedef("file", "/tmp/$name",
27
- "owner" => varref("owner"), "mode" => varref("mode"))]
28
- )
29
-
30
- # Test validattr? a couple different ways
31
- [:owner, "owner", :schedule, "schedule"].each do |var|
32
- assert(klass.validattr?(var), "%s was not considered valid" % var.inspect)
33
- end
34
-
35
- [:random, "random"].each do |var|
36
- assert(! klass.validattr?(var), "%s was considered valid" % var.inspect)
37
- end
38
-
39
- end
40
-
41
- def test_evaluate
42
- parser = mkparser
43
- config = mkcompile
44
- config.send(:evaluate_main)
45
- scope = config.topscope
46
- klass = parser.newdefine "yayness",
47
- :arguments => [["owner", stringobj("nobody")], %w{mode}],
48
- :code => AST::ASTArray.new(
49
- :children => [resourcedef("file", "/tmp/$name",
50
- "owner" => varref("owner"), "mode" => varref("mode"))]
51
- )
52
-
53
- resource = Puppet::Parser::Resource.new(
54
- :title => "first",
55
- :type => "yayness",
56
- :exported => false,
57
- :virtual => false,
58
- :scope => scope,
59
- :source => scope.source
60
- )
61
- resource.send(:set_parameter, "name", "first")
62
- resource.send(:set_parameter, "mode", "755")
63
-
64
- resource.stubs(:title)
65
- assert_nothing_raised do
66
- klass.evaluate(:scope => scope, :resource => resource)
67
- end
68
-
69
- firstobj = config.findresource("File[/tmp/first]")
70
- assert(firstobj, "Did not create /tmp/first obj")
71
-
72
- assert_equal("File", firstobj.type)
73
- assert_equal("/tmp/first", firstobj.title)
74
- assert_equal("nobody", firstobj[:owner])
75
- assert_equal("755", firstobj[:mode])
76
-
77
- # Make sure we can't evaluate it with the same args
78
- assert_raise(Puppet::ParseError) do
79
- klass.evaluate(:scope => scope, :resource => resource)
80
- end
81
-
82
- # Now create another with different args
83
- resource2 = Puppet::Parser::Resource.new(
84
- :title => "second",
85
- :type => "yayness",
86
- :exported => false,
87
- :virtual => false,
88
- :scope => scope,
89
- :source => scope.source
90
- )
91
- resource2.send(:set_parameter, "name", "second")
92
- resource2.send(:set_parameter, "mode", "755")
93
- resource2.send(:set_parameter, "owner", "daemon")
94
-
95
- assert_nothing_raised do
96
- klass.evaluate(:scope => scope, :resource => resource2)
97
- end
98
-
99
- secondobj = config.findresource("File[/tmp/second]")
100
- assert(secondobj, "Did not create /tmp/second obj")
101
-
102
- assert_equal("File", secondobj.type)
103
- assert_equal("/tmp/second", secondobj.title)
104
- assert_equal("daemon", secondobj[:owner])
105
- assert_equal("755", secondobj[:mode])
106
- end
107
-
108
- # #539 - definitions should support both names and titles
109
- def test_names_and_titles
110
- parser = mkparser
111
- scope = mkscope :parser => parser
112
-
113
- [
114
- {:name => "one", :title => "two"},
115
- {:title => "mytitle"}
116
- ].each_with_index do |hash, i|
117
- # Create a definition that uses both name and title. Put this
118
- # inside the loop so the subscope expectations work.
119
- klass = parser.newdefine "yayness%s" % i
120
-
121
- resource = Puppet::Parser::Resource.new(
122
- :title => hash[:title],
123
- :type => "yayness%s" % i,
124
- :exported => false,
125
- :virtual => false,
126
- :scope => scope,
127
- :source => scope.source
128
- )
129
-
130
- subscope = klass.subscope(scope, resource)
131
-
132
- klass.expects(:subscope).returns(subscope)
133
-
134
- if hash[:name]
135
- resource.stubs(:to_hash).returns({:name => hash[:name]})
136
- end
137
-
138
- assert_nothing_raised("Could not evaluate definition with %s" % hash.inspect) do
139
- klass.evaluate(:scope => scope, :resource => resource)
140
- end
141
-
142
- name = hash[:name] || hash[:title]
143
- title = hash[:title]
144
-
145
- assert_equal(name, subscope.lookupvar("name"),
146
- "Name did not get set correctly")
147
- assert_equal(title, subscope.lookupvar("title"),
148
- "title did not get set correctly")
149
-
150
- [:name, :title].each do |param|
151
- val = resource.send(param)
152
- assert(subscope.tags.include?(val),
153
- "Scope was not tagged with %s '%s'" % [param, val])
154
- end
155
- end
156
- end
157
-
158
- # Testing the root cause of #615. We should be using the fqname for the type, instead
159
- # of just the short name.
160
- def test_fully_qualified_types
161
- parser = mkparser
162
- klass = parser.newclass("one::two")
163
-
164
- assert_equal("one::two", klass.classname, "Class did not get fully qualified class name")
165
- end
166
- end