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
@@ -0,0 +1,201 @@
1
+ #! /usr/bin/env ruby
2
+ require 'spec_helper'
3
+ require 'puppet_spec/compiler'
4
+
5
+ describe "when using a hiera data provider" do
6
+ include PuppetSpec::Compiler
7
+
8
+ # There is a fully configured 'sample' environment in fixtures at this location
9
+ let(:environmentpath) { parent_fixture('environments') }
10
+
11
+ let(:facts) { Puppet::Node::Facts.new("facts", {}) }
12
+
13
+ around(:each) do |example|
14
+ # Initialize settings to get a full compile as close as possible to a real
15
+ # environment load
16
+ Puppet.settings.initialize_global_settings
17
+ # Initialize loaders based on the environmentpath. It does not work to
18
+ # just set the setting environmentpath for some reason - this achieves the same:
19
+ # - first a loader is created, loading directory environments from the fixture (there is
20
+ # one environment, 'sample', which will be loaded since the node references this
21
+ # environment by name).
22
+ # - secondly, the created env loader is set as 'environments' in the puppet context.
23
+ #
24
+ loader = Puppet::Environments::Directories.new(environmentpath, [])
25
+ Puppet.override(:environments => loader) do
26
+ example.run
27
+ end
28
+ end
29
+
30
+ def compile_and_get_notifications(environment, code = nil)
31
+ compile(environment, code).resources.map(&:ref).select { |r| r.start_with?('Notify[') }.map { |r| r[7..-2] }
32
+ end
33
+
34
+ def compile(environment, code = nil)
35
+ Puppet[:code] = code if code
36
+ node = Puppet::Node.new("testnode", :facts => facts, :environment => environment)
37
+ compiler = Puppet::Parser::Compiler.new(node)
38
+ block_given? ? compiler.compile() { |catalog| yield(compiler); catalog } : compiler.compile()
39
+ end
40
+
41
+ it 'uses default configuration for environment and module data' do
42
+ resources = compile_and_get_notifications('hiera_defaults')
43
+ expect(resources).to include('module data param_a is 100, param default is 200, env data param_c is 300')
44
+ end
45
+
46
+ it 'reads hiera.yaml in environment root and configures multiple json and yaml providers' do
47
+ resources = compile_and_get_notifications('hiera_env_config')
48
+ expect(resources).to include('env data param_a is 10, env data param_b is 20, env data param_c is 30, env data param_d is 40, env data param_e is 50')
49
+ end
50
+
51
+ it 'reads hiera.yaml in module root and configures multiple json and yaml providers' do
52
+ resources = compile_and_get_notifications('hiera_module_config')
53
+ expect(resources).to include('module data param_a is 100, module data param_b is 200, module data param_c is 300, module data param_d is 400, module data param_e is 500')
54
+ end
55
+
56
+ it 'does not perform merge of values declared in environment and module when resolving parameters' do
57
+ resources = compile_and_get_notifications('hiera_misc')
58
+ expect(resources).to include('env 1, ')
59
+ end
60
+
61
+ it 'performs hash merge of values declared in environment and module' do
62
+ resources = compile_and_get_notifications('hiera_misc', '$r = lookup(one::test::param, Hash[String,String], hash) notify{"${r[key1]}, ${r[key2]}":}')
63
+ expect(resources).to include('env 1, module 2')
64
+ end
65
+
66
+ it 'performs unique merge of values declared in environment and module' do
67
+ resources = compile_and_get_notifications('hiera_misc', '$r = lookup(one::array, Array[String], unique) notify{"${r}":}')
68
+ expect(resources.size).to eq(1)
69
+ expect(resources[0][1..-2].split(', ')).to contain_exactly('first', 'second', 'third', 'fourth')
70
+ end
71
+
72
+ it 'performs merge found in lookup_options in environment of values declared in environment and module' do
73
+ resources = compile_and_get_notifications('hiera_misc', 'include one::lopts_test')
74
+ expect(resources.size).to eq(1)
75
+ expect(resources[0]).to eq('A, B, C, MA, MB, MC')
76
+ end
77
+
78
+ it 'performs merge found in lookup_options in module of values declared in environment and module' do
79
+ resources = compile_and_get_notifications('hiera_misc', 'include one::loptsm_test')
80
+ expect(resources.size).to eq(1)
81
+ expect(resources[0]).to eq('A, B, C, MA, MB, MC')
82
+ end
83
+
84
+ it "can lookup the 'lookup_options' hash as a regular value" do
85
+ resources = compile_and_get_notifications('hiera_misc', '$r = lookup(lookup_options, Hash[String,Hash[String,String]], hash) notify{"${r[one::lopts_test::hash][merge]}":}')
86
+ expect(resources.size).to eq(1)
87
+ expect(resources[0]).to eq('deep')
88
+ end
89
+
90
+ it 'does find unqualified keys in the environment' do
91
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(ukey1):}')
92
+ expect(resources).to include('Some value')
93
+ end
94
+
95
+ it 'does not find unqualified keys in the module' do
96
+ expect do
97
+ compile_and_get_notifications('hiera_misc', 'notify{lookup(ukey2):}')
98
+ end.to raise_error(Puppet::ParseError, /did not find a value for the name 'ukey2'/)
99
+ end
100
+
101
+ it 'can use interpolation lookup method "alias"' do
102
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(km_alias):}')
103
+ expect(resources).to include('Value from interpolation with alias')
104
+ end
105
+
106
+ it 'can use interpolation lookup method "lookup"' do
107
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(km_lookup):}')
108
+ expect(resources).to include('Value from interpolation with lookup')
109
+ end
110
+
111
+ it 'can use interpolation lookup method "hiera"' do
112
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(km_hiera):}')
113
+ expect(resources).to include('Value from interpolation with hiera')
114
+ end
115
+
116
+ it 'can use interpolation lookup method "literal"' do
117
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(km_literal):}')
118
+ expect(resources).to include('Value from interpolation with literal')
119
+ end
120
+
121
+ it 'can use interpolation lookup method "scope"' do
122
+ resources = compile_and_get_notifications('hiera_misc', '$target_scope = "with scope" notify{lookup(km_scope):}')
123
+ expect(resources).to include('Value from interpolation with scope')
124
+ end
125
+
126
+ it 'can use interpolation using default lookup method (scope)' do
127
+ resources = compile_and_get_notifications('hiera_misc', '$target_default = "with default" notify{lookup(km_default):}')
128
+ expect(resources).to include('Value from interpolation with default')
129
+ end
130
+
131
+ it 'performs lookup using qualified expressions in interpolation' do
132
+ resources = compile_and_get_notifications('hiera_misc', "$os = { name => 'Fedora' } notify{lookup(km_qualified):}")
133
+ expect(resources).to include('Value from qualified interpolation OS = Fedora')
134
+ end
135
+
136
+ it 'can have multiple interpolate expressions in one value' do
137
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(km_multi):}')
138
+ expect(resources).to include('cluster/%{::cluster}/%{role}')
139
+ end
140
+
141
+ it 'performs single quoted interpolation' do
142
+ resources = compile_and_get_notifications('hiera_misc', 'notify{lookup(km_sqalias):}')
143
+ expect(resources).to include('Value from interpolation with alias')
144
+ end
145
+
146
+ it 'traps endless interpolate recursion' do
147
+ expect do
148
+ compile_and_get_notifications('hiera_misc', '$r1 = "%{r2}" $r2 = "%{r1}" notify{lookup(recursive):}')
149
+ end.to raise_error(Puppet::DataBinding::RecursiveLookupError, /detected in \[recursive, r1, r2\]/)
150
+ end
151
+
152
+ it 'traps bad alias declarations' do
153
+ expect do
154
+ compile_and_get_notifications('hiera_misc', "$r1 = 'Alias within string %{alias(\"r2\")}' $r2 = '%{r1}' notify{lookup(recursive):}")
155
+ end.to raise_error(Puppet::DataBinding::LookupError, /'alias' interpolation is only permitted if the expression is equal to the entire string/)
156
+ end
157
+
158
+ it 'reports syntax errors for JSON files' do
159
+ expect do
160
+ compile_and_get_notifications('hiera_bad_syntax_json')
161
+ end.to raise_error(Puppet::DataBinding::LookupError, /Unable to parse \(#{environmentpath}[^)]+\):/)
162
+ end
163
+
164
+ it 'reports syntax errors for YAML files' do
165
+ expect do
166
+ compile_and_get_notifications('hiera_bad_syntax_yaml')
167
+ end.to raise_error(Puppet::DataBinding::LookupError, /Unable to parse \(#{environmentpath}[^)]+\):/)
168
+ end
169
+
170
+ describe 'when using explain' do
171
+ it 'will report config path (original and resolved), data path (original and resolved), and interpolation (before and after)' do
172
+ compile('hiera_misc', '$target_scope = "with scope"') do |compiler|
173
+ lookup_invocation = Puppet::Pops::Lookup::Invocation.new(compiler.topscope, {}, {}, true)
174
+ value = Puppet::Pops::Lookup.lookup('km_scope', nil, nil, nil, nil, lookup_invocation)
175
+ expect(lookup_invocation.explainer.to_s).to eq(<<EOS)
176
+ Merge strategy first
177
+ Data Binding "hiera"
178
+ No such key: "km_scope"
179
+ Data Provider "Hiera Data Provider, version 4"
180
+ ConfigurationPath "#{environmentpath}/hiera_misc/hiera.yaml"
181
+ Data Provider "common"
182
+ Path "#{environmentpath}/hiera_misc/data/common.yaml"
183
+ Original path: common
184
+ Interpolation on "Value from interpolation %{scope("target_scope")}"
185
+ Global Scope"
186
+ Found key: "target_scope" value: "with scope"
187
+ Found key: "km_scope" value: "Value from interpolation with scope"
188
+ Merged result: "Value from interpolation with scope"
189
+ EOS
190
+ end
191
+ end
192
+ end
193
+ def parent_fixture(dir_name)
194
+ File.absolute_path(File.join(my_fixture_dir(), "../#{dir_name}"))
195
+ end
196
+
197
+ def resources_in(catalog)
198
+ catalog.resources.map(&:ref)
199
+ end
200
+
201
+ end
@@ -642,6 +642,8 @@ config_version=$vardir/random/scripts
642
642
  end
643
643
 
644
644
  def expired?(env_name)
645
+ # make expired? idempotent
646
+ return true if @expired_envs.include? (env_name)
645
647
  @expired_envs << env_name
646
648
  @expiration_sequence.pop
647
649
  end
@@ -47,7 +47,7 @@ describe Puppet::Face[:node, '0.0.1'] do
47
47
  end
48
48
 
49
49
  it "should not accept a call with no arguments" do
50
- expect { subject.clean() }.to raise_error
50
+ expect { subject.clean() }.to raise_error(RuntimeError, /At least one node should be passed/)
51
51
  end
52
52
 
53
53
  it "should accept a node name" do
@@ -72,6 +72,216 @@ describe Puppet::FileBucket::Dipper, :uses_checksums => true do
72
72
  expect { @dipper.backup(file) }.to raise_error(Puppet::Error)
73
73
  end
74
74
 
75
+ describe "when diffing on a local filebucket" do
76
+ describe "in non-windows environments", :unless => Puppet.features.microsoft_windows? do
77
+ with_digest_algorithms do
78
+
79
+ it "should fail in an informative way when one or more checksum doesn't exists" do
80
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => tmpdir("bucket"))
81
+ wrong_checksum = "DEADBEEF"
82
+
83
+ # First checksum fails
84
+ expect { @dipper.diff(wrong_checksum, "WEIRDCKSM", nil, nil) }.to raise_error(RuntimeError, "Invalid checksum #{wrong_checksum.inspect}")
85
+
86
+ file = make_tmp_file(plaintext)
87
+ @dipper.backup(file)
88
+
89
+ #Diff_with checksum fails
90
+ expect { @dipper.diff(checksum, wrong_checksum, nil, nil) }.to raise_error(RuntimeError, "could not find diff_with #{wrong_checksum}")
91
+ end
92
+
93
+ it "should properly diff files on the filebucket" do
94
+ file1 = make_tmp_file("OriginalContent")
95
+ file2 = make_tmp_file("ModifiedContent")
96
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => tmpdir("bucket"))
97
+ checksum1 = @dipper.backup(file1)
98
+ checksum2 = @dipper.backup(file2)
99
+
100
+ # Diff without the context
101
+ diff12 = `diff -uN #{file1} #{file2} | sed '1,2d'`
102
+ diff21 = `diff -uN #{file2} #{file1} | sed '1,2d'`
103
+
104
+ expect(@dipper.diff(checksum1, checksum2, nil, nil)).to include(diff12)
105
+ expect(@dipper.diff(checksum1, nil, nil, file2)).to include(diff12)
106
+ expect(@dipper.diff(nil, checksum2, file1, nil)).to include(diff12)
107
+ expect(@dipper.diff(nil, nil, file1, file2)).to include(diff12)
108
+ expect(@dipper.diff(checksum2, checksum1, nil, nil)).to include(diff21)
109
+ expect(@dipper.diff(checksum2, nil, nil, file1)).to include(diff21)
110
+ expect(@dipper.diff(nil, checksum1, file2, nil)).to include(diff21)
111
+ expect(@dipper.diff(nil, nil, file2, file1)).to include(diff21)
112
+
113
+ end
114
+ end
115
+ describe "in windows environment", :if => Puppet.features.microsoft_windows? do
116
+ it "should fail in an informative way when trying to diff" do
117
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => tmpdir("bucket"))
118
+ wrong_checksum = "DEADBEEF"
119
+
120
+ # First checksum fails
121
+ expect { @dipper.diff(wrong_checksum, "WEIRDCKSM", nil, nil) }.to raise_error(RuntimeError, "Diff is not supported on this platform")
122
+
123
+ # Diff_with checksum fails
124
+ expect { @dipper.diff(checksum, wrong_checksum, nil, nil) }.to raise_error(RuntimeError, "Diff is not supported on this platform")
125
+ end
126
+ end
127
+ end
128
+ end
129
+ it "should fail in an informative way when there are failures listing files on the server" do
130
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => "/unexistent/bucket")
131
+ Puppet::FileBucket::File.indirection.expects(:find).returns nil
132
+
133
+ expect { @dipper.list(nil, nil) }.to raise_error(Puppet::Error)
134
+ end
135
+
136
+ describe "listing files in local filebucket" do
137
+ with_digest_algorithms do
138
+ it "should list all files present" do
139
+ Puppet[:bucketdir] = "/my/bucket"
140
+ file_bucket = tmpdir("bucket")
141
+
142
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => file_bucket)
143
+
144
+ onehour=60*60
145
+ twohours=onehour*2
146
+
147
+ #First File
148
+ file1 = make_tmp_file(plaintext)
149
+ real_path = Pathname.new(file1).realpath
150
+ expect(digest(plaintext)).to eq(checksum)
151
+ expect(@dipper.backup(file1)).to eq(checksum)
152
+ expected_list1_1 = /#{checksum} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} #{real_path}\n/
153
+
154
+ File.open(file1, 'w') {|f| f.write("Blahhhh")}
155
+ new_checksum = digest("Blahhhh")
156
+ expect(@dipper.backup(file1)).to eq(new_checksum)
157
+ expected_list1_2 = /#{new_checksum} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} #{real_path}\n/
158
+
159
+ #Second File
160
+ content = "DummyFileWithNonSenseTextInIt"
161
+ file2 = make_tmp_file(content)
162
+ real_path = Pathname.new(file2).realpath
163
+ checksum = digest(content)
164
+ expect(@dipper.backup(file2)).to eq(checksum)
165
+ expected_list2 = /#{checksum} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} #{real_path}\n/
166
+
167
+ #Third file : Same as the first one with a different path
168
+ file3 = make_tmp_file(plaintext)
169
+ real_path = Pathname.new(file3).realpath
170
+ checksum = digest(plaintext)
171
+ expect(digest(plaintext)).to eq(checksum)
172
+ expect(@dipper.backup(file3)).to eq(checksum)
173
+ date = Time.now
174
+ expected_list3 = /#{checksum} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} #{real_path}\n/
175
+
176
+ result = @dipper.list(nil, nil)
177
+ expect(result).to match(expected_list1_1)
178
+ expect(result).to match(expected_list1_2)
179
+ expect(result).to match(expected_list2)
180
+ expect(result).to match(expected_list3)
181
+ end
182
+
183
+ it "should filter with the provided dates" do
184
+ Puppet[:bucketdir] = "/my/bucket"
185
+ file_bucket = tmpdir("bucket")
186
+
187
+ twentyminutes=60*20
188
+ thirtyminutes=60*30
189
+ onehour=60*60
190
+ twohours=onehour*2
191
+ threehours=onehour*3
192
+
193
+ # First File created now
194
+ @dipper = Puppet::FileBucket::Dipper.new(:Path => file_bucket)
195
+ file1 = make_tmp_file(plaintext)
196
+ real_path = Pathname.new(file1).realpath
197
+
198
+ expect(digest(plaintext)).to eq(checksum)
199
+ expect(@dipper.backup(file1)).to eq(checksum)
200
+ expected_list1 = /#{checksum} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} #{real_path}\n/
201
+
202
+ # Second File created an hour ago
203
+ content = "DummyFileWithNonSenseTextInIt"
204
+ file2 = make_tmp_file(content)
205
+ real_path = Pathname.new(file2).realpath
206
+ checksum = digest(content)
207
+ expect(@dipper.backup(file2)).to eq(checksum)
208
+
209
+ # Modify mtime of the second file to be an hour ago
210
+ onehourago = Time.now - onehour
211
+ bucketed_paths_file = Dir.glob("#{file_bucket}/**/#{checksum}/paths")
212
+ FileUtils.touch(bucketed_paths_file, :mtime => onehourago)
213
+ expected_list2 = /#{checksum} \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} #{real_path}\n/
214
+
215
+ now = Time.now
216
+
217
+ #Future
218
+ expect(@dipper.list((now + threehours).strftime("%F %T"), nil )).to eq("")
219
+
220
+ #Epoch -> Future = Everything (Sorted (desc) by date)
221
+ expect(@dipper.list(nil, (now + twohours).strftime("%F %T"))).to match(expected_list1)
222
+ expect(@dipper.list(nil, (now + twohours).strftime("%F %T"))).to match(expected_list2)
223
+
224
+ #Now+1sec -> Future = Nothing
225
+ expect(@dipper.list((now + 1).strftime("%F %T"), (now + twohours).strftime("%F %T"))).to eq("")
226
+
227
+ #Now-30mins -> Now-20mins = Nothing
228
+ expect(@dipper.list((now - thirtyminutes).strftime("%F %T"), (now - twentyminutes).strftime("%F %T"))).to eq("")
229
+
230
+ #Now-2hours -> Now-30mins = Second file only
231
+ expect(@dipper.list((now - twohours).strftime("%F %T"), (now - thirtyminutes).strftime("%F %T"))).to match(expected_list2)
232
+ expect(@dipper.list((now - twohours).strftime("%F %T"), (now - thirtyminutes).strftime("%F %T"))).not_to match(expected_list1)
233
+
234
+ #Now-30minutes -> Now = First file only
235
+ expect(@dipper.list((now - thirtyminutes).strftime("%F %T"), now.strftime("%F %T"))).to match(expected_list1)
236
+ expect(@dipper.list((now - thirtyminutes).strftime("%F %T"), now.strftime("%F %T"))).not_to match(expected_list2)
237
+ end
238
+ end
239
+ end
240
+
241
+ describe "when diffing on a remote filebucket" do
242
+ describe "in non-windows environments", :unless => Puppet.features.microsoft_windows? do
243
+ with_digest_algorithms do
244
+ it "should fail in an informative way when one or more checksum doesn't exists" do
245
+ @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port => "31337")
246
+ wrong_checksum = "DEADBEEF"
247
+
248
+ Puppet::FileBucketFile::Rest.any_instance.expects(:find).returns(nil)
249
+ expect { @dipper.diff(wrong_checksum, "WEIRDCKSM", nil, nil) }.to raise_error(Puppet::Error, "Failed to diff files")
250
+
251
+ end
252
+
253
+ it "should properly diff files on the filebucket" do
254
+ @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port => "31337")
255
+
256
+ Puppet::FileBucketFile::Rest.any_instance.expects(:find).returns("Probably valid diff")
257
+
258
+ expect(@dipper.diff("checksum1", "checksum2", nil, nil)).to eq("Probably valid diff")
259
+ end
260
+ end
261
+ end
262
+
263
+ describe "in windows environment", :if => Puppet.features.microsoft_windows? do
264
+ it "should fail in an informative way when trying to diff" do
265
+ @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port => "31337")
266
+ wrong_checksum = "DEADBEEF"
267
+
268
+ expect { @dipper.diff(wrong_checksum, "WEIRDCKSM", nil, nil) }.to raise_error(RuntimeError, "Diff is not supported on this platform")
269
+
270
+ expect { @dipper.diff(wrong_checksum, nil, nil, nil) }.to raise_error(RuntimeError, "Diff is not supported on this platform")
271
+ end
272
+ end
273
+ end
274
+
275
+ describe "listing files in remote filebucket" do
276
+ it "is not allowed" do
277
+ @dipper = Puppet::FileBucket::Dipper.new(:Server => "puppetmaster", :Port=> "31337")
278
+
279
+ expect {
280
+ @dipper.list(nil, nil)
281
+ }.to raise_error(Puppet::Error, "Listing remote file buckets is not allowed")
282
+ end
283
+ end
284
+
75
285
  describe "backing up and retrieving local files" do
76
286
  with_digest_algorithms do
77
287
  it "should backup files to a local bucket" do
@@ -173,4 +383,3 @@ describe Puppet::FileBucket::Dipper, :uses_checksums => true do
173
383
  end
174
384
  end
175
385
  end
176
-
@@ -17,7 +17,7 @@ describe Puppet::FileServing::Configuration do
17
17
  end
18
18
 
19
19
  it "should make :new a private method" do
20
- expect { Puppet::FileServing::Configuration.new }.to raise_error
20
+ expect { Puppet::FileServing::Configuration.new }.to raise_error(NoMethodError, /private method `new' called/)
21
21
  end
22
22
 
23
23
  it "should return the same configuration each time 'configuration' is called" do
@@ -446,6 +446,26 @@ describe "Puppet::FileSystem" do
446
446
  expect(Puppet::FileSystem.readlink(symlink)).to eq(missing_file.to_s)
447
447
  end
448
448
 
449
+ it "should be able to unlink a dangling symlink pointed at a file" do
450
+ symlink = tmpfile("somefile_link")
451
+ Puppet::FileSystem.symlink(file, symlink)
452
+ ::File.delete(file)
453
+ Puppet::FileSystem.unlink(symlink)
454
+
455
+ expect(Puppet::FileSystem).to_not be_exist(file)
456
+ expect(Puppet::FileSystem).to_not be_exist(symlink)
457
+ end
458
+
459
+ it "should be able to unlink a dangling symlink pointed at a directory" do
460
+ symlink = tmpfile("somedir_link")
461
+ Puppet::FileSystem.symlink(dir, symlink)
462
+ Dir.rmdir(dir)
463
+ Puppet::FileSystem.unlink(symlink)
464
+
465
+ expect(Puppet::FileSystem).to_not be_exist(dir)
466
+ expect(Puppet::FileSystem).to_not be_exist(symlink)
467
+ end
468
+
449
469
  it "should delete only the symlink and not the target when calling unlink instance method" do
450
470
  [file, dir].each do |target|
451
471
  symlink = tmpfile("#{Puppet::FileSystem.basename(target)}_link")
@@ -25,13 +25,11 @@ describe 'the assert_type function' do
25
25
  it 'checks that first argument is a type' do
26
26
  expect do
27
27
  func.call({}, 10, 10)
28
- end.to raise_error(ArgumentError, Regexp.new(Regexp.escape(
29
- "function 'assert_type' called with mis-matched arguments
30
- expected one of:
31
- assert_type(Type type, Any value, Callable[Type, Type] block {0,1}) - arg count {2,3}
32
- assert_type(String type_string, Any value, Callable[Type, Type] block {0,1}) - arg count {2,3}
33
- actual:
34
- assert_type(Integer, Integer) - arg count {2}")))
28
+ end.to raise_error(ArgumentError, "'assert_type' expected one of:
29
+ (Type type, Any value, Callable[Type, Type] block?)
30
+ rejected: parameter 'type' expects a Type value, got Integer
31
+ (String type_string, Any value, Callable[Type, Type] block?)
32
+ rejected: parameter 'type_string' expects a String value, got Integer")
35
33
  end
36
34
 
37
35
  it 'allows the second arg to be undef/nil)' do
@@ -268,11 +268,11 @@ describe "the 'defined' function" do
268
268
  end
269
269
 
270
270
  it 'raises error if referencing undef' do
271
- expect{func.call(@scope, nil)}.to raise_error(ArgumentError, /mis-matched arguments/)
271
+ expect{func.call(@scope, nil)}.to raise_error(ArgumentError, /'defined' parameter 'vals' expects a value of type String, Type\[CatalogEntry\], or Type\[Type\[CatalogEntry\]\], got Undef/)
272
272
  end
273
273
 
274
274
  it 'raises error if referencing a number' do
275
- expect{func.call(@scope, 42)}.to raise_error(ArgumentError, /mis-matched arguments/)
275
+ expect{func.call(@scope, 42)}.to raise_error(ArgumentError, /'defined' parameter 'vals' expects a value of type String, Type\[CatalogEntry\], or Type\[Type\[CatalogEntry\]\], got Integer/)
276
276
  end
277
277
 
278
278
  it 'is false if referencing empty string' do
@@ -80,13 +80,13 @@ describe "the epp function" do
80
80
  it "raises an error when the passed value does not match the parameter's type" do
81
81
  expect do
82
82
  eval_template_with_args("<%-|Integer $x|-%><%= $x %>", 'x' => 'incorrect')
83
- end.to raise_error(/expected.*Integer.*actual.*String/m)
83
+ end.to raise_error(/block parameter 'x' expects an Integer value, got String/)
84
84
  end
85
85
 
86
86
  it "raises an error when the default value does not match the parameter's type" do
87
87
  expect do
88
88
  eval_template("<%-|Integer $x = 'nope'|-%><%= $x %>")
89
- end.to raise_error(/expected.*Integer.*actual.*String/m)
89
+ end.to raise_error(/block parameter 'x' expects an Integer value, got String/)
90
90
  end
91
91
 
92
92
  it "allows an parameter to default to undef" do
@@ -122,6 +122,24 @@ describe 'the filter method' do
122
122
  expect(catalog).to have_resource("File[/file_blueb]").with_parameter(:ensure, 'present')
123
123
  end
124
124
 
125
+ it 'filters on an array will not include elements for which the block returns truthy but not true' do
126
+ catalog = compile_to_catalog(<<-MANIFEST)
127
+ $r = [1, 2, 3].filter |$v| { $v } == []
128
+ notify { "eval_${$r}": }
129
+ MANIFEST
130
+
131
+ expect(catalog).to have_resource('Notify[eval_true]')
132
+ end
133
+
134
+ it 'filters on a hash will not include elements for which the block returns truthy but not true' do
135
+ catalog = compile_to_catalog(<<-MANIFEST)
136
+ $r = {a => 1, b => 2, c => 3}.filter |$k, $v| { $v } == {}
137
+ notify { "eval_${$r}": }
138
+ MANIFEST
139
+
140
+ expect(catalog).to have_resource('Notify[eval_true]')
141
+ end
142
+
125
143
  it_should_behave_like 'all iterative functions argument checks', 'filter'
126
144
  it_should_behave_like 'all iterative functions hash handling', 'filter'
127
145
  end
@@ -108,7 +108,7 @@ describe 'when calling' do
108
108
 
109
109
  it 'should use the array resolution_type' do
110
110
  Hiera.any_instance.expects(:lookup).with { |*args| expect(args[4]).to be(:array) }.returns(%w[foo bar baz])
111
- hiera_include.expects(:call_function).with('include', %w[foo bar baz])
111
+ hiera_include.expects(:call_function_with_scope).with(scope, 'include', %w[foo bar baz])
112
112
  hiera_include.call(scope, 'key', {'key' => 'foo_result'})
113
113
  end
114
114
 
@@ -118,7 +118,7 @@ describe 'when calling' do
118
118
  end
119
119
 
120
120
  it 'should use default block' do
121
- hiera_include.expects(:call_function).with('include', %w[key foo])
121
+ hiera_include.expects(:call_function_with_scope).with(scope,'include', %w[key foo])
122
122
  hiera_include.call(scope, 'foo') { |k| ['key', k] }
123
123
  end
124
124
  end