puppet 4.5.3-universal-darwin → 4.6.1-universal-darwin

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (422) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +10 -1
  3. data/ext/debian/control +2 -4
  4. data/ext/project_data.yaml +4 -4
  5. data/install.rb +6 -2
  6. data/lib/puppet.rb +3 -1
  7. data/lib/puppet/agent/locker.rb +1 -1
  8. data/lib/puppet/application.rb +6 -4
  9. data/lib/puppet/application/agent.rb +2 -1
  10. data/lib/puppet/application/cert.rb +35 -2
  11. data/lib/puppet/application/device.rb +1 -1
  12. data/lib/puppet/application/generate.rb +5 -0
  13. data/lib/puppet/application/lookup.rb +3 -3
  14. data/lib/puppet/application_support.rb +1 -1
  15. data/lib/puppet/compilable_resource_type.rb +15 -0
  16. data/lib/puppet/configurer.rb +67 -10
  17. data/lib/puppet/configurer/plugin_handler.rb +2 -4
  18. data/lib/puppet/data_providers/hiera_config.rb +1 -1
  19. data/lib/puppet/defaults.rb +34 -7
  20. data/lib/puppet/environments.rb +4 -2
  21. data/lib/puppet/error.rb +1 -1
  22. data/lib/puppet/external/dot.rb +1 -1
  23. data/lib/puppet/face/ca.rb +4 -1
  24. data/lib/puppet/face/certificate.rb +7 -1
  25. data/lib/puppet/face/epp.rb +5 -5
  26. data/lib/puppet/face/generate.rb +64 -0
  27. data/lib/puppet/face/help.rb +19 -13
  28. data/lib/puppet/face/man.rb +1 -1
  29. data/lib/puppet/feature/external_facts.rb +1 -1
  30. data/lib/puppet/file_system.rb +16 -0
  31. data/lib/puppet/file_system/file_impl.rb +5 -0
  32. data/lib/puppet/file_system/memory_impl.rb +4 -0
  33. data/lib/puppet/file_system/path_pattern.rb +1 -0
  34. data/lib/puppet/file_system/windows.rb +19 -0
  35. data/lib/puppet/functions.rb +3 -5
  36. data/lib/puppet/functions/assert_type.rb +1 -1
  37. data/lib/puppet/functions/defined.rb +7 -5
  38. data/lib/puppet/functions/dig.rb +2 -18
  39. data/lib/puppet/functions/hiera.rb +1 -1
  40. data/lib/puppet/functions/lest.rb +1 -37
  41. data/lib/puppet/functions/new.rb +2 -473
  42. data/lib/puppet/functions/reverse_each.rb +2 -59
  43. data/lib/puppet/functions/scanf.rb +4 -4
  44. data/lib/puppet/functions/step.rb +1 -63
  45. data/lib/puppet/functions/then.rb +1 -61
  46. data/lib/puppet/functions/type.rb +1 -40
  47. data/lib/puppet/functions/unwrap.rb +40 -0
  48. data/lib/puppet/generate/models/type/property.rb +70 -0
  49. data/lib/puppet/generate/models/type/type.rb +57 -0
  50. data/lib/puppet/generate/templates/type/pcore.erb +41 -0
  51. data/lib/puppet/generate/type.rb +239 -0
  52. data/lib/puppet/graph/simple_graph.rb +2 -6
  53. data/lib/puppet/indirector/catalog/static_compiler.rb +5 -2
  54. data/lib/puppet/indirector/facts/facter.rb +1 -1
  55. data/lib/puppet/indirector/key/ca.rb +2 -2
  56. data/lib/puppet/indirector/request.rb +25 -4
  57. data/lib/puppet/indirector/rest.rb +73 -3
  58. data/lib/puppet/info_service/class_information_service.rb +1 -2
  59. data/lib/puppet/interface/documentation.rb +1 -1
  60. data/lib/puppet/loaders.rb +2 -0
  61. data/lib/puppet/metatype/manager.rb +6 -6
  62. data/lib/puppet/module.rb +8 -1
  63. data/lib/puppet/module_tool.rb +2 -2
  64. data/lib/puppet/module_tool/checksums.rb +1 -1
  65. data/lib/puppet/module_tool/errors/installer.rb +2 -2
  66. data/lib/puppet/module_tool/metadata.rb +1 -1
  67. data/lib/puppet/network/http/api/indirected_routes.rb +23 -32
  68. data/lib/puppet/network/http/rack/rest.rb +15 -1
  69. data/lib/puppet/network/rights.rb +1 -11
  70. data/lib/puppet/node/environment.rb +7 -3
  71. data/lib/puppet/node/facts.rb +1 -1
  72. data/lib/puppet/parameter.rb +23 -3
  73. data/lib/puppet/parameter/boolean.rb +1 -1
  74. data/lib/puppet/parameter/value.rb +1 -1
  75. data/lib/puppet/parser.rb +0 -1
  76. data/lib/puppet/parser/ast/pops_bridge.rb +1 -1
  77. data/lib/puppet/parser/ast/resource.rb +5 -0
  78. data/lib/puppet/parser/ast/resource_instance.rb +5 -1
  79. data/lib/puppet/parser/ast/resourceparam.rb +5 -0
  80. data/lib/puppet/parser/compiler.rb +14 -17
  81. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +1 -1
  82. data/lib/puppet/parser/environment_compiler.rb +10 -0
  83. data/lib/puppet/parser/functions/create_resources.rb +39 -24
  84. data/lib/puppet/parser/functions/defined.rb +2 -26
  85. data/lib/puppet/parser/functions/dig.rb +29 -0
  86. data/lib/puppet/parser/functions/lest.rb +49 -0
  87. data/lib/puppet/parser/functions/new.rb +530 -0
  88. data/lib/puppet/parser/functions/require.rb +1 -1
  89. data/lib/puppet/parser/functions/reverse_each.rb +83 -0
  90. data/lib/puppet/parser/functions/scanf.rb +4 -4
  91. data/lib/puppet/parser/functions/step.rb +84 -0
  92. data/lib/puppet/parser/functions/then.rb +73 -0
  93. data/lib/puppet/parser/functions/type.rb +53 -0
  94. data/lib/puppet/parser/resource.rb +16 -7
  95. data/lib/puppet/parser/scope.rb +36 -28
  96. data/lib/puppet/parser/type_loader.rb +1 -1
  97. data/lib/puppet/plugins/data_providers/data_provider.rb +1 -1
  98. data/lib/puppet/pops.rb +13 -0
  99. data/lib/puppet/pops/adapters.rb +49 -49
  100. data/lib/puppet/pops/binder/scheme_handler/confdir_scheme.rb +1 -1
  101. data/lib/puppet/pops/evaluator/access_operator.rb +39 -2
  102. data/lib/puppet/pops/evaluator/closure.rb +39 -13
  103. data/lib/puppet/pops/evaluator/collector_transformer.rb +10 -1
  104. data/lib/puppet/pops/evaluator/evaluator_impl.rb +16 -11
  105. data/lib/puppet/pops/evaluator/external_syntax_support.rb +1 -1
  106. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +0 -1
  107. data/lib/puppet/pops/evaluator/literal_evaluator.rb +0 -1
  108. data/lib/puppet/pops/evaluator/relationship_operator.rb +1 -2
  109. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +119 -0
  110. data/lib/puppet/pops/evaluator/runtime3_support.rb +19 -45
  111. data/lib/puppet/pops/functions/function.rb +5 -0
  112. data/lib/puppet/pops/issues.rb +1 -1
  113. data/lib/puppet/pops/label_provider.rb +2 -2
  114. data/lib/puppet/pops/loader/base_loader.rb +12 -15
  115. data/lib/puppet/pops/loader/loader.rb +15 -50
  116. data/lib/puppet/pops/loader/loader_paths.rb +28 -2
  117. data/lib/puppet/pops/loader/module_loaders.rb +16 -1
  118. data/lib/puppet/pops/loader/null_loader.rb +17 -1
  119. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +12 -11
  120. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +80 -0
  121. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +2 -3
  122. data/lib/puppet/pops/loader/runtime3_type_loader.rb +52 -13
  123. data/lib/puppet/pops/loader/static_loader.rb +55 -0
  124. data/lib/puppet/pops/loader/type_definition_instantiator.rb +30 -14
  125. data/lib/puppet/pops/loader/typed_name.rb +50 -0
  126. data/lib/puppet/pops/loaders.rb +64 -19
  127. data/lib/puppet/pops/merge_strategy.rb +7 -7
  128. data/lib/puppet/pops/migration/migration_checker.rb +4 -0
  129. data/lib/puppet/pops/model/model_label_provider.rb +2 -0
  130. data/lib/puppet/pops/parser/egrammar.ra +8 -5
  131. data/lib/puppet/pops/parser/eparser.rb +1550 -1498
  132. data/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  133. data/lib/puppet/pops/parser/interpolation_support.rb +7 -0
  134. data/lib/puppet/pops/parser/lexer2.rb +14 -1
  135. data/lib/puppet/pops/parser/locator.rb +30 -1
  136. data/lib/puppet/pops/parser/parser_support.rb +0 -3
  137. data/lib/puppet/pops/parser/slurp_support.rb +3 -3
  138. data/lib/puppet/pops/patterns.rb +9 -1
  139. data/lib/puppet/pops/pcore.rb +67 -11
  140. data/lib/puppet/pops/puppet_stack.rb +43 -0
  141. data/lib/puppet/pops/resource/param.rb +51 -0
  142. data/lib/puppet/pops/resource/resource_type_impl.rb +301 -0
  143. data/lib/puppet/pops/resource/resource_type_set.pcore +21 -0
  144. data/lib/puppet/pops/serialization.rb +17 -0
  145. data/lib/puppet/pops/serialization/abstract_reader.rb +149 -0
  146. data/lib/puppet/pops/serialization/abstract_writer.rb +179 -0
  147. data/lib/puppet/pops/serialization/deserializer.rb +60 -0
  148. data/lib/puppet/pops/serialization/extension.rb +126 -0
  149. data/lib/puppet/pops/serialization/instance_reader.rb +19 -0
  150. data/lib/puppet/pops/serialization/instance_writer.rb +14 -0
  151. data/lib/puppet/pops/serialization/json.rb +247 -0
  152. data/lib/puppet/pops/serialization/object.rb +63 -0
  153. data/lib/puppet/pops/serialization/rgen.rb +151 -0
  154. data/lib/puppet/pops/serialization/serializer.rb +91 -0
  155. data/lib/puppet/pops/serialization/time_factory.rb +66 -0
  156. data/lib/puppet/pops/types/annotatable.rb +36 -0
  157. data/lib/puppet/pops/types/implementation_registry.rb +3 -8
  158. data/lib/puppet/pops/types/p_meta_type.rb +83 -0
  159. data/lib/puppet/pops/types/p_object_type.rb +110 -117
  160. data/lib/puppet/pops/types/p_runtime_type.rb +13 -0
  161. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +23 -0
  162. data/lib/puppet/pops/types/p_sem_ver_type.rb +30 -2
  163. data/lib/puppet/pops/types/p_sensitive_type.rb +69 -0
  164. data/lib/puppet/pops/types/p_type_set_type.rb +361 -0
  165. data/lib/puppet/pops/types/puppet_object.rb +0 -5
  166. data/lib/puppet/pops/types/ruby_generator.rb +9 -2
  167. data/lib/puppet/pops/types/type_calculator.rb +6 -1
  168. data/lib/puppet/pops/types/type_factory.rb +14 -12
  169. data/lib/puppet/pops/types/type_formatter.rb +78 -33
  170. data/lib/puppet/pops/types/type_mismatch_describer.rb +0 -2
  171. data/lib/puppet/pops/types/type_parser.rb +27 -2
  172. data/lib/puppet/pops/types/type_set_reference.rb +59 -0
  173. data/lib/puppet/pops/types/types.rb +366 -13
  174. data/lib/puppet/pops/validation.rb +4 -4
  175. data/lib/puppet/pops/validation/checker4_0.rb +5 -2
  176. data/lib/puppet/pops/visitor.rb +2 -2
  177. data/lib/puppet/property.rb +64 -5
  178. data/lib/puppet/provider.rb +1 -1
  179. data/lib/puppet/provider/aixobject.rb +3 -3
  180. data/lib/puppet/provider/group/aix.rb +4 -4
  181. data/lib/puppet/provider/macauthorization/macauthorization.rb +1 -1
  182. data/lib/puppet/provider/mailalias/aliases.rb +1 -1
  183. data/lib/puppet/provider/mcx/mcxcontent.rb +2 -2
  184. data/lib/puppet/provider/mount/parsed.rb +1 -1
  185. data/lib/puppet/provider/nameservice/directoryservice.rb +5 -5
  186. data/lib/puppet/provider/package/appdmg.rb +3 -3
  187. data/lib/puppet/provider/package/apple.rb +1 -1
  188. data/lib/puppet/provider/package/dnf.rb +5 -0
  189. data/lib/puppet/provider/package/nim.rb +1 -1
  190. data/lib/puppet/provider/package/pacman.rb +2 -2
  191. data/lib/puppet/provider/package/pip.rb +5 -3
  192. data/lib/puppet/provider/package/pip3.rb +1 -1
  193. data/lib/puppet/provider/package/pkg.rb +5 -5
  194. data/lib/puppet/provider/package/pkgdmg.rb +4 -4
  195. data/lib/puppet/provider/package/pkgin.rb +1 -1
  196. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  197. data/lib/puppet/provider/package/portage.rb +48 -8
  198. data/lib/puppet/provider/package/sun.rb +1 -1
  199. data/lib/puppet/provider/package/tdnf.rb +28 -0
  200. data/lib/puppet/provider/package/yum.rb +22 -4
  201. data/lib/puppet/provider/parsedfile.rb +2 -2
  202. data/lib/puppet/provider/service/base.rb +1 -1
  203. data/lib/puppet/provider/service/bsd.rb +1 -1
  204. data/lib/puppet/provider/service/daemontools.rb +2 -2
  205. data/lib/puppet/provider/service/debian.rb +3 -3
  206. data/lib/puppet/provider/service/init.rb +5 -3
  207. data/lib/puppet/provider/service/launchd.rb +16 -2
  208. data/lib/puppet/provider/service/runit.rb +1 -1
  209. data/lib/puppet/provider/service/smf.rb +8 -1
  210. data/lib/puppet/provider/service/systemd.rb +39 -6
  211. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  212. data/lib/puppet/provider/user/aix.rb +3 -2
  213. data/lib/puppet/provider/user/directoryservice.rb +4 -3
  214. data/lib/puppet/provider/user/hpux.rb +1 -1
  215. data/lib/puppet/provider/user/user_role_add.rb +1 -1
  216. data/lib/puppet/provider/user/windows_adsi.rb +3 -0
  217. data/lib/puppet/provider/zfs/zfs.rb +1 -1
  218. data/lib/puppet/reference/type.rb +1 -1
  219. data/lib/puppet/resource.rb +33 -7
  220. data/lib/puppet/resource/capability_finder.rb +74 -54
  221. data/lib/puppet/resource/status.rb +11 -2
  222. data/lib/puppet/settings.rb +17 -6
  223. data/lib/puppet/settings/environment_conf.rb +1 -1
  224. data/lib/puppet/settings/server_list_setting.rb +20 -0
  225. data/lib/puppet/ssl/certificate_authority.rb +32 -9
  226. data/lib/puppet/ssl/certificate_authority/interface.rb +164 -24
  227. data/lib/puppet/ssl/host.rb +3 -3
  228. data/lib/puppet/ssl/oids.rb +10 -0
  229. data/lib/puppet/ssl/validator/default_validator.rb +2 -2
  230. data/lib/puppet/test/test_helper.rb +2 -2
  231. data/lib/puppet/transaction.rb +12 -0
  232. data/lib/puppet/transaction/additional_resource_generator.rb +1 -1
  233. data/lib/puppet/transaction/event.rb +29 -2
  234. data/lib/puppet/transaction/event_manager.rb +1 -1
  235. data/lib/puppet/transaction/persistence.rb +84 -0
  236. data/lib/puppet/transaction/report.rb +49 -2
  237. data/lib/puppet/transaction/resource_harness.rb +98 -18
  238. data/lib/puppet/type.rb +63 -21
  239. data/lib/puppet/type/augeas.rb +3 -3
  240. data/lib/puppet/type/cron.rb +1 -1
  241. data/lib/puppet/type/file.rb +39 -2
  242. data/lib/puppet/type/file/data_sync.rb +13 -5
  243. data/lib/puppet/type/host.rb +1 -1
  244. data/lib/puppet/type/mount.rb +2 -6
  245. data/lib/puppet/type/notify.rb +1 -1
  246. data/lib/puppet/type/package.rb +1 -1
  247. data/lib/puppet/type/resources.rb +1 -1
  248. data/lib/puppet/type/scheduled_task.rb +1 -1
  249. data/lib/puppet/type/ssh_authorized_key.rb +2 -2
  250. data/lib/puppet/type/tidy.rb +1 -1
  251. data/lib/puppet/type/yumrepo.rb +3 -3
  252. data/lib/puppet/type/zone.rb +1 -1
  253. data/lib/puppet/util.rb +2 -2
  254. data/lib/puppet/util/classgen.rb +1 -1
  255. data/lib/puppet/util/command_line.rb +6 -2
  256. data/lib/puppet/util/command_line/trollop.rb +1 -1
  257. data/lib/puppet/util/execution.rb +2 -2
  258. data/lib/puppet/util/http_proxy.rb +1 -1
  259. data/lib/puppet/util/inifile.rb +1 -1
  260. data/lib/puppet/util/instance_loader.rb +1 -1
  261. data/lib/puppet/util/logging.rb +1 -1
  262. data/lib/puppet/util/multi_match.rb +1 -1
  263. data/lib/puppet/util/plist.rb +15 -5
  264. data/lib/puppet/util/profiler.rb +1 -1
  265. data/lib/puppet/util/profiler/around_profiler.rb +1 -1
  266. data/lib/puppet/util/psych_support.rb +1 -1
  267. data/lib/puppet/util/rdoc.rb +2 -2
  268. data/lib/puppet/util/rubygems.rb +1 -1
  269. data/lib/puppet/util/watcher/periodic_watcher.rb +2 -2
  270. data/lib/puppet/util/windows/access_control_entry.rb +1 -1
  271. data/lib/puppet/util/windows/adsi.rb +30 -8
  272. data/lib/puppet/util/windows/api_types.rb +1 -1
  273. data/lib/puppet/util/windows/file.rb +59 -0
  274. data/lib/puppet/util/windows/process.rb +10 -0
  275. data/lib/puppet/util/windows/security.rb +1 -1
  276. data/lib/puppet/util/windows/user.rb +22 -4
  277. data/lib/puppet/util/yaml.rb +15 -3
  278. data/lib/puppet/vendor/deep_merge/test/test_deep_merge.rb +1 -1
  279. data/lib/puppet/vendor/rgen_patch.rb +1 -1
  280. data/lib/puppet/version.rb +2 -2
  281. data/spec/fixtures/unit/pops/loaders/loaders/no_modules/manifests/site.pp +10 -0
  282. data/spec/integration/agent/logging_spec.rb +15 -14
  283. data/spec/integration/application/apply_spec.rb +1 -0
  284. data/spec/integration/directory_environments_spec.rb +16 -0
  285. data/spec/integration/environments/settings_spec.rb +32 -4
  286. data/spec/integration/faces/documentation_spec.rb +1 -1
  287. data/spec/integration/network/http/api/indirected_routes_spec.rb +33 -0
  288. data/spec/integration/node/environment_spec.rb +21 -0
  289. data/spec/integration/parser/collection_spec.rb +10 -0
  290. data/spec/integration/parser/compiler_spec.rb +76 -840
  291. data/spec/integration/parser/functions/require_spec.rb +3 -3
  292. data/spec/integration/parser/parameter_defaults_spec.rb +6 -2
  293. data/spec/integration/parser/pcore_resource_spec.rb +208 -0
  294. data/spec/integration/parser/resource_expressions_spec.rb +4 -2
  295. data/spec/integration/provider/yumrepo_spec.rb +4 -1
  296. data/spec/integration/transaction/report_spec.rb +666 -0
  297. data/spec/integration/type/file_spec.rb +11 -12
  298. data/spec/integration/util/windows/adsi_spec.rb +99 -0
  299. data/spec/integration/util/windows/principal_spec.rb +109 -60
  300. data/spec/integration/util/windows/process_spec.rb +4 -2
  301. data/spec/integration/util/windows/security_spec.rb +34 -8
  302. data/spec/integration/util/windows/user_spec.rb +26 -4
  303. data/spec/lib/puppet_spec/files.rb +2 -2
  304. data/spec/lib/puppet_spec/network.rb +12 -8
  305. data/spec/shared_examples/rhel_package_provider.rb +341 -0
  306. data/spec/spec_helper.rb +8 -2
  307. data/spec/unit/application/cert_spec.rb +20 -0
  308. data/spec/unit/configurer/plugin_handler_spec.rb +0 -26
  309. data/spec/unit/configurer_spec.rb +46 -0
  310. data/spec/unit/defaults_spec.rb +14 -0
  311. data/spec/unit/face/generate_spec.rb +230 -0
  312. data/spec/unit/face/help_spec.rb +53 -0
  313. data/spec/unit/face/parser_spec.rb +6 -0
  314. data/spec/unit/face/plugin_spec.rb +0 -4
  315. data/spec/unit/file_system_spec.rb +85 -0
  316. data/spec/unit/functions/lookup_spec.rb +4 -4
  317. data/spec/unit/functions/match_spec.rb +2 -2
  318. data/spec/unit/functions/regsubst_spec.rb +1 -1
  319. data/spec/unit/functions/split_spec.rb +1 -1
  320. data/spec/unit/functions/unwrap_spec.rb +29 -0
  321. data/spec/unit/functions/versioncmp_spec.rb +1 -1
  322. data/spec/unit/functions4_spec.rb +8 -8
  323. data/spec/unit/indirector/facts/facter_spec.rb +1 -9
  324. data/spec/unit/indirector/rest_spec.rb +95 -9
  325. data/spec/unit/module_spec.rb +43 -7
  326. data/spec/unit/module_tool/applications/installer_spec.rb +10 -1
  327. data/spec/unit/module_tool/applications/unpacker_spec.rb +2 -1
  328. data/spec/unit/module_tool/applications/upgrader_spec.rb +8 -0
  329. data/spec/unit/module_tool/tar/mini_spec.rb +3 -3
  330. data/spec/unit/network/http/api/indirected_routes_spec.rb +49 -58
  331. data/spec/unit/network/http/api/master/v3_spec.rb +7 -4
  332. data/spec/unit/network/rights_spec.rb +1 -1
  333. data/spec/unit/parameter_spec.rb +11 -0
  334. data/spec/unit/parser/compiler_spec.rb +19 -33
  335. data/spec/unit/{appmgmt_spec.rb → parser/environment_compiler_spec.rb} +12 -1
  336. data/spec/unit/parser/functions/create_resources_spec.rb +76 -4
  337. data/spec/unit/parser/functions/require_spec.rb +2 -2
  338. data/spec/unit/parser/resource_spec.rb +21 -11
  339. data/spec/unit/parser/scope_spec.rb +1 -5
  340. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +1 -1
  341. data/spec/unit/pops/loaders/dependency_loader_spec.rb +1 -1
  342. data/spec/unit/pops/loaders/loader_paths_spec.rb +1 -1
  343. data/spec/unit/pops/loaders/loaders_spec.rb +63 -5
  344. data/spec/unit/pops/loaders/module_loaders_spec.rb +2 -2
  345. data/spec/unit/pops/loaders/static_loader_spec.rb +1 -1
  346. data/spec/unit/pops/parser/lexer2_spec.rb +27 -3
  347. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +8 -0
  348. data/spec/unit/pops/parser/parse_calls_spec.rb +9 -0
  349. data/spec/unit/pops/puppet_stack_spec.rb +79 -0
  350. data/spec/unit/pops/resource/resource_type_impl_spec.rb +37 -0
  351. data/spec/unit/pops/serialization/packer_spec.rb +153 -0
  352. data/spec/unit/pops/serialization/rgen_spec.rb +88 -0
  353. data/spec/unit/pops/serialization/serialization_spec.rb +228 -0
  354. data/spec/unit/pops/types/p_object_type_spec.rb +44 -2
  355. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +42 -0
  356. data/spec/unit/pops/types/p_sensitive_type_spec.rb +139 -0
  357. data/spec/unit/pops/types/p_type_set_type_spec.rb +424 -0
  358. data/spec/unit/pops/types/ruby_generator_spec.rb +497 -181
  359. data/spec/unit/pops/types/type_calculator_spec.rb +10 -4
  360. data/spec/unit/pops/types/type_formatter_spec.rb +1 -1
  361. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +2 -2
  362. data/spec/unit/pops/types/type_parser_spec.rb +1 -1
  363. data/spec/unit/pops/types/types_spec.rb +1 -1
  364. data/spec/unit/pops/validator/validator_spec.rb +18 -1
  365. data/spec/unit/property_spec.rb +48 -11
  366. data/spec/unit/provider/group/windows_adsi_spec.rb +11 -1
  367. data/spec/unit/provider/package/dnf_spec.rb +1 -99
  368. data/spec/unit/provider/package/pacman_spec.rb +4 -4
  369. data/spec/unit/provider/package/pip_spec.rb +14 -0
  370. data/spec/unit/provider/package/pkg_spec.rb +6 -0
  371. data/spec/unit/provider/package/pkgdmg_spec.rb +0 -3
  372. data/spec/unit/provider/package/portage_spec.rb +64 -8
  373. data/spec/unit/provider/package/tdnf_spec.rb +18 -0
  374. data/spec/unit/provider/package/windows/package_spec.rb +4 -1
  375. data/spec/unit/provider/package/windows_spec.rb +8 -2
  376. data/spec/unit/provider/package/yum_spec.rb +6 -377
  377. data/spec/unit/provider/service/base_spec.rb +6 -0
  378. data/spec/unit/provider/service/debian_spec.rb +16 -7
  379. data/spec/unit/provider/service/gentoo_spec.rb +6 -0
  380. data/spec/unit/provider/service/init_spec.rb +7 -0
  381. data/spec/unit/provider/service/launchd_spec.rb +35 -4
  382. data/spec/unit/provider/service/openrc_spec.rb +6 -0
  383. data/spec/unit/provider/service/smf_spec.rb +31 -6
  384. data/spec/unit/provider/service/src_spec.rb +6 -0
  385. data/spec/unit/provider/service/systemd_spec.rb +70 -20
  386. data/spec/unit/provider/service/upstart_spec.rb +6 -0
  387. data/spec/unit/provider/user/aix_spec.rb +7 -0
  388. data/spec/unit/provider/user/directoryservice_spec.rb +30 -1
  389. data/spec/unit/provider/user/windows_adsi_spec.rb +19 -0
  390. data/spec/unit/resource/capability_finder_spec.rb +51 -3
  391. data/spec/unit/resource/catalog_spec.rb +5 -0
  392. data/spec/unit/resource/type_spec.rb +2 -2
  393. data/spec/unit/resource_spec.rb +19 -0
  394. data/spec/unit/settings_spec.rb +13 -0
  395. data/spec/unit/ssl/certificate_authority/interface_spec.rb +176 -10
  396. data/spec/unit/ssl/certificate_authority_spec.rb +63 -22
  397. data/spec/unit/ssl/host_spec.rb +1 -1
  398. data/spec/unit/ssl/oids_spec.rb +24 -21
  399. data/spec/unit/transaction/event_spec.rb +3 -1
  400. data/spec/unit/transaction/persistence_spec.rb +173 -0
  401. data/spec/unit/transaction/report_spec.rb +64 -1
  402. data/spec/unit/transaction/resource_harness_spec.rb +91 -0
  403. data/spec/unit/type/file/content_spec.rb +47 -15
  404. data/spec/unit/type/file_spec.rb +28 -0
  405. data/spec/unit/type/mount_spec.rb +5 -12
  406. data/spec/unit/type/yumrepo_spec.rb +1 -5
  407. data/spec/unit/type_spec.rb +32 -0
  408. data/spec/unit/util/command_line_spec.rb +11 -0
  409. data/spec/unit/util/execution_spec.rb +1 -1
  410. data/spec/unit/util/plist_spec.rb +16 -3
  411. data/spec/unit/util/storage_spec.rb +4 -1
  412. data/spec/unit/util/windows/adsi_spec.rb +23 -2
  413. data/spec/unit/util/windows/file_spec.rb +56 -1
  414. data/spec/unit/util/windows/sid_spec.rb +31 -7
  415. data/spec/unit/util/yaml_spec.rb +12 -0
  416. data/spec/unit/util_spec.rb +87 -20
  417. metadata +89 -34
  418. data/ext/puppetlisten/puppetlisten.rb +0 -77
  419. data/ext/puppetlisten/puppetrun.rb +0 -38
  420. data/lib/puppet/resource/type_collection_helper.rb +0 -7
  421. data/spec/unit/parser/functions/defined_spec.rb +0 -120
  422. data/spec/unit/resource/type_collection_helper_spec.rb +0 -24
@@ -269,6 +269,11 @@ module Puppet::Util::Windows::Process
269
269
  end
270
270
  module_function :set_environment_variable
271
271
 
272
+ def get_system_default_ui_language
273
+ GetSystemDefaultUILanguage()
274
+ end
275
+ module_function :get_system_default_ui_language
276
+
272
277
  # Returns whether or not the OS has the ability to set elevated
273
278
  # token information.
274
279
  #
@@ -476,4 +481,9 @@ module Puppet::Util::Windows::Process
476
481
  ffi_lib :kernel32
477
482
  attach_function_private :GetVersionExW,
478
483
  [:pointer], :win32_bool
484
+
485
+ # https://msdn.microsoft.com/en-us/library/windows/desktop/dd318123(v=vs.85).aspx
486
+ # LANGID GetSystemDefaultUILanguage(void);
487
+ ffi_lib :kernel32
488
+ attach_function_private :GetSystemDefaultUILanguage, [], :word
479
489
  end
@@ -262,7 +262,7 @@ module Puppet::Util::Windows::Security
262
262
  }
263
263
 
264
264
  # Set the mode of the object referenced by +path+ to the specified
265
- # +mode+. The mode should be specified as POSIX-stye read, write,
265
+ # +mode+. The mode should be specified as POSIX-style read, write,
266
266
  # and execute modes for the user, group, and other classes,
267
267
  # e.g. 0640. The sticky bit, S_ISVTX, is supported, but is only
268
268
  # meaningful for directories. If set, group and others are not
@@ -22,6 +22,14 @@ module Puppet::Util::Windows::User
22
22
  # https://msdn.microsoft.com/en-us/library/windows/desktop/ee207397(v=vs.85).aspx
23
23
  SECURITY_MAX_SID_SIZE = 68
24
24
 
25
+ # https://msdn.microsoft.com/en-us/library/windows/desktop/ms681385(v=vs.85).aspx
26
+ # These error codes indicate successful authentication but failure to
27
+ # logon for a separate reason
28
+ ERROR_ACCOUNT_RESTRICTION = 1327
29
+ ERROR_INVALID_LOGON_HOURS = 1328
30
+ ERROR_INVALID_WORKSTATION = 1329
31
+ ERROR_ACCOUNT_DISABLED = 1331
32
+
25
33
  def check_token_membership
26
34
  is_admin = false
27
35
  FFI::MemoryPointer.new(:byte, SECURITY_MAX_SID_SIZE) do |sid_pointer|
@@ -52,9 +60,19 @@ module Puppet::Util::Windows::User
52
60
  module_function :check_token_membership
53
61
 
54
62
  def password_is?(name, password)
55
- logon_user(name, password) { |token| }
56
- rescue Puppet::Util::Windows::Error
57
- false
63
+ begin
64
+ logon_user(name, password) { |token| }
65
+ rescue Puppet::Util::Windows::Error => detail
66
+
67
+ authenticated_error_codes = Set[
68
+ ERROR_ACCOUNT_RESTRICTION,
69
+ ERROR_INVALID_LOGON_HOURS,
70
+ ERROR_INVALID_WORKSTATION,
71
+ ERROR_ACCOUNT_DISABLED,
72
+ ]
73
+
74
+ return authenticated_error_codes.include?(detail.code)
75
+ end
58
76
  end
59
77
  module_function :password_is?
60
78
 
@@ -65,7 +83,7 @@ module Puppet::Util::Windows::User
65
83
  token = nil
66
84
  begin
67
85
  FFI::MemoryPointer.new(:handle, 1) do |token_pointer|
68
- if LogonUserW(wide_string(name), wide_string('.'), wide_string(password),
86
+ if LogonUserW(wide_string(name), wide_string('.'), password.nil? ? FFI::Pointer::NULL : wide_string(password),
69
87
  fLOGON32_LOGON_NETWORK, fLOGON32_PROVIDER_DEFAULT, token_pointer) == FFI::WIN32_FALSE
70
88
  raise Puppet::Util::Windows::Error.new("Failed to logon user #{name.inspect}")
71
89
  end
@@ -9,9 +9,21 @@ module Puppet::Util::Yaml
9
9
 
10
10
  class YamlLoadError < Puppet::Error; end
11
11
 
12
- def self.load_file(filename, default_value = false)
13
- yaml = YAML.load_file(filename)
14
- yaml || default_value
12
+ def self.load_file(filename, default_value = false, strip_classes = false)
13
+ if(strip_classes) then
14
+ data = YAML::parse_file(filename)
15
+ data.root.each do |o|
16
+ if o.respond_to?(:tag=) and
17
+ o.tag != nil and
18
+ o.tag.start_with?("!ruby")
19
+ o.tag = nil
20
+ end
21
+ end
22
+ data.to_ruby || default_value
23
+ else
24
+ yaml = YAML.load_file(filename)
25
+ yaml || default_value
26
+ end
15
27
  rescue *YamlLoadExceptions => detail
16
28
  raise YamlLoadError.new(detail.message, detail)
17
29
  end
@@ -213,7 +213,7 @@ class TestDeepMerge < Test::Unit::TestCase
213
213
  DeepMerge::deep_merge!(hash_src, hash_dst)
214
214
  assert_equal({"property" => {"bedroom_count" => {"king_bed" => [nil, 3], "queen_bed" => [4, nil, 1]}, "bathroom_count" => [nil, "2", "1"]}}, hash_dst)
215
215
 
216
- # test parameter management for knockout_prefix and overwrite unmergable
216
+ # test parameter management for knockout_prefix and overwrite unmergeable
217
217
  assert_raise(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:knockout_prefix => ""})}
218
218
  assert_raise(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true, :knockout_prefix => ""})}
219
219
  assert_raise(DeepMerge::InvalidParameter) {DeepMerge::deep_merge!(hash_src, hash_dst, {:preserve_unmergeables => true, :knockout_prefix => "--"})}
@@ -12,7 +12,7 @@
12
12
  #
13
13
  # This patch changes the implementation so that the test for MMBase/
14
14
  # MMGeneric is made prior to the iteration, thus avoiding the iteration
15
- # alltogether for all non model objects
15
+ # altogether for all non model objects
16
16
  #
17
17
  # The patch also changes the setXXX method to allow it to optimize the way
18
18
  # it ensures that the added elements are unique. Calling the addXXX method
@@ -2,12 +2,12 @@
2
2
  # simple `require 'puppet/version'` allows a rubygems gemspec or bundler
3
3
  # Gemfile to get the Puppet version of the gem install.
4
4
  #
5
- # The version is programatically settable because we want to allow the
5
+ # The version can be set programmatically because we want to allow the
6
6
  # Raketasks and such to set the version based on the output of `git describe`
7
7
 
8
8
 
9
9
  module Puppet
10
- PUPPETVERSION = '4.5.3'
10
+ PUPPETVERSION = '4.6.1'
11
11
 
12
12
  ##
13
13
  # version is a public API method intended to always provide a fast and
@@ -0,0 +1,10 @@
1
+ function bar() {
2
+ $value_from_scope
3
+ }
4
+
5
+ class foo::bar {
6
+ with(1) |$x| { notice $x }
7
+ notify { bar(): }
8
+ }
9
+
10
+ include foo::bar
@@ -86,21 +86,22 @@ describe 'agent logging' do
86
86
  end
87
87
 
88
88
  else
89
-
90
- it "when evoked with #{argv}, logs to #{expected[:loggers].inspect} at level #{expected[:level]}" do
91
- # This logger is created by the Puppet::Settings object which creates and
92
- # applies a catalog to ensure that configuration files and users are in
93
- # place.
94
- #
95
- # It's not something we are specifically testing here since it occurs
96
- # regardless of user flags.
97
- Puppet::Util::Log.expects(:newdestination).with(instance_of(Puppet::Transaction::Report)).at_least_once
98
- expected[:loggers].each do |logclass|
99
- Puppet::Util::Log.expects(:newdestination).with(logclass).at_least_once
89
+ if no_log_dest_set_in(argv)
90
+ it "when evoked with #{argv}, logs to #{expected[:loggers].inspect} at level #{expected[:level]}" do
91
+ # This logger is created by the Puppet::Settings object which creates and
92
+ # applies a catalog to ensure that configuration files and users are in
93
+ # place.
94
+ #
95
+ # It's not something we are specifically testing here since it occurs
96
+ # regardless of user flags.
97
+ Puppet::Util::Log.expects(:newdestination).with(instance_of(Puppet::Transaction::Report)).at_least_once
98
+ expected[:loggers].each do |logclass|
99
+ Puppet::Util::Log.expects(:newdestination).with(logclass).at_least_once
100
+ end
101
+ double_of_bin_puppet_agent_call(argv)
102
+
103
+ expect(Puppet::Util::Log.level).to eq(expected[:level])
100
104
  end
101
- double_of_bin_puppet_agent_call(argv)
102
-
103
- expect(Puppet::Util::Log.level).to eq(expected[:level])
104
105
  end
105
106
 
106
107
  end
@@ -202,5 +202,6 @@ describe "apply" do
202
202
  expect(logs).to include(match(/doesn't match server specified environment/))
203
203
  end
204
204
  end
205
+
205
206
  end
206
207
  end
@@ -29,6 +29,22 @@ describe "directory environments" do
29
29
  expect { puppet.run }.to exit_with(0)
30
30
  end.to have_printed('/completely/different')
31
31
  end
32
+
33
+ it 'given an 8.3 style path on Windows, will config print an expanded path',
34
+ :if => Puppet::Util::Platform.windows? do
35
+
36
+ # ensure an 8.3 style path is set for environmentpath
37
+ shortened = Puppet::Util::Windows::File.get_short_pathname(Puppet[:environmentpath])
38
+ expanded = Puppet::FileSystem.expand_path(shortened)
39
+
40
+ Puppet[:environmentpath] = shortened
41
+ expect(Puppet[:environmentpath]).to match(/~/)
42
+
43
+ Puppet.settings.initialize_global_settings(args)
44
+ expect do
45
+ expect { puppet.run }.to exit_with(0)
46
+ end.to have_printed(expanded)
47
+ end
32
48
  end
33
49
 
34
50
  context "with an environmentpath having multiple directories" do
@@ -62,15 +62,43 @@ describe "environment settings" do
62
62
  end
63
63
 
64
64
  it "reads the configured manifest" do
65
- expect(Puppet.settings.value(:manifest, :testing)).to eq(File.expand_path('/special/manifest'))
65
+ expect(Puppet.settings.value(:manifest, :testing)).to eq(Puppet::FileSystem.expand_path('/special/manifest'))
66
66
  end
67
67
 
68
68
  it "reads the configured modulepath" do
69
- expect(Puppet.settings.value(:modulepath, :testing)).to eq(File.expand_path('/special/modulepath'))
69
+ expect(Puppet.settings.value(:modulepath, :testing)).to eq(Puppet::FileSystem.expand_path('/special/modulepath'))
70
70
  end
71
71
 
72
72
  it "reads the configured config_version" do
73
- expect(Puppet.settings.value(:config_version, :testing)).to eq(File.expand_path('/special/config_version'))
73
+ expect(Puppet.settings.value(:config_version, :testing)).to eq(Puppet::FileSystem.expand_path('/special/config_version'))
74
+ end
75
+ end
76
+
77
+ context "with an environment.conf containing 8.3 style Windows paths",
78
+ :if => Puppet::Util::Platform.windows? do
79
+
80
+ before(:each) do
81
+ # set 8.3 style Windows paths
82
+ @modulepath = Puppet::Util::Windows::File.get_short_pathname(PuppetSpec::Files.tmpdir('fakemodulepath'))
83
+
84
+ # for expansion to work, the file must actually exist
85
+ @manifest = PuppetSpec::Files.tmpfile('foo.pp', @modulepath)
86
+ # but tmpfile won't create an empty file
87
+ Puppet::FileSystem.touch(@manifest)
88
+ @manifest = Puppet::Util::Windows::File.get_short_pathname(@manifest)
89
+
90
+ set_environment_conf(environmentpath, 'testing', <<-EOF)
91
+ manifest=#{@manifest}
92
+ modulepath=#{@modulepath}
93
+ EOF
94
+ end
95
+
96
+ it "reads the configured manifest as a fully expanded path" do
97
+ expect(Puppet.settings.value(:manifest, :testing)).to eq(Puppet::FileSystem.expand_path(@manifest))
98
+ end
99
+
100
+ it "reads the configured modulepath as a fully expanded path" do
101
+ expect(Puppet.settings.value(:modulepath, :testing)).to eq(Puppet::FileSystem.expand_path(@modulepath))
74
102
  end
75
103
  end
76
104
 
@@ -91,7 +119,7 @@ describe "environment settings" do
91
119
 
92
120
  it "reads manifest from environment.conf settings" do
93
121
  expect(Puppet.settings.value(:environmentpath)).to eq(environmentpath)
94
- expect(Puppet.settings.value(:manifest, :main)).to eq(File.expand_path("/special/manifest"))
122
+ expect(Puppet.settings.value(:manifest, :main)).to eq(Puppet::FileSystem.expand_path("/special/manifest"))
95
123
  end
96
124
  end
97
125
  end
@@ -46,7 +46,7 @@ describe "documentation of faces" do
46
46
  context "licensing of Puppet Labs face '#{face_name}'" do
47
47
  subject { Puppet::Face[face_name, :current] }
48
48
  its :license do should =~ /Apache\s*2/ end
49
- its :copyright do should =~ /Puppet Labs/ end
49
+ its :copyright do should =~ /Puppet Labs|Puppet Inc\./ end
50
50
 
51
51
  # REVISIT: This is less that ideal, I think, but right now I am more
52
52
  # comfortable watching us ship with some copyright than without any; we
@@ -2,6 +2,8 @@
2
2
  require 'spec_helper'
3
3
  require 'puppet/network/http'
4
4
  require 'puppet/network/http/api/indirected_routes'
5
+ require 'rack/mock' if Puppet.features.rack?
6
+ require 'puppet/network/http/rack/rest'
5
7
  require 'puppet/indirector_proxy'
6
8
  require 'puppet_spec/files'
7
9
  require 'puppet_spec/network'
@@ -52,5 +54,36 @@ describe Puppet::Network::HTTP::API::IndirectedRoutes do
52
54
  end
53
55
  end
54
56
  end
57
+
58
+ describe "an error from IndirectedRoutes", :if => Puppet.features.rack? do
59
+ let(:handler) { Puppet::Network::HTTP::RackREST.new }
60
+
61
+ describe "returns json" do
62
+ it "when a standard error" do
63
+ response = Rack::Response.new
64
+ request = Rack::Request.new(
65
+ Rack::MockRequest.env_for("/puppet/v3/invalid-indirector"))
66
+
67
+ handler.process(request, response)
68
+
69
+ expect(response.header["Content-Type"]).to match(/json/)
70
+ resp = JSON.parse(response.body.first)
71
+ expect(resp["message"]).to match(/The indirection name must be purely alphanumeric/)
72
+ expect(resp["issue_kind"]).to be_a_kind_of(String)
73
+ end
74
+ it "when a server error" do
75
+ response = Rack::Response.new
76
+ request = Rack::Request.new(
77
+ Rack::MockRequest.env_for("/puppet/v3/unknown_indirector"))
78
+
79
+ handler.process(request, response)
80
+
81
+ expect(response.header["Content-Type"]).to match(/json/)
82
+ resp = JSON.parse(response.body.first)
83
+ expect(resp["message"]).to match(/Could not find indirection/)
84
+ expect(resp["issue_kind"]).to be_a_kind_of(String)
85
+ end
86
+ end
87
+ end
55
88
  end
56
89
  end
@@ -37,6 +37,27 @@ describe Puppet::Node::Environment do
37
37
  end
38
38
  end
39
39
 
40
+ it "should expand 8.3 paths on Windows when creating an environment",
41
+ :if => Puppet::Util::Platform.windows? do
42
+
43
+ # asking for short names only works on paths that exist
44
+ base = Puppet::Util::Windows::File.get_short_pathname(tmpdir("env_modules"))
45
+ parent_modules_dir = File.join(base, 'testmoduledir')
46
+
47
+ # make sure the paths have ~ in them, indicating unexpanded 8.3 paths
48
+ expect(parent_modules_dir).to match(/~/)
49
+
50
+ module_dir = a_module_in('testmodule', parent_modules_dir)
51
+
52
+ # create the environment with unexpanded 8.3 paths
53
+ environment = Puppet::Node::Environment.create(:foo, [parent_modules_dir])
54
+
55
+ # and expect fully expanded paths inside the environment
56
+ # necessary for comparing module paths internally by the parser
57
+ expect(environment.modulepath).to eq([Puppet::FileSystem.expand_path(parent_modules_dir)])
58
+ expect(environment.modules.first.path).to eq(Puppet::FileSystem.expand_path(module_dir))
59
+ end
60
+
40
61
  it "should not yield the same module from different module paths" do
41
62
  base = tmpfile("env_modules")
42
63
  Dir.mkdir(base)
@@ -201,6 +201,16 @@ describe 'collectors' do
201
201
  end.to raise_error(/Resource type someresource doesn't exist/)
202
202
  end
203
203
 
204
+ it 'allows query for literal undef' do
205
+ expect_the_message_to_be(["foo::baz::quux"], <<-MANIFEST)
206
+ define foo ($x = undef, $y = undef) {
207
+ notify { 'testing': message => "foo::${x}::${y}" }
208
+ }
209
+ foo { 'bar': y => 'quux' }
210
+ Foo <| x == undef |> { x => 'baz' }
211
+ MANIFEST
212
+ end
213
+
204
214
  context "overrides" do
205
215
  it "modifies an existing array" do
206
216
  expect_the_message_to_be([["original message", "extra message"]], <<-MANIFEST)
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
  require 'puppet_spec/compiler'
3
3
  require 'matchers/resource'
4
4
 
5
+ # COPY OF UNIT TEST
5
6
  class CompilerTestResource
6
7
  attr_accessor :builtin, :virtual, :evaluated, :type, :title
7
8
 
@@ -83,435 +84,8 @@ describe Puppet::Parser::Compiler do
83
84
  @scope.resource = @scope_resource
84
85
  end
85
86
 
86
- it "should fail intelligently when a class-level compile fails" do
87
- Puppet::Parser::Compiler.expects(:new).raises ArgumentError
88
- expect { Puppet::Parser::Compiler.compile(@node) }.to raise_error(Puppet::Error)
89
- end
90
-
91
- it "should use the node's environment as its environment" do
92
- expect(@compiler.environment).to equal(@node.environment)
93
- end
94
-
95
- it "fails if the node's environment has validation errors" do
96
- conflicted_environment = Puppet::Node::Environment.create(:testing, [], '/some/environment.conf/manifest.pp')
97
- conflicted_environment.stubs(:validation_errors).returns(['bad environment'])
98
- @node.environment = conflicted_environment
99
- expect { Puppet::Parser::Compiler.compile(@node) }.to raise_error(Puppet::Error, /Compilation has been halted because.*bad environment/)
100
- end
101
-
102
- it "should include the resource type collection helper" do
103
- expect(Puppet::Parser::Compiler.ancestors).to be_include(Puppet::Resource::TypeCollectionHelper)
104
- end
105
-
106
- it "should be able to return a class list containing all added classes" do
107
- @compiler.add_class ""
108
- @compiler.add_class "one"
109
- @compiler.add_class "two"
110
-
111
- expect(@compiler.classlist.sort).to eq(%w{one two}.sort)
112
- end
113
-
114
- describe "when initializing" do
115
-
116
- it "should set its node attribute" do
117
- expect(@compiler.node).to equal(@node)
118
- end
119
- it "should detect when ast nodes are absent" do
120
- expect(@compiler.ast_nodes?).to be_falsey
121
- end
122
-
123
- it "should detect when ast nodes are present" do
124
- @known_resource_types.expects(:nodes?).returns true
125
- expect(@compiler.ast_nodes?).to be_truthy
126
- end
127
-
128
- it "should copy the known_resource_types version to the catalog" do
129
- expect(@compiler.catalog.version).to eq(@known_resource_types.version)
130
- end
131
-
132
- it "should copy any node classes into the class list" do
133
- node = Puppet::Node.new("mynode")
134
- node.classes = %w{foo bar}
135
- compiler = Puppet::Parser::Compiler.new(node)
136
-
137
- expect(compiler.classlist).to match_array(['foo', 'bar'])
138
- end
139
-
140
- it "should transform node class hashes into a class list" do
141
- node = Puppet::Node.new("mynode")
142
- node.classes = {'foo'=>{'one'=>'p1'}, 'bar'=>{'two'=>'p2'}}
143
- compiler = Puppet::Parser::Compiler.new(node)
144
-
145
- expect(compiler.classlist).to match_array(['foo', 'bar'])
146
- end
147
-
148
- it "should add a 'main' stage to the catalog" do
149
- expect(@compiler.catalog.resource(:stage, :main)).to be_instance_of(Puppet::Parser::Resource)
150
- end
151
- end
152
-
153
- describe "when managing scopes" do
154
-
155
- it "should create a top scope" do
156
- expect(@compiler.topscope).to be_instance_of(Puppet::Parser::Scope)
157
- end
158
-
159
- it "should be able to create new scopes" do
160
- expect(@compiler.newscope(@compiler.topscope)).to be_instance_of(Puppet::Parser::Scope)
161
- end
162
-
163
- it "should set the parent scope of the new scope to be the passed-in parent" do
164
- scope = mock 'scope'
165
- newscope = @compiler.newscope(scope)
166
-
167
- expect(newscope.parent).to equal(scope)
168
- end
169
-
170
- it "should set the parent scope of the new scope to its topscope if the parent passed in is nil" do
171
- scope = mock 'scope'
172
- newscope = @compiler.newscope(nil)
173
-
174
- expect(newscope.parent).to equal(@compiler.topscope)
175
- end
176
- end
177
-
178
- describe "when compiling" do
179
-
180
- def compile_methods
181
- [:set_node_parameters, :evaluate_main, :evaluate_ast_node, :evaluate_node_classes, :evaluate_generators, :fail_on_unevaluated,
182
- :finish, :store, :extract, :evaluate_relationships]
183
- end
184
-
185
- # Stub all of the main compile methods except the ones we're specifically interested in.
186
- def compile_stub(*except)
187
- (compile_methods - except).each { |m| @compiler.stubs(m) }
188
- end
189
-
190
- it "should set node parameters as variables in the top scope" do
191
- params = {"a" => "b", "c" => "d"}
192
- @node.stubs(:parameters).returns(params)
193
- compile_stub(:set_node_parameters)
194
- @compiler.compile
195
- expect(@compiler.topscope['a']).to eq("b")
196
- expect(@compiler.topscope['c']).to eq("d")
197
- end
198
-
199
- it "should set the client and server versions on the catalog" do
200
- params = {"clientversion" => "2", "serverversion" => "3"}
201
- @node.stubs(:parameters).returns(params)
202
- compile_stub(:set_node_parameters)
203
- @compiler.compile
204
- expect(@compiler.catalog.client_version).to eq("2")
205
- expect(@compiler.catalog.server_version).to eq("3")
206
- end
207
-
208
- it "should evaluate the main class if it exists" do
209
- compile_stub(:evaluate_main)
210
- main_class = @known_resource_types.add Puppet::Resource::Type.new(:hostclass, "")
211
- main_class.expects(:evaluate_code).with { |r| r.is_a?(Puppet::Parser::Resource) }
212
- @compiler.topscope.expects(:source=).with(main_class)
213
-
214
- @compiler.compile
215
- end
216
-
217
- it "should create a new, empty 'main' if no main class exists" do
218
- compile_stub(:evaluate_main)
219
- @compiler.compile
220
- expect(@known_resource_types.find_hostclass("")).to be_instance_of(Puppet::Resource::Type)
221
- end
222
-
223
- it "should add an edge between the main stage and main class" do
224
- @compiler.compile
225
- expect(stage = @compiler.catalog.resource(:stage, "main")).to be_instance_of(Puppet::Parser::Resource)
226
- expect(klass = @compiler.catalog.resource(:class, "")).to be_instance_of(Puppet::Parser::Resource)
227
-
228
- expect(@compiler.catalog.edge?(stage, klass)).to be_truthy
229
- end
230
-
231
- it "should evaluate all added collections" do
232
- colls = []
233
- # And when the collections fail to evaluate.
234
- colls << mock("coll1-false")
235
- colls << mock("coll2-false")
236
- colls.each { |c| c.expects(:evaluate).returns(false) }
237
-
238
- @compiler.add_collection(colls[0])
239
- @compiler.add_collection(colls[1])
240
-
241
- compile_stub(:evaluate_generators)
242
- @compiler.compile
243
- end
244
-
245
- it "should ignore builtin resources" do
246
- resource = resource(:file, "testing")
247
-
248
- @compiler.add_resource(@scope, resource)
249
- resource.expects(:evaluate).never
250
-
251
- @compiler.compile
252
- end
253
-
254
- it "should evaluate unevaluated resources" do
255
- resource = CompilerTestResource.new(:file, "testing")
256
-
257
- @compiler.add_resource(@scope, resource)
258
-
259
- # We have to now mark the resource as evaluated
260
- resource.expects(:evaluate).with { |*whatever| resource.evaluated = true }
261
-
262
- @compiler.compile
263
- end
264
-
265
- it "should not evaluate already-evaluated resources" do
266
- resource = resource(:file, "testing")
267
- resource.stubs(:evaluated?).returns true
268
-
269
- @compiler.add_resource(@scope, resource)
270
- resource.expects(:evaluate).never
271
-
272
- @compiler.compile
273
- end
274
-
275
- it "should evaluate unevaluated resources created by evaluating other resources" do
276
- resource = CompilerTestResource.new(:file, "testing")
277
- @compiler.add_resource(@scope, resource)
278
-
279
- resource2 = CompilerTestResource.new(:file, "other")
280
-
281
- # We have to now mark the resource as evaluated
282
- resource.expects(:evaluate).with { |*whatever| resource.evaluated = true; @compiler.add_resource(@scope, resource2) }
283
- resource2.expects(:evaluate).with { |*whatever| resource2.evaluated = true }
284
-
285
-
286
- @compiler.compile
287
- end
288
-
289
- describe "when finishing" do
290
- before do
291
- @compiler.send(:evaluate_main)
292
- @catalog = @compiler.catalog
293
- end
294
-
295
- def add_resource(name, parent = nil)
296
- resource = Puppet::Parser::Resource.new "file", name, :scope => @scope
297
- @compiler.add_resource(@scope, resource)
298
- @catalog.add_edge(parent, resource) if parent
299
- resource
300
- end
301
-
302
- it "should call finish() on all resources" do
303
- # Add a resource that does respond to :finish
304
- resource = Puppet::Parser::Resource.new "file", "finish", :scope => @scope
305
- resource.expects(:finish)
306
-
307
- @compiler.add_resource(@scope, resource)
308
-
309
- # And one that does not
310
- dnf_resource = stub_everything "dnf", :ref => "File[dnf]", :type => "file"
311
-
312
- @compiler.add_resource(@scope, dnf_resource)
313
-
314
- @compiler.send(:finish)
315
- end
316
-
317
- it "should call finish() in add_resource order" do
318
- resources = sequence('resources')
319
-
320
- resource1 = add_resource("finish1")
321
- resource1.expects(:finish).in_sequence(resources)
322
-
323
- resource2 = add_resource("finish2")
324
- resource2.expects(:finish).in_sequence(resources)
325
-
326
- @compiler.send(:finish)
327
- end
328
-
329
- it "should add each container's metaparams to its contained resources" do
330
- main = @catalog.resource(:class, :main)
331
- main[:noop] = true
332
-
333
- resource1 = add_resource("meh", main)
334
-
335
- @compiler.send(:finish)
336
- expect(resource1[:noop]).to be_truthy
337
- end
338
-
339
- it "should add metaparams recursively" do
340
- main = @catalog.resource(:class, :main)
341
- main[:noop] = true
342
-
343
- resource1 = add_resource("meh", main)
344
- resource2 = add_resource("foo", resource1)
345
-
346
- @compiler.send(:finish)
347
- expect(resource2[:noop]).to be_truthy
348
- end
349
-
350
- it "should prefer metaparams from immediate parents" do
351
- main = @catalog.resource(:class, :main)
352
- main[:noop] = true
353
-
354
- resource1 = add_resource("meh", main)
355
- resource2 = add_resource("foo", resource1)
356
-
357
- resource1[:noop] = false
358
-
359
- @compiler.send(:finish)
360
- expect(resource2[:noop]).to be_falsey
361
- end
362
-
363
- it "should merge tags downward" do
364
- main = @catalog.resource(:class, :main)
365
- main.tag("one")
366
-
367
- resource1 = add_resource("meh", main)
368
- resource1.tag "two"
369
- resource2 = add_resource("foo", resource1)
370
-
371
- @compiler.send(:finish)
372
- expect(resource2.tags).to be_include("one")
373
- expect(resource2.tags).to be_include("two")
374
- end
375
-
376
- it "should work if only middle resources have metaparams set" do
377
- main = @catalog.resource(:class, :main)
378
-
379
- resource1 = add_resource("meh", main)
380
- resource1[:noop] = true
381
- resource2 = add_resource("foo", resource1)
382
-
383
- @compiler.send(:finish)
384
- expect(resource2[:noop]).to be_truthy
385
- end
386
- end
387
-
388
- it "should return added resources in add order" do
389
- resource1 = resource(:file, "yay")
390
- @compiler.add_resource(@scope, resource1)
391
- resource2 = resource(:file, "youpi")
392
- @compiler.add_resource(@scope, resource2)
393
-
394
- expect(@compiler.resources).to eq([resource1, resource2])
395
- end
396
-
397
- it "should add resources that do not conflict with existing resources" do
398
- resource = resource(:file, "yay")
399
- @compiler.add_resource(@scope, resource)
400
-
401
- expect(@compiler.catalog).to be_vertex(resource)
402
- end
403
-
404
- it "should fail to add resources that conflict with existing resources" do
405
- path = make_absolute("/foo")
406
- file1 = resource(:file, path)
407
- file2 = resource(:file, path)
408
-
409
- @compiler.add_resource(@scope, file1)
410
- expect { @compiler.add_resource(@scope, file2) }.to raise_error(Puppet::Resource::Catalog::DuplicateResourceError)
411
- end
412
-
413
- it "should add an edge from the scope resource to the added resource" do
414
- resource = resource(:file, "yay")
415
- @compiler.add_resource(@scope, resource)
416
-
417
- expect(@compiler.catalog).to be_edge(@scope.resource, resource)
418
- end
419
-
420
- it "should not add non-class resources that don't specify a stage to the 'main' stage" do
421
- main = @compiler.catalog.resource(:stage, :main)
422
- resource = resource(:file, "foo")
423
- @compiler.add_resource(@scope, resource)
424
-
425
- expect(@compiler.catalog).not_to be_edge(main, resource)
426
- end
427
-
428
- it "should not add any parent-edges to stages" do
429
- stage = resource(:stage, "other")
430
- @compiler.add_resource(@scope, stage)
431
-
432
- @scope.resource = resource(:class, "foo")
433
-
434
- expect(@compiler.catalog.edge?(@scope.resource, stage)).to be_falsey
435
- end
436
-
437
- it "should not attempt to add stages to other stages" do
438
- other_stage = resource(:stage, "other")
439
- second_stage = resource(:stage, "second")
440
- @compiler.add_resource(@scope, other_stage)
441
- @compiler.add_resource(@scope, second_stage)
442
-
443
- second_stage[:stage] = "other"
444
-
445
- expect(@compiler.catalog.edge?(other_stage, second_stage)).to be_falsey
446
- end
447
-
448
- it "should have a method for looking up resources" do
449
- resource = resource(:yay, "foo")
450
- @compiler.add_resource(@scope, resource)
451
- expect(@compiler.findresource("Yay[foo]")).to equal(resource)
452
- end
453
-
454
- it "should be able to look resources up by type and title" do
455
- resource = resource(:yay, "foo")
456
- @compiler.add_resource(@scope, resource)
457
- expect(@compiler.findresource("Yay", "foo")).to equal(resource)
458
- end
459
-
460
- it "should not evaluate virtual defined resources" do
461
- resource = resource(:file, "testing")
462
- resource.virtual = true
463
- @compiler.add_resource(@scope, resource)
464
-
465
- resource.expects(:evaluate).never
466
-
467
- @compiler.compile
468
- end
469
- end
470
-
87
+ # NEW INTEGRATION TEST
471
88
  describe "when evaluating collections" do
472
-
473
- it "should evaluate each collection" do
474
- 2.times { |i|
475
- coll = mock 'coll%s' % i
476
- @compiler.add_collection(coll)
477
-
478
- # This is the hard part -- we have to emulate the fact that
479
- # collections delete themselves if they are done evaluating.
480
- coll.expects(:evaluate).with do
481
- @compiler.delete_collection(coll)
482
- end
483
- }
484
-
485
- @compiler.compile
486
- end
487
-
488
- it "should not fail when there are unevaluated resource collections that do not refer to specific resources" do
489
- coll = stub 'coll', :evaluate => false
490
- coll.expects(:unresolved_resources).returns(nil)
491
-
492
- @compiler.add_collection(coll)
493
-
494
- expect { @compiler.compile }.not_to raise_error
495
- end
496
-
497
- it "should fail when there are unevaluated resource collections that refer to a specific resource" do
498
- coll = stub 'coll', :evaluate => false
499
- coll.expects(:unresolved_resources).returns(:something)
500
-
501
- @compiler.add_collection(coll)
502
-
503
- expect { @compiler.compile }.to raise_error(Puppet::ParseError, 'Failed to realize virtual resources something')
504
- end
505
-
506
- it "should fail when there are unevaluated resource collections that refer to multiple specific resources" do
507
- coll = stub 'coll', :evaluate => false
508
- coll.expects(:unresolved_resources).returns([:one, :two])
509
-
510
- @compiler.add_collection(coll)
511
-
512
- expect { @compiler.compile }.to raise_error(Puppet::ParseError, 'Failed to realize virtual resources one, two')
513
- end
514
-
515
89
  it 'matches on container inherited tags' do
516
90
  Puppet[:code] = <<-MANIFEST
517
91
  class xport_test {
@@ -539,364 +113,10 @@ describe Puppet::Parser::Compiler do
539
113
  end
540
114
  end
541
115
 
542
- describe "when evaluating relationships" do
543
- it "should evaluate each relationship with its catalog" do
544
- dep = stub 'dep'
545
- dep.expects(:evaluate).with(@compiler.catalog)
546
- @compiler.add_relationship dep
547
- @compiler.evaluate_relationships
548
- end
549
- end
550
-
551
- describe "when told to evaluate missing classes" do
552
-
553
- it "should fail if there's no source listed for the scope" do
554
- scope = stub 'scope', :source => nil
555
- expect { @compiler.evaluate_classes(%w{one two}, scope) }.to raise_error(Puppet::DevError)
556
- end
557
-
558
- it "should raise an error if a class is not found" do
559
- @scope.expects(:find_hostclass).with("notfound").returns(nil)
560
- expect{ @compiler.evaluate_classes(%w{notfound}, @scope) }.to raise_error(Puppet::Error, /Could not find class/)
561
- end
562
-
563
- it "should raise an error when it can't find class" do
564
- klasses = {'foo'=>nil}
565
- @node.classes = klasses
566
- @compiler.topscope.expects(:find_hostclass).with('foo').returns(nil)
567
- expect{ @compiler.compile }.to raise_error(Puppet::Error, /Could not find class foo for testnode/)
568
- end
569
- end
570
-
571
- describe "when evaluating found classes" do
572
-
573
- before do
574
- Puppet.settings[:data_binding_terminus] = "none"
575
- @class = stub 'class', :name => "my::class"
576
- @scope.stubs(:find_hostclass).with("myclass").returns(@class)
577
-
578
- @resource = stub 'resource', :ref => "Class[myclass]", :type => "file"
579
- end
580
-
581
- around do |example|
582
- Puppet.override(
583
- :environments => Puppet::Environments::Static.new(environment),
584
- :description => "Static loader for specs"
585
- ) do
586
- example.run
587
- end
588
- end
589
-
590
- it "should evaluate each class" do
591
- @compiler.catalog.stubs(:tag)
592
-
593
- @class.expects(:ensure_in_catalog).with(@scope)
594
- @scope.stubs(:class_scope).with(@class)
595
-
596
- @compiler.evaluate_classes(%w{myclass}, @scope)
597
- end
598
-
599
- describe "and the classes are specified as a hash with parameters" do
600
- before do
601
- @node.classes = {}
602
- @ast_obj = Puppet::Parser::AST::Leaf.new(:value => 'foo')
603
- end
604
-
605
- # Define the given class with default parameters
606
- def define_class(name, parameters)
607
- @node.classes[name] = parameters
608
- klass = Puppet::Resource::Type.new(:hostclass, name, :arguments => {'p1' => @ast_obj, 'p2' => @ast_obj})
609
- @compiler.topscope.known_resource_types.add klass
610
- end
611
-
612
- def compile
613
- @catalog = @compiler.compile
614
- end
615
-
616
- it "should record which classes are evaluated" do
617
- classes = {'foo'=>{}, 'bar::foo'=>{}, 'bar'=>{}}
618
- classes.each { |c, params| define_class(c, params) }
619
- compile()
620
- classes.each { |name, p| expect(@catalog.classes).to include(name) }
621
- end
622
-
623
- it "should provide default values for parameters that have no values specified" do
624
- define_class('foo', {})
625
- compile()
626
- expect(@catalog.resource(:class, 'foo')['p1']).to eq("foo")
627
- end
628
-
629
- it "should use any provided values" do
630
- define_class('foo', {'p1' => 'real_value'})
631
- compile()
632
- expect(@catalog.resource(:class, 'foo')['p1']).to eq("real_value")
633
- end
634
-
635
- it "should support providing some but not all values" do
636
- define_class('foo', {'p1' => 'real_value'})
637
- compile()
638
- expect(@catalog.resource(:class, 'Foo')['p1']).to eq("real_value")
639
- expect(@catalog.resource(:class, 'Foo')['p2']).to eq("foo")
640
- end
641
-
642
- it "should ensure each node class is in catalog and has appropriate tags" do
643
- klasses = ['bar::foo']
644
- @node.classes = klasses
645
- ast_obj = Puppet::Parser::AST::Leaf.new(:value => 'foo')
646
- klasses.each do |name|
647
- klass = Puppet::Resource::Type.new(:hostclass, name, :arguments => {'p1' => ast_obj, 'p2' => ast_obj})
648
- @compiler.topscope.known_resource_types.add klass
649
- end
650
- catalog = @compiler.compile
651
-
652
- r2 = catalog.resources.detect {|r| r.title == 'Bar::Foo' }
653
- expect(r2.tags).to eq(Puppet::Util::TagSet.new(['bar::foo', 'class', 'bar', 'foo']))
654
- end
655
- end
656
-
657
- it "should fail if required parameters are missing" do
658
- klass = {'foo'=>{'a'=>'one'}}
659
- @node.classes = klass
660
- klass = Puppet::Resource::Type.new(:hostclass, 'foo', :arguments => {'a' => nil, 'b' => nil})
661
- @compiler.topscope.known_resource_types.add klass
662
- expect { @compiler.compile }.to raise_error(Puppet::PreformattedError, /Class\[Foo\]: expects a value for parameter 'b'/)
663
- end
664
-
665
- it "should fail if invalid parameters are passed" do
666
- klass = {'foo'=>{'3'=>'one'}}
667
- @node.classes = klass
668
- klass = Puppet::Resource::Type.new(:hostclass, 'foo', :arguments => {})
669
- @compiler.topscope.known_resource_types.add klass
670
- expect { @compiler.compile }.to raise_error(Puppet::PreformattedError, /Class\[Foo\]: has no parameter named '3'/)
671
- end
672
-
673
- it "should ensure class is in catalog without params" do
674
- @node.classes = klasses = {'foo'=>nil}
675
- foo = Puppet::Resource::Type.new(:hostclass, 'foo')
676
- @compiler.topscope.known_resource_types.add foo
677
- catalog = @compiler.compile
678
- expect(catalog.classes).to include 'foo'
679
- end
680
-
681
- it "should not evaluate the resources created for found classes unless asked" do
682
- @compiler.catalog.stubs(:tag)
683
-
684
- @resource.expects(:evaluate).never
685
-
686
- @class.expects(:ensure_in_catalog).returns(@resource)
687
- @scope.stubs(:class_scope).with(@class)
688
-
689
- @compiler.evaluate_classes(%w{myclass}, @scope)
690
- end
691
-
692
- it "should immediately evaluate the resources created for found classes when asked" do
693
- @compiler.catalog.stubs(:tag)
694
-
695
- @resource.expects(:evaluate)
696
- @class.expects(:ensure_in_catalog).returns(@resource)
697
- @scope.stubs(:class_scope).with(@class)
698
-
699
- @compiler.evaluate_classes(%w{myclass}, @scope, false)
700
- end
701
-
702
- it "should skip classes that have already been evaluated" do
703
- @compiler.catalog.stubs(:tag)
704
-
705
- @scope.stubs(:class_scope).with(@class).returns(@scope)
706
-
707
- @compiler.expects(:add_resource).never
708
-
709
- @resource.expects(:evaluate).never
710
-
711
- Puppet::Parser::Resource.expects(:new).never
712
- @compiler.evaluate_classes(%w{myclass}, @scope, false)
713
- end
714
-
715
- it "should skip classes previously evaluated with different capitalization" do
716
- @compiler.catalog.stubs(:tag)
717
- @scope.stubs(:find_hostclass).with("MyClass").returns(@class)
718
- @scope.stubs(:class_scope).with(@class).returns(@scope)
719
- @compiler.expects(:add_resource).never
720
- @resource.expects(:evaluate).never
721
- Puppet::Parser::Resource.expects(:new).never
722
- @compiler.evaluate_classes(%w{MyClass}, @scope, false)
723
- end
724
- end
725
-
726
- describe "when evaluating AST nodes with no AST nodes present" do
727
-
728
- it "should do nothing" do
729
- @compiler.expects(:ast_nodes?).returns(false)
730
- @compiler.known_resource_types.expects(:nodes).never
731
- Puppet::Parser::Resource.expects(:new).never
732
-
733
- @compiler.send(:evaluate_ast_node)
734
- end
735
- end
736
-
737
- describe "when evaluating AST nodes with AST nodes present" do
738
-
739
- before do
740
- @compiler.known_resource_types.stubs(:nodes?).returns true
741
-
742
- # Set some names for our test
743
- @node.stubs(:names).returns(%w{a b c})
744
- @compiler.known_resource_types.stubs(:node).with("a").returns(nil)
745
- @compiler.known_resource_types.stubs(:node).with("b").returns(nil)
746
- @compiler.known_resource_types.stubs(:node).with("c").returns(nil)
747
-
748
- # It should check this last, of course.
749
- @compiler.known_resource_types.stubs(:node).with("default").returns(nil)
750
- end
751
-
752
- it "should fail if the named node cannot be found" do
753
- expect { @compiler.send(:evaluate_ast_node) }.to raise_error(Puppet::ParseError)
754
- end
755
-
756
- it "should evaluate the first node class matching the node name" do
757
- node_class = stub 'node', :name => "c", :evaluate_code => nil
758
- @compiler.known_resource_types.stubs(:node).with("c").returns(node_class)
759
-
760
- node_resource = stub 'node resource', :ref => "Node[c]", :evaluate => nil, :type => "node"
761
- node_class.expects(:ensure_in_catalog).returns(node_resource)
762
-
763
- @compiler.compile
764
- end
765
-
766
- it "should match the default node if no matching node can be found" do
767
- node_class = stub 'node', :name => "default", :evaluate_code => nil
768
- @compiler.known_resource_types.stubs(:node).with("default").returns(node_class)
769
-
770
- node_resource = stub 'node resource', :ref => "Node[default]", :evaluate => nil, :type => "node"
771
- node_class.expects(:ensure_in_catalog).returns(node_resource)
772
-
773
- @compiler.compile
774
- end
775
-
776
- it "should evaluate the node resource immediately rather than using lazy evaluation" do
777
- node_class = stub 'node', :name => "c"
778
- @compiler.known_resource_types.stubs(:node).with("c").returns(node_class)
779
-
780
- node_resource = stub 'node resource', :ref => "Node[c]", :type => "node"
781
- node_class.expects(:ensure_in_catalog).returns(node_resource)
782
-
783
- node_resource.expects(:evaluate)
784
-
785
- @compiler.send(:evaluate_ast_node)
786
- end
787
- end
788
-
789
116
  describe "when evaluating node classes" do
790
117
  include PuppetSpec::Compiler
791
118
 
792
- describe "when provided classes in array format" do
793
- let(:node) { Puppet::Node.new('someone', :classes => ['something']) }
794
-
795
- describe "when the class exists" do
796
- it "should succeed if the class is already included" do
797
- manifest = <<-MANIFEST
798
- class something {}
799
- include something
800
- MANIFEST
801
-
802
- catalog = compile_to_catalog(manifest, node)
803
-
804
- expect(catalog.resource('Class', 'Something')).not_to be_nil
805
- end
806
-
807
- it "should evaluate the class without parameters if it's not already included" do
808
- manifest = "class something {}"
809
-
810
- catalog = compile_to_catalog(manifest, node)
811
-
812
- expect(catalog.resource('Class', 'Something')).not_to be_nil
813
- end
814
- end
815
-
816
- it "should fail if the class doesn't exist" do
817
- expect { compile_to_catalog('', node) }.to raise_error(Puppet::Error, /Could not find class something/)
818
- end
819
- end
820
-
821
119
  describe "when provided classes in hash format" do
822
- describe "for classes without parameters" do
823
- let(:node) { Puppet::Node.new('someone', :classes => {'something' => {}}) }
824
-
825
- describe "when the class exists" do
826
- it "should succeed if the class is already included" do
827
- manifest = <<-MANIFEST
828
- class something {}
829
- include something
830
- MANIFEST
831
-
832
- catalog = compile_to_catalog(manifest, node)
833
-
834
- expect(catalog.resource('Class', 'Something')).not_to be_nil
835
- end
836
-
837
- it "should evaluate the class if it's not already included" do
838
- manifest = <<-MANIFEST
839
- class something {}
840
- MANIFEST
841
-
842
- catalog = compile_to_catalog(manifest, node)
843
-
844
- expect(catalog.resource('Class', 'Something')).not_to be_nil
845
- end
846
- end
847
-
848
- it "should fail if the class doesn't exist" do
849
- expect { compile_to_catalog('', node) }.to raise_error(Puppet::Error, /Could not find class something/)
850
- end
851
- end
852
-
853
- describe "for classes with parameters" do
854
- let(:node) { Puppet::Node.new('someone', :classes => {'something' => {'configuron' => 'defrabulated'}}) }
855
-
856
- describe "when the class exists" do
857
- it "should fail if the class is already included" do
858
- manifest = <<-MANIFEST
859
- class something($configuron=frabulated) {}
860
- include something
861
- MANIFEST
862
-
863
- expect { compile_to_catalog(manifest, node) }.to raise_error(Puppet::Error, /Class\[Something\] is already declared/)
864
- end
865
-
866
- it "should evaluate the class if it's not already included" do
867
- manifest = <<-MANIFEST
868
- class something($configuron=frabulated) {}
869
- MANIFEST
870
-
871
- catalog = compile_to_catalog(manifest, node)
872
-
873
- resource = catalog.resource('Class', 'Something')
874
- expect(resource['configuron']).to eq('defrabulated')
875
- end
876
- end
877
-
878
- it "should fail if the class doesn't exist" do
879
- expect { compile_to_catalog('', node) }.to raise_error(Puppet::Error, /Could not find class something/)
880
- end
881
-
882
- it 'evaluates classes declared with parameters before unparameterized classes' do
883
- node = Puppet::Node.new('someone', :classes => { 'app::web' => {}, 'app' => { 'port' => 8080 } })
884
- manifest = <<-MANIFEST
885
- class app($port = 80) { }
886
-
887
- class app::web($port = $app::port) inherits app {
888
- notify { expected: message => "$port" }
889
- }
890
- MANIFEST
891
-
892
- catalog = compile_to_catalog(manifest, node)
893
-
894
- expect(catalog).to have_resource("Class[App]").with_parameter(:port, 8080)
895
- expect(catalog).to have_resource("Class[App::Web]")
896
- expect(catalog).to have_resource("Notify[expected]").with_parameter(:message, "8080")
897
- end
898
- end
899
-
900
120
  it 'looks up default parameter values from inherited class (PUP-2532)' do
901
121
  catalog = compile_to_catalog(<<-CODE)
902
122
  class a {
@@ -918,47 +138,6 @@ describe Puppet::Parser::Compiler do
918
138
  end
919
139
  end
920
140
 
921
- describe "when managing resource overrides" do
922
-
923
- before do
924
- @override = stub 'override', :ref => "File[/foo]", :type => "my"
925
- @resource = resource(:file, "/foo")
926
- end
927
-
928
- it "should be able to store overrides" do
929
- expect { @compiler.add_override(@override) }.not_to raise_error
930
- end
931
-
932
- it "should apply overrides to the appropriate resources" do
933
- @compiler.add_resource(@scope, @resource)
934
- @resource.expects(:merge).with(@override)
935
-
936
- @compiler.add_override(@override)
937
-
938
- @compiler.compile
939
- end
940
-
941
- it "should accept overrides before the related resource has been created" do
942
- @resource.expects(:merge).with(@override)
943
-
944
- # First store the override
945
- @compiler.add_override(@override)
946
-
947
- # Then the resource
948
- @compiler.add_resource(@scope, @resource)
949
-
950
- # And compile, so they get resolved
951
- @compiler.compile
952
- end
953
-
954
- it "should fail if the compile is finished and resource overrides have not been applied" do
955
- @compiler.add_override(@override)
956
-
957
- expect { @compiler.compile }.to raise_error Puppet::ParseError, 'Could not find resource(s) File[/foo] for overriding'
958
- end
959
- end
960
-
961
-
962
141
  context "when converting catalog to resource" do
963
142
  it "the same environment is used for compilation as for transformation to resource form" do
964
143
  Puppet[:code] = <<-MANIFEST
@@ -1031,7 +210,7 @@ describe Puppet::Parser::Compiler do
1031
210
  end
1032
211
  end
1033
212
  end
1034
- describe "the compiler when using future parser and evaluator" do
213
+ describe "the compiler when using 4.x language constructs" do
1035
214
  include PuppetSpec::Compiler
1036
215
 
1037
216
  if Puppet.features.microsoft_windows?
@@ -1169,15 +348,77 @@ describe Puppet::Parser::Compiler do
1169
348
  end.to raise_error(/Resource Override can only.*got: Class\[a\].*/)
1170
349
  end
1171
350
 
1172
- describe "when resolving class references" do
351
+ describe 'when resolving class references' do
1173
352
  include Matchers::Resource
353
+
354
+ { 'string' => 'myWay',
355
+ 'class reference' => 'Class["myWay"]',
356
+ 'resource reference' => 'Resource["class", "myWay"]'
357
+ }.each do |label, code|
358
+ it "allows camel cased class name reference in 'include' using a #{label}" do
359
+ catalog = compile_to_catalog(<<-"PP")
360
+ class myWay {
361
+ notify { 'I did it': message => 'my way'}
362
+ }
363
+ include #{code}
364
+ PP
365
+ expect(catalog).to have_resource("Notify[I did it]")
366
+ end
367
+ end
368
+
369
+ describe 'and classname is a Resource Reference and strict == :error' do
370
+ before(:each) do
371
+ Puppet[:strict] = :error
372
+ end
373
+
374
+ it 'is reported as an error' do
375
+ expect {
376
+ compile_to_catalog(<<-PP)
377
+ notice Class[ToothFairy]
378
+ PP
379
+ }.to raise_error(/Illegal Class name in class reference. A TypeReference\['ToothFairy'\]-Type cannot be used where a String is expected/)
380
+ end
381
+ end
382
+
383
+ describe 'and classname is a Resource Reference and strict == :warning' do
384
+ before(:each) do
385
+ Puppet[:strict] = :warning
386
+ end
387
+
388
+ it 'is reported as a deprecation warning' do
389
+ expect {
390
+ compile_to_catalog(<<-PP)
391
+ notice Class[ToothFairy]
392
+ PP
393
+ expect(@logs).to have_matching_log(/Upper cased class-name in a Class\[<class-name>\] is deprecated, class-name should be a lowercase string/)
394
+
395
+ }.to_not raise_error()
396
+ end
397
+ end
398
+
399
+ describe 'and classname is a Resource Reference and strict == :off' do
400
+ before(:each) do
401
+ Puppet[:strict] = :off
402
+ end
403
+
404
+ it 'is not reported' do
405
+ expect {
406
+ compile_to_catalog(<<-PP)
407
+ notice Class[ToothFairy]
408
+ PP
409
+ expect(@logs).to_not have_matching_log(/Warning: Upper cased class-name in a Class\[<class-name>\] is deprecated, class-name should be a lowercase string/)
410
+
411
+ }.to_not raise_error()
412
+ end
413
+ end
414
+
1174
415
  it "should not favor local scope (with class included in topscope)" do
1175
416
  catalog = compile_to_catalog(<<-PP)
1176
417
  class experiment {
1177
418
  class baz {
1178
419
  }
1179
- notify {"x" : require => Class[Baz] }
1180
- notify {"y" : require => Class[Experiment::Baz] }
420
+ notify {"x" : require => Class['baz'] }
421
+ notify {"y" : require => Class['experiment::baz'] }
1181
422
  }
1182
423
  class baz {
1183
424
  }
@@ -1195,8 +436,8 @@ describe Puppet::Parser::Compiler do
1195
436
  class experiment {
1196
437
  class baz {
1197
438
  }
1198
- notify {"x" : require => Class[Baz] }
1199
- notify {"y" : require => Class[Experiment::Baz] }
439
+ notify {"x" : require => Class['baz'] }
440
+ notify {"y" : require => Class['experiment::baz'] }
1200
441
  }
1201
442
  class baz {
1202
443
  }
@@ -1691,17 +932,12 @@ describe Puppet::Parser::Compiler do
1691
932
  expect(catalog).to have_resource("Notify[value second]")
1692
933
  end
1693
934
 
1694
- # Conditinoally left out for Ruby 1.8.x since the Proc created for the expected number of arguments will accept
1695
- # a call with fewer arguments and then pass all arguments to the closure. The closure then receives an argument
1696
- # array of correct size with nil values instead of an array with too few arguments
1697
- unless RUBY_VERSION[0,3] == '1.8'
1698
- it 'denies when missing required arguments' do
1699
- expect do
1700
- compile_to_catalog(<<-MANIFEST)
1701
- with(1) |$x, $y| { }
1702
- MANIFEST
1703
- end.to raise_error(/Parameter \$y is required but no value was given/m)
1704
- end
935
+ it 'denies when missing required arguments' do
936
+ expect do
937
+ compile_to_catalog(<<-MANIFEST)
938
+ with(1) |$x, $y| { }
939
+ MANIFEST
940
+ end.to raise_error(/Parameter \$y is required but no value was given/m)
1705
941
  end
1706
942
 
1707
943
  it 'accepts anything when parameters are untyped' do