puppet 5.5.16-x64-mingw32 → 5.5.21-x64-mingw32

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 (359) hide show
  1. checksums.yaml +4 -4
  2. data/CODEOWNERS +10 -10
  3. data/Gemfile +2 -3
  4. data/Gemfile.lock +57 -52
  5. data/ext/build_defaults.yaml +1 -0
  6. data/ext/cert_inspector +3 -3
  7. data/ext/project_data.yaml +2 -2
  8. data/ext/puppet-test +2 -2
  9. data/ext/regexp_nodes/regexp_nodes.rb +4 -4
  10. data/ext/windows/service/daemon.rb +54 -8
  11. data/install.rb +6 -24
  12. data/lib/puppet.rb +5 -2
  13. data/lib/puppet/agent.rb +5 -13
  14. data/lib/puppet/application.rb +1 -1
  15. data/lib/puppet/application/agent.rb +15 -1
  16. data/lib/puppet/application/apply.rb +2 -2
  17. data/lib/puppet/application/describe.rb +3 -9
  18. data/lib/puppet/application/device.rb +4 -4
  19. data/lib/puppet/application/doc.rb +1 -1
  20. data/lib/puppet/application/filebucket.rb +13 -0
  21. data/lib/puppet/application/lookup.rb +1 -1
  22. data/lib/puppet/application/resource.rb +4 -4
  23. data/lib/puppet/application/script.rb +2 -2
  24. data/lib/puppet/configurer.rb +86 -28
  25. data/lib/puppet/configurer/downloader.rb +2 -6
  26. data/lib/puppet/daemon.rb +1 -1
  27. data/lib/puppet/defaults.rb +82 -38
  28. data/lib/puppet/error.rb +9 -1
  29. data/lib/puppet/external/nagios/base.rb +1 -1
  30. data/lib/puppet/face/ca.rb +1 -1
  31. data/lib/puppet/face/config.rb +10 -48
  32. data/lib/puppet/face/facts.rb +1 -1
  33. data/lib/puppet/face/module/list.rb +5 -5
  34. data/lib/puppet/face/module/search.rb +1 -1
  35. data/lib/puppet/face/module/uninstall.rb +1 -1
  36. data/lib/puppet/face/module/upgrade.rb +1 -1
  37. data/lib/puppet/face/plugin.rb +9 -2
  38. data/lib/puppet/file_serving/http_metadata.rb +1 -1
  39. data/lib/puppet/file_system.rb +0 -8
  40. data/lib/puppet/file_system/memory_file.rb +1 -1
  41. data/lib/puppet/file_system/posix.rb +3 -2
  42. data/lib/puppet/file_system/uniquefile.rb +4 -0
  43. data/lib/puppet/forge.rb +3 -3
  44. data/lib/puppet/functions/epp.rb +4 -4
  45. data/lib/puppet/functions/inline_epp.rb +5 -5
  46. data/lib/puppet/functions/reduce.rb +2 -4
  47. data/lib/puppet/gettext/module_translations.rb +1 -1
  48. data/lib/puppet/graph/rb_tree_map.rb +2 -2
  49. data/lib/puppet/graph/simple_graph.rb +6 -5
  50. data/lib/puppet/indirector/catalog/compiler.rb +8 -0
  51. data/lib/puppet/indirector/file_bucket_file/file.rb +1 -1
  52. data/lib/puppet/indirector/hiera.rb +2 -0
  53. data/lib/puppet/indirector/resource/ral.rb +1 -3
  54. data/lib/puppet/indirector/resource/validator.rb +1 -1
  55. data/lib/puppet/interface.rb +2 -1
  56. data/lib/puppet/loaders.rb +0 -1
  57. data/lib/puppet/metatype/manager.rb +1 -1
  58. data/lib/puppet/module.rb +1 -1
  59. data/lib/puppet/module_tool/applications/builder.rb +1 -1
  60. data/lib/puppet/module_tool/applications/installer.rb +1 -1
  61. data/lib/puppet/module_tool/applications/uninstaller.rb +3 -3
  62. data/lib/puppet/module_tool/metadata.rb +1 -1
  63. data/lib/puppet/module_tool/shared_behaviors.rb +4 -4
  64. data/lib/puppet/module_tool/tar/mini.rb +12 -2
  65. data/lib/puppet/network/http/api/indirected_routes.rb +13 -12
  66. data/lib/puppet/network/http/api/master/v3/environment.rb +3 -0
  67. data/lib/puppet/network/http/connection.rb +14 -12
  68. data/lib/puppet/network/http/factory.rb +1 -11
  69. data/lib/puppet/network/http/pool.rb +7 -1
  70. data/lib/puppet/network/http/rack/rest.rb +2 -2
  71. data/lib/puppet/network/http/site.rb +1 -1
  72. data/lib/puppet/network/resolver.rb +2 -2
  73. data/lib/puppet/node/environment.rb +4 -2
  74. data/lib/puppet/parameter.rb +8 -0
  75. data/lib/puppet/parser/ast.rb +1 -1
  76. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  77. data/lib/puppet/parser/compiler/catalog_validator/env_relationship_validator.rb +2 -0
  78. data/lib/puppet/parser/compiler/catalog_validator/site_validator.rb +2 -0
  79. data/lib/puppet/parser/environment_compiler.rb +3 -0
  80. data/lib/puppet/parser/functions.rb +1 -1
  81. data/lib/puppet/parser/functions/epp.rb +3 -3
  82. data/lib/puppet/parser/functions/inline_epp.rb +5 -5
  83. data/lib/puppet/parser/resource.rb +3 -2
  84. data/lib/puppet/parser/resource/param.rb +6 -0
  85. data/lib/puppet/pops/evaluator/access_operator.rb +2 -2
  86. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +1 -1
  87. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +1 -1
  88. data/lib/puppet/pops/evaluator/evaluator_impl.rb +1 -1
  89. data/lib/puppet/pops/evaluator/external_syntax_support.rb +3 -2
  90. data/lib/puppet/pops/evaluator/runtime3_support.rb +4 -4
  91. data/lib/puppet/pops/issues.rb +5 -0
  92. data/lib/puppet/pops/loaders.rb +1 -1
  93. data/lib/puppet/pops/lookup/hiera_config.rb +1 -0
  94. data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
  95. data/lib/puppet/pops/merge_strategy.rb +22 -18
  96. data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  97. data/lib/puppet/pops/parser/interpolation_support.rb +4 -4
  98. data/lib/puppet/pops/parser/locator.rb +1 -1
  99. data/lib/puppet/pops/parser/pn_parser.rb +17 -16
  100. data/lib/puppet/pops/puppet_stack.rb +51 -48
  101. data/lib/puppet/pops/resource/resource_type_impl.rb +2 -0
  102. data/lib/puppet/pops/types/p_sensitive_type.rb +1 -1
  103. data/lib/puppet/pops/types/string_converter.rb +10 -10
  104. data/lib/puppet/pops/types/type_calculator.rb +24 -0
  105. data/lib/puppet/pops/types/types.rb +3 -3
  106. data/lib/puppet/pops/validation/checker4_0.rb +10 -0
  107. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  108. data/lib/puppet/property.rb +1 -1
  109. data/lib/puppet/property/ensure.rb +1 -1
  110. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  111. data/lib/puppet/provider/cron/crontab.rb +1 -1
  112. data/lib/puppet/provider/exec.rb +6 -2
  113. data/lib/puppet/provider/file/posix.rb +5 -0
  114. data/lib/puppet/provider/group/groupadd.rb +19 -19
  115. data/lib/puppet/provider/group/windows_adsi.rb +3 -3
  116. data/lib/puppet/provider/mailalias/aliases.rb +1 -1
  117. data/lib/puppet/provider/mount.rb +1 -1
  118. data/lib/puppet/provider/mount/parsed.rb +8 -8
  119. data/lib/puppet/provider/nameservice.rb +10 -3
  120. data/lib/puppet/provider/nameservice/directoryservice.rb +1 -1
  121. data/lib/puppet/provider/nameservice/pw.rb +2 -2
  122. data/lib/puppet/provider/package/aix.rb +17 -2
  123. data/lib/puppet/provider/package/apt.rb +14 -3
  124. data/lib/puppet/provider/package/dnf.rb +1 -1
  125. data/lib/puppet/provider/package/dnfmodule.rb +141 -0
  126. data/lib/puppet/provider/package/dpkg.rb +16 -18
  127. data/lib/puppet/provider/package/fink.rb +20 -3
  128. data/lib/puppet/provider/package/openbsd.rb +14 -2
  129. data/lib/puppet/provider/package/pip.rb +37 -10
  130. data/lib/puppet/provider/package/pkg.rb +18 -5
  131. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  132. data/lib/puppet/provider/package/pkgng.rb +16 -4
  133. data/lib/puppet/provider/package/portage.rb +4 -4
  134. data/lib/puppet/provider/package/rpm.rb +57 -19
  135. data/lib/puppet/provider/package/windows/package.rb +1 -1
  136. data/lib/puppet/provider/package/yum.rb +35 -24
  137. data/lib/puppet/provider/package/zypper.rb +1 -0
  138. data/lib/puppet/provider/package_targetable.rb +5 -4
  139. data/lib/puppet/provider/parsedfile.rb +1 -1
  140. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +3 -3
  141. data/lib/puppet/provider/selmodule/semodule.rb +43 -26
  142. data/lib/puppet/provider/service/daemontools.rb +9 -9
  143. data/lib/puppet/provider/service/launchd.rb +20 -5
  144. data/lib/puppet/provider/service/openbsd.rb +1 -1
  145. data/lib/puppet/provider/service/rcng.rb +2 -2
  146. data/lib/puppet/provider/service/runit.rb +2 -8
  147. data/lib/puppet/provider/service/systemd.rb +35 -22
  148. data/lib/puppet/provider/service/windows.rb +8 -0
  149. data/lib/puppet/provider/user/directoryservice.rb +31 -6
  150. data/lib/puppet/provider/user/hpux.rb +1 -1
  151. data/lib/puppet/provider/user/pw.rb +12 -3
  152. data/lib/puppet/provider/user/user_role_add.rb +5 -1
  153. data/lib/puppet/provider/user/useradd.rb +62 -27
  154. data/lib/puppet/provider/user/windows_adsi.rb +4 -5
  155. data/lib/puppet/provider/yumrepo/inifile.rb +2 -2
  156. data/lib/puppet/reference/indirection.rb +2 -2
  157. data/lib/puppet/reference/metaparameter.rb +1 -3
  158. data/lib/puppet/reference/providers.rb +1 -1
  159. data/lib/puppet/reference/type.rb +3 -9
  160. data/lib/puppet/reports.rb +1 -1
  161. data/lib/puppet/resource.rb +18 -1
  162. data/lib/puppet/resource/catalog.rb +1 -1
  163. data/lib/puppet/resource/type.rb +8 -0
  164. data/lib/puppet/settings.rb +43 -3
  165. data/lib/puppet/settings/environment_conf.rb +1 -0
  166. data/lib/puppet/ssl/certificate.rb +2 -1
  167. data/lib/puppet/ssl/certificate_authority.rb +6 -5
  168. data/lib/puppet/ssl/certificate_authority/interface.rb +1 -1
  169. data/lib/puppet/ssl/certificate_factory.rb +2 -2
  170. data/lib/puppet/ssl/host.rb +3 -3
  171. data/lib/puppet/ssl/oids.rb +1 -1
  172. data/lib/puppet/test/test_helper.rb +15 -10
  173. data/lib/puppet/transaction/report.rb +1 -1
  174. data/lib/puppet/transaction/resource_harness.rb +1 -1
  175. data/lib/puppet/type.rb +15 -4
  176. data/lib/puppet/type/cron.rb +1 -1
  177. data/lib/puppet/type/exec.rb +21 -9
  178. data/lib/puppet/type/file.rb +14 -2
  179. data/lib/puppet/type/file/data_sync.rb +5 -1
  180. data/lib/puppet/type/group.rb +4 -2
  181. data/lib/puppet/type/interface.rb +1 -1
  182. data/lib/puppet/type/notify.rb +3 -2
  183. data/lib/puppet/type/package.rb +107 -8
  184. data/lib/puppet/type/schedule.rb +1 -1
  185. data/lib/puppet/type/selboolean.rb +17 -3
  186. data/lib/puppet/type/service.rb +9 -10
  187. data/lib/puppet/type/user.rb +6 -24
  188. data/lib/puppet/type/yumrepo.rb +3 -7
  189. data/lib/puppet/util.rb +47 -25
  190. data/lib/puppet/util/command_line/trollop.rb +1 -1
  191. data/lib/puppet/util/execution.rb +4 -3
  192. data/lib/puppet/util/http_proxy.rb +24 -16
  193. data/lib/puppet/util/instance_loader.rb +1 -1
  194. data/lib/puppet/util/log.rb +1 -1
  195. data/lib/puppet/util/log/destinations.rb +3 -12
  196. data/lib/puppet/util/logging.rb +30 -18
  197. data/lib/puppet/util/metric.rb +2 -2
  198. data/lib/puppet/util/monkey_patches.rb +1 -1
  199. data/lib/puppet/util/nagios_maker.rb +2 -2
  200. data/lib/puppet/util/network_device/cisco/device.rb +1 -1
  201. data/lib/puppet/util/network_device/cisco/interface.rb +2 -2
  202. data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
  203. data/lib/puppet/util/pidlock.rb +12 -6
  204. data/lib/puppet/util/plist.rb +6 -0
  205. data/lib/puppet/util/provider_features.rb +2 -4
  206. data/lib/puppet/util/rdoc.rb +1 -1
  207. data/lib/puppet/util/reference.rb +1 -1
  208. data/lib/puppet/util/resource_template.rb +1 -1
  209. data/lib/puppet/util/selinux.rb +8 -2
  210. data/lib/puppet/util/windows/adsi.rb +60 -30
  211. data/lib/puppet/util/windows/api_types.rb +45 -32
  212. data/lib/puppet/util/windows/eventlog.rb +1 -6
  213. data/lib/puppet/util/windows/principal.rb +8 -6
  214. data/lib/puppet/util/windows/process.rb +16 -15
  215. data/lib/puppet/util/windows/registry.rb +17 -15
  216. data/lib/puppet/util/windows/security.rb +3 -0
  217. data/lib/puppet/util/windows/service.rb +149 -4
  218. data/lib/puppet/util/windows/sid.rb +4 -3
  219. data/lib/puppet/vendor.rb +1 -1
  220. data/lib/puppet/version.rb +1 -1
  221. data/lib/puppet_pal.rb +2 -2
  222. data/locales/puppet.pot +479 -443
  223. data/man/man5/puppet.conf.5 +38 -8
  224. data/man/man8/puppet-agent.8 +2 -2
  225. data/man/man8/puppet-apply.8 +1 -1
  226. data/man/man8/puppet-ca.8 +1 -1
  227. data/man/man8/puppet-catalog.8 +1 -1
  228. data/man/man8/puppet-cert.8 +1 -1
  229. data/man/man8/puppet-certificate.8 +1 -1
  230. data/man/man8/puppet-certificate_request.8 +1 -1
  231. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  232. data/man/man8/puppet-config.8 +1 -1
  233. data/man/man8/puppet-describe.8 +1 -1
  234. data/man/man8/puppet-device.8 +1 -1
  235. data/man/man8/puppet-doc.8 +1 -1
  236. data/man/man8/puppet-epp.8 +1 -1
  237. data/man/man8/puppet-facts.8 +1 -1
  238. data/man/man8/puppet-filebucket.8 +16 -1
  239. data/man/man8/puppet-generate.8 +1 -1
  240. data/man/man8/puppet-help.8 +1 -1
  241. data/man/man8/puppet-key.8 +1 -1
  242. data/man/man8/puppet-lookup.8 +1 -1
  243. data/man/man8/puppet-man.8 +1 -1
  244. data/man/man8/puppet-master.8 +1 -1
  245. data/man/man8/puppet-module.8 +1 -1
  246. data/man/man8/puppet-node.8 +1 -1
  247. data/man/man8/puppet-parser.8 +1 -1
  248. data/man/man8/puppet-plugin.8 +1 -1
  249. data/man/man8/puppet-report.8 +1 -1
  250. data/man/man8/puppet-resource.8 +1 -1
  251. data/man/man8/puppet-script.8 +1 -1
  252. data/man/man8/puppet-status.8 +1 -1
  253. data/man/man8/puppet.8 +2 -2
  254. data/spec/fixtures/integration/provider/mailalias/aliases/test1 +1 -0
  255. data/spec/fixtures/unit/provider/package/dnfmodule/dnf-module-list.txt +19 -0
  256. data/spec/fixtures/unit/provider/package/pkgng/pkg.version +2 -0
  257. data/spec/fixtures/unit/provider/package/yum/yum-check-update-subscription-manager.txt +9 -0
  258. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services +9 -0
  259. data/spec/integration/configurer_spec.rb +52 -0
  260. data/spec/integration/defaults_spec.rb +1 -2
  261. data/spec/integration/indirector/facts/facter_spec.rb +4 -0
  262. data/spec/integration/parser/compiler_spec.rb +11 -0
  263. data/spec/integration/provider/service/systemd_spec.rb +8 -5
  264. data/spec/integration/type/file_spec.rb +28 -0
  265. data/spec/integration/type/notify_spec.rb +46 -0
  266. data/spec/integration/util/execution_spec.rb +27 -0
  267. data/spec/integration/util/windows/adsi_spec.rb +6 -1
  268. data/spec/integration/util/windows/registry_spec.rb +7 -7
  269. data/spec/unit/agent_spec.rb +34 -26
  270. data/spec/unit/application/agent_spec.rb +18 -0
  271. data/spec/unit/application/apply_spec.rb +2 -12
  272. data/spec/unit/application/device_spec.rb +1 -1
  273. data/spec/unit/configurer/fact_handler_spec.rb +0 -4
  274. data/spec/unit/configurer_spec.rb +377 -397
  275. data/spec/unit/daemon_spec.rb +0 -1
  276. data/spec/unit/face/facts_spec.rb +9 -0
  277. data/spec/unit/face/plugin_spec.rb +8 -0
  278. data/spec/unit/file_system/uniquefile_spec.rb +11 -0
  279. data/spec/unit/forge/forge_spec.rb +1 -3
  280. data/spec/unit/forge/repository_spec.rb +1 -3
  281. data/spec/unit/indirector/catalog/compiler_spec.rb +45 -26
  282. data/spec/unit/indirector/resource/ral_spec.rb +4 -4
  283. data/spec/unit/module_tool/tar/mini_spec.rb +1 -1
  284. data/spec/unit/network/http/api/indirected_routes_spec.rb +28 -11
  285. data/spec/unit/network/http/connection_spec.rb +43 -1
  286. data/spec/unit/network/http/factory_spec.rb +27 -5
  287. data/spec/unit/network/http/pool_spec.rb +32 -0
  288. data/spec/unit/node_spec.rb +7 -4
  289. data/spec/unit/parser/environment_compiler_spec.rb +7 -0
  290. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +8 -3
  291. data/spec/unit/pops/validator/validator_spec.rb +7 -0
  292. data/spec/unit/provider/exec_spec.rb +209 -0
  293. data/spec/unit/provider/group/groupadd_spec.rb +30 -1
  294. data/spec/unit/provider/group/windows_adsi_spec.rb +43 -10
  295. data/spec/unit/provider/package/aix_spec.rb +29 -0
  296. data/spec/unit/provider/package/apt_spec.rb +13 -2
  297. data/spec/unit/provider/package/aptitude_spec.rb +1 -0
  298. data/spec/unit/provider/package/aptrpm_spec.rb +1 -1
  299. data/spec/unit/provider/package/dnf_spec.rb +7 -0
  300. data/spec/unit/provider/package/dnfmodule_spec.rb +247 -0
  301. data/spec/unit/provider/package/dpkg_spec.rb +35 -7
  302. data/spec/unit/provider/package/openbsd_spec.rb +17 -0
  303. data/spec/unit/provider/package/pip_spec.rb +93 -22
  304. data/spec/unit/provider/package/pkg_spec.rb +13 -1
  305. data/spec/unit/provider/package/pkgdmg_spec.rb +1 -1
  306. data/spec/unit/provider/package/pkgng_spec.rb +36 -0
  307. data/spec/unit/provider/package/portage_spec.rb +4 -4
  308. data/spec/unit/provider/package/rpm_spec.rb +150 -16
  309. data/spec/unit/provider/package/yum_spec.rb +66 -0
  310. data/spec/unit/provider/package/zypper_spec.rb +13 -0
  311. data/spec/unit/provider/package_targetable_spec.rb +60 -0
  312. data/spec/unit/provider/selmodule_spec.rb +118 -47
  313. data/spec/unit/provider/service/daemontools_spec.rb +24 -0
  314. data/spec/unit/provider/service/launchd_spec.rb +28 -0
  315. data/spec/unit/provider/service/runit_spec.rb +24 -0
  316. data/spec/unit/provider/service/systemd_spec.rb +109 -36
  317. data/spec/unit/provider/service/windows_spec.rb +20 -0
  318. data/spec/unit/provider/user/directoryservice_spec.rb +41 -0
  319. data/spec/unit/provider/user/hpux_spec.rb +2 -2
  320. data/spec/unit/provider/user/openbsd_spec.rb +1 -0
  321. data/spec/unit/provider/user/pw_spec.rb +37 -0
  322. data/spec/unit/provider/user/useradd_spec.rb +122 -15
  323. data/spec/unit/provider/user/windows_adsi_spec.rb +3 -3
  324. data/spec/unit/puppet_pal_2pec.rb +3 -0
  325. data/spec/unit/resource_spec.rb +26 -1
  326. data/spec/unit/ssl/certificate_authority_spec.rb +2 -3
  327. data/spec/unit/ssl/certificate_spec.rb +7 -0
  328. data/spec/unit/test/test_helper_spec.rb +17 -0
  329. data/spec/unit/transaction_spec.rb +18 -0
  330. data/spec/unit/type/exec_spec.rb +15 -12
  331. data/spec/unit/type/file/content_spec.rb +9 -3
  332. data/spec/unit/type/file/source_spec.rb +4 -4
  333. data/spec/unit/type/file_spec.rb +9 -4
  334. data/spec/unit/type/package_spec.rb +8 -0
  335. data/spec/unit/type/schedule_spec.rb +3 -1
  336. data/spec/unit/type/selboolean_spec.rb +4 -6
  337. data/spec/unit/type/service_spec.rb +25 -8
  338. data/spec/unit/type/user_spec.rb +32 -26
  339. data/spec/unit/type/yumrepo_spec.rb +30 -0
  340. data/spec/unit/type_spec.rb +40 -0
  341. data/spec/unit/util/execution_spec.rb +16 -0
  342. data/spec/unit/util/http_proxy_spec.rb +121 -1
  343. data/spec/unit/util/log/destinations_spec.rb +2 -26
  344. data/spec/unit/util/log_spec.rb +0 -112
  345. data/spec/unit/util/logging_spec.rb +200 -0
  346. data/spec/unit/util/pidlock_spec.rb +67 -40
  347. data/spec/unit/util/plist_spec.rb +20 -0
  348. data/spec/unit/util/windows/adsi_spec.rb +55 -4
  349. data/spec/unit/util/windows/api_types_spec.rb +104 -40
  350. data/spec/unit/util/windows/service_spec.rb +9 -0
  351. data/spec/unit/util/windows/sid_spec.rb +2 -2
  352. data/tasks/manpages.rake +1 -0
  353. metadata +18 -13
  354. data/ext/windows/eventlog/Rakefile +0 -32
  355. data/ext/windows/eventlog/puppetres.dll +0 -0
  356. data/ext/windows/eventlog/puppetres.mc +0 -18
  357. data/lib/puppet/pops/loader/null_loader.rb +0 -60
  358. data/locales/ja/puppet.po +0 -12114
  359. data/spec/integration/test/test_helper_spec.rb +0 -31
@@ -590,6 +590,24 @@ describe Puppet::Application::Agent do
590
590
  end
591
591
  end
592
592
 
593
+ describe "when starting in daemon mode on non-windows", :unless => Puppet.features.microsoft_windows? do
594
+ before :each do
595
+ allow(Puppet).to receive(:notice)
596
+ Puppet[:daemonize] = true
597
+ end
598
+
599
+ it "should not print config in default mode" do
600
+ execute_agent
601
+ expect(@logs).to be_empty
602
+ end
603
+
604
+ it "should print config in debug mode" do
605
+ @puppetd.options[:debug] = true
606
+ execute_agent
607
+ expect(@logs).to include(an_object_having_attributes(level: :debug, message: /agent_catalog_run_lockfile=/))
608
+ end
609
+ end
610
+
593
611
  def execute_agent
594
612
  @puppetd.setup
595
613
  @puppetd.run_command
@@ -14,14 +14,6 @@ describe Puppet::Application::Apply do
14
14
  Puppet[:reports] = "none"
15
15
  end
16
16
 
17
- after :each do
18
- Puppet::Node::Facts.indirection.reset_terminus_class
19
- Puppet::Node::Facts.indirection.cache_class = nil
20
-
21
- Puppet::Node.indirection.reset_terminus_class
22
- Puppet::Node.indirection.cache_class = nil
23
- end
24
-
25
17
  [:debug,:loadclasses,:test,:verbose,:use_nodes,:detailed_exitcodes,:catalog, :write_catalog_summary].each do |option|
26
18
  it "should declare handle_#{option} method" do
27
19
  expect(@apply).to respond_to("handle_#{option}".to_sym)
@@ -182,13 +174,11 @@ describe Puppet::Application::Apply do
182
174
  Puppet[:prerun_command] = ''
183
175
  Puppet[:postrun_command] = ''
184
176
 
185
- Puppet::Node::Facts.indirection.terminus_class = :memory
186
- Puppet::Node::Facts.indirection.cache_class = :memory
187
177
  Puppet::Node.indirection.terminus_class = :memory
188
178
  Puppet::Node.indirection.cache_class = :memory
189
179
 
190
- @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
191
- Puppet::Node::Facts.indirection.save(@facts)
180
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
181
+ Puppet::Node::Facts.indirection.save(facts)
192
182
 
193
183
  @node = Puppet::Node.new(Puppet[:node_name_value])
194
184
  Puppet::Node.indirection.save(@node)
@@ -481,7 +481,7 @@ describe Puppet::Application::Device do
481
481
  allow(@device.options).to receive(:[]).with(:to_yaml).and_return(true)
482
482
  allow(@device.command_line).to receive(:args).and_return(['user'])
483
483
  expect(Puppet::Resource.indirection).to receive(:search).with('user/', {}).and_return(resources)
484
- expect(@device).to receive(:puts).with("user:\n title:\n")
484
+ expect(@device).to receive(:puts).with("---\nuser:\n title: {}\n")
485
485
  expect { @device.main }.to exit_with 0
486
486
  end
487
487
 
@@ -22,10 +22,6 @@ describe Puppet::Configurer::FactHandler do
22
22
 
23
23
  let(:facthandler) { FactHandlerTester.new('production') }
24
24
 
25
- before :each do
26
- Puppet::Node::Facts.indirection.terminus_class = :memory
27
- end
28
-
29
25
  describe "when finding facts" do
30
26
  it "should use the node name value to retrieve the facts" do
31
27
  foo_facts = Puppet::Node::Facts.new('foo')
@@ -1,108 +1,89 @@
1
1
  require 'spec_helper'
2
2
  require 'puppet/configurer'
3
+ require 'webmock/rspec'
3
4
 
4
5
  describe Puppet::Configurer do
5
6
  before do
6
- allow(Puppet.settings).to receive(:use).and_return(true)
7
- @agent = Puppet::Configurer.new
8
- allow(@agent).to receive(:init_storage)
9
- allow(Puppet::Util::Storage).to receive(:store)
10
7
  Puppet[:server] = "puppetmaster"
11
8
  Puppet[:report] = true
12
- end
13
9
 
14
- it "should include the Fact Handler module" do
15
- expect(Puppet::Configurer.ancestors).to be_include(Puppet::Configurer::FactHandler)
10
+ catalog.add_resource(resource)
11
+
12
+ allow(Puppet::SSL::Host).to receive(:localhost).and_return(double('host'))
16
13
  end
17
14
 
15
+ let(:configurer) { Puppet::Configurer.new }
16
+ let(:report) { Puppet::Transaction::Report.new }
17
+ let(:catalog) { Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym)) }
18
+ let(:resource) { Puppet::Resource.new(:notice, 'a') }
19
+ let(:facts) { Puppet::Node::Facts.new(Puppet[:node_name_value]) }
20
+
18
21
  describe "when executing a pre-run hook" do
19
22
  it "should do nothing if the hook is set to an empty string" do
20
23
  Puppet.settings[:prerun_command] = ""
21
- expect(Puppet::Util).not_to receive(:exec)
24
+ expect(Puppet::Util::Execution).not_to receive(:execute)
22
25
 
23
- @agent.execute_prerun_command
26
+ configurer.execute_prerun_command
24
27
  end
25
28
 
26
29
  it "should execute any pre-run command provided via the 'prerun_command' setting" do
27
30
  Puppet.settings[:prerun_command] = "/my/command"
28
31
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
29
32
 
30
- @agent.execute_prerun_command
33
+ configurer.execute_prerun_command
31
34
  end
32
35
 
33
36
  it "should fail if the command fails" do
34
37
  Puppet.settings[:prerun_command] = "/my/command"
35
38
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
36
39
 
37
- expect(@agent.execute_prerun_command).to be_falsey
40
+ expect(configurer.execute_prerun_command).to be_falsey
38
41
  end
39
42
  end
40
43
 
41
44
  describe "when executing a post-run hook" do
42
45
  it "should do nothing if the hook is set to an empty string" do
43
46
  Puppet.settings[:postrun_command] = ""
44
- expect(Puppet::Util).not_to receive(:exec)
47
+ expect(Puppet::Util::Execution).not_to receive(:execute)
45
48
 
46
- @agent.execute_postrun_command
49
+ configurer.execute_postrun_command
47
50
  end
48
51
 
49
52
  it "should execute any post-run command provided via the 'postrun_command' setting" do
50
53
  Puppet.settings[:postrun_command] = "/my/command"
51
54
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
52
55
 
53
- @agent.execute_postrun_command
56
+ configurer.execute_postrun_command
54
57
  end
55
58
 
56
59
  it "should fail if the command fails" do
57
60
  Puppet.settings[:postrun_command] = "/my/command"
58
61
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
59
62
 
60
- expect(@agent.execute_postrun_command).to be_falsey
63
+ expect(configurer.execute_postrun_command).to be_falsey
61
64
  end
62
65
  end
63
66
 
64
67
  describe "when executing a catalog run" do
65
68
  before do
66
- allow(Puppet.settings).to receive(:use).and_return(true)
67
- allow(@agent).to receive(:download_plugins)
68
- Puppet::Node::Facts.indirection.terminus_class = :memory
69
- @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
70
- Puppet::Node::Facts.indirection.save(@facts)
71
-
72
- @catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym))
73
- allow(@catalog).to receive(:to_ral).and_return(@catalog)
74
69
  Puppet::Resource::Catalog.indirection.terminus_class = :rest
75
- allow(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(@catalog)
76
- allow(@agent).to receive(:send_report)
77
- allow(@agent).to receive(:save_last_run_summary)
78
-
79
- allow(Puppet::Util::Log).to receive(:close_all)
80
- end
81
-
82
- after :all do
83
- Puppet::Node::Facts.indirection.reset_terminus_class
84
- Puppet::Resource::Catalog.indirection.reset_terminus_class
85
- end
86
-
87
- it "should initialize storage" do
88
- expect(Puppet::Util::Storage).to receive(:load)
89
- @agent.run
70
+ allow(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(catalog)
90
71
  end
91
72
 
92
73
  it "downloads plugins when told" do
93
- expect(@agent).to receive(:download_plugins)
94
- @agent.run(:pluginsync => true)
74
+ expect(configurer).to receive(:download_plugins)
75
+ configurer.run(:pluginsync => true)
95
76
  end
96
77
 
97
78
  it "does not download plugins when told" do
98
- expect(@agent).not_to receive(:download_plugins)
99
- @agent.run(:pluginsync => false)
79
+ expect(configurer).not_to receive(:download_plugins)
80
+ configurer.run(:pluginsync => false)
100
81
  end
101
82
 
102
83
  it "should carry on when it can't fetch its node definition" do
103
84
  error = Net::HTTPError.new(400, 'dummy server communication error')
104
85
  expect(Puppet::Node.indirection).to receive(:find).and_raise(error)
105
- expect(@agent.run).to eq(0)
86
+ expect(configurer.run).to eq(0)
106
87
  end
107
88
 
108
89
  it "applies a cached catalog when it can't connect to the master" do
@@ -110,200 +91,157 @@ describe Puppet::Configurer do
110
91
 
111
92
  expect(Puppet::Node.indirection).to receive(:find).and_raise(error)
112
93
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_cache => true)).and_raise(error)
113
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_terminus => true)).and_return(@catalog)
94
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_terminus => true)).and_return(catalog)
114
95
 
115
- expect(@agent.run).to eq(0)
96
+ expect(configurer.run).to eq(0)
116
97
  end
117
98
 
118
99
  it "should initialize a transaction report if one is not provided" do
119
- report = Puppet::Transaction::Report.new
120
100
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
121
101
 
122
- @agent.run
102
+ configurer.run
123
103
  end
124
104
 
125
105
  it "should respect node_name_fact when setting the host on a report" do
126
106
  Puppet[:node_name_fact] = 'my_name_fact'
127
- @facts.values = {'my_name_fact' => 'node_name_from_fact'}
107
+ facts.values = {'my_name_fact' => 'node_name_from_fact'}
108
+ Puppet::Node::Facts.indirection.save(facts)
128
109
 
129
- report = Puppet::Transaction::Report.new
130
-
131
- @agent.run(:report => report)
110
+ configurer.run(:report => report)
132
111
  expect(report.host).to eq('node_name_from_fact')
133
112
  end
134
113
 
135
- it "should pass the new report to the catalog" do
136
- report = Puppet::Transaction::Report.new
137
- allow(Puppet::Transaction::Report).to receive(:new).and_return(report)
138
- expect(@catalog).to receive(:apply).with(hash_including(report: report))
139
-
140
- @agent.run
141
- end
142
-
143
- it "should use the provided report if it was passed one" do
144
- report = Puppet::Transaction::Report.new
145
- expect(@catalog).to receive(:apply).with(hash_including(report: report))
146
-
147
- @agent.run(:report => report)
148
- end
149
-
150
- it "should set the report as a log destination" do
151
- report = Puppet::Transaction::Report.new
152
-
153
- expect(report).to receive(:<<).with(instance_of(Puppet::Util::Log)).at_least(:once)
114
+ it "creates a new report when applying the catalog" do
115
+ options = {}
116
+ configurer.run(options)
154
117
 
155
- @agent.run(:report => report)
118
+ expect(options[:report].metrics['time']['catalog_application']).to be_an_instance_of(Float)
156
119
  end
157
120
 
158
- it "should retrieve the catalog" do
159
- expect(@agent).to receive(:retrieve_catalog)
121
+ it "uses the provided report when applying the catalog" do
122
+ configurer.run(:report => report)
160
123
 
161
- @agent.run
124
+ expect(report.metrics['time']['catalog_application']).to be_an_instance_of(Float)
162
125
  end
163
126
 
164
127
  it "should log a failure and do nothing if no catalog can be retrieved" do
165
- expect(@agent).to receive(:retrieve_catalog).and_return(nil)
128
+ expect(configurer).to receive(:retrieve_catalog).and_return(nil)
166
129
 
167
130
  expect(Puppet).to receive(:err).with("Could not retrieve catalog; skipping run")
168
131
 
169
- @agent.run
170
- end
171
-
172
- it "should apply the catalog with all options to :run" do
173
- expect(@agent).to receive(:retrieve_catalog).and_return(@catalog)
174
-
175
- expect(@catalog).to receive(:apply).with(hash_including(one: true))
176
- @agent.run :one => true
132
+ configurer.run
177
133
  end
178
134
 
179
- it "should accept a catalog and use it instead of retrieving a different one" do
180
- expect(@agent).not_to receive(:retrieve_catalog)
135
+ it "passes arbitrary options when applying the catalog" do
136
+ expect(catalog).to receive(:apply).with(hash_including(one: true))
181
137
 
182
- expect(@catalog).to receive(:apply)
183
- @agent.run :one => true, :catalog => @catalog
138
+ configurer.run(catalog: catalog, one: true)
184
139
  end
185
140
 
186
141
  it "should benchmark how long it takes to apply the catalog" do
187
- expect(@agent).to receive(:benchmark).with(:notice, instance_of(String))
188
-
189
- expect(@agent).to receive(:retrieve_catalog).and_return(@catalog)
190
-
191
- expect(@catalog).not_to receive(:apply) # because we're not yielding
192
- @agent.run
193
- end
194
-
195
- it "should execute post-run hooks after the run" do
196
- expect(@agent).to receive(:execute_postrun_command)
142
+ configurer.run(report: report)
197
143
 
198
- @agent.run
144
+ expect(report.logs).to include(an_object_having_attributes(level: :notice, message: /Applied catalog in .* seconds/))
199
145
  end
200
146
 
201
147
  it "should create report with passed transaction_uuid and job_id" do
202
- @agent = Puppet::Configurer.new("test_tuuid", "test_jid")
203
- allow(@agent).to receive(:init_storage)
148
+ configurer = Puppet::Configurer.new("test_tuuid", "test_jid")
204
149
 
205
150
  report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
206
151
  expect(Puppet::Transaction::Report).to receive(:new).with(anything, anything, 'test_tuuid', 'test_jid').and_return(report)
207
- expect(@agent).to receive(:send_report).with(report)
152
+ expect(configurer).to receive(:send_report).with(report)
208
153
 
209
- @agent.run
154
+ configurer.run
210
155
  end
211
156
 
212
157
  it "should send the report" do
213
158
  report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
214
159
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
215
- expect(@agent).to receive(:send_report).with(report)
160
+ expect(configurer).to receive(:send_report).with(report)
216
161
 
217
162
  expect(report.environment).to eq("test")
218
163
  expect(report.transaction_uuid).to eq("aaaa")
219
164
 
220
- @agent.run
165
+ configurer.run
221
166
  end
222
167
 
223
168
  it "should send the transaction report even if the catalog could not be retrieved" do
224
- expect(@agent).to receive(:retrieve_catalog).and_return(nil)
169
+ expect(configurer).to receive(:retrieve_catalog).and_return(nil)
225
170
 
226
171
  report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
227
172
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
228
- expect(@agent).to receive(:send_report).with(report)
173
+ expect(configurer).to receive(:send_report).with(report)
229
174
 
230
175
  expect(report.environment).to eq("test")
231
176
  expect(report.transaction_uuid).to eq("aaaa")
232
177
 
233
- @agent.run
178
+ configurer.run
234
179
  end
235
180
 
236
181
  it "should send the transaction report even if there is a failure" do
237
- expect(@agent).to receive(:retrieve_catalog).and_raise("whatever")
182
+ expect(configurer).to receive(:retrieve_catalog).and_raise("whatever")
238
183
 
239
184
  report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
240
185
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
241
- expect(@agent).to receive(:send_report).with(report)
186
+ expect(configurer).to receive(:send_report).with(report)
242
187
 
243
188
  expect(report.environment).to eq("test")
244
189
  expect(report.transaction_uuid).to eq("aaaa")
245
190
 
246
- expect(@agent.run).to be_nil
191
+ expect(configurer.run).to be_nil
247
192
  end
248
193
 
249
194
  it "should remove the report as a log destination when the run is finished" do
250
- report = Puppet::Transaction::Report.new
251
195
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
252
196
 
253
- @agent.run
197
+ configurer.run
254
198
 
255
199
  expect(Puppet::Util::Log.destinations).not_to include(report)
256
200
  end
257
201
 
258
202
  it "should return the report exit_status as the result of the run" do
259
- report = Puppet::Transaction::Report.new
260
203
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
261
204
  expect(report).to receive(:exit_status).and_return(1234)
262
205
 
263
- expect(@agent.run).to eq(1234)
206
+ expect(configurer.run).to eq(1234)
264
207
  end
265
208
 
266
209
  it "should return nil if catalog application fails" do
267
- expect(@catalog).to receive(:apply).and_raise(Puppet::Error, 'One or more resource dependency cycles detected in graph')
268
- report = Puppet::Transaction::Report.new
269
- expect(@agent.run(catalog: @catalog, report: report)).to be_nil
210
+ expect_any_instance_of(Puppet::Resource::Catalog).to receive(:apply).and_raise(Puppet::Error, 'One or more resource dependency cycles detected in graph')
211
+ expect(configurer.run(catalog: catalog, report: report)).to be_nil
270
212
  end
271
213
 
272
214
  it "should send the transaction report even if the pre-run command fails" do
273
- report = Puppet::Transaction::Report.new
274
215
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
275
216
 
276
217
  Puppet.settings[:prerun_command] = "/my/command"
277
218
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
278
- expect(@agent).to receive(:send_report).with(report)
219
+ expect(configurer).to receive(:send_report).with(report)
279
220
 
280
- expect(@agent.run).to be_nil
221
+ expect(configurer.run).to be_nil
281
222
  end
282
223
 
283
224
  it "should include the pre-run command failure in the report" do
284
- report = Puppet::Transaction::Report.new
285
225
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
286
226
 
287
227
  Puppet.settings[:prerun_command] = "/my/command"
288
228
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
289
229
 
290
- expect(@agent.run).to be_nil
230
+ expect(configurer.run).to be_nil
291
231
  expect(report.logs.find { |x| x.message =~ /Could not run command from prerun_command/ }).to be
292
232
  end
293
233
 
294
234
  it "should send the transaction report even if the post-run command fails" do
295
- report = Puppet::Transaction::Report.new
296
235
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
297
236
 
298
237
  Puppet.settings[:postrun_command] = "/my/command"
299
238
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
300
- expect(@agent).to receive(:send_report).with(report)
239
+ expect(configurer).to receive(:send_report).with(report)
301
240
 
302
- expect(@agent.run).to be_nil
241
+ expect(configurer.run).to be_nil
303
242
  end
304
243
 
305
244
  it "should include the post-run command failure in the report" do
306
- report = Puppet::Transaction::Report.new
307
245
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
308
246
 
309
247
  Puppet.settings[:postrun_command] = "/my/command"
@@ -311,7 +249,7 @@ describe Puppet::Configurer do
311
249
 
312
250
  expect(report).to receive(:<<) { |log, _| expect(log.message).to match(/Could not run command from postrun_command/) }.at_least(:once)
313
251
 
314
- expect(@agent.run).to be_nil
252
+ expect(configurer.run).to be_nil
315
253
  end
316
254
 
317
255
  it "should execute post-run command even if the pre-run command fails" do
@@ -320,47 +258,42 @@ describe Puppet::Configurer do
320
258
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/precommand"]).and_raise(Puppet::ExecutionFailure, "Failed")
321
259
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/postcommand"])
322
260
 
323
- expect(@agent.run).to be_nil
261
+ expect(configurer.run).to be_nil
324
262
  end
325
263
 
326
264
  it "should finalize the report" do
327
- report = Puppet::Transaction::Report.new
328
265
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
329
266
 
330
267
  expect(report).to receive(:finalize_report)
331
- @agent.run
268
+ configurer.run
332
269
  end
333
270
 
334
271
  it "should not apply the catalog if the pre-run command fails" do
335
- report = Puppet::Transaction::Report.new
336
272
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
337
273
 
338
274
  Puppet.settings[:prerun_command] = "/my/command"
339
275
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
340
276
 
341
- expect(@catalog).not_to receive(:apply)
342
- expect(@agent).to receive(:send_report)
277
+ expect_any_instance_of(Puppet::Resource::Catalog).not_to receive(:apply)
278
+ expect(configurer).to receive(:send_report)
343
279
 
344
- expect(@agent.run).to be_nil
280
+ expect(configurer.run).to be_nil
345
281
  end
346
282
 
347
283
  it "should apply the catalog, send the report, and return nil if the post-run command fails" do
348
- report = Puppet::Transaction::Report.new
349
284
  expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
350
285
 
351
286
  Puppet.settings[:postrun_command] = "/my/command"
352
287
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
353
288
 
354
- expect(@catalog).to receive(:apply)
355
- expect(@agent).to receive(:send_report)
289
+ expect_any_instance_of(Puppet::Resource::Catalog).to receive(:apply)
290
+ expect(configurer).to receive(:send_report)
356
291
 
357
- expect(@agent.run).to be_nil
292
+ expect(configurer.run).to be_nil
358
293
  end
359
294
 
360
295
  it 'includes total time metrics in the report after successfully applying the catalog' do
361
- report = Puppet::Transaction::Report.new
362
- allow(@catalog).to receive(:apply).with(:report => report)
363
- @agent.run(report: report)
296
+ configurer.run(report: report)
364
297
 
365
298
  expect(report.metrics['time']).to be
366
299
  expect(report.metrics['time']['total']).to be_a_kind_of(Numeric)
@@ -370,17 +303,15 @@ describe Puppet::Configurer do
370
303
  Puppet.settings[:prerun_command] = "/my/command"
371
304
  expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
372
305
 
373
- report = Puppet::Transaction::Report.new
374
- @agent.run(report: report)
306
+ configurer.run(report: report)
375
307
 
376
308
  expect(report.metrics['time']).to be
377
309
  expect(report.metrics['time']['total']).to be_a_kind_of(Numeric)
378
310
  end
379
311
 
380
312
  it 'includes total time metrics in the report even if catalog retrieval fails' do
381
- report = Puppet::Transaction::Report.new
382
- allow(@agent).to receive(:prepare_and_retrieve_catalog_from_cache).and_raise
383
- @agent.run(:report => report)
313
+ allow(configurer).to receive(:prepare_and_retrieve_catalog_from_cache).and_raise
314
+ configurer.run(:report => report)
384
315
 
385
316
  expect(report.metrics['time']).to be
386
317
  expect(report.metrics['time']['total']).to be_a_kind_of(Numeric)
@@ -388,96 +319,93 @@ describe Puppet::Configurer do
388
319
 
389
320
  it "should refetch the catalog if the server specifies a new environment in the catalog" do
390
321
  catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
391
- expect(@agent).to receive(:retrieve_catalog).and_return(catalog).twice
322
+ expect(configurer).to receive(:retrieve_catalog).and_return(catalog).twice
392
323
 
393
- @agent.run
324
+ configurer.run
394
325
  end
395
326
 
396
- it "should change the environment setting if the server specifies a new environment in the catalog" do
397
- allow(@catalog).to receive(:environment).and_return("second_env")
327
+ it "changes the configurer's environment if the server specifies a new environment in the catalog" do
328
+ allow_any_instance_of(Puppet::Resource::Catalog).to receive(:environment).and_return("second_env")
398
329
 
399
- @agent.run
330
+ configurer.run
400
331
 
401
- expect(@agent.environment).to eq("second_env")
332
+ expect(configurer.environment).to eq("second_env")
402
333
  end
403
334
 
404
- it "should fix the report if the server specifies a new environment in the catalog" do
405
- report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
406
- expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
407
- expect(@agent).to receive(:send_report).with(report)
335
+ it "changes the report's environment if the server specifies a new environment in the catalog" do
336
+ allow_any_instance_of(Puppet::Resource::Catalog).to receive(:environment).and_return("second_env")
408
337
 
409
- allow(@catalog).to receive(:environment).and_return("second_env")
410
- allow(@agent).to receive(:retrieve_catalog).and_return(@catalog)
411
-
412
- @agent.run
338
+ configurer.run(report: report)
413
339
 
414
340
  expect(report.environment).to eq("second_env")
415
341
  end
416
342
 
417
343
  it "sends the transaction uuid in a catalog request" do
418
- @agent.instance_variable_set(:@transaction_uuid, 'aaa')
344
+ configurer = Puppet::Configurer.new('aaa')
419
345
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(transaction_uuid: 'aaa'))
420
- @agent.run
346
+ configurer.run
421
347
  end
422
348
 
423
349
  it "sends the transaction uuid in a catalog request" do
424
- @agent.instance_variable_set(:@job_id, 'aaa')
350
+ configurer = Puppet::Configurer.new('b', 'aaa')
425
351
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(job_id: 'aaa'))
426
- @agent.run
352
+ configurer.run
427
353
  end
428
354
 
429
355
  it "sets the static_catalog query param to true in a catalog request" do
430
356
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(static_catalog: true))
431
- @agent.run
357
+ configurer.run
432
358
  end
433
359
 
434
360
  it "sets the checksum_type query param to the default supported_checksum_types in a catalog request" do
435
361
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything,
436
362
  hash_including(checksum_type: 'md5.sha256.sha384.sha512.sha224'))
437
- @agent.run
363
+ configurer.run
438
364
  end
439
365
 
440
366
  it "sets the checksum_type query param to the supported_checksum_types setting in a catalog request" do
441
- # Regenerate the agent to pick up the new setting
442
367
  Puppet[:supported_checksum_types] = ['sha256']
443
- @agent = Puppet::Configurer.new
444
- allow(@agent).to receive(:init_storage)
445
- allow(@agent).to receive(:download_plugins)
446
- allow(@agent).to receive(:send_report)
447
- allow(@agent).to receive(:save_last_run_summary)
368
+ # Regenerate the agent to pick up the new setting
369
+ configurer = Puppet::Configurer.new
448
370
 
449
371
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(checksum_type: 'sha256'))
450
- @agent.run
372
+ configurer.run
451
373
  end
452
374
 
453
375
  describe "when not using a REST terminus for catalogs" do
454
376
  it "should not pass any facts when retrieving the catalog" do
377
+ # This is weird, we collect facts when constructing the node,
378
+ # but we don't send them in the indirector request. Then the compiler
379
+ # looks up the node, and collects its facts, which we could have sent
380
+ # in the first place. This seems like a bug.
455
381
  Puppet::Resource::Catalog.indirection.terminus_class = :compiler
456
- expect(@agent).not_to receive(:facts_for_uploading)
382
+
457
383
  expect(Puppet::Resource::Catalog.indirection).to receive(:find) do |name, options|
458
- options[:facts].nil?
459
- end.and_return(@catalog)
384
+ expect(options[:facts]).to be_nil
385
+ end.and_return(catalog)
460
386
 
461
- @agent.run
387
+ configurer.run
462
388
  end
463
389
  end
464
390
 
465
391
  describe "when using a REST terminus for catalogs" do
466
- it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
392
+ it "should pass the url encoded facts and facts format as arguments when retrieving the catalog" do
467
393
  Puppet::Resource::Catalog.indirection.terminus_class = :rest
468
- expect(@agent).to receive(:facts_for_uploading).and_return(:facts => "myfacts", :facts_format => :foo)
469
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(facts: "myfacts", facts_format: :foo)).and_return(@catalog)
470
394
 
471
- @agent.run
472
- end
473
- end
474
- end
395
+ facts.values = { 'foo' => 'bar' }
396
+ Puppet::Node::Facts.indirection.save(facts)
397
+
398
+ expect(
399
+ Puppet::Resource::Catalog.indirection
400
+ ).to receive(:find) do |_, options|
401
+ expect(options[:facts_format]).to eq("application/json")
475
402
 
476
- describe "when initialized with a transaction_uuid" do
477
- it "stores it" do
478
- expect(SecureRandom).not_to receive(:uuid)
479
- configurer = Puppet::Configurer.new('foo')
480
- expect(configurer.instance_variable_get(:@transaction_uuid) == 'foo')
403
+ unescaped = JSON.parse(CGI.unescape(options[:facts]))
404
+ expect(unescaped).to include("values" => {"foo" => "bar"})
405
+ end.and_return(catalog)
406
+
407
+ configurer.run
408
+ end
481
409
  end
482
410
  end
483
411
 
@@ -485,56 +413,52 @@ describe Puppet::Configurer do
485
413
  include PuppetSpec::Files
486
414
 
487
415
  before do
488
- allow(Puppet.settings).to receive(:use).and_return(true)
489
- @configurer = Puppet::Configurer.new
490
416
  Puppet[:lastrunfile] = tmpfile('last_run_file')
491
-
492
- @report = Puppet::Transaction::Report.new
493
417
  Puppet[:reports] = "none"
494
418
  end
495
419
 
496
420
  it "should print a report summary if configured to do so" do
497
421
  Puppet.settings[:summarize] = true
498
422
 
499
- expect(@report).to receive(:summary).and_return("stuff")
423
+ expect(report).to receive(:summary).and_return("stuff")
500
424
 
501
- expect(@configurer).to receive(:puts).with("stuff")
502
- @configurer.send_report(@report)
425
+ expect(configurer).to receive(:puts).with("stuff")
426
+ configurer.send_report(report)
503
427
  end
504
428
 
505
429
  it "should not print a report summary if not configured to do so" do
506
430
  Puppet.settings[:summarize] = false
507
431
 
508
- expect(@configurer).not_to receive(:puts)
509
- @configurer.send_report(@report)
432
+ expect(configurer).not_to receive(:puts)
433
+ configurer.send_report(report)
510
434
  end
511
435
 
512
436
  it "should save the report if reporting is enabled" do
513
437
  Puppet.settings[:report] = true
514
438
 
515
- expect(Puppet::Transaction::Report.indirection).to receive(:save).with(@report, nil, instance_of(Hash))
516
- @configurer.send_report(@report)
439
+ expect(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, instance_of(Hash))
440
+ configurer.send_report(report)
517
441
  end
518
442
 
519
443
  it "should not save the report if reporting is disabled" do
520
444
  Puppet.settings[:report] = false
521
445
 
522
- expect(Puppet::Transaction::Report.indirection).not_to receive(:save).with(@report, nil, instance_of(Hash))
523
- @configurer.send_report(@report)
446
+ expect(Puppet::Transaction::Report.indirection).not_to receive(:save).with(report, nil, instance_of(Hash))
447
+ configurer.send_report(report)
524
448
  end
525
449
 
526
450
  it "should save the last run summary if reporting is enabled" do
527
451
  Puppet.settings[:report] = true
528
452
 
529
- expect(@configurer).to receive(:save_last_run_summary).with(@report)
530
- @configurer.send_report(@report)
453
+ expect(configurer).to receive(:save_last_run_summary).with(report)
454
+ configurer.send_report(report)
531
455
  end
532
456
 
533
457
  it "should save the last run summary if reporting is disabled" do
534
458
  Puppet.settings[:report] = false
535
459
 
536
- expect(@configurer).to receive(:save_last_run_summary).with(@report)
537
- @configurer.send_report(@report)
460
+ expect(configurer).to receive(:save_last_run_summary).with(report)
461
+ configurer.send_report(report)
538
462
  end
539
463
 
540
464
  it "should log but not fail if saving the report fails" do
@@ -543,7 +467,7 @@ describe Puppet::Configurer do
543
467
  expect(Puppet::Transaction::Report.indirection).to receive(:save).and_raise("whatever")
544
468
 
545
469
  expect(Puppet).to receive(:err)
546
- expect { @configurer.send_report(@report) }.not_to raise_error
470
+ expect { configurer.send_report(report) }.not_to raise_error
547
471
  end
548
472
  end
549
473
 
@@ -551,22 +475,17 @@ describe Puppet::Configurer do
551
475
  include PuppetSpec::Files
552
476
 
553
477
  before do
554
- allow(Puppet.settings).to receive(:use).and_return(true)
555
- @configurer = Puppet::Configurer.new
556
-
557
- @report = double('report', :raw_summary => {})
558
-
559
478
  Puppet[:lastrunfile] = tmpfile('last_run_file')
560
479
  end
561
480
 
562
481
  it "should write the last run file" do
563
- @configurer.save_last_run_summary(@report)
482
+ configurer.save_last_run_summary(report)
564
483
  expect(Puppet::FileSystem.exist?(Puppet[:lastrunfile])).to be_truthy
565
484
  end
566
485
 
567
486
  it "should write the raw summary as yaml" do
568
- expect(@report).to receive(:raw_summary).and_return("summary")
569
- @configurer.save_last_run_summary(@report)
487
+ expect(report).to receive(:raw_summary).and_return("summary")
488
+ configurer.save_last_run_summary(report)
570
489
  expect(File.read(Puppet[:lastrunfile])).to eq(YAML.dump("summary"))
571
490
  end
572
491
 
@@ -582,12 +501,12 @@ describe Puppet::Configurer do
582
501
  expect(Puppet::Util).to receive(:replace_file).and_yield(fh)
583
502
 
584
503
  expect(Puppet).to receive(:err)
585
- expect { @configurer.save_last_run_summary(@report) }.to_not raise_error
504
+ expect { configurer.save_last_run_summary(report) }.to_not raise_error
586
505
  end
587
506
 
588
507
  it "should create the last run file with the correct mode" do
589
508
  expect(Puppet.settings.setting(:lastrunfile)).to receive(:mode).and_return('664')
590
- @configurer.save_last_run_summary(@report)
509
+ configurer.save_last_run_summary(report)
591
510
 
592
511
  if Puppet::Util::Platform.windows?
593
512
  require 'puppet/util/windows/security'
@@ -601,25 +520,25 @@ describe Puppet::Configurer do
601
520
  it "should report invalid last run file permissions" do
602
521
  expect(Puppet.settings.setting(:lastrunfile)).to receive(:mode).and_return('892')
603
522
  expect(Puppet).to receive(:err).with(/Could not save last run local report.*892 is invalid/)
604
- @configurer.save_last_run_summary(@report)
523
+ configurer.save_last_run_summary(report)
605
524
  end
606
525
  end
607
526
 
608
527
  describe "when requesting a node" do
609
528
  it "uses the transaction uuid in the request" do
610
529
  expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(transaction_uuid: anything)).twice
611
- @agent.run
530
+ configurer.run
612
531
  end
613
532
 
614
533
  it "sends an explicitly configured environment request" do
615
534
  expect(Puppet.settings).to receive(:set_by_config?).with(:environment).and_return(true)
616
535
  expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: Puppet[:environment])).twice
617
- @agent.run
536
+ configurer.run
618
537
  end
619
538
 
620
539
  it "does not send a configured_environment when using the default" do
621
540
  expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: nil)).twice
622
- @agent.run
541
+ configurer.run
623
542
  end
624
543
  end
625
544
 
@@ -650,14 +569,6 @@ describe Puppet::Configurer do
650
569
 
651
570
  describe "when retrieving a catalog" do
652
571
  before do
653
- allow(Puppet.settings).to receive(:use).and_return(true)
654
- allow(@agent).to receive(:facts_for_uploading).and_return({})
655
- allow(@agent).to receive(:download_plugins)
656
-
657
- # retrieve a catalog in the current environment, so we don't try to converge unexpectedly
658
- @catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym))
659
-
660
- # this is the default when using a Configurer instance
661
572
  allow(Puppet::Resource::Catalog.indirection).to receive(:terminus_class).and_return(:rest)
662
573
  end
663
574
 
@@ -667,100 +578,128 @@ describe Puppet::Configurer do
667
578
  end
668
579
 
669
580
  it "should first look in the cache for a catalog" do
670
- expects_cached_catalog_only(@catalog)
581
+ expects_cached_catalog_only(catalog)
671
582
 
672
- expect(@agent.retrieve_catalog({})).to eq(@catalog)
583
+ configurer.run
673
584
  end
674
585
 
675
586
  it "should not make a node request or pluginsync when a cached catalog is successfully retrieved" do
676
587
  expect(Puppet::Node.indirection).not_to receive(:find)
677
- expects_cached_catalog_only(@catalog)
678
- expect(@agent).not_to receive(:download_plugins)
588
+ expects_cached_catalog_only(catalog)
589
+ expect(configurer).not_to receive(:download_plugins)
679
590
 
680
- @agent.run
591
+ configurer.run
681
592
  end
682
593
 
683
594
  it "should make a node request and pluginsync when a cached catalog cannot be retrieved" do
684
595
  expect(Puppet::Node.indirection).to receive(:find).and_return(nil)
685
- expects_fallback_to_new_catalog(@catalog)
686
- expect(@agent).to receive(:download_plugins)
596
+ expects_fallback_to_new_catalog(catalog)
597
+ expect(configurer).to receive(:download_plugins)
687
598
 
688
- @agent.run
599
+ configurer.run
689
600
  end
690
601
 
691
602
  it "should set its cached_catalog_status to 'explicitly_requested'" do
692
- expects_cached_catalog_only(@catalog)
603
+ expects_cached_catalog_only(catalog)
604
+
605
+ options = {}
606
+ configurer.run(options)
693
607
 
694
- @agent.retrieve_catalog({})
695
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('explicitly_requested')
608
+ expect(options[:report].cached_catalog_status).to eq('explicitly_requested')
696
609
  end
697
610
 
698
611
  it "should set its cached_catalog_status to 'explicitly requested' if the cached catalog is from a different environment" do
699
612
  cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
700
613
  expects_cached_catalog_only(cached_catalog)
701
614
 
702
- @agent.retrieve_catalog({})
703
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('explicitly_requested')
615
+ options = {}
616
+ configurer.run(options)
617
+
618
+ expect(options[:report].cached_catalog_status).to eq('explicitly_requested')
704
619
  end
705
620
 
706
621
  it "should compile a new catalog if none is found in the cache" do
707
- expects_fallback_to_new_catalog(@catalog)
708
-
709
- expect(@agent.retrieve_catalog({})).to eq(@catalog)
710
- end
622
+ expects_fallback_to_new_catalog(catalog)
711
623
 
712
- it "should set its cached_catalog_status to 'not_used' if no catalog is found in the cache" do
713
- expects_fallback_to_new_catalog(@catalog)
624
+ options = {}
625
+ configurer.run(options)
714
626
 
715
- @agent.retrieve_catalog({})
716
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('not_used')
627
+ expect(options[:report].cached_catalog_status).to eq('not_used')
717
628
  end
718
629
 
719
630
  it "should not attempt to retrieve a cached catalog again if the first attempt failed" do
720
631
  expect(Puppet::Node.indirection).to receive(:find).and_return(nil)
721
632
  expects_neither_new_or_cached_catalog
722
633
 
723
- @agent.run
634
+ configurer.run
724
635
  end
725
636
 
726
637
  it "should return the cached catalog when the environment doesn't match" do
727
638
  cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
728
639
  expects_cached_catalog_only(cached_catalog)
729
640
 
641
+ allow(Puppet).to receive(:info)
730
642
  expect(Puppet).to receive(:info).with("Using cached catalog from environment 'second_env'")
731
- expect(@agent.retrieve_catalog({})).to eq(cached_catalog)
643
+
644
+ configurer.run
645
+ end
646
+
647
+ it "applies the catalog passed as options when the catalog cache terminus is not set" do
648
+ stub_request(:get, %r{/puppet/v3/file_metadatas?/plugins}).to_return(:status => 404)
649
+ stub_request(:get, %r{/puppet/v3/file_metadatas?/pluginfacts}).to_return(:status => 404)
650
+
651
+ catalog.add_resource(Puppet::Resource.new('notify', 'from apply'))
652
+ configurer.run(catalog: catalog.to_ral)
653
+
654
+ # make sure cache class is not set to avoid surprises later
655
+ expect(Puppet::Resource::Catalog.indirection).to_not be_cache
656
+ expect(@logs).to include(an_object_having_attributes(level: :notice, message: /defined 'message' as 'from apply'/))
657
+ end
658
+
659
+ it "applies the cached catalog when the catalog cache terminus is set, ignoring the catalog passed as options" do
660
+ Puppet::Resource::Catalog.indirection.cache_class = :json
661
+
662
+ cached_catalog = Puppet::Resource::Catalog.new(Puppet[:node_name_value], Puppet[:environment])
663
+ cached_catalog.add_resource(Puppet::Resource.new('notify', 'from cache'))
664
+
665
+ # update cached catalog
666
+ Puppet.settings.use(:main, :agent)
667
+ path = Puppet::Resource::Catalog.indirection.cache.path(cached_catalog.name)
668
+ FileUtils.mkdir(File.dirname(path))
669
+ File.write(path, cached_catalog.render(:json))
670
+
671
+ configurer.run(catalog: catalog.to_ral)
672
+
673
+ expect(@logs).to include(an_object_having_attributes(level: :notice, message: /defined 'message' as 'from cache'/))
732
674
  end
733
675
  end
734
676
 
735
677
  describe "and strict environment mode is set" do
736
678
  before do
737
- allow(@catalog).to receive(:to_ral).and_return(@catalog)
738
- allow(@catalog).to receive(:write_class_file)
739
- allow(@catalog).to receive(:write_resource_file)
740
- allow(@agent).to receive(:send_report)
741
- allow(@agent).to receive(:save_last_run_summary)
742
679
  Puppet.settings[:strict_environment_mode] = true
743
680
  end
744
681
 
745
682
  it "should not make a node request" do
746
683
  expect(Puppet::Node.indirection).not_to receive(:find)
747
684
 
748
- @agent.run
685
+ configurer.run
749
686
  end
750
687
 
751
688
  it "should return nil when the catalog's environment doesn't match the agent specified environment" do
752
- @agent.instance_variable_set(:@environment, 'second_env')
753
- expects_new_catalog_only(@catalog)
689
+ Puppet[:environment] = 'second_env'
690
+ configurer = Puppet::Configurer.new
691
+
692
+ catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote("production"))
693
+ expects_new_catalog_only(catalog)
754
694
 
755
695
  expect(Puppet).to receive(:err).with("Not using catalog because its environment 'production' does not match agent specified environment 'second_env' and strict_environment_mode is set")
756
- expect(@agent.run).to be_nil
696
+ expect(configurer.run).to be_nil
757
697
  end
758
698
 
759
- it "should not return nil when the catalog's environment matches the agent specified environment" do
760
- @agent.instance_variable_set(:@environment, 'production')
761
- expects_new_catalog_only(@catalog)
699
+ it "should return 0 when the catalog's environment matches the agent specified environment" do
700
+ expects_new_catalog_only(catalog)
762
701
 
763
- expect(@agent.run).to eq(0)
702
+ expect(configurer.run).to eq(0)
764
703
  end
765
704
 
766
705
  describe "and a cached catalog is explicitly requested" do
@@ -769,83 +708,81 @@ describe Puppet::Configurer do
769
708
  end
770
709
 
771
710
  it "should return nil when the cached catalog's environment doesn't match the agent specified environment" do
772
- @agent.instance_variable_set(:@environment, 'second_env')
773
- expects_cached_catalog_only(@catalog)
711
+ Puppet[:environment] = 'second_env'
712
+ configurer = Puppet::Configurer.new
713
+
714
+ catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote("production"))
715
+ expects_cached_catalog_only(catalog)
774
716
 
775
717
  expect(Puppet).to receive(:err).with("Not using catalog because its environment 'production' does not match agent specified environment 'second_env' and strict_environment_mode is set")
776
- expect(@agent.run).to be_nil
718
+ expect(configurer.run).to be_nil
777
719
  end
778
720
 
779
721
  it "should proceed with the cached catalog if its environment matchs the local environment" do
780
- Puppet.settings[:use_cached_catalog] = true
781
- @agent.instance_variable_set(:@environment, 'production')
782
- expects_cached_catalog_only(@catalog)
722
+ expects_cached_catalog_only(catalog)
783
723
 
784
- expect(@agent.run).to eq(0)
724
+ expect(configurer.run).to eq(0)
785
725
  end
786
726
  end
787
727
  end
788
728
 
789
- it "should use the Catalog class to get its catalog" do
790
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(@catalog)
791
-
792
- @agent.retrieve_catalog({})
793
- end
794
-
795
729
  it "should set its cached_catalog_status to 'not_used' when downloading a new catalog" do
796
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(@catalog)
730
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(catalog)
731
+
732
+ options = {}
733
+ configurer.run(options)
797
734
 
798
- @agent.retrieve_catalog({})
799
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('not_used')
735
+ expect(options[:report].cached_catalog_status).to eq('not_used')
800
736
  end
801
737
 
802
738
  it "should use its node_name_value to retrieve the catalog" do
803
- allow(Facter).to receive(:value).and_return("eh")
804
- Puppet.settings[:node_name_value] = "myhost.domain.com"
805
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with("myhost.domain.com", anything).and_return(@catalog)
806
-
807
- @agent.retrieve_catalog({})
808
- end
739
+ myhost_facts = Puppet::Node::Facts.new("myhost.domain.com")
740
+ Puppet::Node::Facts.indirection.save(myhost_facts)
809
741
 
810
- it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
811
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(@catalog)
742
+ Puppet.settings[:node_name_value] = "myhost.domain.com"
743
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with("myhost.domain.com", anything).and_return(catalog)
812
744
 
813
- expect(@agent.retrieve_catalog({})).to eq(@catalog)
745
+ configurer.run
814
746
  end
815
747
 
816
- it "should log and return the cached catalog when no catalog can be retrieved from the server" do
817
- expects_fallback_to_cached_catalog(@catalog)
748
+ it "should log when no catalog can be retrieved from the server" do
749
+ expects_fallback_to_cached_catalog(catalog)
818
750
 
751
+ allow(Puppet).to receive(:info)
819
752
  expect(Puppet).to receive(:info).with("Using cached catalog from environment 'production'")
820
- expect(@agent.retrieve_catalog({})).to eq(@catalog)
753
+ configurer.run
821
754
  end
822
755
 
823
756
  it "should set its cached_catalog_status to 'on_failure' when no catalog can be retrieved from the server" do
824
- expects_fallback_to_cached_catalog(@catalog)
757
+ expects_fallback_to_cached_catalog(catalog)
758
+
759
+ options = {}
760
+ configurer.run(options)
825
761
 
826
- @agent.retrieve_catalog({})
827
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('on_failure')
762
+ expect(options[:report].cached_catalog_status).to eq('on_failure')
828
763
  end
829
764
 
830
765
  it "should not look in the cache for a catalog if one is returned from the server" do
831
- expects_new_catalog_only(@catalog)
766
+ expects_new_catalog_only(catalog)
832
767
 
833
- expect(@agent.retrieve_catalog({})).to eq(@catalog)
768
+ configurer.run
834
769
  end
835
770
 
836
771
  it "should return the cached catalog when retrieving the remote catalog throws an exception" do
837
772
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_raise("eh")
838
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(@catalog)
773
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(catalog)
839
774
 
840
- expect(@agent.retrieve_catalog({})).to eq(@catalog)
775
+ configurer.run
841
776
  end
842
777
 
843
778
  it "should set its cached_catalog_status to 'on_failure' when retrieving the remote catalog throws an exception" do
844
779
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_raise("eh")
845
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(@catalog)
780
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(catalog)
781
+
782
+ options = {}
783
+ configurer.run(options)
846
784
 
847
- @agent.retrieve_catalog({})
848
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('on_failure')
785
+ expect(options[:report].cached_catalog_status).to eq('on_failure')
849
786
  end
850
787
 
851
788
  it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
@@ -854,120 +791,173 @@ describe Puppet::Configurer do
854
791
 
855
792
  expect(Puppet).to receive(:warning).with('Not using cache on failed catalog')
856
793
 
857
- expect(@agent.retrieve_catalog({})).to be_nil
794
+ expect(configurer.run).to be_nil
858
795
  end
859
796
 
860
797
  it "should set its cached_catalog_status to 'not_used' if no catalog can be retrieved from the server and :usecacheonfailure is disabled or fails to retrieve a catalog" do
861
798
  Puppet[:usecacheonfailure] = false
862
799
  expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(nil)
863
800
 
864
- @agent.retrieve_catalog({})
865
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('not_used')
801
+ options = {}
802
+ configurer.run(options)
803
+
804
+ expect(options[:report].cached_catalog_status).to eq('not_used')
866
805
  end
867
806
 
868
807
  it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
869
808
  expects_neither_new_or_cached_catalog
870
809
 
871
- expect(@agent.retrieve_catalog({})).to be_nil
810
+ expect(configurer.run).to be_nil
872
811
  end
873
812
 
874
813
  it "should return nil if its cached catalog environment doesn't match server-specified environment" do
875
814
  cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
876
- @agent.instance_variable_set(:@node_environment, 'production')
877
815
 
878
816
  expects_fallback_to_cached_catalog(cached_catalog)
879
817
 
818
+ allow(Puppet).to receive(:err)
880
819
  expect(Puppet).to receive(:err).with("Not using cached catalog because its environment 'second_env' does not match 'production'")
881
- expect(@agent.retrieve_catalog({})).to be_nil
820
+ expect(configurer.run).to be_nil
882
821
  end
883
822
 
884
823
  it "should set its cached_catalog_status to 'not_used' if the cached catalog environment doesn't match server-specified environment" do
885
824
  cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
886
- @agent.instance_variable_set(:@node_environment, 'production')
887
-
888
- expects_fallback_to_cached_catalog(cached_catalog)
889
-
890
- @agent.retrieve_catalog({})
891
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('not_used')
892
- end
893
-
894
- it "should return its cached catalog if the environment matches the server-specified environment" do
895
- cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment]))
896
- @agent.instance_variable_set(:@node_environment, cached_catalog.environment)
897
825
 
898
826
  expects_fallback_to_cached_catalog(cached_catalog)
899
827
 
900
- expect(@agent.retrieve_catalog({})).to eq(cached_catalog)
828
+ options = {}
829
+ configurer.run(options)
830
+ expect(options[:report].cached_catalog_status).to eq('not_used')
901
831
  end
902
832
 
903
833
  it "should set its cached_catalog_status to 'on_failure' if the cached catalog environment matches server-specified environment" do
904
- cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment]))
905
- @agent.instance_variable_set(:@node_environment, cached_catalog.environment)
906
-
907
- expects_fallback_to_cached_catalog(cached_catalog)
834
+ expects_fallback_to_cached_catalog(catalog)
908
835
 
909
- @agent.retrieve_catalog({})
910
- expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('on_failure')
836
+ options = {}
837
+ configurer.run(options)
838
+ expect(options[:report].cached_catalog_status).to eq('on_failure')
911
839
  end
912
840
 
913
841
  it "should not update the cached catalog in noop mode" do
914
842
  Puppet[:noop] = true
915
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true, ignore_cache_save: true)).and_return(@catalog)
916
843
 
917
- @agent.retrieve_catalog({})
844
+ stub_request(:get, %r{/puppet/v3/catalog}).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
845
+
846
+ Puppet::Resource::Catalog.indirection.cache_class = :json
847
+ path = Puppet::Resource::Catalog.indirection.cache.path(catalog.name)
848
+
849
+ expect(File).to_not be_exist(path)
850
+ configurer.run
851
+ expect(File).to_not be_exist(path)
918
852
  end
919
853
 
920
854
  it "should update the cached catalog when not in noop mode" do
921
855
  Puppet[:noop] = false
922
- expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true, ignore_cache_save: false)).and_return(@catalog)
856
+ Puppet[:log_level] = 'info'
857
+
858
+ stub_request(:get, %r{/puppet/v3/catalog}).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
859
+
860
+ Puppet::Resource::Catalog.indirection.cache_class = :json
861
+ cache_path = Puppet::Resource::Catalog.indirection.cache.path(Puppet[:node_name_value])
862
+
863
+ expect(File).to_not be_exist(cache_path)
864
+ configurer.run
865
+ expect(File).to be_exist(cache_path)
866
+
867
+ expect(@logs).to include(an_object_having_attributes(level: :info, message: "Caching catalog for #{Puppet[:node_name_value]}"))
868
+ end
869
+
870
+ it "successfully applies the catalog without a cache" do
871
+ stub_request(:get, %r{/puppet/v3/catalog}).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
872
+
873
+ Puppet::Resource::Catalog.indirection.cache_class = nil
874
+
875
+ expect(configurer.run).to eq(0)
876
+ end
877
+
878
+ it "should not update the cached catalog when running puppet apply" do
879
+ Puppet::Resource::Catalog.indirection.cache_class = :json
880
+ path = Puppet::Resource::Catalog.indirection.cache.path(catalog.name)
923
881
 
924
- @agent.retrieve_catalog({})
882
+ expect(File).to_not be_exist(path)
883
+ configurer.run(catalog: catalog)
884
+ expect(File).to_not be_exist(path)
925
885
  end
926
886
  end
927
887
 
928
- describe "when converting the catalog" do
929
- before do
930
- allow(Puppet.settings).to receive(:use).and_return(true)
888
+ describe "when converging the environment" do
889
+ let(:apple) { Puppet::Resource::Catalog.new(Puppet[:node_name_value], Puppet::Node::Environment.remote('apple')) }
890
+ let(:banana) { Puppet::Resource::Catalog.new(Puppet[:node_name_value], Puppet::Node::Environment.remote('banana')) }
891
+
892
+ before :each do
893
+ apple.add_resource(resource)
894
+ banana.add_resource(resource)
895
+ end
931
896
 
932
- allow(catalog).to receive(:to_ral).and_return(ral_catalog)
897
+ it "converges after multiple attempts" do
898
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(apple, banana, banana)
899
+
900
+ allow(Puppet).to receive(:notice)
901
+ expect(Puppet).to receive(:notice).with("Local environment: 'production' doesn't match server specified environment 'apple', restarting agent run with environment 'apple'")
902
+ expect(Puppet).to receive(:notice).with("Local environment: 'apple' doesn't match server specified environment 'banana', restarting agent run with environment 'banana'")
903
+
904
+ configurer.run
933
905
  end
934
906
 
935
- let (:catalog) { Puppet::Resource::Catalog.new('tester', Puppet::Node::Environment.remote(Puppet[:environment].to_sym)) }
936
- let (:ral_catalog) { Puppet::Resource::Catalog.new('tester', Puppet::Node::Environment.remote(Puppet[:environment].to_sym)) }
907
+ it "raises if it can't converge after 4 tries after the initial catalog request" do
908
+ expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(apple, banana, apple, banana, apple)
937
909
 
938
- it "should convert the catalog to a RAL-formed catalog" do
939
- expect(@agent.convert_catalog(catalog, 10)).to equal(ral_catalog)
910
+ expect(Puppet).to receive(:err).with("Failed to apply catalog: Catalog environment didn't stabilize after 4 fetches, aborting run")
911
+
912
+ configurer.run
940
913
  end
914
+ end
941
915
 
942
- it "should finalize the catalog" do
943
- expect(ral_catalog).to receive(:finalize)
916
+ describe "when converting the catalog" do
917
+ it "converts Puppet::Resource into Puppet::Type::Notify" do
918
+ expect(configurer).to receive(:apply_catalog) do |ral, _|
919
+ expect(ral.resources).to contain(an_instance_of(Puppet::Type::Notify))
920
+ end
944
921
 
945
- @agent.convert_catalog(catalog, 10)
922
+ configurer.run(catalog: catalog)
946
923
  end
947
924
 
948
- it "should record the passed retrieval time with the RAL catalog" do
949
- expect(ral_catalog).to receive(:retrieval_duration=).with(10)
925
+ it "adds default schedules" do
926
+ expect(configurer).to receive(:apply_catalog) do |ral, _|
927
+ expect(ral.resources.map(&:to_ref)).to contain(%w{Schedule[puppet] Schedule[hourly] Schedule[daily] Schedule[weekly] Schedule[monthly] Schedule[never]})
928
+ end
950
929
 
951
- @agent.convert_catalog(catalog, 10)
930
+ configurer.run
952
931
  end
953
932
 
954
- it "should write the RAL catalog's class file" do
955
- expect(ral_catalog).to receive(:write_class_file)
933
+ it "records the retrieval duration to the catalog" do
934
+ expect(configurer).to receive(:apply_catalog) do |ral, _|
935
+ expect(ral.retrieval_duration).to be_an_instance_of(Float)
936
+ end
956
937
 
957
- @agent.convert_catalog(catalog, 10)
938
+ configurer.run
958
939
  end
959
940
 
960
- it "should write the RAL catalog's resource file" do
961
- expect(ral_catalog).to receive(:write_resource_file)
941
+ it "writes the class file containing applied settings classes" do
942
+ expect(File).to_not be_exist(Puppet[:classfile])
962
943
 
963
- @agent.convert_catalog(catalog, 10)
944
+ configurer.run
945
+
946
+ expect(File.read(Puppet[:classfile]).chomp).to eq('settings')
964
947
  end
965
948
 
966
- it "should set catalog conversion time on the report" do
967
- report = Puppet::Transaction::Report.new
949
+ it "writes an empty resource file since no resources are 'managed'" do
950
+ expect(File).to_not be_exist(Puppet[:resourcefile])
951
+
952
+ configurer.run
968
953
 
969
- expect(report).to receive(:add_times).with(:convert_catalog, kind_of(Numeric))
970
- @agent.convert_catalog(catalog, 10, {:report => report})
954
+ expect(File.read(Puppet[:resourcefile]).chomp).to eq("")
955
+ end
956
+
957
+ it "adds the conversion time to the report" do
958
+ configurer.run(report: report)
959
+
960
+ expect(report.metrics['time']['convert_catalog']).to be_an_instance_of(Float)
971
961
  end
972
962
  end
973
963
 
@@ -1002,80 +992,70 @@ describe Puppet::Configurer do
1002
992
  describe "when attempting failover" do
1003
993
  it "should not failover if server_list is not set" do
1004
994
  Puppet.settings[:server_list] = []
1005
- expect(@agent).not_to receive(:find_functional_server)
1006
- @agent.run
995
+ configurer.run
1007
996
  end
1008
997
 
1009
998
  it "should not failover during an apply run" do
1010
999
  Puppet.settings[:server_list] = ["myserver:123"]
1011
- expect(@agent).not_to receive(:find_functional_server)
1012
1000
  catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym))
1013
- @agent.run :catalog => catalog
1001
+ configurer.run(catalog: catalog)
1014
1002
  end
1015
1003
 
1016
1004
  it "should select a server when it receives 200 OK response" do
1017
1005
  Puppet.settings[:server_list] = ["myserver:123"]
1018
- response = Net::HTTPOK.new(nil, 200, 'OK')
1019
- allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(double('request', get: response))
1020
- allow(@agent).to receive(:run_internal)
1006
+
1007
+ stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 200)
1021
1008
 
1022
1009
  options = {}
1023
- @agent.run(options)
1010
+ configurer.run(options)
1024
1011
  expect(options[:report].master_used).to eq('myserver:123')
1025
1012
  end
1026
1013
 
1027
1014
  it "should select a server when it receives 403 Forbidden" do
1028
1015
  Puppet.settings[:server_list] = ["myserver:123"]
1029
- response = Net::HTTPForbidden.new(nil, 403, 'Forbidden')
1030
- allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(double('request', get: response))
1031
- allow(@agent).to receive(:run_internal)
1016
+
1017
+ stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 403)
1032
1018
 
1033
1019
  options = {}
1034
- @agent.run(options)
1020
+ configurer.run(options)
1035
1021
  expect(options[:report].master_used).to eq('myserver:123')
1036
1022
  end
1037
1023
 
1038
- it "queries the simple status for the 'master' service" do
1039
- Puppet.settings[:server_list] = ["myserver:123"]
1040
- response = Net::HTTPOK.new(nil, 200, 'OK')
1041
- http = double('request')
1042
- expect(http).to receive(:get).with('/status/v1/simple/master').and_return(response)
1043
- allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(http)
1044
- allow(@agent).to receive(:run_internal)
1045
-
1046
- @agent.run
1047
- end
1048
-
1049
1024
  it "should report when a server is unavailable" do
1050
1025
  Puppet.settings[:server_list] = ["myserver:123"]
1051
- response = Net::HTTPInternalServerError.new(nil, 500, 'Internal Server Error')
1052
- allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(double('request', get: response))
1053
- allow(@agent).to receive(:run_internal)
1054
1026
 
1027
+ stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: [500, "Internal Server Error"])
1028
+
1029
+ allow(Puppet).to receive(:debug)
1055
1030
  expect(Puppet).to receive(:debug).with("Puppet server myserver:123 is unavailable: 500 Internal Server Error")
1056
- expect { @agent.run }.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list:/)
1031
+ expect {
1032
+ configurer.run
1033
+ }.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list:/)
1057
1034
  end
1058
1035
 
1059
1036
  it "should error when no servers in 'server_list' are reachable" do
1060
1037
  Puppet.settings[:server_list] = "myserver:123,someotherservername"
1061
- pool = Puppet::Network::HTTP::Pool.new(Puppet[:http_keepalive_timeout])
1062
- allow(Puppet::Network::HTTP::Pool).to receive(:new).and_return(pool)
1063
- allow(Puppet).to receive(:override).with({:http_pool => pool}).and_yield
1064
- allow(Puppet).to receive(:override).with({:server => "myserver", :serverport => '123'}).and_yield
1065
- allow(Puppet).to receive(:override).with({:server => "someotherservername", :serverport => 8140}).and_yield
1066
- error = Net::HTTPError.new(400, 'dummy server communication error')
1067
- allow(Puppet::Node.indirection).to receive(:find).and_raise(error)
1068
- expect{ @agent.run }.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list: 'myserver:123,someotherservername'/)
1038
+
1039
+ stub_request(:get, 'https://myserver/status/v1/simple/master').to_return(status: 400)
1040
+ stub_request(:get, 'https://someotherservername/status/v1/simple/master').to_return(status: 400)
1041
+
1042
+ expect{
1043
+ configurer.run
1044
+ }.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list: 'myserver:123,someotherservername'/)
1069
1045
  end
1070
1046
 
1071
- it "should not make multiple node requets when the server is found" do
1072
- response = Net::HTTPOK.new(nil, 200, 'OK')
1073
- allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(double('request', get: response))
1074
-
1047
+ it "should not make multiple node requests when the server is found" do
1075
1048
  Puppet.settings[:server_list] = ["myserver:123"]
1076
- expect(Puppet::Node.indirection).to receive(:find).and_return("mynode").once
1077
- expect(@agent).to receive(:prepare_and_retrieve_catalog).and_return(nil)
1078
- @agent.run
1049
+ Puppet::Node.indirection.terminus_class = :rest
1050
+ Puppet::Resource::Catalog.indirection.terminus_class = :rest
1051
+
1052
+ stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 200)
1053
+ stub_request(:get, %r{https://myserver:123/puppet/v3/catalog}).to_return(status: 200)
1054
+ node_request = stub_request(:get, %r{https://myserver:123/puppet/v3/node/}).to_return(status: 200)
1055
+
1056
+ configurer.run
1057
+
1058
+ expect(node_request).to have_been_requested.once
1079
1059
  end
1080
1060
  end
1081
1061
  end