puppet 2.6.4 → 2.6.5

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 (221) hide show
  1. data/CHANGELOG +147 -0
  2. data/LICENSE +2 -2
  3. data/Rakefile +3 -4
  4. data/lib/puppet.rb +1 -1
  5. data/lib/puppet/application.rb +22 -5
  6. data/lib/puppet/application/apply.rb +2 -18
  7. data/lib/puppet/application/doc.rb +1 -4
  8. data/lib/puppet/application/inspect.rb +178 -0
  9. data/lib/puppet/configurer.rb +9 -11
  10. data/lib/puppet/configurer/plugin_handler.rb +0 -2
  11. data/lib/puppet/defaults.rb +12 -3
  12. data/lib/puppet/external/pson/pure/generator.rb +1 -22
  13. data/lib/puppet/file_bucket/dipper.rb +9 -3
  14. data/lib/puppet/file_bucket/file.rb +14 -94
  15. data/lib/puppet/indirector.rb +4 -0
  16. data/lib/puppet/indirector/catalog/active_record.rb +1 -1
  17. data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
  18. data/lib/puppet/indirector/indirection.rb +18 -8
  19. data/lib/puppet/indirector/resource/ral.rb +7 -2
  20. data/lib/puppet/indirector/rest.rb +19 -2
  21. data/lib/puppet/network/http/api/v1.rb +3 -0
  22. data/lib/puppet/network/http/handler.rb +16 -1
  23. data/lib/puppet/network/http/rack/rest.rb +1 -3
  24. data/lib/puppet/network/rest_authconfig.rb +4 -12
  25. data/lib/puppet/network/rights.rb +28 -14
  26. data/lib/puppet/parser/ast.rb +4 -0
  27. data/lib/puppet/parser/compiler.rb +18 -3
  28. data/lib/puppet/parser/functions/defined.rb +28 -6
  29. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
  30. data/lib/puppet/parser/templatewrapper.rb +1 -0
  31. data/lib/puppet/property.rb +16 -1
  32. data/lib/puppet/property/keyvalue.rb +0 -2
  33. data/lib/puppet/property/list.rb +0 -2
  34. data/lib/puppet/provider/file/posix.rb +1 -3
  35. data/lib/puppet/provider/file/win32.rb +1 -3
  36. data/lib/puppet/provider/maillist/mailman.rb +3 -5
  37. data/lib/puppet/provider/mount.rb +2 -0
  38. data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
  39. data/lib/puppet/provider/package/freebsd.rb +2 -2
  40. data/lib/puppet/provider/zone/solaris.rb +1 -1
  41. data/lib/puppet/reference/configuration.rb +2 -2
  42. data/lib/puppet/reference/function.rb +4 -0
  43. data/lib/puppet/relationship.rb +4 -0
  44. data/lib/puppet/reports/store.rb +1 -19
  45. data/lib/puppet/resource.rb +11 -2
  46. data/lib/puppet/resource/status.rb +24 -3
  47. data/lib/puppet/resource/type.rb +24 -16
  48. data/lib/puppet/resource/type_collection.rb +4 -1
  49. data/lib/puppet/simple_graph.rb +4 -0
  50. data/lib/puppet/transaction.rb +1 -28
  51. data/lib/puppet/transaction/event.rb +9 -4
  52. data/lib/puppet/transaction/report.rb +42 -22
  53. data/lib/puppet/transaction/resource_harness.rb +99 -71
  54. data/lib/puppet/type.rb +22 -9
  55. data/lib/puppet/type/cron.rb +1 -5
  56. data/lib/puppet/type/exec.rb +4 -34
  57. data/lib/puppet/type/file.rb +19 -26
  58. data/lib/puppet/type/file/checksum.rb +1 -1
  59. data/lib/puppet/type/file/content.rb +2 -1
  60. data/lib/puppet/type/file/ctime.rb +18 -0
  61. data/lib/puppet/type/file/ensure.rb +1 -1
  62. data/lib/puppet/type/file/mode.rb +10 -44
  63. data/lib/puppet/type/file/mtime.rb +17 -0
  64. data/lib/puppet/type/file/owner.rb +1 -1
  65. data/lib/puppet/type/file/source.rb +0 -1
  66. data/lib/puppet/type/file/target.rb +1 -1
  67. data/lib/puppet/type/file/type.rb +5 -12
  68. data/lib/puppet/type/host.rb +1 -1
  69. data/lib/puppet/type/mount.rb +2 -2
  70. data/lib/puppet/type/package.rb +0 -2
  71. data/lib/puppet/type/service.rb +11 -5
  72. data/lib/puppet/type/user.rb +7 -9
  73. data/lib/puppet/type/yumrepo.rb +2 -2
  74. data/lib/puppet/type/zpool.rb +0 -4
  75. data/lib/puppet/util/checksums.rb +24 -1
  76. data/lib/puppet/util/command_line.rb +6 -2
  77. data/lib/puppet/util/command_line/puppet +5 -1
  78. data/lib/puppet/util/command_line/puppetca +2 -2
  79. data/lib/puppet/util/command_line/puppetd +11 -9
  80. data/lib/puppet/util/command_line/puppetdoc +2 -2
  81. data/lib/puppet/util/command_line/puppetmasterd +5 -0
  82. data/lib/puppet/util/log.rb +15 -8
  83. data/lib/puppet/util/log/destinations.rb +2 -0
  84. data/lib/puppet/util/log_paths.rb +1 -1
  85. data/lib/puppet/util/logging.rb +1 -1
  86. data/lib/puppet/util/metric.rb +1 -0
  87. data/lib/puppet/util/reference.rb +1 -10
  88. data/lib/puppet/util/settings.rb +1 -1
  89. data/lib/puppet/util/zaml.rb +30 -31
  90. data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
  91. data/spec/integration/application/apply_spec.rb +1 -2
  92. data/spec/integration/defaults_spec.rb +1 -0
  93. data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
  94. data/spec/integration/indirector/report/rest_spec.rb +13 -17
  95. data/spec/integration/network/formats_spec.rb +2 -5
  96. data/spec/integration/network/server/mongrel_spec.rb +1 -2
  97. data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
  98. data/spec/integration/provider/package_spec.rb +1 -3
  99. data/spec/integration/provider/service/init_spec.rb +3 -9
  100. data/spec/integration/reference/providers_spec.rb +2 -2
  101. data/spec/integration/resource/catalog_spec.rb +1 -2
  102. data/spec/integration/transaction/report_spec.rb +1 -1
  103. data/spec/monkey_patches/alias_should_to_must.rb +2 -0
  104. data/spec/shared_behaviours/file_server_terminus.rb +1 -1
  105. data/spec/shared_behaviours/file_serving.rb +1 -1
  106. data/spec/shared_behaviours/memory_terminus.rb +1 -1
  107. data/spec/spec_helper.rb +8 -6
  108. data/spec/unit/application/agent_spec.rb +1 -0
  109. data/spec/unit/application/apply_spec.rb +7 -7
  110. data/spec/unit/application/doc_spec.rb +2 -2
  111. data/spec/unit/application/filebucket_spec.rb +1 -0
  112. data/spec/unit/application/inspect_spec.rb +278 -0
  113. data/spec/unit/application/kick_spec.rb +1 -3
  114. data/spec/unit/application/master_spec.rb +1 -3
  115. data/spec/unit/application/queue_spec.rb +1 -0
  116. data/spec/unit/application_spec.rb +63 -5
  117. data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
  118. data/spec/unit/configurer_spec.rb +33 -49
  119. data/spec/unit/file_bucket/dipper_spec.rb +69 -77
  120. data/spec/unit/file_bucket/file_spec.rb +12 -127
  121. data/spec/unit/file_serving/fileset_spec.rb +1 -0
  122. data/spec/unit/file_serving/metadata_spec.rb +4 -4
  123. data/spec/unit/indirector/active_record_spec.rb +1 -0
  124. data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
  125. data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
  126. data/spec/unit/indirector/facts/couch_spec.rb +1 -2
  127. data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
  128. data/spec/unit/indirector/file_server_spec.rb +6 -7
  129. data/spec/unit/indirector/indirection_spec.rb +71 -2
  130. data/spec/unit/indirector/ldap_spec.rb +2 -6
  131. data/spec/unit/indirector/node/active_record_spec.rb +1 -3
  132. data/spec/unit/indirector/queue_spec.rb +1 -3
  133. data/spec/unit/indirector/rest_spec.rb +37 -1
  134. data/spec/unit/indirector/ssl_file_spec.rb +5 -5
  135. data/spec/unit/indirector_spec.rb +6 -1
  136. data/spec/unit/module_spec.rb +1 -3
  137. data/spec/unit/network/formats_spec.rb +2 -5
  138. data/spec/unit/network/http/api/v1_spec.rb +4 -0
  139. data/spec/unit/network/http/compression_spec.rb +1 -3
  140. data/spec/unit/network/http/handler_spec.rb +39 -0
  141. data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
  142. data/spec/unit/network/http/mongrel_spec.rb +3 -9
  143. data/spec/unit/network/http/rack/rest_spec.rb +1 -3
  144. data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
  145. data/spec/unit/network/http/rack_spec.rb +2 -3
  146. data/spec/unit/network/http/webrick_spec.rb +1 -0
  147. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  148. data/spec/unit/network/rights_spec.rb +43 -23
  149. data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
  150. data/spec/unit/parameter_spec.rb +1 -2
  151. data/spec/unit/parser/collector_spec.rb +3 -6
  152. data/spec/unit/parser/compiler_spec.rb +90 -5
  153. data/spec/unit/parser/lexer_spec.rb +3 -2
  154. data/spec/unit/parser/templatewrapper_spec.rb +1 -0
  155. data/spec/unit/property/keyvalue_spec.rb +5 -5
  156. data/spec/unit/property/list_spec.rb +7 -7
  157. data/spec/unit/provider/mount/parsed_spec.rb +1 -2
  158. data/spec/unit/provider/mount_spec.rb +8 -0
  159. data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
  160. data/spec/unit/provider/package/freebsd_spec.rb +55 -0
  161. data/spec/unit/provider/service/init_spec.rb +2 -0
  162. data/spec/unit/rails/host_spec.rb +1 -3
  163. data/spec/unit/rails/param_value_spec.rb +2 -3
  164. data/spec/unit/rails/resource_spec.rb +2 -3
  165. data/spec/unit/rails_spec.rb +5 -15
  166. data/spec/unit/relationship_spec.rb +2 -6
  167. data/spec/unit/reports/http_spec.rb +1 -1
  168. data/spec/unit/reports/store_spec.rb +31 -0
  169. data/spec/unit/reports/tagmail_spec.rb +1 -1
  170. data/spec/unit/resource/catalog_spec.rb +2 -6
  171. data/spec/unit/resource/status_spec.rb +53 -3
  172. data/spec/unit/resource/type_collection_spec.rb +0 -8
  173. data/spec/unit/resource/type_spec.rb +50 -4
  174. data/spec/unit/resource_spec.rb +10 -6
  175. data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
  176. data/spec/unit/transaction/event_spec.rb +21 -2
  177. data/spec/unit/transaction/report_spec.rb +91 -35
  178. data/spec/unit/transaction/resource_harness_spec.rb +289 -208
  179. data/spec/unit/transaction_spec.rb +1 -6
  180. data/spec/unit/type/augeas_spec.rb +1 -3
  181. data/spec/unit/type/file/content_spec.rb +63 -10
  182. data/spec/unit/type/file/ctime.rb +35 -0
  183. data/spec/unit/type/file/ensure_spec.rb +8 -7
  184. data/spec/unit/type/file/group_spec.rb +5 -5
  185. data/spec/unit/type/file/mtime.rb +35 -0
  186. data/spec/unit/type/file/owner_spec.rb +7 -7
  187. data/spec/unit/type/file/selinux_spec.rb +2 -2
  188. data/spec/unit/type/file/source_spec.rb +3 -3
  189. data/spec/unit/type/file/type.rb +20 -0
  190. data/spec/unit/type/file_spec.rb +131 -8
  191. data/spec/unit/type/mount_spec.rb +4 -4
  192. data/spec/unit/type/package_spec.rb +3 -3
  193. data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
  194. data/spec/unit/type/user_spec.rb +31 -3
  195. data/spec/unit/type/zpool_spec.rb +12 -12
  196. data/spec/unit/type_spec.rb +2 -2
  197. data/spec/unit/util/checksums_spec.rb +9 -1
  198. data/spec/unit/util/command_line_spec.rb +29 -0
  199. data/spec/unit/util/log/destinations_spec.rb +13 -0
  200. data/spec/unit/util/log_spec.rb +24 -12
  201. data/spec/unit/util/logging_spec.rb +1 -1
  202. data/spec/unit/util/metric_spec.rb +7 -7
  203. data/spec/unit/util/pson_spec.rb +15 -0
  204. data/spec/unit/util/queue/stomp_spec.rb +2 -6
  205. data/spec/unit/util/settings/file_setting_spec.rb +1 -3
  206. data/spec/unit/util/zaml_spec.rb +51 -0
  207. data/test/language/snippets.rb +3 -0
  208. data/test/lib/puppettest/fileparsing.rb +2 -0
  209. data/test/lib/puppettest/reporttesting.rb +1 -1
  210. data/test/lib/puppettest/support/utils.rb +1 -1
  211. data/test/network/server/mongrel_test.rb +0 -6
  212. data/test/other/report.rb +1 -1
  213. data/test/ral/providers/cron/crontab.rb +4 -1
  214. data/test/ral/type/file.rb +1 -1
  215. data/test/ral/type/filesources.rb +1 -4
  216. metadata +1119 -1113
  217. data/lib/puppet/transaction/change.rb +0 -87
  218. data/spec/Rakefile +0 -91
  219. data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
  220. data/spec/spec_specs/runnable_spec.rb +0 -95
  221. data/spec/unit/transaction/change_spec.rb +0 -193
@@ -180,18 +180,13 @@ class Puppet::Indirector::Indirection
180
180
  request = request(:find, key, *args)
181
181
  terminus = prepare(request)
182
182
 
183
- begin
184
- if result = find_in_cache(request)
185
- return result
186
- end
187
- rescue => detail
188
- puts detail.backtrace if Puppet[:trace]
189
- Puppet.err "Cached #{self.name} for #{request.key} failed: #{detail}"
183
+ if result = find_in_cache(request)
184
+ return result
190
185
  end
191
186
 
192
187
  # Otherwise, return the result from the terminus, caching if appropriate.
193
188
  if ! request.ignore_terminus? and result = terminus.find(request)
194
- result.expiration ||= self.expiration
189
+ result.expiration ||= self.expiration if result.respond_to?(:expiration)
195
190
  if cache? and request.use_cache?
196
191
  Puppet.info "Caching #{self.name} for #{request.key}"
197
192
  cache.save request(:save, result, *args)
@@ -203,6 +198,17 @@ class Puppet::Indirector::Indirection
203
198
  nil
204
199
  end
205
200
 
201
+ # Search for an instance in the appropriate terminus, and return a
202
+ # boolean indicating whether the instance was found.
203
+ def head(key, *args)
204
+ request = request(:head, key, *args)
205
+ terminus = prepare(request)
206
+
207
+ # Look in the cache first, then in the terminus. Force the result
208
+ # to be a boolean.
209
+ !!(find_in_cache(request) || terminus.head(request))
210
+ end
211
+
206
212
  def find_in_cache(request)
207
213
  # See if our instance is in the cache and up to date.
208
214
  return nil unless cache? and ! request.ignore_cache? and cached = cache.find(request)
@@ -213,6 +219,10 @@ class Puppet::Indirector::Indirection
213
219
 
214
220
  Puppet.debug "Using cached #{self.name} for #{request.key}"
215
221
  cached
222
+ rescue => detail
223
+ puts detail.backtrace if Puppet[:trace]
224
+ Puppet.err "Cached #{self.name} for #{request.key} failed: #{detail}"
225
+ nil
216
226
  end
217
227
 
218
228
  # Remove something via the terminus.
@@ -34,12 +34,17 @@ class Puppet::Resource::Ral < Puppet::Indirector::Code
34
34
 
35
35
  private
36
36
 
37
+ # {type,resource}_name: the resource name may contain slashes:
38
+ # File["/etc/hosts"]. To handle, assume the type name does
39
+ # _not_ have any slashes in it, and split only on the first.
40
+
37
41
  def type_name( request )
38
- request.key.split('/')[0]
42
+ request.key.split('/', 2)[0]
39
43
  end
40
44
 
41
45
  def resource_name( request )
42
- request.key.split('/')[1]
46
+ name = request.key.split('/', 2)[1]
47
+ name unless name == ""
43
48
  end
44
49
 
45
50
  def type( request )
@@ -53,11 +53,15 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
53
53
  end
54
54
  else
55
55
  # Raise the http error if we didn't get a 'success' of some kind.
56
- message = "Error #{response.code} on SERVER: #{(response.body||'').empty? ? response.message : uncompress_body(response)}"
57
- raise Net::HTTPError.new(message, response)
56
+ raise convert_to_http_error(response)
58
57
  end
59
58
  end
60
59
 
60
+ def convert_to_http_error(response)
61
+ message = "Error #{response.code} on SERVER: #{(response.body||'').empty? ? response.message : uncompress_body(response)}"
62
+ Net::HTTPError.new(message, response)
63
+ end
64
+
61
65
  # Provide appropriate headers.
62
66
  def headers
63
67
  add_accept_encoding({"Accept" => model.supported_formats.join(", ")})
@@ -73,6 +77,19 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
73
77
  result
74
78
  end
75
79
 
80
+ def head(request)
81
+ response = network(request).head(indirection2uri(request), headers)
82
+ case response.code
83
+ when "404"
84
+ return false
85
+ when /^2/
86
+ return true
87
+ else
88
+ # Raise the http error if we didn't get a 'success' of some kind.
89
+ raise convert_to_http_error(response)
90
+ end
91
+ end
92
+
76
93
  def search(request)
77
94
  unless result = deserialize(network(request).get(indirection2uri(request), headers), true)
78
95
  return []
@@ -13,6 +13,9 @@ module Puppet::Network::HTTP::API::V1
13
13
  },
14
14
  "DELETE" => {
15
15
  :singular => :destroy
16
+ },
17
+ "HEAD" => {
18
+ :singular => :head
16
19
  }
17
20
  }
18
21
 
@@ -109,7 +109,22 @@ module Puppet::Network::HTTP::Handler
109
109
  format = format_to_use(request)
110
110
  set_content_type(response, format)
111
111
 
112
- set_response(response, result.render(format))
112
+ if result.respond_to?(:render)
113
+ set_response(response, result.render(format))
114
+ else
115
+ set_response(response, result)
116
+ end
117
+ end
118
+
119
+ # Execute our head.
120
+ def do_head(indirection_request, request, response)
121
+ unless indirection_request.model.head(indirection_request.key, indirection_request.to_hash)
122
+ Puppet.info("Could not find #{indirection_request.indirection_name} for '#{indirection_request.key}'")
123
+ return do_exception(response, "Could not find #{indirection_request.indirection_name} #{indirection_request.key}", 404)
124
+ end
125
+
126
+ # No need to set a response because no response is expected from a
127
+ # HEAD request. All we need to do is not die.
113
128
  end
114
129
 
115
130
  # Execute our search.
@@ -76,9 +76,7 @@ class Puppet::Network::HTTP::RackREST < Puppet::Network::HTTP::RackHttpHandler
76
76
  # request.body has some limitiations, so we need to concat it back
77
77
  # into a regular string, which is something puppet can use.
78
78
  def body(request)
79
- body = ''
80
- request.body.each { |part| body += part }
81
- body
79
+ request.body.read
82
80
  end
83
81
 
84
82
  def extract_client_info(request)
@@ -38,14 +38,10 @@ module Puppet
38
38
  # fail_on_deny could as well be called in the XMLRPC context
39
39
  # with a ClientRequest.
40
40
 
41
- @rights.fail_on_deny(
42
- build_uri(request),
43
-
44
- :node => request.node,
45
- :ip => request.ip,
46
- :method => request.method,
47
- :environment => request.environment,
48
- :authenticated => request.authenticated)
41
+ if authorization_failure_exception = @rights.is_request_forbidden_and_why?(request)
42
+ Puppet.warning("Denying access: #{authorization_failure_exception}")
43
+ raise authorization_failure_exception
44
+ end
49
45
  end
50
46
 
51
47
  def initialize(file = nil, parsenow = true)
@@ -88,9 +84,5 @@ module Puppet
88
84
  end
89
85
  @rights.restrict_authenticated(acl[:acl], acl[:authenticated]) unless acl[:authenticated].nil?
90
86
  end
91
-
92
- def build_uri(request)
93
- "/#{request.indirection_name}/#{request.key}"
94
- end
95
87
  end
96
88
  end
@@ -26,19 +26,34 @@ class Rights
26
26
 
27
27
  # Check that name is allowed or not
28
28
  def allowed?(name, *args)
29
- begin
30
- fail_on_deny(name, :node => args[0], :ip => args[1])
31
- rescue AuthorizationError
32
- return false
33
- rescue ArgumentError
34
- # the namespace contract says we should raise this error
35
- # if we didn't find the right acl
36
- raise
29
+ !is_forbidden_and_why?(name, :node => args[0], :ip => args[1])
30
+ end
31
+
32
+ def is_request_forbidden_and_why?(request)
33
+ methods_to_check = if request.method == :head
34
+ # :head is ok if either :find or :save is ok.
35
+ [:find, :save]
36
+ else
37
+ [request.method]
38
+ end
39
+ authorization_failure_exceptions = methods_to_check.map do |method|
40
+ is_forbidden_and_why?("/#{request.indirection_name}/#{request.key}",
41
+ :node => request.node,
42
+ :ip => request.ip,
43
+ :method => method,
44
+ :environment => request.environment,
45
+ :authenticated => request.authenticated)
46
+ end
47
+ if authorization_failure_exceptions.include? nil
48
+ # One of the methods we checked is ok, therefore this request is ok.
49
+ nil
50
+ else
51
+ # Just need to return any of the failure exceptions.
52
+ authorization_failure_exceptions.first
37
53
  end
38
- true
39
54
  end
40
55
 
41
- def fail_on_deny(name, args = {})
56
+ def is_forbidden_and_why?(name, args = {})
42
57
  res = :nomatch
43
58
  right = @rights.find do |acl|
44
59
  found = false
@@ -49,7 +64,7 @@ class Rights
49
64
  args[:match] = match
50
65
  if (res = acl.allowed?(args[:node], args[:ip], args)) != :dunno
51
66
  # return early if we're allowed
52
- return if res
67
+ return nil if res
53
68
  # we matched, select this acl
54
69
  found = true
55
70
  end
@@ -70,13 +85,12 @@ class Rights
70
85
  error.file = right.file
71
86
  error.line = right.line
72
87
  end
73
- Puppet.warning("Denying access: #{error}")
74
88
  else
75
89
  # there were no rights allowing/denying name
76
90
  # if name is not a path, let's throw
77
- error = ArgumentError.new "Unknown namespace right '#{name}'"
91
+ raise ArgumentError, "Unknown namespace right '#{name}'"
78
92
  end
79
- raise error
93
+ error
80
94
  end
81
95
 
82
96
  def initialize
@@ -19,6 +19,10 @@ class Puppet::Parser::AST
19
19
 
20
20
  attr_accessor :parent, :scope
21
21
 
22
+ def inspect
23
+ "( #{self.class} #{self.to_s} #{@children.inspect} )"
24
+ end
25
+
22
26
  # don't fetch lexer comment by default
23
27
  def use_docs
24
28
  self.class.use_docs
@@ -139,12 +139,23 @@ class Puppet::Parser::Compiler
139
139
  def evaluate_classes(classes, scope, lazy_evaluate = true)
140
140
  raise Puppet::DevError, "No source for scope passed to evaluate_classes" unless scope.source
141
141
  found = []
142
+ param_classes = nil
143
+ # if we are a param class, save the classes hash
144
+ # and transform classes to be the keys
145
+ if classes.class == Hash
146
+ param_classes = classes
147
+ classes = classes.keys
148
+ end
142
149
  classes.each do |name|
143
150
  # If we can find the class, then make a resource that will evaluate it.
144
151
  if klass = scope.find_hostclass(name)
145
- found << name and next if scope.class_scope(klass)
146
152
 
147
- resource = klass.ensure_in_catalog(scope)
153
+ if param_classes
154
+ resource = klass.ensure_in_catalog(scope, param_classes[name] || {})
155
+ else
156
+ found << name and next if scope.class_scope(klass)
157
+ resource = klass.ensure_in_catalog(scope)
158
+ end
148
159
 
149
160
  # If they've disabled lazy evaluation (which the :include function does),
150
161
  # then evaluate our resource immediately.
@@ -432,7 +443,11 @@ class Puppet::Parser::Compiler
432
443
  @resources = []
433
444
 
434
445
  # Make sure any external node classes are in our class list
435
- @catalog.add_class(*@node.classes)
446
+ if @node.classes.class == Hash
447
+ @catalog.add_class(*@node.classes.keys)
448
+ else
449
+ @catalog.add_class(*@node.classes)
450
+ end
436
451
  end
437
452
 
438
453
  # Set the node's parameters into the top-scope as variables.
@@ -1,10 +1,32 @@
1
1
  # Test whether a given class or definition is defined
2
- Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given
3
- type is defined, either as a native type or a defined type, or whether a class is defined.
4
- This is useful for checking whether a class is defined and only including it if it is.
5
- This function can also test whether a resource has been defined, using resource references
6
- (e.g., `if defined(File['/tmp/myfile']) { ... }`). This function is unfortunately
7
- dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals|
2
+ Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Determine whether
3
+ a given class or resource type is defined. This function can also determine whether a
4
+ specific resource has been declared. Returns true or false. Accepts class names,
5
+ type names, and resource references.
6
+
7
+ The `defined` function checks both native and defined types, including types
8
+ provided as plugins via modules. Types and classes are both checked using their names:
9
+
10
+ defined(\"file\")
11
+ defined(\"customtype\")
12
+ defined(\"foo\")
13
+ defined(\"foo::bar\")
14
+
15
+ Resource declarations are checked using resource references, e.g.
16
+ `defined( File['/tmp/myfile'] )`. Checking whether a given resource
17
+ has been declared is, unfortunately, dependent on the parse order of
18
+ the configuration, and the following code will not work:
19
+
20
+ if defined(File['/tmp/foo']) {
21
+ notify(\"This configuration includes the /tmp/foo file.\")
22
+ }
23
+ file {\"/tmp/foo\":
24
+ ensure => present,
25
+ }
26
+
27
+ However, this order requirement refers to parse order only, and ordering of
28
+ resources in the configuration graph (e.g. with `before` or `require`) does not
29
+ affect the behavior of `defined`.") do |vals|
8
30
  result = false
9
31
  vals = [vals] unless vals.is_a?(Array)
10
32
  vals.each do |val|
@@ -1,7 +1,10 @@
1
1
  Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rvalue, :doc =>
2
- "Generates random numbers based on the node's fqdn. The first argument
3
- sets the range. Additional (optional) arguments may be used to further
4
- distinguish the seed.") do |args|
2
+ "Generates random numbers based on the node's fqdn. Generated random values
3
+ will be a range from 0 up to and excluding n, where n is the first parameter.
4
+ The second argument specifies a number to add to the seed and is optional, for example:
5
+
6
+ $random_number = fqdn_rand(30)
7
+ $random_number_seed = fqdn_rand(30,30)") do |args|
5
8
  require 'md5'
6
9
  max = args.shift
7
10
  srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex
@@ -1,6 +1,7 @@
1
1
  # A simple wrapper for templates, so they don't have full access to
2
2
  # the scope objects.
3
3
  require 'puppet/parser/files'
4
+ require 'erb'
4
5
 
5
6
  class Puppet::Parser::TemplateWrapper
6
7
  attr_writer :scope
@@ -152,9 +152,24 @@ class Puppet::Property < Puppet::Parameter
152
152
  # since we cannot fix it. Otherwise, we expect our should value
153
153
  # to be an array, and if @is matches any of those values, then
154
154
  # we consider it to be in-sync.
155
- def insync?(is)
155
+ #
156
+ # Don't override this method.
157
+ def safe_insync?(is)
158
+ # If there is no @should value, consider the property to be in sync.
156
159
  return true unless @should
157
160
 
161
+ # Otherwise delegate to the (possibly derived) insync? method.
162
+ insync?(is)
163
+ end
164
+
165
+ def self.method_added(sym)
166
+ raise "Puppet::Property#safe_insync? shouldn't be overridden; please override insync? instead" if sym == :safe_insync?
167
+ end
168
+
169
+ # This method should be overridden by derived classes if necessary
170
+ # to provide extra logic to determine whether the property is in
171
+ # sync.
172
+ def insync?(is)
158
173
  self.devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array)
159
174
 
160
175
  # an empty array is analogous to no should values
@@ -77,8 +77,6 @@ module Puppet
77
77
  end
78
78
 
79
79
  def insync?(is)
80
- return true unless @should
81
-
82
80
  return true unless is
83
81
 
84
82
  (is == self.should)
@@ -66,8 +66,6 @@ module Puppet
66
66
  end
67
67
 
68
68
  def insync?(is)
69
- return true unless @should
70
-
71
69
  return true unless is
72
70
 
73
71
  (prepare_is_for_comparison(is) == self.should)
@@ -27,9 +27,7 @@ Puppet::Type.type(:file).provide :posix do
27
27
  end
28
28
  end
29
29
 
30
- def insync?(current, should)
31
- return true unless should
32
-
30
+ def is_owner_insync?(current, should)
33
31
  should.each do |value|
34
32
  if value =~ /^\d+$/
35
33
  uid = Integer(value)
@@ -14,9 +14,7 @@ Puppet::Type.type(:file).provide :microsoft_windows do
14
14
  id
15
15
  end
16
16
 
17
- def insync?(current, should)
18
- return true unless should
19
-
17
+ def is_owner_insync?(current, should)
20
18
  should.each do |value|
21
19
  if value =~ /^\d+$/
22
20
  uid = Integer(value)
@@ -14,11 +14,9 @@ Puppet::Type.type(:maillist).provide(:mailman) do
14
14
 
15
15
  # Return a list of existing mailman instances.
16
16
  def self.instances
17
- list_lists.split("\n").reject { |line| line.include?("matching mailing lists") }.collect do |line|
18
- name, description = line.sub(/^\s+/, '').sub(/\s+$/, '').split(/\s+-\s+/)
19
- description = :absent if description.include?("no description available")
20
- new(:ensure => :present, :name => name, :description => description)
21
- end
17
+ list_lists('--bare').
18
+ split("\n").
19
+ collect { |line| new(:ensure => :present, :name => line.strip) }
22
20
  end
23
21
 
24
22
  # Prefetch our list list, yo.