puppet 4.2.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (422) hide show
  1. data/CONTRIBUTING.md +1 -1
  2. data/Gemfile +5 -7
  3. data/README.md +1 -1
  4. data/Rakefile +20 -0
  5. data/ext/debian/puppet.init +0 -1
  6. data/ext/debian/puppet.logrotate +14 -5
  7. data/ext/osx/puppet.plist +2 -4
  8. data/ext/project_data.yaml +1 -1
  9. data/ext/redhat/client.init +65 -12
  10. data/ext/redhat/logrotate +15 -3
  11. data/ext/redhat/puppet.spec.erb +5 -1
  12. data/ext/redhat/server.init +1 -1
  13. data/ext/solaris/smf/puppet +44 -0
  14. data/ext/solaris/smf/puppet.xml +44 -0
  15. data/ext/suse/client.init +27 -27
  16. data/ext/suse/server.init +2 -2
  17. data/ext/systemd/puppet.service +1 -0
  18. data/install.rb +21 -39
  19. data/lib/hiera/puppet_function.rb +5 -5
  20. data/lib/puppet/agent/locker.rb +11 -2
  21. data/lib/puppet/agent.rb +4 -4
  22. data/lib/puppet/application/agent.rb +28 -14
  23. data/lib/puppet/application/apply.rb +17 -4
  24. data/lib/puppet/application/cert.rb +16 -0
  25. data/lib/puppet/application/filebucket.rb +78 -4
  26. data/lib/puppet/application/lookup.rb +356 -0
  27. data/lib/puppet/application/master.rb +5 -1
  28. data/lib/puppet/configurer.rb +9 -5
  29. data/lib/puppet/context/trusted_information.rb +21 -1
  30. data/lib/puppet/context.rb +16 -1
  31. data/lib/puppet/daemon.rb +17 -13
  32. data/lib/puppet/data_binding.rb +4 -2
  33. data/lib/puppet/data_providers/data_adapter.rb +7 -68
  34. data/lib/puppet/data_providers/data_function_support.rb +5 -26
  35. data/lib/puppet/data_providers/function_env_data_provider.rb +0 -10
  36. data/lib/puppet/data_providers/function_module_data_provider.rb +0 -22
  37. data/lib/puppet/data_providers/hiera_config.rb +106 -0
  38. data/lib/puppet/data_providers/hiera_env_data_provider.rb +18 -0
  39. data/lib/puppet/data_providers/hiera_interpolate.rb +97 -0
  40. data/lib/puppet/data_providers/hiera_module_data_provider.rb +23 -0
  41. data/lib/puppet/data_providers/hiera_support.rb +37 -0
  42. data/lib/puppet/data_providers/json_data_provider_factory.rb +31 -0
  43. data/lib/puppet/data_providers/lookup_adapter.rb +200 -0
  44. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +32 -0
  45. data/lib/puppet/data_providers.rb +12 -13
  46. data/lib/puppet/defaults.rb +14 -3
  47. data/lib/puppet/environments.rb +94 -6
  48. data/lib/puppet/error.rb +4 -0
  49. data/lib/puppet/face/module/changes.rb +2 -1
  50. data/lib/puppet/feature/cfacter.rb +1 -0
  51. data/lib/puppet/file_bucket/dipper.rb +58 -2
  52. data/lib/puppet/file_system/windows.rb +3 -1
  53. data/lib/puppet/functions/assert_type.rb +48 -12
  54. data/lib/puppet/functions/defined.rb +79 -48
  55. data/lib/puppet/functions/each.rb +85 -27
  56. data/lib/puppet/functions/epp.rb +29 -37
  57. data/lib/puppet/functions/filter.rb +60 -25
  58. data/lib/puppet/functions/hiera.rb +76 -3
  59. data/lib/puppet/functions/hiera_array.rb +65 -3
  60. data/lib/puppet/functions/hiera_hash.rb +74 -2
  61. data/lib/puppet/functions/hiera_include.rb +77 -4
  62. data/lib/puppet/functions/inline_epp.rb +44 -71
  63. data/lib/puppet/functions/lookup.rb +19 -17
  64. data/lib/puppet/functions/map.rb +56 -21
  65. data/lib/puppet/functions/match.rb +29 -12
  66. data/lib/puppet/functions/reduce.rb +95 -58
  67. data/lib/puppet/functions/versioncmp.rb +36 -0
  68. data/lib/puppet/functions/with.rb +15 -7
  69. data/lib/puppet/functions.rb +2 -4
  70. data/lib/puppet/indirector/catalog/compiler.rb +3 -3
  71. data/lib/puppet/indirector/catalog/static_compiler.rb +46 -30
  72. data/lib/puppet/indirector/data_binding/none.rb +4 -1
  73. data/lib/puppet/indirector/file_bucket_file/file.rb +58 -1
  74. data/lib/puppet/indirector/hiera.rb +4 -0
  75. data/lib/puppet/indirector/indirection.rb +6 -1
  76. data/lib/puppet/indirector/json.rb +1 -1
  77. data/lib/puppet/indirector/msgpack.rb +1 -1
  78. data/lib/puppet/indirector/request.rb +7 -8
  79. data/lib/puppet/indirector/resource_type/parser.rb +5 -3
  80. data/lib/puppet/info_service/class_information_service.rb +111 -0
  81. data/lib/puppet/info_service.rb +7 -0
  82. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  83. data/lib/puppet/module_tool/metadata.rb +32 -9
  84. data/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +42 -38
  85. data/lib/puppet/module_tool/skeleton/templates/generator/manifests/init.pp.erb +25 -18
  86. data/lib/puppet/network/authconfig.rb +21 -1
  87. data/lib/puppet/network/authorization.rb +8 -1
  88. data/lib/puppet/network/http/api/master/v3/environment.rb +59 -0
  89. data/lib/puppet/network/http/api/master/v3.rb +7 -1
  90. data/lib/puppet/node/environment.rb +9 -2
  91. data/lib/puppet/node.rb +11 -5
  92. data/lib/puppet/parser/ast/pops_bridge.rb +39 -1
  93. data/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +64 -0
  94. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +38 -0
  95. data/lib/puppet/parser/compiler/catalog_validator/site_validator.rb +20 -0
  96. data/lib/puppet/parser/compiler/catalog_validator.rb +33 -0
  97. data/lib/puppet/parser/compiler.rb +300 -12
  98. data/lib/puppet/parser/environment_compiler.rb +165 -0
  99. data/lib/puppet/parser/functions/assert_type.rb +46 -16
  100. data/lib/puppet/parser/functions/defined.rb +105 -68
  101. data/lib/puppet/parser/functions/each.rb +85 -27
  102. data/lib/puppet/parser/functions/epp.rb +29 -37
  103. data/lib/puppet/parser/functions/filter.rb +59 -23
  104. data/lib/puppet/parser/functions/hiera.rb +83 -27
  105. data/lib/puppet/parser/functions/hiera_array.rb +71 -28
  106. data/lib/puppet/parser/functions/hiera_hash.rb +81 -30
  107. data/lib/puppet/parser/functions/hiera_include.rb +81 -40
  108. data/lib/puppet/parser/functions/inline_epp.rb +35 -60
  109. data/lib/puppet/parser/functions/inline_template.rb +2 -2
  110. data/lib/puppet/parser/functions/map.rb +55 -20
  111. data/lib/puppet/parser/functions/match.rb +27 -12
  112. data/lib/puppet/parser/functions/reduce.rb +97 -60
  113. data/lib/puppet/parser/functions/with.rb +16 -8
  114. data/lib/puppet/parser/resource.rb +103 -21
  115. data/lib/puppet/parser.rb +3 -0
  116. data/lib/puppet/plugins/configuration.rb +3 -2
  117. data/lib/puppet/plugins/data_providers/data_provider.rb +283 -0
  118. data/lib/puppet/plugins/data_providers/registry.rb +84 -0
  119. data/lib/puppet/plugins/data_providers.rb +12 -60
  120. data/lib/puppet/pops/adapters.rb +12 -0
  121. data/lib/puppet/pops/binder/binder.rb +2 -2
  122. data/lib/puppet/pops/binder/bindings_checker.rb +1 -1
  123. data/lib/puppet/pops/binder/bindings_label_provider.rb +3 -1
  124. data/lib/puppet/pops/binder/bindings_loader.rb +6 -2
  125. data/lib/puppet/pops/binder/bindings_model_meta.rb +2 -2
  126. data/lib/puppet/pops/binder/config/binder_config.rb +1 -1
  127. data/lib/puppet/pops/binder/injector.rb +4 -4
  128. data/lib/puppet/pops/binder/key_factory.rb +3 -9
  129. data/lib/puppet/pops/binder/scheme_handler/module_scheme.rb +68 -9
  130. data/lib/puppet/pops/evaluator/access_operator.rb +27 -60
  131. data/lib/puppet/pops/evaluator/closure.rb +8 -8
  132. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +1 -1
  133. data/lib/puppet/pops/evaluator/evaluator_impl.rb +10 -6
  134. data/lib/puppet/pops/evaluator/literal_evaluator.rb +87 -0
  135. data/lib/puppet/pops/evaluator/relationship_operator.rb +7 -1
  136. data/lib/puppet/pops/functions/dispatcher.rb +3 -3
  137. data/lib/puppet/pops/issues.rb +11 -3
  138. data/lib/puppet/pops/label_provider.rb +1 -1
  139. data/lib/puppet/pops/lookup/explainer.rb +402 -0
  140. data/lib/puppet/pops/lookup/invocation.rb +117 -0
  141. data/lib/puppet/pops/lookup.rb +25 -47
  142. data/lib/puppet/pops/merge_strategy.rb +73 -5
  143. data/lib/puppet/pops/model/factory.rb +38 -3
  144. data/lib/puppet/pops/model/model_label_provider.rb +10 -1
  145. data/lib/puppet/pops/model/model_meta.rb +19 -1
  146. data/lib/puppet/pops/model/model_tree_dumper.rb +18 -0
  147. data/lib/puppet/pops/parser/code_merger.rb +13 -1
  148. data/lib/puppet/pops/parser/egrammar.ra +65 -2
  149. data/lib/puppet/pops/parser/eparser.rb +1569 -1241
  150. data/lib/puppet/pops/parser/lexer2.rb +32 -1
  151. data/lib/puppet/pops/parser/locator.rb +1 -1
  152. data/lib/puppet/pops/parser/parser_support.rb +25 -13
  153. data/lib/puppet/pops/patterns.rb +3 -0
  154. data/lib/puppet/pops/types/enumeration.rb +1 -2
  155. data/lib/puppet/pops/types/type_asserter.rb +16 -15
  156. data/lib/puppet/pops/types/type_assertion_error.rb +1 -0
  157. data/lib/puppet/pops/types/type_calculator.rb +171 -1020
  158. data/lib/puppet/pops/types/type_factory.rb +87 -148
  159. data/lib/puppet/pops/types/type_mismatch_describer.rb +743 -0
  160. data/lib/puppet/pops/types/type_parser.rb +118 -129
  161. data/lib/puppet/pops/types/types.rb +1394 -255
  162. data/lib/puppet/pops/types/types_meta.rb +0 -234
  163. data/lib/puppet/pops/validation/checker4_0.rb +49 -1
  164. data/lib/puppet/pops/validation/validator_factory_4_0.rb +3 -1
  165. data/lib/puppet/pops/validation.rb +7 -2
  166. data/lib/puppet/pops.rb +19 -17
  167. data/lib/puppet/provider/augeas/augeas.rb +50 -0
  168. data/lib/puppet/provider/exec.rb +6 -1
  169. data/lib/puppet/provider/group/directoryservice.rb +10 -0
  170. data/lib/puppet/provider/package/dnf.rb +41 -0
  171. data/lib/puppet/provider/package/gem.rb +7 -2
  172. data/lib/puppet/provider/package/nim.rb +1 -1
  173. data/lib/puppet/provider/package/rpm.rb +1 -0
  174. data/lib/puppet/provider/package/windows/exe_package.rb +10 -8
  175. data/lib/puppet/provider/package/windows/msi_package.rb +4 -3
  176. data/lib/puppet/provider/package/windows/package.rb +9 -1
  177. data/lib/puppet/provider/package/yum.rb +20 -9
  178. data/lib/puppet/provider/service/bsd.rb +1 -1
  179. data/lib/puppet/provider/service/debian.rb +21 -0
  180. data/lib/puppet/provider/service/init.rb +6 -0
  181. data/lib/puppet/provider/service/launchd.rb +36 -7
  182. data/lib/puppet/provider/service/rcng.rb +51 -0
  183. data/lib/puppet/provider/service/redhat.rb +2 -1
  184. data/lib/puppet/provider/service/smf.rb +43 -2
  185. data/lib/puppet/provider/service/src.rb +27 -0
  186. data/lib/puppet/provider/service/systemd.rb +25 -5
  187. data/lib/puppet/provider/sshkey/parsed.rb +19 -9
  188. data/lib/puppet/provider/zone/solaris.rb +2 -2
  189. data/lib/puppet/reference/configuration.rb +10 -4
  190. data/lib/puppet/reference/report.rb +9 -12
  191. data/lib/puppet/reports.rb +5 -1
  192. data/lib/puppet/resource/capability_finder.rb +95 -0
  193. data/lib/puppet/resource/catalog.rb +47 -7
  194. data/lib/puppet/resource/status.rb +0 -2
  195. data/lib/puppet/resource/type.rb +238 -44
  196. data/lib/puppet/resource/type_collection.rb +60 -2
  197. data/lib/puppet/resource.rb +50 -73
  198. data/lib/puppet/settings/file_setting.rb +10 -9
  199. data/lib/puppet/settings.rb +2 -2
  200. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  201. data/lib/puppet/ssl/oids.rb +9 -1
  202. data/lib/puppet/transaction/additional_resource_generator.rb +71 -8
  203. data/lib/puppet/transaction/resource_harness.rb +9 -4
  204. data/lib/puppet/transaction.rb +8 -1
  205. data/lib/puppet/type/augeas.rb +8 -0
  206. data/lib/puppet/type/file/source.rb +14 -12
  207. data/lib/puppet/type/package.rb +9 -6
  208. data/lib/puppet/type/user.rb +4 -2
  209. data/lib/puppet/type.rb +78 -7
  210. data/lib/puppet/util/command_line.rb +4 -0
  211. data/lib/puppet/util/execution.rb +18 -2
  212. data/lib/puppet/util/tagging.rb +7 -1
  213. data/lib/puppet/util/windows/adsi.rb +5 -2
  214. data/lib/puppet/util/windows/security.rb +4 -1
  215. data/lib/puppet/util/windows/taskscheduler.rb +1 -1
  216. data/lib/puppet/util.rb +9 -1
  217. data/lib/puppet/version.rb +1 -1
  218. data/lib/puppet.rb +12 -0
  219. data/spec/fixtures/unit/application/environments/production/data/common.yaml +3 -0
  220. data/spec/fixtures/unit/application/environments/production/environment.conf +1 -0
  221. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/data/bad.json +3 -0
  222. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/environment.conf +2 -0
  223. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/hiera.yaml +5 -0
  224. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_json/manifests/site.pp +5 -0
  225. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/data/bad.yaml +3 -0
  226. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/environment.conf +2 -0
  227. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/hiera.yaml +5 -0
  228. data/spec/fixtures/unit/data_providers/environments/hiera_bad_syntax_yaml/manifests/site.pp +5 -0
  229. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/data/common.yaml +2 -0
  230. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/environment.conf +2 -0
  231. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/manifests/site.pp +1 -0
  232. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/data/common.yaml +2 -0
  233. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/manifests/init.pp +5 -0
  234. data/spec/fixtures/unit/data_providers/environments/hiera_defaults/modules/one/metadata.json +9 -0
  235. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/first.json +3 -0
  236. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/name.yaml +2 -0
  237. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/second.json +3 -0
  238. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/single.yaml +2 -0
  239. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data2/single.yaml +2 -0
  240. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/environment.conf +2 -0
  241. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/hiera.yaml +18 -0
  242. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/manifests/site.pp +5 -0
  243. data/spec/fixtures/unit/data_providers/environments/hiera_misc/data/common.yaml +46 -0
  244. data/spec/fixtures/unit/data_providers/environments/hiera_misc/environment.conf +2 -0
  245. data/spec/fixtures/unit/data_providers/environments/hiera_misc/manifests/site.pp +1 -0
  246. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/data/common.yaml +30 -0
  247. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/manifests/init.pp +13 -0
  248. data/spec/fixtures/unit/data_providers/environments/hiera_misc/modules/one/metadata.json +9 -0
  249. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/environment.conf +2 -0
  250. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/manifests/site.pp +1 -0
  251. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/first.json +3 -0
  252. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/name.yaml +1 -0
  253. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/second.json +3 -0
  254. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data1/single.yaml +2 -0
  255. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/data2/single.yaml +2 -0
  256. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/hiera.yaml +18 -0
  257. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/manifests/init.pp +5 -0
  258. data/spec/fixtures/unit/data_providers/environments/hiera_module_config/modules/one/metadata.json +9 -0
  259. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_env_data.rb +1 -0
  260. data/spec/fixtures/unit/data_providers/environments/sample/modules/dataprovider/lib/puppet_x/helindbe/sample_module_data.rb +1 -0
  261. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/data/first.json +3 -0
  262. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/hiera.yaml +8 -0
  263. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/manifests/init.pp +5 -0
  264. data/spec/fixtures/unit/functions/lookup/environments/production/modules/hieraprovider/metadata.json +9 -0
  265. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/lib/puppet/functions/meta/data.rb +9 -0
  266. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/manifests/init.pp +3 -0
  267. data/spec/fixtures/unit/functions/lookup/environments/production/modules/meta/metadata.json +9 -0
  268. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/lib/puppet/bindings/metawcp/default.rb +10 -0
  269. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/lib/puppet_x/thallgren/sample_module_data.rb +23 -0
  270. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/manifests/init.pp +3 -0
  271. data/spec/fixtures/unit/functions/lookup/environments/production/modules/metawcp/metadata.json +9 -0
  272. data/spec/fixtures/unit/provider/package/yum/yum-check-update-security.txt +184 -0
  273. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_get/should_yield_to_the_block.yml +24 -0
  274. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_head/should_yield_to_the_block.yml +24 -0
  275. data/spec/fixtures/vcr/cassettes/Puppet_Network_HTTP_Connection/when_handling_requests/_request_post/should_yield_to_the_block.yml +24 -0
  276. data/spec/integration/data_binding_spec.rb +229 -0
  277. data/spec/integration/file_bucket/file_spec.rb +2 -2
  278. data/spec/integration/parser/compiler_spec.rb +30 -24
  279. data/spec/integration/parser/resource_expressions_spec.rb +4 -4
  280. data/spec/integration/parser/undef_param_spec.rb +1 -1
  281. data/spec/integration/provider/package_spec.rb +3 -1
  282. data/spec/integration/resource/catalog_spec.rb +1 -1
  283. data/spec/integration/ssl/certificate_authority_spec.rb +0 -1
  284. data/spec/integration/ssl/certificate_request_spec.rb +0 -1
  285. data/spec/integration/ssl/certificate_revocation_list_spec.rb +0 -1
  286. data/spec/integration/ssl/host_spec.rb +0 -1
  287. data/spec/integration/type/package_spec.rb +2 -0
  288. data/spec/integration/util/rdoc/parser_spec.rb +1 -1
  289. data/spec/integration/util/windows/security_spec.rb +18 -0
  290. data/spec/lib/matchers/include_in_order.rb +2 -2
  291. data/spec/shared_behaviours/iterative_functions.rb +8 -8
  292. data/spec/spec_helper.rb +7 -0
  293. data/spec/unit/agent/locker_spec.rb +4 -4
  294. data/spec/unit/agent_spec.rb +0 -8
  295. data/spec/unit/application/agent_spec.rb +5 -0
  296. data/spec/unit/application/apply_spec.rb +9 -1
  297. data/spec/unit/application/filebucket_spec.rb +88 -2
  298. data/spec/unit/application/lookup_spec.rb +195 -0
  299. data/spec/unit/application/master_spec.rb +2 -2
  300. data/spec/unit/application_spec.rb +3 -3
  301. data/spec/unit/appmgmt_spec.rb +657 -0
  302. data/spec/unit/capability_spec.rb +414 -0
  303. data/spec/unit/configurer_spec.rb +7 -1
  304. data/spec/unit/context/trusted_information_spec.rb +24 -1
  305. data/spec/unit/daemon_spec.rb +18 -8
  306. data/spec/unit/data_providers/hiera_data_provider_spec.rb +201 -0
  307. data/spec/unit/environments_spec.rb +2 -0
  308. data/spec/unit/face/node_spec.rb +1 -1
  309. data/spec/unit/file_bucket/dipper_spec.rb +210 -1
  310. data/spec/unit/file_serving/configuration_spec.rb +1 -1
  311. data/spec/unit/file_system_spec.rb +20 -0
  312. data/spec/unit/functions/assert_type_spec.rb +5 -7
  313. data/spec/unit/functions/defined_spec.rb +2 -2
  314. data/spec/unit/functions/epp_spec.rb +2 -2
  315. data/spec/unit/functions/filter_spec.rb +18 -0
  316. data/spec/unit/functions/hiera_spec.rb +2 -2
  317. data/spec/unit/functions/lookup_spec.rb +200 -9
  318. data/spec/unit/functions/regsubst_spec.rb +17 -8
  319. data/spec/unit/functions/scanf_spec.rb +1 -1
  320. data/spec/unit/functions/split_spec.rb +2 -2
  321. data/spec/unit/functions/versioncmp_spec.rb +36 -0
  322. data/spec/unit/functions4_spec.rb +58 -72
  323. data/spec/unit/graph/sequential_prioritizer_spec.rb +1 -1
  324. data/spec/unit/indirector/catalog/compiler_spec.rb +28 -8
  325. data/spec/unit/indirector/catalog/static_compiler_spec.rb +38 -20
  326. data/spec/unit/indirector/data_binding/none_spec.rb +2 -2
  327. data/spec/unit/indirector/file_bucket_file/file_spec.rb +52 -1
  328. data/spec/unit/indirector/indirection_spec.rb +13 -2
  329. data/spec/unit/indirector/request_spec.rb +8 -8
  330. data/spec/unit/indirector/ssl_file_spec.rb +1 -1
  331. data/spec/unit/indirector/yaml_spec.rb +1 -1
  332. data/spec/unit/info_service_spec.rb +236 -0
  333. data/spec/unit/module_tool/application_spec.rb +1 -1
  334. data/spec/unit/module_tool/applications/builder_spec.rb +1 -1
  335. data/spec/unit/module_tool/metadata_spec.rb +31 -2
  336. data/spec/unit/network/authconfig_spec.rb +62 -32
  337. data/spec/unit/network/authorization_spec.rb +30 -2
  338. data/spec/unit/network/authstore_spec.rb +1 -1
  339. data/spec/unit/network/http/compression_spec.rb +1 -1
  340. data/spec/unit/network/http/connection_spec.rb +14 -19
  341. data/spec/unit/network/http/handler_spec.rb +0 -5
  342. data/spec/unit/network/rights_spec.rb +3 -3
  343. data/spec/unit/node_spec.rb +27 -0
  344. data/spec/unit/parser/ast/leaf_spec.rb +1 -1
  345. data/spec/unit/parser/compiler_spec.rb +86 -2
  346. data/spec/unit/parser/functions/create_resources_spec.rb +1 -1
  347. data/spec/unit/parser/resource_spec.rb +2 -20
  348. data/spec/unit/pops/binder/config/binder_config_spec.rb +1 -1
  349. data/spec/unit/pops/binder/injector_spec.rb +3 -3
  350. data/spec/unit/pops/evaluator/access_ops_spec.rb +13 -11
  351. data/spec/unit/pops/evaluator/basic_expressions_spec.rb +1 -2
  352. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +20 -11
  353. data/spec/unit/pops/evaluator/literal_evaluator_spec.rb +43 -0
  354. data/spec/unit/pops/label_provider_spec.rb +5 -1
  355. data/spec/unit/pops/parser/lexer2_spec.rb +39 -0
  356. data/spec/unit/pops/parser/parse_application_spec.rb +40 -0
  357. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +4 -0
  358. data/spec/unit/pops/parser/parse_capabilities_spec.rb +47 -0
  359. data/spec/unit/pops/parser/parse_site_spec.rb +38 -0
  360. data/spec/unit/pops/parser/parser_rspec_helper.rb +5 -0
  361. data/spec/unit/pops/parser/parser_spec.rb +18 -0
  362. data/spec/unit/pops/types/type_calculator_spec.rb +427 -444
  363. data/spec/unit/pops/types/type_factory_spec.rb +12 -12
  364. data/spec/unit/pops/types/type_parser_spec.rb +15 -12
  365. data/spec/unit/pops/validator/validator_spec.rb +68 -0
  366. data/spec/unit/property_spec.rb +1 -1
  367. data/spec/unit/provider/augeas/augeas_spec.rb +50 -0
  368. data/spec/unit/provider/group/directoryservice_spec.rb +33 -0
  369. data/spec/unit/provider/group/windows_adsi_spec.rb +3 -0
  370. data/spec/unit/provider/package/dnf_spec.rb +92 -0
  371. data/spec/unit/provider/package/gem_spec.rb +7 -0
  372. data/spec/unit/provider/package/nim_spec.rb +6 -6
  373. data/spec/unit/provider/package/rpm_spec.rb +25 -2
  374. data/spec/unit/provider/package/windows/package_spec.rb +41 -0
  375. data/spec/unit/provider/package/yum_spec.rb +35 -12
  376. data/spec/unit/provider/scheduled_task/win32_taskscheduler_spec.rb +10 -0
  377. data/spec/unit/provider/service/debian_spec.rb +28 -0
  378. data/spec/unit/provider/service/gentoo_spec.rb +1 -0
  379. data/spec/unit/provider/service/init_spec.rb +6 -0
  380. data/spec/unit/provider/service/launchd_spec.rb +85 -10
  381. data/spec/unit/provider/service/openrc_spec.rb +1 -0
  382. data/spec/unit/provider/service/rcng_spec.rb +41 -0
  383. data/spec/unit/provider/service/redhat_spec.rb +8 -1
  384. data/spec/unit/provider/service/smf_spec.rb +30 -5
  385. data/spec/unit/provider/service/src_spec.rb +20 -4
  386. data/spec/unit/provider/service/systemd_spec.rb +79 -29
  387. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -1
  388. data/spec/unit/provider/sshkey/parsed_spec.rb +23 -0
  389. data/spec/unit/provider/user/windows_adsi_spec.rb +2 -1
  390. data/spec/unit/provider/zone/solaris_spec.rb +19 -0
  391. data/spec/unit/reports_spec.rb +10 -0
  392. data/spec/unit/resource/capability_finder_spec.rb +56 -0
  393. data/spec/unit/resource/catalog_spec.rb +31 -8
  394. data/spec/unit/resource/type_collection_spec.rb +23 -2
  395. data/spec/unit/resource/type_spec.rb +1 -1
  396. data/spec/unit/resource_spec.rb +23 -5
  397. data/spec/unit/settings/file_setting_spec.rb +31 -0
  398. data/spec/unit/settings_spec.rb +91 -2
  399. data/spec/unit/ssl/certificate_authority/interface_spec.rb +4 -3
  400. data/spec/unit/ssl/certificate_authority_spec.rb +5 -3
  401. data/spec/unit/ssl/host_spec.rb +2 -2
  402. data/spec/unit/ssl/oids_spec.rb +8 -0
  403. data/spec/unit/transaction/additional_resource_generator_spec.rb +78 -5
  404. data/spec/unit/transaction/report_spec.rb +24 -1
  405. data/spec/unit/transaction_spec.rb +7 -0
  406. data/spec/unit/type/exec_spec.rb +16 -8
  407. data/spec/unit/type/host_spec.rb +4 -4
  408. data/spec/unit/type/package_spec.rb +1 -0
  409. data/spec/unit/type/tidy_spec.rb +4 -4
  410. data/spec/unit/type/user_spec.rb +14 -7
  411. data/spec/unit/type/vlan_spec.rb +1 -1
  412. data/spec/unit/type_spec.rb +1 -1
  413. data/spec/unit/util/ldap/generator_spec.rb +1 -1
  414. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  415. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -1
  416. data/spec/unit/util/network_device_spec.rb +1 -1
  417. data/spec/unit/util/storage_spec.rb +5 -1
  418. data/spec/unit/util/windows/adsi_spec.rb +13 -0
  419. data/spec/unit/util_spec.rb +21 -2
  420. metadata +173 -7
  421. data/lib/puppet/pops/evaluator/callable_mismatch_describer.rb +0 -175
  422. data/spec/integration/data_binding.rb +0 -104
@@ -4,28 +4,27 @@ module Puppet::DataProviders
4
4
  unless @loaded
5
5
  require 'puppet/pops'
6
6
  require 'puppet/data_providers/data_adapter'
7
+ require 'puppet/data_providers/lookup_adapter'
7
8
  end
8
9
  @loaded = true
9
10
  end
10
11
 
11
- def self.lookup_in_environment(name, scope, merge)
12
- assert_loaded()
13
- adapter = Puppet::DataProviders::DataAdapter.adapt(Puppet.lookup(:current_environment))
14
- adapter.env_provider.lookup(name, scope, merge)
12
+ # @deprecated use `lookup_adapter(lookup_invocation).lookup` instead
13
+ def self.lookup_in_environment(name, lookup_invocation, merge)
14
+ Puppet.deprecation_warning('The method Puppet::DataProviders.lookup_in_environment is deprecated and will be removed in the next major release of Puppet.')
15
+ lookup_adapter(lookup_invocation).lookup_in_environment(name, lookup_invocation, Puppet::Pops::MergeStrategy.strategy(merge))
15
16
  end
16
17
 
17
18
  MODULE_NAME = 'module_name'.freeze
18
19
 
19
- def self.lookup_in_module(name, scope, merge)
20
- # Do not attempt to do a lookup in a module unless the name is qualified.
21
- qual_index = name.index('::')
22
- throw :no_such_key if qual_index.nil?
23
- module_name = name[0..qual_index-1]
20
+ # @deprecated use `adapter(lookup_invocation).lookup` instead
21
+ def self.lookup_in_module(name, lookup_invocation, merge)
22
+ Puppet.deprecation_warning('The method Puppet::DataProviders.lookup_in_module is deprecated and will be removed in the next major release of Puppet.')
23
+ lookup_adapter(lookup_invocation).lookup_in_module(name, lookup_invocation, Puppet::Pops::MergeStrategy.strategy(merge))
24
+ end
24
25
 
26
+ def self.lookup_adapter(lookup_invocation)
25
27
  assert_loaded()
26
- adapter = Puppet::DataProviders::DataAdapter.adapt(Puppet.lookup(:current_environment))
27
- data_provider = adapter.module_provider(module_name)
28
- throw :no_such_key if data_provider.nil?
29
- data_provider.lookup(name, scope, merge)
28
+ LookupAdapter.adapt(lookup_invocation.scope.environment)
30
29
  end
31
30
  end
@@ -20,7 +20,9 @@ module Puppet
20
20
  :cfacter => {
21
21
  :default => false,
22
22
  :type => :boolean,
23
- :desc => 'Whether or not to use the native facter (cfacter) implementation instead of the Ruby one (facter). Defaults to false.',
23
+ :desc => 'Whether to enable a pre-Facter 3.0 release of native Facter (distributed as
24
+ the "cfacter" package). This is not necessary if Facter 3.0 or later is installed.
25
+ This setting is deprecated, as Facter 3 is now the default in puppet-agent.',
24
26
  :hook => proc do |value|
25
27
  return unless value
26
28
  raise ArgumentError, 'facter has already evaluated facts.' if Facter.instance_variable_get(:@collection)
@@ -525,13 +527,22 @@ module Puppet
525
527
  :desc => "The directory where catalog previews per node are generated."
526
528
  }
527
529
  )
530
+
531
+ define_settings(:main,
532
+ :app_management => {
533
+ :default => false,
534
+ :type => :boolean,
535
+ :desc => "Whether the application management feature is on or off. You must restart Puppet Server after changing this setting.",
536
+ }
537
+ )
538
+
528
539
  Puppet.define_settings(:module_tool,
529
540
  :module_repository => {
530
541
  :default => 'https://forgeapi.puppetlabs.com',
531
542
  :desc => "The module repository",
532
543
  },
533
544
  :module_working_dir => {
534
- :default => '$vardir/puppet-module',
545
+ :default => (Puppet.features.microsoft_windows? ? Dir.tmpdir() : '$vardir/puppet-module'),
535
546
  :desc => "The directory into which module tool data is stored",
536
547
  },
537
548
  :module_skeleton_dir => {
@@ -544,7 +555,7 @@ module Puppet
544
555
  },
545
556
  :module_groups => {
546
557
  :default => nil,
547
- :desc => "Extra module groups to request from the Puppet Forge",
558
+ :desc => "Extra module groups to request from the Puppet Forge. This is an internal setting, and users should never change it.",
548
559
  }
549
560
  )
550
561
 
@@ -38,6 +38,9 @@ module Puppet::Environments
38
38
  raise EnvironmentNotFound, name
39
39
  end
40
40
  end
41
+
42
+ def clear_all
43
+ end
41
44
  end
42
45
 
43
46
  # @!macro [new] loader_search_paths
@@ -193,12 +196,13 @@ module Puppet::Environments
193
196
  def create_environment(name)
194
197
  env_symbol = name.intern
195
198
  setting_values = Puppet.settings.values(env_symbol, Puppet.settings.preferred_run_mode)
196
- Puppet::Node::Environment.create(
199
+ env = Puppet::Node::Environment.create(
197
200
  env_symbol,
198
201
  Puppet::Node::Environment.split_path(setting_values.interpolate(:modulepath)),
199
202
  setting_values.interpolate(:manifest),
200
203
  setting_values.interpolate(:config_version)
201
204
  )
205
+ env
202
206
  end
203
207
 
204
208
  def valid_directory?(envdir)
@@ -257,6 +261,9 @@ module Puppet::Environments
257
261
  nil
258
262
  end
259
263
 
264
+ def clear_all
265
+ @loaders.each {|loader| loader.clear_all}
266
+ end
260
267
  end
261
268
 
262
269
  class Cached
@@ -282,10 +289,29 @@ module Puppet::Environments
282
289
  @cache_expiration_service || DefaultCacheExpirationService.new
283
290
  end
284
291
 
292
+ # Returns the end of time (the next Mesoamerican Long Count cycle-end after 2012 (5125+2012) = 7137,
293
+ # of for a 32 bit machine using Ruby < 1.9.3, the year 2038.
294
+ def self.end_of_time
295
+ begin
296
+ Time.gm(7137)
297
+ rescue ArgumentError
298
+ Time.gm(2038)
299
+ end
300
+ end
301
+
302
+ END_OF_TIME = end_of_time
303
+ START_OF_TIME = Time.gm(1)
304
+
285
305
  def initialize(loader)
286
306
  @loader = loader
287
- @cache = {}
288
307
  @cache_expiration_service = Puppet::Environments::Cached.cache_expiration_service
308
+ @cache = {}
309
+
310
+ # Holds expiration times in sorted order - next to expire is first
311
+ @expirations = SortedSet.new
312
+
313
+ # Infinity since it there are no entries, this is a cache of the first to expire time
314
+ @next_expiration = END_OF_TIME
289
315
  end
290
316
 
291
317
  # @!macro loader_list
@@ -300,15 +326,34 @@ module Puppet::Environments
300
326
 
301
327
  # @!macro loader_get
302
328
  def get(name)
303
- evict_if_expired(name)
329
+ # Aggressively evict all that has expired
330
+ # This strategy favors smaller memory footprint over environment
331
+ # retrieval time.
332
+ clear_all_expired
304
333
  if result = @cache[name]
334
+ # found in cache
305
335
  return result.value
306
336
  elsif (result = @loader.get(name))
307
- @cache[name] = entry(result)
337
+ # environment loaded, cache it
338
+ cache_entry = entry(result)
339
+ @cache_expiration_service.created(result)
340
+ add_entry(name, cache_entry)
308
341
  result
309
342
  end
310
343
  end
311
344
 
345
+ # Adds a cache entry to the cache
346
+ def add_entry(name, cache_entry)
347
+ Puppet.debug {"Caching environment '#{name}' #{cache_entry.label}"}
348
+ @cache[name] = cache_entry
349
+ expires = cache_entry.expires
350
+ @expirations.add(expires)
351
+ if @next_expiration > expires
352
+ @next_expiration = expires
353
+ end
354
+ end
355
+ private :add_entry
356
+
312
357
  # Clears the cache of the environment with the given name.
313
358
  # (The intention is that this could be used from a MANUAL cache eviction command (TBD)
314
359
  def clear(name)
@@ -318,7 +363,27 @@ module Puppet::Environments
318
363
  # Clears all cached environments.
319
364
  # (The intention is that this could be used from a MANUAL cache eviction command (TBD)
320
365
  def clear_all()
366
+ super
321
367
  @cache = {}
368
+ @expirations.clear
369
+ @next_expiration = END_OF_TIME
370
+ end
371
+
372
+ # Clears all environments that have expired, either by exceeding their time to live, or
373
+ # through an explicit eviction determined by the cache expiration service.
374
+ #
375
+ def clear_all_expired()
376
+ t = Time.now
377
+ return if t < @next_expiration && ! @cache.any? {|name, _| @cache_expiration_service.expired?(name.to_sym) }
378
+ to_expire = @cache.select { |name, entry| entry.expires < t || @cache_expiration_service.expired?(name.to_sym) }
379
+ to_expire.each do |name, entry|
380
+ Puppet.debug {"Evicting cache entry for environment '#{name}'"}
381
+ @cache_expiration_service.evicted(name)
382
+ clear(name)
383
+ @expirations.delete(entry.expires)
384
+ Puppet.settings.clear_environment_settings(name)
385
+ end
386
+ @next_expiration = @expirations.first || END_OF_TIME
322
387
  end
323
388
 
324
389
  # This implementation evicts the cache, and always gets the current
@@ -337,9 +402,7 @@ module Puppet::Environments
337
402
  # Creates a suitable cache entry given the time to live for one environment
338
403
  #
339
404
  def entry(env)
340
- @cache_expiration_service.created(env)
341
405
  ttl = (conf = get_conf(env.name)) ? conf.environment_timeout : Puppet.settings.value(:environment_timeout)
342
- Puppet.debug {"Caching environment '#{env.name}' (cache ttl: #{ttl})"}
343
406
  case ttl
344
407
  when 0
345
408
  NotCachedEntry.new(env) # Entry that is always expired (avoids syscall to get time)
@@ -373,6 +436,14 @@ module Puppet::Environments
373
436
  def expired?
374
437
  false
375
438
  end
439
+
440
+ def label
441
+ ""
442
+ end
443
+
444
+ def expires
445
+ END_OF_TIME
446
+ end
376
447
  end
377
448
 
378
449
  # Always evicting entry
@@ -380,6 +451,14 @@ module Puppet::Environments
380
451
  def expired?
381
452
  true
382
453
  end
454
+
455
+ def label
456
+ "(ttl = 0 sec)"
457
+ end
458
+
459
+ def expires
460
+ START_OF_TIME
461
+ end
383
462
  end
384
463
 
385
464
  # Time to Live eviction policy entry
@@ -387,11 +466,20 @@ module Puppet::Environments
387
466
  def initialize(value, ttl_seconds)
388
467
  super value
389
468
  @ttl = Time.now + ttl_seconds
469
+ @ttl_seconds = ttl_seconds
390
470
  end
391
471
 
392
472
  def expired?
393
473
  Time.now > @ttl
394
474
  end
475
+
476
+ def label
477
+ "(ttl = #{@ttl_seconds} sec)"
478
+ end
479
+
480
+ def expires
481
+ @ttl
482
+ end
395
483
  end
396
484
  end
397
485
  end
data/lib/puppet/error.rb CHANGED
@@ -93,4 +93,8 @@ module Puppet
93
93
  class MissingCommand < Puppet::Error
94
94
  end
95
95
 
96
+ # Raised when we failed to aquire a lock
97
+ class LockError < Puppet::Error
98
+ end
99
+
96
100
  end
@@ -4,7 +4,8 @@ Puppet::Face.define(:module, '1.0.0') do
4
4
  description <<-EOT
5
5
  Shows any files in a module that have been modified since it was
6
6
  installed. This action compares the files on disk to the md5 checksums
7
- included in the module's metadata.
7
+ included in the module's checksums.json or, if that is missing, in
8
+ metadata.json.
8
9
  EOT
9
10
 
10
11
  returns "Array of strings representing paths of modified files."
@@ -2,6 +2,7 @@ require 'facter'
2
2
  require 'puppet/util/feature'
3
3
 
4
4
  Puppet.features.add :cfacter do
5
+ Puppet.deprecation_warning("The cfacter setting is deprecated. You can use Facter 3 and higher without this setting.")
5
6
  begin
6
7
  require 'cfacter'
7
8
 
@@ -2,6 +2,8 @@ require 'pathname'
2
2
  require 'puppet/file_bucket'
3
3
  require 'puppet/file_bucket/file'
4
4
  require 'puppet/indirector/request'
5
+ require 'puppet/util/diff'
6
+ require 'tempfile'
5
7
 
6
8
  class Puppet::FileBucket::Dipper
7
9
  include Puppet::Util::Checksums
@@ -22,7 +24,7 @@ class Puppet::FileBucket::Dipper
22
24
  @rest_path = nil
23
25
  else
24
26
  @local_path = nil
25
- @rest_path = "https://#{server}:#{port}/#{environment}/file_bucket_file/"
27
+ @rest_path = "filebucket://#{server}:#{port}/"
26
28
  end
27
29
  @checksum_type = Puppet[:digest_algorithm].to_sym
28
30
  @digest = method(@checksum_type)
@@ -56,6 +58,46 @@ class Puppet::FileBucket::Dipper
56
58
  end
57
59
  end
58
60
 
61
+ # Diffs two filebucket files identified by their sums
62
+ def diff(checksum_a, checksum_b, file_a, file_b)
63
+ raise RuntimeError, "Diff is not supported on this platform" if Puppet[:diff] == ""
64
+ if checksum_a
65
+ source_path = "#{@rest_path}#{@checksum_type}/#{checksum_a}"
66
+ if checksum_b
67
+ file_diff = Puppet::FileBucket::File.indirection.find(
68
+ source_path,
69
+ :bucket_path => @local_path,
70
+ :diff_with => checksum_b)
71
+ elsif file_b
72
+ tmp_file = ::Tempfile.new('diff')
73
+ begin
74
+ restore(tmp_file.path, checksum_a)
75
+ file_diff = Puppet::Util::Diff.diff(tmp_file.path, file_b)
76
+ ensure
77
+ tmp_file.close
78
+ tmp_file.unlink
79
+ end
80
+ else
81
+ raise Puppet::Error, "Please provide a file or checksum do diff with"
82
+ end
83
+ elsif file_a
84
+ if checksum_b
85
+ tmp_file = ::Tempfile.new('diff')
86
+ begin
87
+ restore(tmp_file.path, checksum_b)
88
+ file_diff = Puppet::Util::Diff.diff(file_a, tmp_file.path)
89
+ ensure
90
+ tmp_file.close
91
+ tmp_file.unlink
92
+ end
93
+ elsif file_b
94
+ file_diff = Puppet::Util::Diff.diff(file_a, file_b)
95
+ end
96
+ end
97
+ raise Puppet::Error, "Failed to diff files" unless file_diff
98
+ file_diff.to_s
99
+ end
100
+
59
101
  # Retrieves a file by sum.
60
102
  def getfile(sum)
61
103
  get_bucket_file(sum).to_s
@@ -109,10 +151,24 @@ class Puppet::FileBucket::Dipper
109
151
  end
110
152
  end
111
153
 
154
+ # List Filebucket content.
155
+ def list(fromdate, todate)
156
+ raise Puppet::Error, "Listing remote file buckets is not allowed" unless local?
157
+
158
+ source_path = "#{@rest_path}#{@checksum_type}/"
159
+ file_bucket_list = Puppet::FileBucket::File.indirection.find(
160
+ source_path,
161
+ :bucket_path => @local_path,
162
+ :list_all => true,
163
+ :fromdate => fromdate,
164
+ :todate => todate)
165
+ raise Puppet::Error, "File not found" unless file_bucket_list
166
+ file_bucket_list.to_s
167
+ end
168
+
112
169
  private
113
170
  def absolutize_path( path )
114
171
  Pathname.new(path).realpath
115
172
  end
116
173
 
117
174
  end
118
-
@@ -62,7 +62,9 @@ class Puppet::FileSystem::Windows < Puppet::FileSystem::Posix
62
62
  stat = Puppet::Util::Windows::File.stat(file_name) rescue nil
63
63
 
64
64
  # sigh, Ruby + Windows :(
65
- if stat && stat.ftype == 'directory'
65
+ if !stat
66
+ ::File.unlink(file_name) rescue Dir.rmdir(file_name)
67
+ elsif stat.ftype == 'directory'
66
68
  if Puppet::Util::Windows::File.symlink?(file_name)
67
69
  Dir.rmdir(file_name)
68
70
  else
@@ -1,18 +1,54 @@
1
- # Returns the given value if it is an instance of the given type, and raises an error otherwise.
2
- # Optionally, if a block is given (accepting two parameters), it will be called instead of raising
3
- # an error. This to enable giving the user richer feedback, or to supply a default value.
1
+ # Returns the given value if it is of the given
2
+ # [data type](https://docs.puppetlabs.com/puppet/latest/reference/lang_data.html), or
3
+ # otherwise either raises an error or executes an optional two-parameter
4
+ # [lambda](https://docs.puppetlabs.com/puppet/latest/reference/lang_lambdas.html).
4
5
  #
5
- # @example how to assert type
6
- # # assert that `$b` is a non empty `String` and assign to `$a`
7
- # $a = assert_type(String[1], $b)
6
+ # The function takes two mandatory arguments, in this order:
8
7
  #
9
- # @example using custom error message
10
- # $a = assert_type(String[1], $b) |$expected, $actual| { fail("The name cannot be empty") }
8
+ # 1. The expected data type.
9
+ # 2. A value to compare against the expected data type.
11
10
  #
12
- # @example using a warning and a default
13
- # $a = assert_type(String[1], $b) |$expected, $actual| { warning("Name is empty, using default") 'anonymous' }
11
+ # @example Using `assert_type`
14
12
  #
15
- # See the documentation for "The Puppet Type System" for more information about types.
13
+ # ~~~ puppet
14
+ # $raw_username = 'Amy Berry'
15
+ #
16
+ # # Assert that $raw_username is a non-empty string and assign it to $valid_username.
17
+ # $valid_username = assert_type(String[1], $raw_username)
18
+ #
19
+ # # $valid_username contains "Amy Berry".
20
+ # # If $raw_username was an empty string or a different data type, the Puppet run would
21
+ # # fail with an "Expected type does not match actual" error.
22
+ # ~~~
23
+ #
24
+ # You can use an optional lambda to provide enhanced feedback. The lambda takes two
25
+ # mandatory parameters, in this order:
26
+ #
27
+ # 1. The expected data type as described in the function's first argument.
28
+ # 2. The actual data type of the value.
29
+ #
30
+ # @example Using `assert_type` with a warning and default value
31
+ #
32
+ # ~~~ puppet
33
+ # $raw_username = 'Amy Berry'
34
+ #
35
+ # # Assert that $raw_username is a non-empty string and assign it to $valid_username.
36
+ # # If it isn't, output a warning describing the problem and use a default value.
37
+ # $valid_username = assert_type(String[1], $raw_username) |$expected, $actual| {
38
+ # warning( "The username should be \'${expected}\', not \'${actual}\'. Using 'anonymous'." )
39
+ # 'anonymous'
40
+ # }
41
+ #
42
+ # # $valid_username contains "Amy Berry".
43
+ # # If $raw_username was an empty string, the Puppet run would set $valid_username to
44
+ # # "anonymous" and output a warning: "The username should be 'String[1, default]', not
45
+ # # 'String[0, 0]'. Using 'anonymous'."
46
+ # ~~~
47
+ #
48
+ # For more information about data types, see the
49
+ # [documentation](https://docs.puppetlabs.com/puppet/latest/reference/lang_data.html).
50
+ #
51
+ # @since 4.0.0
16
52
  #
17
53
  Puppet::Functions.create_function(:assert_type) do
18
54
  dispatch :assert_type do
@@ -42,7 +78,7 @@ Puppet::Functions.create_function(:assert_type) do
42
78
  # Do not give all the details - i.e. format as Integer, instead of Integer[n, n] for exact value, which
43
79
  # is just confusing. (OTOH: may need to revisit, or provide a better "type diff" output.
44
80
  #
45
- actual = Puppet::Pops::Types::TypeCalculator.generalize!(inferred_type)
81
+ actual = Puppet::Pops::Types::TypeCalculator.generalize(inferred_type)
46
82
  raise Puppet::Pops::Types::TypeAssertionError.new("assert_type(): Expected type #{type} does not match actual: #{actual}", type,actual)
47
83
  end
48
84
  end
@@ -1,70 +1,101 @@
1
- # Determines whether
2
- # a given class or resource type is defined. This function can also determine whether a
3
- # specific resource has been declared, or whether a variable has been assigned a value
4
- # (including undef...as opposed to never having been assigned anything). Returns true
5
- # or false. Accepts class names, type names, resource references, and variable
6
- # reference strings of the form '$name'. When more than one argument is
7
- # supplied, defined() returns true if any are defined.
1
+ # Determines whether a given class or resource type is defined and returns a Boolean
2
+ # value. You can also use `defined` to determine whether a specific resource is defined,
3
+ # or whether a variable has a value (including `undef`, as opposed to the variable never
4
+ # being declared or assigned).
5
+ #
6
+ # This function takes at least one string argument, which can be a class name, type name,
7
+ # resource reference, or variable reference of the form `'$name'`.
8
8
  #
9
9
  # The `defined` function checks both native and defined types, including types
10
- # provided as plugins via modules. Types and classes are both checked using their names:
10
+ # provided by modules. Types and classes are matched by their names. The function matches
11
+ # resource declarations by using resource references.
12
+ #
13
+ # **Examples**: Different types of `defined` function matches
14
+ #
15
+ # ~~~ puppet
16
+ # # Matching resource types
17
+ # defined("file")
18
+ # defined("customtype")
19
+ #
20
+ # # Matching defines and classes
21
+ # defined("foo")
22
+ # defined("foo::bar")
23
+ #
24
+ # # Matching variables
25
+ # defined('$name')
26
+ #
27
+ # # Matching declared resources
28
+ # defined(File['/tmp/file'])
29
+ # ~~~
30
+ #
31
+ # Puppet depends on the configuration's evaluation order when checking whether a resource
32
+ # is declared.
11
33
  #
12
- # defined("file")
13
- # defined("customtype")
14
- # defined("foo")
15
- # defined("foo::bar")
16
- # defined('$name')
34
+ # @example Importance of evaluation order when using `defined`
17
35
  #
18
- # Resource declarations are checked using resource references, e.g.
19
- # `defined( File['/tmp/myfile'] )`, or `defined( Class[myclass] )`.
20
- # Checking whether a given resource
21
- # has been declared is, unfortunately, dependent on the evaluation order of
22
- # the configuration, and the following code will not work:
36
+ # ~~~ puppet
37
+ # # Assign values to $is_defined_before and $is_defined_after using identical `defined`
38
+ # # functions.
23
39
  #
24
- # if defined(File['/tmp/foo']) {
25
- # notify { "This configuration includes the /tmp/foo file.":}
26
- # }
27
- # file { "/tmp/foo":
28
- # ensure => present,
29
- # }
40
+ # $is_defined_before = defined(File['/tmp/file'])
30
41
  #
31
- # However, this order requirement refers to evaluation order only, and ordering of
32
- # resources in the configuration graph (e.g. with `before` or `require`) does not
33
- # affect the behavior of `defined`.
42
+ # file { "/tmp/file":
43
+ # ensure => present,
44
+ # }
34
45
  #
35
- # You may also search using types:
46
+ # $is_defined_after = defined(File['/tmp/file'])
36
47
  #
37
- # defined(Resource['file','/some/file'])
38
- # defined(File['/some/file'])
39
- # defined(Class['foo'])
48
+ # # $is_defined_before returns false, but $is_defined_after returns true.
49
+ # ~~~
40
50
  #
41
- # The `defined` function does not answer if data types (e.g. `Integer`) are defined. If
42
- # given the string 'integer' the result is false, and if given a non CatalogEntry type,
43
- # an error is raised.
51
+ # This order requirement only refers to evaluation order. The order of resources in the
52
+ # configuration graph (e.g. with `before` or `require`) does not affect the `defined`
53
+ # function's behavior.
44
54
  #
45
- # The rules for asking for undef, empty strings, and the main class are different from 3.x
46
- # (non future parser) and 4.x (with future parser or in Puppet 4.0.0 and later):
55
+ # > **Warning:** Avoid relying on the result of the `defined` function in modules, as you
56
+ # > might not be able to guarantee the evaluation order well enough to produce consistent
57
+ # > results. This can cause other code that relies on the function's result to behave
58
+ # > inconsistently or fail.
47
59
  #
48
- # defined('') # 3.x => true, 4.x => false
49
- # defined(undef) # 3.x => true, 4.x => error
50
- # defined('main') # 3.x => false, 4.x => true
60
+ # If you pass more than one argument to `defined`, the function returns `true` if _any_
61
+ # of the arguments are defined. You can also match resources by type, allowing you to
62
+ # match conditions of different levels of specificity, such as whether a specific resource
63
+ # is of a specific data type.
51
64
  #
52
- # With the future parser, it is also possible to ask specifically if a name is
53
- # a resource type (built in or defined), or a class, by giving its type:
65
+ # @example Matching multiple resources and resources by different types with `defined`
54
66
  #
55
- # defined(Type[Class['foo']])
56
- # defined(Type[Resource['foo']])
67
+ # ~~~ puppet
68
+ # file { "/tmp/file1":
69
+ # ensure => file,
70
+ # }
57
71
  #
58
- # Which is different from asking:
72
+ # $tmp_file = file { "/tmp/file2":
73
+ # ensure => file,
74
+ # }
59
75
  #
60
- # defined('foo')
76
+ # # Each of these statements return `true` ...
77
+ # defined(File['/tmp/file1'])
78
+ # defined(File['/tmp/file1'],File['/tmp/file2'])
79
+ # defined(File['/tmp/file1'],File['/tmp/file2'],File['/tmp/file3'])
80
+ # # ... but this returns `false`.
81
+ # defined(File['/tmp/file3'])
61
82
  #
62
- # Since the later returns true if 'foo' is either a class, a built-in resource type, or a user defined
63
- # resource type, and a specific request like `Type[Class['foo']]` only returns true if `'foo'` is a class.
83
+ # # Each of these statements returns `true` ...
84
+ # defined(Type[Resource['file','/tmp/file2']])
85
+ # defined(Resource['file','/tmp/file2'])
86
+ # defined(File['/tmp/file2'])
87
+ # defined('$tmp_file')
88
+ # # ... but each of these returns `false`.
89
+ # defined(Type[Resource['exec','/tmp/file2']])
90
+ # defined(Resource['exec','/tmp/file2'])
91
+ # defined(File['/tmp/file3'])
92
+ # defined('$tmp_file2')
93
+ # ~~~
64
94
  #
65
95
  # @since 2.7.0
66
- # @since 3.6.0 variable reference and future parser types")
96
+ # @since 3.6.0 variable reference and future parser types
67
97
  # @since 3.8.1 type specific requests with future parser
98
+ # @since 4.0.0
68
99
  #
69
100
  Puppet::Functions.create_function(:'defined', Puppet::Functions::InternalFunction) do
70
101