puppet 4.7.1 → 4.8.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 (276) hide show
  1. data/Gemfile +0 -3
  2. data/MAINTAINERS +76 -0
  3. data/README.md +0 -6
  4. data/Rakefile +2 -2
  5. data/lib/puppet/agent.rb +3 -3
  6. data/lib/puppet/application/apply.rb +1 -1
  7. data/lib/puppet/configurer.rb +2 -2
  8. data/lib/puppet/data_providers.rb +1 -0
  9. data/lib/puppet/data_providers/data_adapter.rb +1 -0
  10. data/lib/puppet/data_providers/data_function_support.rb +1 -0
  11. data/lib/puppet/data_providers/function_env_data_provider.rb +1 -0
  12. data/lib/puppet/data_providers/function_module_data_provider.rb +1 -0
  13. data/lib/puppet/data_providers/hiera_config.rb +1 -0
  14. data/lib/puppet/data_providers/hiera_env_data_provider.rb +1 -0
  15. data/lib/puppet/data_providers/hiera_interpolate.rb +1 -0
  16. data/lib/puppet/data_providers/hiera_module_data_provider.rb +1 -0
  17. data/lib/puppet/data_providers/hiera_support.rb +1 -2
  18. data/lib/puppet/data_providers/json_data_provider_factory.rb +2 -0
  19. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -0
  20. data/lib/puppet/defaults.rb +20 -1
  21. data/lib/puppet/environments.rb +5 -2
  22. data/lib/puppet/face/catalog.rb +1 -1
  23. data/lib/puppet/face/epp.rb +57 -11
  24. data/lib/puppet/face/module/install.rb +6 -6
  25. data/lib/puppet/functions.rb +23 -24
  26. data/lib/puppet/functions/alert.rb +14 -0
  27. data/lib/puppet/functions/binary_file.rb +25 -0
  28. data/lib/puppet/functions/break.rb +22 -0
  29. data/lib/puppet/functions/contain.rb +33 -0
  30. data/lib/puppet/functions/crit.rb +14 -0
  31. data/lib/puppet/functions/debug.rb +14 -0
  32. data/lib/puppet/functions/emerg.rb +14 -0
  33. data/lib/puppet/functions/epp.rb +1 -1
  34. data/lib/puppet/functions/err.rb +14 -0
  35. data/lib/puppet/functions/find_file.rb +31 -0
  36. data/lib/puppet/functions/include.rb +21 -0
  37. data/lib/puppet/functions/info.rb +14 -0
  38. data/lib/puppet/functions/new.rb +1 -1
  39. data/lib/puppet/functions/next.rb +23 -0
  40. data/lib/puppet/functions/notice.rb +14 -0
  41. data/lib/puppet/functions/regsubst.rb +12 -16
  42. data/lib/puppet/functions/require.rb +37 -0
  43. data/lib/puppet/functions/return.rb +22 -0
  44. data/lib/puppet/functions/strftime.rb +35 -0
  45. data/lib/puppet/functions/warning.rb +14 -0
  46. data/lib/puppet/generate/models/type/type.rb +4 -0
  47. data/lib/puppet/generate/templates/type/pcore.erb +2 -1
  48. data/lib/puppet/indirector/face.rb +6 -1
  49. data/lib/puppet/network/http/error.rb +2 -2
  50. data/lib/puppet/network/http/handler.rb +2 -2
  51. data/lib/puppet/node/environment.rb +11 -0
  52. data/lib/puppet/parser/ast.rb +5 -0
  53. data/lib/puppet/parser/ast/pops_bridge.rb +17 -4
  54. data/lib/puppet/parser/compiler.rb +29 -1
  55. data/lib/puppet/parser/functions.rb +6 -0
  56. data/lib/puppet/parser/functions/assert_type.rb +1 -1
  57. data/lib/puppet/parser/functions/binary_file.rb +24 -0
  58. data/lib/puppet/parser/functions/break.rb +39 -0
  59. data/lib/puppet/parser/functions/contain.rb +7 -15
  60. data/lib/puppet/parser/functions/defined.rb +2 -2
  61. data/lib/puppet/parser/functions/dig.rb +1 -1
  62. data/lib/puppet/parser/functions/each.rb +1 -1
  63. data/lib/puppet/parser/functions/epp.rb +2 -2
  64. data/lib/puppet/parser/functions/filter.rb +1 -1
  65. data/lib/puppet/parser/functions/find_file.rb +28 -0
  66. data/lib/puppet/parser/functions/hiera.rb +4 -4
  67. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  68. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  69. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  70. data/lib/puppet/parser/functions/include.rb +4 -8
  71. data/lib/puppet/parser/functions/inline_epp.rb +1 -1
  72. data/lib/puppet/parser/functions/lest.rb +1 -1
  73. data/lib/puppet/parser/functions/lookup.rb +4 -2
  74. data/lib/puppet/parser/functions/map.rb +1 -1
  75. data/lib/puppet/parser/functions/match.rb +1 -1
  76. data/lib/puppet/parser/functions/new.rb +414 -18
  77. data/lib/puppet/parser/functions/next.rb +38 -0
  78. data/lib/puppet/parser/functions/reduce.rb +1 -1
  79. data/lib/puppet/parser/functions/regsubst.rb +4 -2
  80. data/lib/puppet/parser/functions/require.rb +4 -27
  81. data/lib/puppet/parser/functions/return.rb +71 -0
  82. data/lib/puppet/parser/functions/reverse_each.rb +1 -1
  83. data/lib/puppet/parser/functions/scanf.rb +13 -8
  84. data/lib/puppet/parser/functions/slice.rb +1 -1
  85. data/lib/puppet/parser/functions/split.rb +1 -1
  86. data/lib/puppet/parser/functions/step.rb +1 -1
  87. data/lib/puppet/parser/functions/strftime.rb +185 -0
  88. data/lib/puppet/parser/functions/then.rb +1 -1
  89. data/lib/puppet/parser/functions/type.rb +1 -1
  90. data/lib/puppet/parser/functions/with.rb +3 -3
  91. data/lib/puppet/parser/resource.rb +8 -5
  92. data/lib/puppet/parser/scope.rb +1 -1
  93. data/lib/puppet/plugins/configuration.rb +8 -0
  94. data/lib/puppet/plugins/data_providers.rb +1 -0
  95. data/lib/puppet/plugins/data_providers/data_provider.rb +7 -28
  96. data/lib/puppet/plugins/data_providers/registry.rb +1 -0
  97. data/lib/puppet/pops.rb +4 -0
  98. data/lib/puppet/pops/evaluator/access_operator.rb +36 -5
  99. data/lib/puppet/pops/evaluator/closure.rb +81 -12
  100. data/lib/puppet/pops/evaluator/compare_operator.rb +24 -1
  101. data/lib/puppet/pops/evaluator/evaluator_impl.rb +29 -5
  102. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +1 -1
  103. data/lib/puppet/pops/evaluator/runtime3_converter.rb +53 -62
  104. data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -6
  105. data/lib/puppet/pops/functions/dispatch.rb +9 -2
  106. data/lib/puppet/pops/functions/dispatcher.rb +3 -1
  107. data/lib/puppet/pops/functions/function.rb +19 -2
  108. data/lib/puppet/pops/issues.rb +9 -0
  109. data/lib/puppet/pops/label_provider.rb +2 -2
  110. data/lib/puppet/pops/loader/loader.rb +17 -0
  111. data/lib/puppet/pops/loader/static_loader.rb +0 -41
  112. data/lib/puppet/pops/lookup.rb +12 -0
  113. data/lib/puppet/pops/lookup/context.rb +86 -0
  114. data/lib/puppet/pops/lookup/explainer.rb +46 -6
  115. data/lib/puppet/pops/lookup/invocation.rb +19 -0
  116. data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
  117. data/lib/puppet/pops/model/factory.rb +20 -8
  118. data/lib/puppet/pops/model/model_label_provider.rb +3 -0
  119. data/lib/puppet/pops/model/model_meta.rb +2 -0
  120. data/lib/puppet/pops/model/model_tree_dumper.rb +14 -0
  121. data/lib/puppet/pops/parser/egrammar.ra +11 -6
  122. data/lib/puppet/pops/parser/eparser.rb +1112 -1086
  123. data/lib/puppet/pops/parser/heredoc_support.rb +1 -2
  124. data/lib/puppet/pops/pcore.rb +1 -0
  125. data/lib/puppet/pops/puppet_stack.rb +3 -3
  126. data/lib/puppet/pops/resource/param.rb +5 -1
  127. data/lib/puppet/pops/resource/resource_type_impl.rb +8 -4
  128. data/lib/puppet/pops/resource/resource_type_set.pcore +1 -0
  129. data/lib/puppet/pops/serialization/abstract_reader.rb +19 -2
  130. data/lib/puppet/pops/serialization/abstract_writer.rb +16 -3
  131. data/lib/puppet/pops/serialization/deserializer.rb +5 -1
  132. data/lib/puppet/pops/serialization/extension.rb +2 -0
  133. data/lib/puppet/pops/serialization/json.rb +76 -26
  134. data/lib/puppet/pops/serialization/serializer.rb +5 -1
  135. data/lib/puppet/pops/serialization/time_factory.rb +2 -1
  136. data/lib/puppet/pops/time/timespan.rb +718 -0
  137. data/lib/puppet/pops/time/timestamp.rb +148 -0
  138. data/lib/puppet/pops/types/p_binary_type.rb +220 -0
  139. data/lib/puppet/pops/types/p_object_type.rb +12 -6
  140. data/lib/puppet/pops/types/p_sensitive_type.rb +5 -1
  141. data/lib/puppet/pops/types/p_timespan_type.rb +141 -0
  142. data/lib/puppet/pops/types/p_timestamp_type.rb +69 -0
  143. data/lib/puppet/pops/types/string_converter.rb +62 -0
  144. data/lib/puppet/pops/types/type_asserter.rb +1 -1
  145. data/lib/puppet/pops/types/type_calculator.rb +17 -3
  146. data/lib/puppet/pops/types/type_factory.rb +35 -1
  147. data/lib/puppet/pops/types/type_formatter.rb +64 -11
  148. data/lib/puppet/pops/types/type_mismatch_describer.rb +110 -61
  149. data/lib/puppet/pops/types/type_parser.rb +18 -4
  150. data/lib/puppet/pops/types/types.rb +98 -63
  151. data/lib/puppet/pops/validation.rb +9 -1
  152. data/lib/puppet/pops/validation/checker4_0.rb +7 -0
  153. data/lib/puppet/property.rb +1 -1
  154. data/lib/puppet/provider.rb +3 -6
  155. data/lib/puppet/provider/mcx/mcxcontent.rb +1 -1
  156. data/lib/puppet/provider/mount/parsed.rb +18 -4
  157. data/lib/puppet/provider/nameservice/directoryservice.rb +15 -7
  158. data/lib/puppet/provider/package/gem.rb +6 -1
  159. data/lib/puppet/provider/package/pip.rb +0 -1
  160. data/lib/puppet/provider/package/pkg.rb +5 -1
  161. data/lib/puppet/provider/package/pkgng.rb +1 -1
  162. data/lib/puppet/provider/package/yum.rb +10 -0
  163. data/lib/puppet/provider/service/launchd.rb +1 -0
  164. data/lib/puppet/provider/user/directoryservice.rb +6 -6
  165. data/lib/puppet/provider/yumrepo/inifile.rb +1 -1
  166. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  167. data/lib/puppet/resource.rb +54 -12
  168. data/lib/puppet/resource/capability_finder.rb +15 -9
  169. data/lib/puppet/resource/catalog.rb +25 -6
  170. data/lib/puppet/resource/type.rb +3 -1
  171. data/lib/puppet/settings.rb +1 -1
  172. data/lib/puppet/settings/environment_conf.rb +12 -4
  173. data/lib/puppet/syntax_checkers/base64.rb +41 -0
  174. data/lib/puppet/syntax_checkers/json.rb +0 -2
  175. data/lib/puppet/transaction.rb +6 -0
  176. data/lib/puppet/transaction/additional_resource_generator.rb +5 -0
  177. data/lib/puppet/transaction/report.rb +7 -2
  178. data/lib/puppet/type.rb +2 -1
  179. data/lib/puppet/type/file/checksum.rb +1 -0
  180. data/lib/puppet/type/file/content.rb +4 -4
  181. data/lib/puppet/type/mount.rb +44 -0
  182. data/lib/puppet/type/ssh_authorized_key.rb +1 -1
  183. data/lib/puppet/type/tidy.rb +3 -0
  184. data/lib/puppet/type/user.rb +12 -6
  185. data/lib/puppet/util/log.rb +25 -0
  186. data/lib/puppet/util/plist.rb +8 -3
  187. data/lib/puppet/version.rb +1 -1
  188. data/lib/puppet_x.rb +7 -1
  189. data/spec/integration/application/apply_spec.rb +118 -0
  190. data/spec/integration/parser/compiler_spec.rb +28 -0
  191. data/spec/integration/parser/pcore_resource_spec.rb +40 -3
  192. data/spec/integration/provider/mount_spec.rb +2 -1
  193. data/spec/integration/util/windows/principal_spec.rb +2 -2
  194. data/spec/integration/util/windows/registry_spec.rb +4 -4
  195. data/spec/lib/puppet_spec/compiler.rb +5 -1
  196. data/spec/lib/puppet_spec/unindent.rb +5 -0
  197. data/spec/shared_contexts/types_setup.rb +6 -0
  198. data/spec/shared_examples/rhel_package_provider.rb +16 -0
  199. data/spec/spec_helper.rb +1 -0
  200. data/spec/unit/agent_spec.rb +11 -0
  201. data/spec/unit/application/lookup_spec.rb +94 -3
  202. data/spec/unit/capability_spec.rb +22 -0
  203. data/spec/unit/configurer_spec.rb +8 -0
  204. data/spec/unit/face/epp_face_spec.rb +22 -3
  205. data/spec/unit/functions/assert_type_spec.rb +3 -3
  206. data/spec/unit/functions/binary_file_spec.rb +46 -0
  207. data/spec/unit/functions/break_spec.rb +89 -0
  208. data/spec/unit/{parser/functions → functions}/contain_spec.rb +68 -3
  209. data/spec/unit/functions/find_file_spec.rb +69 -0
  210. data/spec/unit/functions/include_spec.rb +175 -0
  211. data/spec/unit/functions/logging_spec.rb +54 -0
  212. data/spec/unit/functions/lookup_spec.rb +3 -3
  213. data/spec/unit/functions/new_spec.rb +105 -5
  214. data/spec/unit/functions/next_spec.rb +93 -0
  215. data/spec/unit/functions/require_spec.rb +83 -0
  216. data/spec/unit/functions/return_spec.rb +105 -0
  217. data/spec/unit/{parser/functions → functions}/shared.rb +14 -11
  218. data/spec/unit/functions/strftime_spec.rb +152 -0
  219. data/spec/unit/functions4_spec.rb +22 -0
  220. data/spec/unit/indirector/face_spec.rb +10 -2
  221. data/spec/unit/network/http/error_spec.rb +1 -2
  222. data/spec/unit/network/http/handler_spec.rb +6 -5
  223. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  224. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  225. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  226. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  227. data/spec/unit/parser/functions/lookup_spec.rb +1 -1
  228. data/spec/unit/parser/functions/regsubst_spec.rb +1 -1
  229. data/spec/unit/parser/functions/split_spec.rb +1 -1
  230. data/spec/unit/pops/evaluator/access_ops_spec.rb +81 -1
  231. data/spec/unit/pops/evaluator/arithmetic_ops_spec.rb +170 -0
  232. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +29 -4
  233. data/spec/unit/pops/evaluator/runtime3_converter_spec.rb +112 -4
  234. data/spec/unit/pops/loaders/dependency_loader_spec.rb +12 -0
  235. data/spec/unit/pops/loaders/static_loader_spec.rb +0 -26
  236. data/spec/unit/pops/lookup/context_spec.rb +149 -0
  237. data/spec/unit/pops/parser/parse_functions_spec.rb +19 -0
  238. data/spec/unit/pops/parser/parse_lambda_spec.rb +19 -0
  239. data/spec/unit/pops/puppet_stack_spec.rb +1 -1
  240. data/spec/unit/pops/resource/resource_type_impl_spec.rb +74 -0
  241. data/spec/unit/pops/serialization/packer_spec.rb +34 -14
  242. data/spec/unit/pops/serialization/serialization_spec.rb +67 -5
  243. data/spec/unit/pops/time/timespan_spec.rb +121 -0
  244. data/spec/unit/pops/types/p_binary_type_spec.rb +243 -0
  245. data/spec/unit/pops/types/p_object_type_spec.rb +7 -7
  246. data/spec/unit/pops/types/p_sensitive_type_spec.rb +1 -1
  247. data/spec/unit/pops/types/p_timespan_type_spec.rb +273 -0
  248. data/spec/unit/pops/types/p_timestamp_type_spec.rb +311 -0
  249. data/spec/unit/pops/types/p_type_set_type_spec.rb +13 -13
  250. data/spec/unit/pops/types/ruby_generator_spec.rb +12 -12
  251. data/spec/unit/pops/types/string_converter_spec.rb +89 -0
  252. data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
  253. data/spec/unit/pops/types/type_calculator_spec.rb +113 -5
  254. data/spec/unit/pops/types/type_formatter_spec.rb +40 -0
  255. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +49 -38
  256. data/spec/unit/pops/types/type_parser_spec.rb +87 -4
  257. data/spec/unit/pops/types/types_spec.rb +1 -1
  258. data/spec/unit/pops/validator/validator_spec.rb +23 -0
  259. data/spec/unit/provider/mount/parsed_spec.rb +47 -29
  260. data/spec/unit/provider/package/pkg_spec.rb +109 -99
  261. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
  262. data/spec/unit/provider/user/aix_spec.rb +1 -1
  263. data/spec/unit/provider/user/directoryservice_spec.rb +101 -30
  264. data/spec/unit/resource/capability_finder_spec.rb +29 -7
  265. data/spec/unit/resource/catalog_spec.rb +127 -0
  266. data/spec/unit/ssl/certificate_request_spec.rb +1 -1
  267. data/spec/unit/transaction/additional_resource_generator_spec.rb +30 -0
  268. data/spec/unit/transaction/persistence_spec.rb +1 -6
  269. data/spec/unit/transaction/report_spec.rb +23 -0
  270. data/spec/unit/transaction_spec.rb +38 -0
  271. data/spec/unit/type/mount_spec.rb +5 -0
  272. data/spec/unit/util/plist_spec.rb +14 -2
  273. metadata +71 -12
  274. data/spec/integration/parser/functions/require_spec.rb +0 -43
  275. data/spec/unit/parser/functions/include_spec.rb +0 -55
  276. data/spec/unit/parser/functions/require_spec.rb +0 -68
@@ -488,7 +488,7 @@ class Puppet::Property < Puppet::Parameter
488
488
  rescue Puppet::Error
489
489
  raise
490
490
  rescue => detail
491
- error = Puppet::ResourceError.new("Could not set '#{value}' on #{self.class.name}: #{detail}", @resource.line, @resource.file, detail)
491
+ error = Puppet::ResourceError.new("Could not set '#{value}' on #{self.class.name}: #{detail}", @resource.file, @resource.line, detail)
492
492
  error.set_backtrace detail.backtrace
493
493
  Puppet.log_exception(detail, error.message)
494
494
  raise error
@@ -96,8 +96,7 @@ class Puppet::Provider
96
96
  attr_accessor :resource
97
97
 
98
98
  # Convenience methods - see class method with the same name.
99
- # @see execute
100
- # @return (see execute)
99
+ # @return (see self.execute)
101
100
  def execute(*args)
102
101
  Puppet::Util::Execution.execute(*args)
103
102
  end
@@ -108,8 +107,7 @@ class Puppet::Provider
108
107
  end
109
108
 
110
109
  # Convenience methods - see class method with the same name.
111
- # @see execpipe
112
- # @return (see execpipe)
110
+ # @return (see self.execpipe)
113
111
  def execpipe(*args, &block)
114
112
  Puppet::Util::Execution.execpipe(*args, &block)
115
113
  end
@@ -120,8 +118,7 @@ class Puppet::Provider
120
118
  end
121
119
 
122
120
  # Convenience methods - see class method with the same name.
123
- # @see execfail
124
- # @return (see execfail)
121
+ # @return (see self.execfail)
125
122
  def execfail(*args)
126
123
  Puppet::Util::Execution.execfail(*args)
127
124
  end
@@ -36,7 +36,7 @@ Puppet::Type.type(:mcx).provide :mcxcontent, :parent => Puppet::Provider do
36
36
 
37
37
  def self.instances
38
38
  mcx_list = []
39
- TypeMap.keys.each do |ds_type|
39
+ TypeMap.each_key do |ds_type|
40
40
  ds_path = "/Local/Default/#{TypeMap[ds_type]}"
41
41
  output = dscl 'localhost', '-list', ds_path
42
42
  member_list = output.split
@@ -209,14 +209,20 @@ Puppet::Type.type(:mount).provide(
209
209
 
210
210
  # Update fstab entries that are mounted
211
211
  providers.each do |prov|
212
- if mounts.delete({:name => prov.get(:name), :mounted => :yes}) then
213
- prov.set(:ensure => :mounted)
212
+ mounts.delete_if do |mount|
213
+ if mount[:name] == prov.get(:name) && mount[:mounted] == :yes
214
+ prov.set(:ensure => :mounted)
215
+ prov.set(:live_options => mount[:live_options])
216
+ true
217
+ else
218
+ false
219
+ end
214
220
  end
215
221
  end
216
222
 
217
223
  # Add mounts that are not in fstab but mounted
218
224
  mounts.each do |mount|
219
- providers << new(:ensure => :ghost, :name => mount[:name])
225
+ providers << new(:ensure => :ghost, :name => mount[:name], :live_options => mount[:live_options])
220
226
  end
221
227
  providers
222
228
  end
@@ -232,6 +238,7 @@ Puppet::Type.type(:mount).provide(
232
238
  # to fstab we need to know if the device was mounted before)
233
239
  mountinstances.each do |hash|
234
240
  if mount = resources[hash[:name]]
241
+ mount.provider.set(:live_options => hash[:live_options])
235
242
  case mount.provider.get(:ensure)
236
243
  when :absent # Mount not in fstab
237
244
  mount.provider.set(:ensure => :ghost)
@@ -254,6 +261,7 @@ Puppet::Type.type(:mount).provide(
254
261
  else
255
262
  / on (\S*)/
256
263
  end
264
+
257
265
  instances = []
258
266
  mount_output = mountcmd.split("\n")
259
267
  if mount_output.length >= 2 and mount_output[1] =~ /^[- \t]*$/
@@ -264,7 +272,13 @@ Puppet::Type.type(:mount).provide(
264
272
  end
265
273
  mount_output.each do |line|
266
274
  if match = regex.match(line) and name = match.captures.first
267
- instances << {:name => name, :mounted => :yes} # Only :name is important here
275
+ live_options_platforms = ["Linux", "Darwin"]
276
+ if live_options_platforms.include? Facter.value(:kernel)
277
+ options = line[/\(.*\)/].tr('()', '')
278
+ instances << {:name => name, :mounted => :yes, :live_options => options}
279
+ else
280
+ instances << {:name => name, :mounted => :yes}
281
+ end
268
282
  else
269
283
  raise Puppet::Error, "Could not understand line #{line} from mount output"
270
284
  end
@@ -22,6 +22,12 @@ class Puppet::Provider::NameService::DirectoryService < Puppet::Provider::NameSe
22
22
  confine :feature => :cfpropertylist
23
23
  defaultfor :operatingsystem => :darwin
24
24
 
25
+ # There is no generalized mechanism for provider cache management, but we can
26
+ # use post_resource_eval, which will be run for each suitable provider at the
27
+ # end of each transaction. Use this to clear @all_present after each run.
28
+ def self.post_resource_eval
29
+ @all_present = nil
30
+ end
25
31
 
26
32
  # JJM 2007-07-25: This map is used to map NameService attributes to their
27
33
  # corresponding DirectoryService attribute names.
@@ -87,13 +93,15 @@ class Puppet::Provider::NameService::DirectoryService < Puppet::Provider::NameSe
87
93
  end
88
94
 
89
95
  def self.list_all_present
90
- # JJM: List all objects of this Puppet::Type already present on the system.
91
- begin
92
- dscl_output = execute(get_exec_preamble("-list"))
93
- rescue Puppet::ExecutionFailure
94
- fail("Could not get #{@resource_type.name} list from DirectoryService")
96
+ @all_present ||= begin
97
+ # JJM: List all objects of this Puppet::Type already present on the system.
98
+ begin
99
+ dscl_output = execute(get_exec_preamble("-list"))
100
+ rescue Puppet::ExecutionFailure
101
+ fail("Could not get #{@resource_type.name} list from DirectoryService")
102
+ end
103
+ dscl_output.split("\n")
95
104
  end
96
- dscl_output.split("\n")
97
105
  end
98
106
 
99
107
  def self.parse_dscl_plist_data(dscl_output)
@@ -102,7 +110,7 @@ class Puppet::Provider::NameService::DirectoryService < Puppet::Provider::NameSe
102
110
 
103
111
  def self.generate_attribute_hash(input_hash, *type_properties)
104
112
  attribute_hash = {}
105
- input_hash.keys.each do |key|
113
+ input_hash.each_key do |key|
106
114
  ds_attribute = key.sub("dsAttrTypeStandard:", "")
107
115
  next unless (ds_to_ns_attribute_map.keys.include?(ds_attribute) and type_properties.include? ds_to_ns_attribute_map[ds_attribute])
108
116
  ds_value = input_hash[key]
@@ -92,7 +92,12 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d
92
92
 
93
93
  def install(useversion = true)
94
94
  command = [command(:gemcmd), "install"]
95
- command << "-v" << resource[:ensure] if (! resource[:ensure].is_a? Symbol) and useversion
95
+ if Puppet.features.microsoft_windows?
96
+ version = resource[:ensure]
97
+ command << "-v" << %Q["#{version}"] if (! resource[:ensure].is_a? Symbol) and useversion
98
+ else
99
+ command << "-v" << resource[:ensure] if (! resource[:ensure].is_a? Symbol) and useversion
100
+ end
96
101
 
97
102
  if source = resource[:source]
98
103
  begin
@@ -2,7 +2,6 @@
2
2
  # <http://pip.pypa.io/>
3
3
 
4
4
  require 'puppet/provider/package'
5
- require 'xmlrpc/client'
6
5
  require 'puppet/util/http_proxy'
7
6
 
8
7
  Puppet::Type.type(:package).provide :pip,
@@ -203,10 +203,14 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
203
203
  else
204
204
  command = 'update'
205
205
  end
206
+ args = ['--accept']
207
+ if Puppet::Util::Package.versioncmp(Facter.value(:operatingsystemrelease), '11.2') >= 0
208
+ args.push('--sync-actuators-timeout', '900')
209
+ end
206
210
  unless should.is_a? Symbol
207
211
  name += "@#{should}"
208
212
  end
209
- r = exec_cmd(command(:pkg), command, '--accept', name)
213
+ r = exec_cmd(command(:pkg), command, *args, name)
210
214
  return r if nofail
211
215
  raise Puppet::Error, "Unable to update #{r[:out]}" if r[:exit] != 0
212
216
  end
@@ -62,7 +62,7 @@ Puppet::Type.type(:package).provide :pkgng, :parent => Puppet::Provider::Package
62
62
 
63
63
  def self.prefetch(resources)
64
64
  packages = instances
65
- resources.keys.each do |name|
65
+ resources.each_key do |name|
66
66
  if provider = packages.find{|p| p.name == name or p.origin == name }
67
67
  resources[name].provider = provider
68
68
  end
@@ -156,6 +156,16 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
156
156
  operation = :install
157
157
 
158
158
  case should
159
+ when :latest
160
+ current_package = self.query
161
+ if current_package && !current_package[:ensure].to_s.empty?
162
+ operation = update_command
163
+ self.debug "Ensuring latest, so using #{operation}"
164
+ else
165
+ self.debug "Ensuring latest, but package is absent, so using #{:install}"
166
+ operation = :install
167
+ end
168
+ should = nil
159
169
  when true, false, Symbol
160
170
  # pass
161
171
  should = nil
@@ -135,6 +135,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
135
135
  @label_to_path_map = {}
136
136
  launchd_paths.each do |path|
137
137
  return_globbed_list_of_file_paths(path).each do |filepath|
138
+ Puppet.debug("Reading launchd plist #{filepath}")
138
139
  job = read_plist(filepath)
139
140
  next if job.nil?
140
141
  if job.has_key?("Label")
@@ -100,7 +100,7 @@ Puppet::Type.type(:user).provide :directoryservice do
100
100
  # supported by the user type.
101
101
  def self.generate_attribute_hash(input_hash)
102
102
  attribute_hash = {}
103
- input_hash.keys.each do |key|
103
+ input_hash.each_key do |key|
104
104
  ds_attribute = key.sub("dsAttrTypeStandard:", "")
105
105
  next unless ds_to_ns_attribute_map.keys.include?(ds_attribute)
106
106
  ds_value = input_hash[key]
@@ -121,7 +121,7 @@ Puppet::Type.type(:user).provide :directoryservice do
121
121
  end
122
122
  attribute_hash[:ensure] = :present
123
123
  attribute_hash[:provider] = :directoryservice
124
- attribute_hash[:shadowhashdata] = get_attribute_from_dscl('Users', attribute_hash[:name], 'ShadowHashData')
124
+ attribute_hash[:shadowhashdata] = input_hash['dsAttrTypeNative:ShadowHashData']
125
125
 
126
126
  ##############
127
127
  # Get Groups #
@@ -145,12 +145,12 @@ Puppet::Type.type(:user).provide :directoryservice do
145
145
  attribute_hash[:password] = '*'
146
146
  else
147
147
  embedded_binary_plist = get_embedded_binary_plist(attribute_hash[:shadowhashdata])
148
- if embedded_binary_plist['SALTED-SHA512']
149
- attribute_hash[:password] = get_salted_sha512(embedded_binary_plist)
150
- else
148
+ if embedded_binary_plist['SALTED-SHA512-PBKDF2']
151
149
  attribute_hash[:password] = get_salted_sha512_pbkdf2('entropy', embedded_binary_plist)
152
150
  attribute_hash[:salt] = get_salted_sha512_pbkdf2('salt', embedded_binary_plist)
153
151
  attribute_hash[:iterations] = get_salted_sha512_pbkdf2('iterations', embedded_binary_plist)
152
+ elsif embedded_binary_plist['SALTED-SHA512']
153
+ attribute_hash[:password] = get_salted_sha512(embedded_binary_plist)
154
154
  end
155
155
  end
156
156
 
@@ -178,7 +178,7 @@ Puppet::Type.type(:user).provide :directoryservice do
178
178
  # plist library doesn't read binary plists, so we need to
179
179
  # extract the binary plist, convert it to XML, and return it.
180
180
  def self.get_embedded_binary_plist(shadow_hash_data)
181
- embedded_binary_plist = Array(shadow_hash_data['dsAttrTypeNative:ShadowHashData'][0].delete(' ')).pack('H*')
181
+ embedded_binary_plist = Array(shadow_hash_data[0].delete(' ')).pack('H*')
182
182
  convert_binary_to_hash(embedded_binary_plist)
183
183
  end
184
184
 
@@ -58,7 +58,7 @@ Puppet::Type.type(:yumrepo).provide(:inifile) do
58
58
  # @return [void]
59
59
  def self.prefetch(resources)
60
60
  repos = instances
61
- resources.keys.each do |name|
61
+ resources.each_key do |name|
62
62
  if provider = repos.find { |repo| repo.name == name }
63
63
  resources[name].provider = provider
64
64
  end
@@ -23,7 +23,7 @@ Puppet::Type.type(:zpool).provide(:zpool) do
23
23
  tmp = []
24
24
 
25
25
  #order matters here :(
26
- pool_array.reverse.each do |value|
26
+ pool_array.reverse_each do |value|
27
27
  sym = nil
28
28
  case value
29
29
  when "spares";
@@ -31,7 +31,7 @@ class Puppet::Resource
31
31
  TYPE_NODE = 'Node'.freeze
32
32
  TYPE_SITE = 'Site'.freeze
33
33
 
34
- def self.from_data_hash(data)
34
+ def self.from_data_hash(data, json_deserializer = nil)
35
35
  raise ArgumentError, "No resource type provided in serialized data" unless type = data['type']
36
36
  raise ArgumentError, "No resource title provided in serialized data" unless title = data['title']
37
37
 
@@ -41,6 +41,15 @@ class Puppet::Resource
41
41
  params.each { |param, value| resource[param] = value }
42
42
  end
43
43
 
44
+ if ext_params = data['ext_parameters']
45
+ raise Puppet::Error, 'Unable to deserialize non-Data type parameters unless a deserializer is provided' unless json_deserializer
46
+ reader = json_deserializer.reader
47
+ ext_params.each do |param, value|
48
+ reader.re_initialize([value])
49
+ resource[param] = json_deserializer.read
50
+ end
51
+ end
52
+
44
53
  if sensitive_parameters = data['sensitive_parameters']
45
54
  resource.sensitive_parameters = sensitive_parameters.map(&:to_sym)
46
55
  end
@@ -62,7 +71,7 @@ class Puppet::Resource
62
71
  "#{@type}[#{@title}]#{to_hash.inspect}"
63
72
  end
64
73
 
65
- def to_data_hash
74
+ def to_data_hash(json_serializer = nil)
66
75
  data = ([:type, :title, :tags] + ATTRIBUTES).inject({}) do |hash, param|
67
76
  next hash unless value = self.send(param)
68
77
  hash[param.to_s] = value
@@ -71,23 +80,56 @@ class Puppet::Resource
71
80
 
72
81
  data["exported"] ||= false
73
82
 
74
- params = self.to_hash.inject({}) do |hash, ary|
75
- param, value = ary
76
-
83
+ ext_params = {}
84
+ params = {}
85
+ self.to_hash.each_pair do |param, value|
77
86
  # Don't duplicate the title as the namevar
78
- next hash if param == namevar and value == title
79
-
80
- hash[param] = Puppet::Resource.value_to_pson_data(value)
81
- hash
87
+ unless param == namevar && value == title
88
+ value = Puppet::Resource.value_to_pson_data(value)
89
+ if is_json_type?(value)
90
+ params[param] = value
91
+ elsif json_serializer.nil?
92
+ Puppet.warning("Resource '#{to_s}' contains a #{value.class.name} value. It will be converted to the String '#{value}'")
93
+ params[param] = value
94
+ else
95
+ ext_params[param] = value
96
+ end
97
+ end
82
98
  end
83
99
 
84
- data["parameters"] = params unless params.empty?
100
+ data['parameters'] = params unless params.empty?
101
+ unless ext_params.empty?
102
+ writer = json_serializer.writer
103
+ ext_params.each_key do |key|
104
+ writer.clear_io
105
+ json_serializer.write(ext_params[key])
106
+ writer.finish
107
+ ext_params[key] = writer.to_a[0]
108
+ end
109
+ data['ext_parameters'] = ext_params
110
+ end
85
111
 
86
112
  data["sensitive_parameters"] = sensitive_parameters unless sensitive_parameters.empty?
87
113
 
88
114
  data
89
115
  end
90
116
 
117
+ # @param [Object] value The value to test
118
+ # @return [Boolean] `true` if the value can be represented as JSON
119
+ # @api private
120
+ def is_json_type?(value)
121
+ case value
122
+ when NilClass, TrueClass, FalseClass, Integer, Float, String
123
+ true
124
+ when Array
125
+ value.all? { |elem| is_json_type?(elem) }
126
+ when Hash
127
+ value.all? { |key, val| key.is_a?(String) && is_json_type?(val) }
128
+ else
129
+ false
130
+ end
131
+ end
132
+
91
133
  def self.value_to_pson_data(value)
92
134
  if value.is_a? Array
93
135
  value.map{|v| value_to_pson_data(v) }
@@ -252,7 +294,7 @@ class Puppet::Resource
252
294
  # * a "classic" 3.x ruby plugin
253
295
  # * a compatible implementation (e.g. loading from pcore metadata)
254
296
  # * a resolved user defined type
255
- #
297
+ #
256
298
  # ...then, modify the parameters to the "old" (agent side compatible) way
257
299
  # of describing the type/title with string/symbols.
258
300
  #
@@ -319,7 +361,7 @@ class Puppet::Resource
319
361
  # A resource is a capability (instance) if its underlying type is a
320
362
  # capability type
321
363
  def is_capability?
322
- resource_type and resource_type.is_capability?
364
+ !resource_type.nil? && resource_type.is_capability?
323
365
  end
324
366
 
325
367
  # Returns the value of the 'export' metaparam as an Array
@@ -26,7 +26,12 @@ module Puppet::Resource::CapabilityFinder
26
26
  raise Puppet::DevError, 'PuppetDB is not available'
27
27
  end
28
28
 
29
- resources = search(environment, nil, cap)
29
+ resources = search(nil, nil, cap)
30
+
31
+ if resources.size > 1
32
+ Puppet.debug "Found multiple resources when looking up capability #{cap}, filtering by environment #{environment}"
33
+ resources = resources.select { |r| r['tags'].any? { |t| t == "producer:#{environment}" } }
34
+ end
30
35
 
31
36
  if resources.size > 1 && code_id
32
37
  Puppet.debug "Found multiple resources when looking up capability #{cap}, filtering by code id #{code_id}"
@@ -41,6 +46,7 @@ module Puppet::Resource::CapabilityFinder
41
46
  end
42
47
 
43
48
  if resource_hash = resources.first
49
+ resource_hash['type'] = cap.resource_type
44
50
  instantiate_resource(resource_hash)
45
51
  else
46
52
  Puppet.debug "Could not find capability resource #{cap} in PuppetDB"
@@ -53,9 +59,14 @@ module Puppet::Resource::CapabilityFinder
53
59
  'and',
54
60
  ['=', 'type', cap.type.capitalize],
55
61
  ['=', 'title', cap.title.to_s],
56
- ['=', 'tag', "producer:#{environment}"]
57
62
  ]
58
63
 
64
+ if environment.nil?
65
+ query_terms << ['~', 'tag', "^producer:"]
66
+ else
67
+ query_terms << ['=', 'tag', "producer:#{environment}"]
68
+ end
69
+
59
70
  unless code_id.nil?
60
71
  query_terms << ['in', 'certname',
61
72
  ['extract', 'certname',
@@ -101,13 +112,8 @@ module Puppet::Resource::CapabilityFinder
101
112
  private
102
113
 
103
114
  def self.instantiate_resource(resource_hash)
104
- resource = Puppet::Resource.new(resource_hash['type'],
105
- resource_hash['title'])
106
- real_type = Puppet::Type.type(resource.type)
107
- if real_type.nil?
108
- fail Puppet::ParseError,
109
- "Could not find resource type #{resource.type} returned from PuppetDB"
110
- end
115
+ real_type = resource_hash['type']
116
+ resource = Puppet::Resource.new(real_type, resource_hash['title'])
111
117
  real_type.parameters.each do |param|
112
118
  param = param.to_s
113
119
  next if param == 'name'