chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +4 -110
  6. data/bin/chef-service-manager +3 -1
  7. data/distro/common/html/knife_cookbook_site.html +18 -18
  8. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  9. data/lib/chef.rb +1 -1
  10. data/lib/chef/application.rb +1 -1
  11. data/lib/chef/application/apply.rb +19 -1
  12. data/lib/chef/application/client.rb +11 -5
  13. data/lib/chef/application/knife.rb +2 -2
  14. data/lib/chef/application/solo.rb +1 -1
  15. data/lib/chef/application/windows_service_manager.rb +19 -12
  16. data/lib/chef/chef_class.rb +46 -0
  17. data/lib/chef/chef_fs/config.rb +22 -24
  18. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  19. data/lib/chef/chef_fs/file_pattern.rb +4 -15
  20. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  21. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  22. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  23. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  27. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  28. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  29. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  30. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
  31. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  32. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  33. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  34. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  35. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  36. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  37. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  38. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  39. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  40. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  41. data/lib/chef/chef_fs/knife.rb +35 -7
  42. data/lib/chef/chef_fs/path_utils.rb +65 -34
  43. data/lib/chef/client.rb +2 -3
  44. data/lib/chef/config.rb +34 -2
  45. data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
  46. data/lib/chef/cookbook/metadata.rb +25 -3
  47. data/lib/chef/cookbook/synchronizer.rb +1 -1
  48. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  49. data/lib/chef/cookbook_version.rb +3 -3
  50. data/lib/chef/delayed_evaluator.rb +21 -0
  51. data/lib/chef/deprecation/mixin/template.rb +1 -2
  52. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  53. data/lib/chef/deprecation/provider/file.rb +1 -1
  54. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  55. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  56. data/lib/chef/deprecation/provider/template.rb +1 -1
  57. data/lib/chef/deprecation/warnings.rb +3 -4
  58. data/lib/chef/dsl/reboot_pending.rb +3 -2
  59. data/lib/chef/dsl/recipe.rb +26 -7
  60. data/lib/chef/dsl/resources.rb +2 -2
  61. data/lib/chef/event_dispatch/base.rb +51 -22
  62. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  63. data/lib/chef/event_dispatch/dsl.rb +64 -0
  64. data/lib/chef/exceptions.rb +28 -1
  65. data/lib/chef/file_content_management/tempfile.rb +1 -1
  66. data/lib/chef/formatters/base.rb +3 -0
  67. data/lib/chef/formatters/doc.rb +56 -6
  68. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  69. data/lib/chef/formatters/minimal.rb +2 -2
  70. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
  71. data/lib/chef/http/http_request.rb +1 -1
  72. data/lib/chef/knife.rb +35 -55
  73. data/lib/chef/knife/bootstrap.rb +41 -0
  74. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  75. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  76. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  77. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  78. data/lib/chef/knife/cookbook_create.rb +1 -1
  79. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  80. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  81. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  82. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  83. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  84. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  85. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  86. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  87. data/lib/chef/knife/core/node_presenter.rb +24 -1
  88. data/lib/chef/knife/core/object_loader.rb +1 -0
  89. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  90. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  91. data/lib/chef/knife/null.rb +10 -0
  92. data/lib/chef/knife/rehash.rb +62 -0
  93. data/lib/chef/knife/search.rb +3 -3
  94. data/lib/chef/knife/ssh.rb +52 -30
  95. data/lib/chef/knife/ssl_check.rb +3 -2
  96. data/lib/chef/knife/user_edit.rb +1 -2
  97. data/lib/chef/local_mode.rb +5 -0
  98. data/lib/chef/log.rb +5 -1
  99. data/lib/chef/mixin/deprecation.rb +8 -8
  100. data/lib/chef/mixin/params_validate.rb +362 -135
  101. data/lib/chef/mixin/template.rb +48 -0
  102. data/lib/chef/mixin/which.rb +1 -1
  103. data/lib/chef/mixin/wide_string.rb +72 -0
  104. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  105. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  106. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  107. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  108. data/lib/chef/node.rb +116 -3
  109. data/lib/chef/node_map.rb +2 -2
  110. data/lib/chef/platform/handler_map.rb +0 -5
  111. data/lib/chef/platform/provider_mapping.rb +5 -6
  112. data/lib/chef/platform/query_helpers.rb +46 -4
  113. data/lib/chef/platform/rebooter.rb +1 -1
  114. data/lib/chef/platform/service_helpers.rb +30 -32
  115. data/lib/chef/policy_builder.rb +1 -8
  116. data/lib/chef/policy_builder/dynamic.rb +186 -0
  117. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  118. data/lib/chef/policy_builder/policyfile.rb +155 -18
  119. data/lib/chef/property.rb +568 -0
  120. data/lib/chef/provider.rb +222 -13
  121. data/lib/chef/provider/batch.rb +8 -0
  122. data/lib/chef/provider/deploy.rb +5 -7
  123. data/lib/chef/provider/directory.rb +14 -2
  124. data/lib/chef/provider/dsc_resource.rb +5 -9
  125. data/lib/chef/provider/group/pw.rb +1 -1
  126. data/lib/chef/provider/ifconfig.rb +2 -2
  127. data/lib/chef/provider/lwrp_base.rb +1 -75
  128. data/lib/chef/provider/mount.rb +7 -3
  129. data/lib/chef/provider/package.rb +1 -1
  130. data/lib/chef/provider/package/dpkg.rb +5 -11
  131. data/lib/chef/provider/package/rpm.rb +2 -2
  132. data/lib/chef/provider/package/rubygems.rb +1 -1
  133. data/lib/chef/provider/package/windows/msi.rb +2 -2
  134. data/lib/chef/provider/package/yum.rb +17 -5
  135. data/lib/chef/provider/powershell_script.rb +59 -23
  136. data/lib/chef/provider/registry_key.rb +5 -5
  137. data/lib/chef/provider/remote_directory.rb +190 -102
  138. data/lib/chef/provider/service.rb +12 -2
  139. data/lib/chef/provider/service/aix.rb +1 -1
  140. data/lib/chef/provider/service/debian.rb +3 -5
  141. data/lib/chef/provider/service/freebsd.rb +1 -1
  142. data/lib/chef/provider/service/gentoo.rb +3 -3
  143. data/lib/chef/provider/service/init.rb +3 -3
  144. data/lib/chef/provider/service/insserv.rb +2 -4
  145. data/lib/chef/provider/service/invokercd.rb +2 -4
  146. data/lib/chef/provider/service/macosx.rb +5 -1
  147. data/lib/chef/provider/service/openbsd.rb +2 -1
  148. data/lib/chef/provider/service/redhat.rb +52 -16
  149. data/lib/chef/provider/service/simple.rb +2 -2
  150. data/lib/chef/provider/service/systemd.rb +3 -5
  151. data/lib/chef/provider/service/upstart.rb +4 -6
  152. data/lib/chef/provider/subversion.rb +13 -7
  153. data/lib/chef/provider/template/content.rb +16 -6
  154. data/lib/chef/provider/user/solaris.rb +32 -4
  155. data/lib/chef/provider/windows_script.rb +3 -5
  156. data/lib/chef/provider_resolver.rb +2 -2
  157. data/lib/chef/recipe.rb +1 -8
  158. data/lib/chef/resource.rb +563 -90
  159. data/lib/chef/resource/action_class.rb +83 -0
  160. data/lib/chef/resource/chef_gem.rb +3 -3
  161. data/lib/chef/resource/deploy.rb +8 -2
  162. data/lib/chef/resource/dsc_script.rb +2 -0
  163. data/lib/chef/resource/file/verification.rb +7 -1
  164. data/lib/chef/resource/lwrp_base.rb +1 -7
  165. data/lib/chef/resource/registry_key.rb +1 -1
  166. data/lib/chef/resource/service.rb +10 -2
  167. data/lib/chef/resource/subversion.rb +5 -0
  168. data/lib/chef/resource/windows_script.rb +6 -2
  169. data/lib/chef/resource/yum_package.rb +10 -1
  170. data/lib/chef/resource_resolver.rb +3 -3
  171. data/lib/chef/run_context.rb +402 -83
  172. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  173. data/lib/chef/run_lock.rb +30 -21
  174. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  175. data/lib/chef/util/windows.rb +0 -32
  176. data/lib/chef/util/windows/net_group.rb +85 -106
  177. data/lib/chef/util/windows/net_use.rb +35 -71
  178. data/lib/chef/util/windows/net_user.rb +0 -1
  179. data/lib/chef/util/windows/volume.rb +19 -19
  180. data/lib/chef/version.rb +3 -3
  181. data/lib/chef/win32/api.rb +1 -0
  182. data/lib/chef/win32/api/file.rb +20 -0
  183. data/lib/chef/win32/api/net.rb +163 -43
  184. data/lib/chef/win32/api/registry.rb +51 -0
  185. data/lib/chef/win32/api/system.rb +23 -0
  186. data/lib/chef/win32/api/unicode.rb +0 -43
  187. data/lib/chef/win32/crypto.rb +2 -1
  188. data/lib/chef/win32/file.rb +28 -3
  189. data/lib/chef/win32/mutex.rb +1 -2
  190. data/lib/chef/win32/net.rb +162 -8
  191. data/lib/chef/win32/process.rb +13 -0
  192. data/lib/chef/win32/registry.rb +35 -30
  193. data/lib/chef/win32/security.rb +1 -1
  194. data/lib/chef/win32/security/token.rb +1 -1
  195. data/lib/chef/win32/system.rb +62 -0
  196. data/lib/chef/win32/unicode.rb +7 -2
  197. data/lib/chef/win32/version.rb +0 -4
  198. data/lib/chef/workstation_config_loader.rb +3 -158
  199. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  200. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  201. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  202. data/spec/data/dsc_lcm.pfx +0 -0
  203. data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
  204. data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
  205. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  206. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  207. data/spec/functional/knife/ssh_spec.rb +16 -0
  208. data/spec/functional/rebooter_spec.rb +1 -1
  209. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  210. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  211. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  212. data/spec/functional/resource/group_spec.rb +67 -44
  213. data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
  214. data/spec/functional/resource/windows_service_spec.rb +1 -1
  215. data/spec/functional/run_lock_spec.rb +368 -189
  216. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
  217. data/spec/functional/win32/service_manager_spec.rb +2 -2
  218. data/spec/integration/client/client_spec.rb +51 -0
  219. data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
  220. data/spec/integration/knife/download_spec.rb +4 -0
  221. data/spec/integration/knife/list_spec.rb +8 -0
  222. data/spec/integration/knife/upload_spec.rb +1 -1
  223. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
  224. data/spec/integration/recipes/remote_directory.rb +74 -0
  225. data/spec/integration/recipes/resource_action_spec.rb +363 -0
  226. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  227. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  228. data/spec/spec_helper.rb +9 -0
  229. data/spec/support/platform_helpers.rb +13 -0
  230. data/spec/support/shared/context/win32.rb +34 -0
  231. data/spec/support/shared/functional/win32_service.rb +2 -1
  232. data/spec/support/shared/functional/windows_script.rb +63 -26
  233. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  234. data/spec/support/shared/unit/provider/file.rb +10 -4
  235. data/spec/unit/application/client_spec.rb +16 -3
  236. data/spec/unit/application/knife_spec.rb +2 -2
  237. data/spec/unit/application/solo_spec.rb +4 -3
  238. data/spec/unit/chef_class_spec.rb +23 -4
  239. data/spec/unit/chef_fs/path_util_spec.rb +108 -0
  240. data/spec/unit/client_spec.rb +6 -1
  241. data/spec/unit/config_spec.rb +31 -0
  242. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  243. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  244. data/spec/unit/deprecation_spec.rb +3 -6
  245. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  246. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  247. data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
  248. data/spec/unit/formatters/doc_spec.rb +32 -0
  249. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  250. data/spec/unit/json_compat_spec.rb +4 -3
  251. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  252. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  253. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  254. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  255. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  256. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  257. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  258. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  259. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  260. data/spec/unit/knife/ssl_check_spec.rb +4 -0
  261. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  262. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  263. data/spec/unit/mixin/template_spec.rb +5 -1
  264. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  265. data/spec/unit/node_spec.rb +220 -0
  266. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  267. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  268. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  269. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  270. data/spec/unit/property/state_spec.rb +506 -0
  271. data/spec/unit/property/validation_spec.rb +663 -0
  272. data/spec/unit/property_spec.rb +1094 -0
  273. data/spec/unit/provider/deploy_spec.rb +5 -5
  274. data/spec/unit/provider/directory_spec.rb +35 -0
  275. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  276. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  277. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  278. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  279. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  280. data/spec/unit/provider/mount_spec.rb +12 -1
  281. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  282. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  283. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  284. data/spec/unit/provider/package/yum_spec.rb +97 -24
  285. data/spec/unit/provider/powershell_script_spec.rb +106 -0
  286. data/spec/unit/provider/registry_key_spec.rb +12 -0
  287. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  288. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  289. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  290. data/spec/unit/provider/service/macosx_spec.rb +4 -4
  291. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  292. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  293. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  294. data/spec/unit/provider/service/windows_spec.rb +211 -200
  295. data/spec/unit/provider/subversion_spec.rb +50 -31
  296. data/spec/unit/provider/template/content_spec.rb +93 -2
  297. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  298. data/spec/unit/provider_resolver_spec.rb +707 -650
  299. data/spec/unit/provider_spec.rb +1 -3
  300. data/spec/unit/recipe_spec.rb +0 -4
  301. data/spec/unit/resource/deploy_spec.rb +7 -1
  302. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  303. data/spec/unit/resource/file/verification_spec.rb +33 -5
  304. data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
  305. data/spec/unit/resource/service_spec.rb +4 -4
  306. data/spec/unit/resource/subversion_spec.rb +4 -0
  307. data/spec/unit/resource/yum_package_spec.rb +10 -1
  308. data/spec/unit/resource_spec.rb +2 -2
  309. data/spec/unit/run_context/child_run_context_spec.rb +133 -0
  310. data/spec/unit/run_context_spec.rb +7 -0
  311. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  312. data/spec/unit/win32/registry_spec.rb +394 -0
  313. data/tasks/external_tests.rb +47 -23
  314. data/tasks/maintainers.rb +155 -14
  315. metadata +64 -53
  316. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  317. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  318. data/spec/unit/provider/powershell_spec.rb +0 -80
  319. data/spec/unit/registry_helper_spec.rb +0 -376
  320. data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -65,19 +65,16 @@ describe Chef::Deprecation do
65
65
  end
66
66
 
67
67
  context 'deprecation warning messages' do
68
- before(:each) do
69
- @warning_output = [ ]
70
- allow(Chef::Log).to receive(:warn) { |msg| @warning_output << msg }
71
- end
68
+ RSpec::Matchers.define_negated_matcher :a_non_empty_array, :be_empty
72
69
 
73
70
  it 'should be enabled for deprecated methods' do
71
+ expect(Chef::Log).to receive(:warn).with(a_non_empty_array)
74
72
  TestClass.new.deprecated_method(10)
75
- expect(@warning_output).not_to be_empty
76
73
  end
77
74
 
78
75
  it 'should contain stack trace' do
76
+ expect(Chef::Log).to receive(:warn).with(a_string_including(".rb"))
79
77
  TestClass.new.deprecated_method(10)
80
- expect(@warning_output.join("").include?(".rb")).to be_truthy
81
78
  end
82
79
  end
83
80
 
@@ -46,15 +46,21 @@ describe Chef::DSL::RebootPending do
46
46
  end
47
47
 
48
48
  it 'should return true if key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired" exists' do
49
- allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootRequired').and_return(true)
49
+ allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending').and_return(true)
50
50
  expect(recipe.reboot_pending?).to be_truthy
51
51
  end
52
52
 
53
- it 'should return true if value "HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile" contains specific data' do
54
- allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(true)
55
- allow(recipe).to receive(:registry_get_values).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(
56
- [{:name => "Flags", :type => :dword, :data => 3}])
57
- expect(recipe.reboot_pending?).to be_truthy
53
+ context "version is server 2003" do
54
+ before do
55
+ allow(Chef::Platform).to receive(:windows_server_2003?).and_return(true)
56
+ end
57
+
58
+ it 'should return true if value "HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile" contains specific data on 2k3' do
59
+ allow(recipe).to receive(:registry_key_exists?).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(true)
60
+ allow(recipe).to receive(:registry_get_values).with('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile').and_return(
61
+ [{:name => "Flags", :type => :dword, :data => 3}])
62
+ expect(recipe.reboot_pending?).to be_truthy
63
+ end
58
64
  end
59
65
  end
60
66
 
@@ -47,15 +47,77 @@ describe Chef::EventDispatch::Dispatcher do
47
47
  expect(event_sink).to receive(:run_start).with("12.4.0")
48
48
  dispatcher.run_start("12.4.0")
49
49
 
50
- expect(event_sink).to receive(:synchronized_cookbook).with("apache2")
51
- dispatcher.synchronized_cookbook("apache2")
50
+ cookbook_version = double("cookbook_version")
51
+ expect(event_sink).to receive(:synchronized_cookbook).with("apache2", cookbook_version)
52
+ dispatcher.synchronized_cookbook("apache2", cookbook_version)
52
53
 
53
54
  exception = StandardError.new("foo")
54
55
  expect(event_sink).to receive(:recipe_file_load_failed).with("/path/to/file.rb", exception)
55
56
  dispatcher.recipe_file_load_failed("/path/to/file.rb", exception)
56
57
  end
57
58
 
59
+ context "when an event sink has fewer arguments for an event" do
60
+ # Can't use a double because they don't report arity correctly.
61
+ let(:event_sink) do
62
+ Class.new(Chef::EventDispatch::Base) do
63
+ attr_reader :synchronized_cookbook_args
64
+ def synchronized_cookbook(cookbook_name)
65
+ @synchronized_cookbook_args = [cookbook_name]
66
+ end
67
+ end.new
68
+ end
69
+
70
+ it "trims the arugment list" do
71
+ cookbook_version = double("cookbook_version")
72
+ dispatcher.synchronized_cookbook("apache2", cookbook_version)
73
+ expect(event_sink.synchronized_cookbook_args).to eq ["apache2"]
74
+ end
75
+ end
58
76
  end
59
77
 
60
- end
61
78
 
79
+ context "when two event sinks have different arguments for an event" do
80
+ let(:event_sink_1) do
81
+ Class.new(Chef::EventDispatch::Base) do
82
+ attr_reader :synchronized_cookbook_args
83
+ def synchronized_cookbook(cookbook_name)
84
+ @synchronized_cookbook_args = [cookbook_name]
85
+ end
86
+ end.new
87
+ end
88
+ let(:event_sink_2) do
89
+ Class.new(Chef::EventDispatch::Base) do
90
+ attr_reader :synchronized_cookbook_args
91
+ def synchronized_cookbook(cookbook_name, cookbook)
92
+ @synchronized_cookbook_args = [cookbook_name, cookbook]
93
+ end
94
+ end.new
95
+ end
96
+
97
+ context "and the one with fewer arguments comes first" do
98
+ before do
99
+ dispatcher.register(event_sink_1)
100
+ dispatcher.register(event_sink_2)
101
+ end
102
+ it "trims the arugment list" do
103
+ cookbook_version = double("cookbook_version")
104
+ dispatcher.synchronized_cookbook("apache2", cookbook_version)
105
+ expect(event_sink_1.synchronized_cookbook_args).to eq ["apache2"]
106
+ expect(event_sink_2.synchronized_cookbook_args).to eq ["apache2", cookbook_version]
107
+ end
108
+ end
109
+
110
+ context "and the one with fewer arguments comes last" do
111
+ before do
112
+ dispatcher.register(event_sink_2)
113
+ dispatcher.register(event_sink_1)
114
+ end
115
+ it "trims the arugment list" do
116
+ cookbook_version = double("cookbook_version")
117
+ dispatcher.synchronized_cookbook("apache2", cookbook_version)
118
+ expect(event_sink_1.synchronized_cookbook_args).to eq ["apache2"]
119
+ expect(event_sink_2.synchronized_cookbook_args).to eq ["apache2", cookbook_version]
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,83 @@
1
+ #
2
+ # Author:: Ranjib Dey (<ranjib@linux.com>)
3
+ #
4
+ # Copyright:: Copyright (c) 2015 Ranjib Dey
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ require 'spec_helper'
20
+ require 'chef/event_dispatch/dsl'
21
+
22
+ describe Chef::EventDispatch::DSL do
23
+ let(:events) do
24
+ Chef::EventDispatch::Dispatcher.new
25
+ end
26
+
27
+ let(:run_context) do
28
+ Chef::RunContext.new(Chef::Node.new, nil, events)
29
+ end
30
+
31
+ before do
32
+ Chef.set_run_context(run_context)
33
+ end
34
+
35
+ subject{ described_class.new('test') }
36
+
37
+ it 'set handler name' do
38
+ subject.on(:run_started) {}
39
+ expect(events.subscribers.first.name).to eq('test')
40
+ end
41
+
42
+ it 'raise error when invalid event type is supplied' do
43
+ expect do
44
+ subject.on(:foo_bar) {}
45
+ end.to raise_error(Chef::Exceptions::InvalidEventType)
46
+ end
47
+
48
+ it 'register user hooks against valid event type' do
49
+ subject.on(:run_failed) {'testhook'}
50
+ expect(events.subscribers.first.run_failed).to eq('testhook')
51
+ end
52
+
53
+ it 'preserve state across event hooks' do
54
+ calls = []
55
+ Chef.event_handler do
56
+ on :resource_updated do
57
+ calls << :updated
58
+ end
59
+ on :resource_action_start do
60
+ calls << :started
61
+ end
62
+ end
63
+ resource = Chef::Resource::RubyBlock.new('foo', run_context)
64
+ resource.block { }
65
+ resource.run_action(:run)
66
+ expect(calls).to eq([:started, :updated])
67
+ end
68
+
69
+ it 'preserve instance variables across handler callbacks' do
70
+ Chef.event_handler do
71
+ on :resource_action_start do
72
+ @ivar = [1]
73
+ end
74
+ on :resource_updated do
75
+ @ivar << 2
76
+ end
77
+ end
78
+ resource = Chef::Resource::RubyBlock.new('foo', run_context)
79
+ resource.block { }
80
+ resource.run_action(:run)
81
+ expect(events.subscribers.first.instance_variable_get(:@ivar)).to eq([1, 2])
82
+ end
83
+ end
@@ -43,4 +43,36 @@ describe Chef::Formatters::Base do
43
43
  expect(out.string).to include("Using policy 'jenkins' at revision '613f803bdd035d574df7fa6da525b38df45a74ca82b38b79655efed8a189e073'")
44
44
  end
45
45
 
46
+ it "prints cookbook name and version" do
47
+ cookbook_version = double(name: "apache2", version: "1.2.3")
48
+ formatter.synchronized_cookbook("apache2", cookbook_version)
49
+ expect(out.string).to include("- apache2 (1.2.3")
50
+ end
51
+
52
+ it "prints only seconds when elapsed time is less than 60 seconds" do
53
+ @now = Time.now
54
+ allow(Time).to receive(:now).and_return(@now, @now + 10.0)
55
+ formatter.run_completed(nil)
56
+ expect(formatter.elapsed_time).to eql(10.0)
57
+ expect(formatter.pretty_elapsed_time).to include("10 seconds")
58
+ expect(formatter.pretty_elapsed_time).not_to include("minutes")
59
+ expect(formatter.pretty_elapsed_time).not_to include("hours")
60
+ end
61
+
62
+ it "prints minutes and seconds when elapsed time is more than 60 seconds" do
63
+ @now = Time.now
64
+ allow(Time).to receive(:now).and_return(@now, @now + 610.0)
65
+ formatter.run_completed(nil)
66
+ expect(formatter.elapsed_time).to eql(610.0)
67
+ expect(formatter.pretty_elapsed_time).to include("10 minutes 10 seconds")
68
+ expect(formatter.pretty_elapsed_time).not_to include("hours")
69
+ end
70
+
71
+ it "prints hours, minutes and seconds when elapsed time is more than 3600 seconds" do
72
+ @now = Time.now
73
+ allow(Time).to receive(:now).and_return(@now, @now + 36610.0)
74
+ formatter.run_completed(nil)
75
+ expect(formatter.elapsed_time).to eql(36610.0)
76
+ expect(formatter.pretty_elapsed_time).to include("10 hours 10 minutes 10 seconds")
77
+ end
46
78
  end
@@ -110,6 +110,32 @@ describe Chef::Formatters::ErrorInspectors::CompileErrorInspector do
110
110
  end
111
111
  end
112
112
 
113
+ context "when the error is a RuntimeError about frozen object" do
114
+ let(:exception) do
115
+ e = RuntimeError.new("can't modify frozen Array")
116
+ e.set_backtrace(trace)
117
+ e
118
+ end
119
+
120
+ let(:path_to_failed_file) { "/tmp/kitchen/cache/cookbooks/foo/recipes/default.rb" }
121
+
122
+ let(:trace) do
123
+ [
124
+ "/tmp/kitchen/cache/cookbooks/foo/recipes/default.rb:2:in `block in from_file'",
125
+ "/tmp/kitchen/cache/cookbooks/foo/recipes/default.rb:1:in `from_file'"
126
+ ]
127
+ end
128
+
129
+ describe "when explaining a runtime error in the compile phase" do
130
+ it "correctly detects RuntimeError for frozen objects" do
131
+ expect(inspector.exception_message_modifying_frozen?).to be(true)
132
+ end
133
+
134
+ # could also test for description.section to be called, but would have
135
+ # to adjust every other test to begin using a test double for description
136
+ end
137
+ end
138
+
113
139
  context "when the error does not contain any lines from cookbooks" do
114
140
 
115
141
  let(:trace) do
@@ -72,8 +72,6 @@ describe Chef::JSONCompat do
72
72
  end
73
73
  end
74
74
 
75
- # On FreeBSD 10.1 i386 rspec fails with a SystemStackError loading the expect line with more that 252 entries
76
- # https://github.com/chef/chef/issues/3101
77
75
  describe "with the file with 252 or less nested entries" do
78
76
  let(:json) { IO.read(File.join(CHEF_SPEC_DATA, 'nested.json')) }
79
77
  let(:hash) { Chef::JSONCompat.from_json(json) }
@@ -84,7 +82,10 @@ describe Chef::JSONCompat do
84
82
  end
85
83
 
86
84
  it "should has 'test' as a 252 nested value" do
87
- expect(hash['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']['key']).to eq('test')
85
+ v = 252.times.inject(hash) do |memo, _|
86
+ memo['key']
87
+ end
88
+ expect(v).to eq('test')
88
89
  end
89
90
  end
90
91
  end
@@ -149,6 +149,22 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
149
149
  client_builder.run
150
150
  end
151
151
 
152
+ it "does not add tags by default" do
153
+ allow(node).to receive(:run_list).with([])
154
+ expect(node).to_not receive(:tags)
155
+ client_builder.run
156
+ end
157
+
158
+ it "adds tags to the node when given" do
159
+ tag_receiver = []
160
+
161
+ knife_config[:tags] = %w[foo bar]
162
+ allow(node).to receive(:run_list).with([])
163
+ allow(node).to receive(:tags).and_return(tag_receiver)
164
+ client_builder.run
165
+ expect(tag_receiver).to eq %w[foo bar]
166
+ end
167
+
152
168
  it "builds a node when the run_list is a string" do
153
169
  knife_config[:run_list] = "role[base],role[app]"
154
170
  expect(node).to receive(:run_list).with(["role[base]", "role[app]"])
@@ -174,5 +190,16 @@ describe Chef::Knife::Bootstrap::ClientBuilder do
174
190
  expect(node).to receive(:run_list).with([])
175
191
  client_builder.run
176
192
  end
193
+
194
+ it "builds a node with policy_name and policy_group when given" do
195
+ knife_config[:policy_name] = "my-app"
196
+ knife_config[:policy_group] = "staging"
197
+
198
+ expect(node).to receive(:run_list).with([])
199
+ expect(node).to receive(:policy_name=).with("my-app")
200
+ expect(node).to receive(:policy_group=).with("staging")
201
+
202
+ client_builder.run
203
+ end
177
204
  end
178
205
  end
@@ -250,14 +250,14 @@ describe Chef::Knife::Bootstrap do
250
250
  it "should create a hint file when told to" do
251
251
  knife.parse_options(["--hint", "openstack"])
252
252
  knife.merge_configs
253
- expect(knife.render_template).to match /\/etc\/chef\/ohai\/hints\/openstack.json/
253
+ expect(knife.render_template).to match(/\/etc\/chef\/ohai\/hints\/openstack.json/)
254
254
  end
255
255
 
256
256
  it "should populate a hint file with JSON when given a file to read" do
257
257
  allow(::File).to receive(:read).and_return('{ "foo" : "bar" }')
258
258
  knife.parse_options(["--hint", "openstack=hints/openstack.json"])
259
259
  knife.merge_configs
260
- expect(knife.render_template).to match /\{\"foo\":\"bar\"\}/
260
+ expect(knife.render_template).to match(/\{\"foo\":\"bar\"\}/)
261
261
  end
262
262
  end
263
263
 
@@ -395,6 +395,58 @@ describe Chef::Knife::Bootstrap do
395
395
  end
396
396
  end
397
397
 
398
+ describe "handling policyfile options" do
399
+
400
+ context "when only policy_name is given" do
401
+
402
+ let(:bootstrap_cli_options) { %w[ --policy-name my-app-server ] }
403
+
404
+ it "returns an error stating that policy_name and policy_group must be given together" do
405
+ expect { knife.validate_options! }.to raise_error(SystemExit)
406
+ expect(stderr.string).to include("ERROR: --policy-name and --policy-group must be specified together")
407
+ end
408
+
409
+ end
410
+
411
+ context "when only policy_group is given" do
412
+
413
+ let(:bootstrap_cli_options) { %w[ --policy-group staging ] }
414
+
415
+ it "returns an error stating that policy_name and policy_group must be given together" do
416
+ expect { knife.validate_options! }.to raise_error(SystemExit)
417
+ expect(stderr.string).to include("ERROR: --policy-name and --policy-group must be specified together")
418
+ end
419
+
420
+ end
421
+
422
+ context "when both policy_name and policy_group are given, but run list is also given" do
423
+
424
+ let(:bootstrap_cli_options) { %w[ --policy-name my-app --policy-group staging --run-list cookbook ] }
425
+
426
+ it "returns an error stating that policyfile and run_list are exclusive" do
427
+ expect { knife.validate_options! }.to raise_error(SystemExit)
428
+ expect(stderr.string).to include("ERROR: Policyfile options and --run-list are exclusive")
429
+ end
430
+
431
+ end
432
+
433
+ context "when policy_name and policy_group are given with no conflicting options" do
434
+
435
+ let(:bootstrap_cli_options) { %w[ --policy-name my-app --policy-group staging ] }
436
+
437
+ it "passes options validation" do
438
+ expect { knife.validate_options! }.to_not raise_error
439
+ end
440
+
441
+ it "passes them into the bootstrap context" do
442
+ expect(knife.bootstrap_context.first_boot).to have_key(:policy_name)
443
+ expect(knife.bootstrap_context.first_boot).to have_key(:policy_group)
444
+ end
445
+
446
+ end
447
+
448
+ end
449
+
398
450
  describe "when configuring the underlying knife ssh command" do
399
451
  context "from the command line" do
400
452
  let(:knife_ssh) do
@@ -525,7 +577,7 @@ describe Chef::Knife::Bootstrap do
525
577
  it "verifies that a server to bootstrap was given as a command line arg" do
526
578
  knife.name_args = nil
527
579
  expect { knife.run }.to raise_error(SystemExit)
528
- expect(stderr.string).to match /ERROR:.+FQDN or ip/
580
+ expect(stderr.string).to match(/ERROR:.+FQDN or ip/)
529
581
  end
530
582
 
531
583
  describe "when running the bootstrap" do
@@ -78,21 +78,21 @@ describe Chef::Knife::CookbookSiteShare do
78
78
 
79
79
  it 'should not fail when given only 1 argument and can determine category' do
80
80
  @knife.name_args = ['cookbook_name']
81
- expect(@noauth_rest).to receive(:get_rest).with("http://cookbooks.opscode.com/api/v1/cookbooks/cookbook_name").and_return(@category_response)
81
+ expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@category_response)
82
82
  expect(@knife).to receive(:do_upload)
83
83
  @knife.run
84
84
  end
85
85
 
86
86
  it 'should print error and exit when given only 1 argument and cannot determine category' do
87
87
  @knife.name_args = ['cookbook_name']
88
- expect(@noauth_rest).to receive(:get_rest).with("http://cookbooks.opscode.com/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
88
+ expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name").and_return(@bad_category_response)
89
89
  expect(@knife.ui).to receive(:fatal)
90
90
  expect { @knife.run }.to raise_error(SystemExit)
91
91
  end
92
92
 
93
93
  it 'should print error and exit when given only 1 argument and Chef::REST throws an exception' do
94
94
  @knife.name_args = ['cookbook_name']
95
- expect(@noauth_rest).to receive(:get_rest).with("http://cookbooks.opscode.com/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
95
+ expect(@noauth_rest).to receive(:get_rest).with("https://supermarket.chef.io/api/v1/cookbooks/cookbook_name") { raise Errno::ECONNREFUSED, "Connection refused" }
96
96
  expect(@knife.ui).to receive(:fatal)
97
97
  expect { @knife.run }.to raise_error(SystemExit)
98
98
  end