chef 12.5.0.alpha.1 → 12.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) 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 +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -0,0 +1,46 @@
1
+ #
2
+ # Author:: John Keiser <jkeiser@chef.io>
3
+ # Copyright:: Copyright (c) 2015 John Keiser.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ #
20
+ # Mocks shellout results. Examples:
21
+ # mock_shellout_command("systemctl --all", exitstatus: 1)
22
+ #
23
+ class MockShellout
24
+ module RSpec
25
+ def mock_shellout_command(command, **result)
26
+ allow(::Mixlib::ShellOut).to receive(:new).with(command, anything).and_return MockShellout.new(result)
27
+ end
28
+ end
29
+
30
+ def initialize(**properties)
31
+ @properties = {
32
+ stdout: "",
33
+ stderr: "",
34
+ exitstatus: 0
35
+ }.merge(properties)
36
+ end
37
+ def method_missing(name, *args)
38
+ @properties[name.to_sym]
39
+ end
40
+ def error?
41
+ exitstatus != 0
42
+ end
43
+ def error!
44
+ raise Mixlib::ShellOut::ShellCommandFailed, "Expected process to exit with 0, but received #{exitstatus}" if error?
45
+ end
46
+ end
@@ -465,11 +465,13 @@ shared_examples_for Chef::Provider::File do
465
465
  t
466
466
  }
467
467
 
468
- let(:verification) { double("Verification") }
468
+ let(:verification) { instance_double(Chef::Resource::File::Verification) }
469
+ let(:verification_fail) { instance_double(Chef::Resource::File::Verification) }
469
470
 
470
471
  context "with user-supplied verifications" do
471
472
  it "calls #verify on each verification with tempfile path" do
472
- allow(Chef::Resource::File::Verification).to receive(:new).and_return(verification)
473
+ allow(Chef::Resource::File::Verification).to(
474
+ receive(:new).with(anything(), "true", anything()).and_return(verification))
473
475
  provider.new_resource.verify "true"
474
476
  provider.new_resource.verify "true"
475
477
  expect(verification).to receive(:verify).with(tempfile.path).twice.and_return(true)
@@ -477,10 +479,14 @@ shared_examples_for Chef::Provider::File do
477
479
  end
478
480
 
479
481
  it "raises an exception if any verification fails" do
482
+ allow(Chef::Resource::File::Verification).to(
483
+ receive(:new).with(anything(), "true", anything()).and_return(verification))
484
+ allow(Chef::Resource::File::Verification).to(
485
+ receive(:new).with(anything(), "false", anything()).and_return(verification_fail))
480
486
  provider.new_resource.verify "true"
481
487
  provider.new_resource.verify "false"
482
- allow(verification).to receive(:verify).with("true").and_return(true)
483
- allow(verification).to receive(:verify).with("false").and_return(false)
488
+ expect(verification).to receive(:verify).with(tempfile.path).and_return(true)
489
+ expect(verification_fail).to receive(:verify).with(tempfile.path).and_return(false)
484
490
  expect{provider.send(:do_validate_content)}.to raise_error(Chef::Exceptions::ValidationFailed)
485
491
  end
486
492
  end
@@ -47,6 +47,19 @@ describe Chef::Application::Client, "reconfigure" do
47
47
  expect(app).to receive(:set_specific_recipes).and_return(true)
48
48
  app.reconfigure
49
49
  end
50
+
51
+ context "when given a named_run_list" do
52
+
53
+ before do
54
+ ARGV.replace( %w[ --named-run-list arglebargle-example ] )
55
+ app.reconfigure
56
+ end
57
+
58
+ it "sets named_run_list in Chef::Config" do
59
+ expect(Chef::Config[:named_run_list]).to eq("arglebargle-example")
60
+ end
61
+
62
+ end
50
63
  end
51
64
 
52
65
  describe "when configured to not fork the client process" do
@@ -237,7 +250,7 @@ Enable chef-client interval runs by setting `:client_fork = true` in your config
237
250
  end
238
251
 
239
252
  it "should throw an exception" do
240
- expect { @app.reconfigure }.to raise_error
253
+ expect { app.reconfigure }.to raise_error(Chef::Exceptions::PIDFileLockfileMatch)
241
254
  end
242
255
  end
243
256
  end
@@ -275,9 +288,9 @@ describe Chef::Application::Client, "configure_chef" do
275
288
  ARGV.replace(@original_argv)
276
289
  end
277
290
 
278
- it "should set the colored output to false by default on windows and true otherwise" do
291
+ it "should set the colored output to true by default on windows and true on all other platforms as well" do
279
292
  if windows?
280
- expect(Chef::Config[:color]).to be_falsey
293
+ expect(Chef::Config[:color]).to be_truthy
281
294
  else
282
295
  expect(Chef::Config[:color]).to be_truthy
283
296
  end
@@ -70,13 +70,13 @@ describe Chef::Application::Knife do
70
70
  end
71
71
  end
72
72
 
73
- it "should set the colored output to false by default on windows and true otherwise" do
73
+ it "should set the colored output to true by default on windows and true on all other platforms as well" do
74
74
  with_argv(*%w{noop knife command}) do
75
75
  expect(@knife).to receive(:exit).with(0)
76
76
  @knife.run
77
77
  end
78
78
  if windows?
79
- expect(Chef::Config[:color]).to be_falsey
79
+ expect(Chef::Config[:color]).to be_truthy
80
80
  else
81
81
  expect(Chef::Config[:color]).to be_truthy
82
82
  end
@@ -46,10 +46,6 @@ describe "Chef class" do
46
46
  Chef.set_provider_priority_map(provider_priority_map)
47
47
  end
48
48
 
49
- after do
50
- Chef.reset!
51
- end
52
-
53
49
  context "priority maps" do
54
50
  context "#get_provider_priority_array" do
55
51
  it "should use the current node to get the right priority_map" do
@@ -364,6 +364,8 @@ describe Chef::Client do
364
364
  expect(node[:expanded_run_list]).to be_nil
365
365
 
366
366
  allow(client.policy_builder).to receive(:node).and_return(node)
367
+ client.policy_builder.select_implementation(node)
368
+ allow(client.policy_builder.implementation).to receive(:node).and_return(node)
367
369
 
368
370
  # chefspec and possibly others use the return value of this method
369
371
  expect(client.build_node).to eq(node)
@@ -373,7 +375,8 @@ describe Chef::Client do
373
375
  expect(node[:roles].length).to eq(1)
374
376
  expect(node[:roles]).to include("role_containing_cookbook1")
375
377
  expect(node[:recipes]).not_to be_nil
376
- expect(node[:recipes].length).to eq(1)
378
+ expect(node[:recipes].length).to eq(2)
379
+ expect(node[:recipes]).to include("cookbook1")
377
380
  expect(node[:recipes]).to include("cookbook1::default")
378
381
  expect(node[:expanded_run_list]).not_to be_nil
379
382
  expect(node[:expanded_run_list].length).to eq(1)
@@ -391,6 +394,8 @@ describe Chef::Client do
391
394
  expect(mock_chef_rest).to receive(:get_rest).with("environments/A").and_return(test_env)
392
395
  expect(Chef::REST).to receive(:new).and_return(mock_chef_rest)
393
396
  allow(client.policy_builder).to receive(:node).and_return(node)
397
+ client.policy_builder.select_implementation(node)
398
+ allow(client.policy_builder.implementation).to receive(:node).and_return(node)
394
399
  expect(client.build_node).to eq(node)
395
400
 
396
401
  expect(node.chef_environment).to eq("A")
@@ -0,0 +1,31 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ require 'chef/config'
5
+
6
+ RSpec.describe Chef::Config do
7
+
8
+ shared_examples_for "deprecated by ohai but not deprecated" do
9
+ it "does not emit a deprecation warning when set" do
10
+ expect(Chef::Log).to_not receive(:warn).
11
+ with(/Ohai::Config\[:#{option}\] is deprecated/)
12
+ Chef::Config[option] = value
13
+ expect(Chef::Config[option]).to eq(value)
14
+ end
15
+ end
16
+
17
+ describe ":log_level" do
18
+ include_examples "deprecated by ohai but not deprecated" do
19
+ let(:option) { :log_level }
20
+ let(:value) { :debug }
21
+ end
22
+ end
23
+
24
+ describe ":log_location" do
25
+ include_examples "deprecated by ohai but not deprecated" do
26
+ let(:option) { :log_location }
27
+ let(:value) { "path/to/log" }
28
+ end
29
+ end
30
+
31
+ end
@@ -30,7 +30,7 @@ describe Chef::Cookbook::Metadata do
30
30
  :maintainer_email, :license, :platforms, :dependencies,
31
31
  :recommendations, :suggestions, :conflicting, :providing,
32
32
  :replacing, :attributes, :groupings, :recipes, :version,
33
- :source_url, :issues_url ]
33
+ :source_url, :issues_url, :privacy ]
34
34
  end
35
35
 
36
36
  it "does not depend on object identity for equality" do
@@ -148,6 +148,10 @@ describe Chef::Cookbook::Metadata do
148
148
  it "has an empty issues_url string" do
149
149
  expect(metadata.issues_url).to eq('')
150
150
  end
151
+
152
+ it "is not private" do
153
+ expect(metadata.privacy).to eq(false)
154
+ end
151
155
  end
152
156
 
153
157
  describe "validation" do
@@ -198,7 +202,8 @@ describe Chef::Cookbook::Metadata do
198
202
  :long_description => "Much Longer\nSeriously",
199
203
  :version => "0.6.0",
200
204
  :source_url => "http://example.com",
201
- :issues_url => "http://example.com/issues"
205
+ :issues_url => "http://example.com/issues",
206
+ :privacy => true
202
207
  }
203
208
  params.sort { |a,b| a.to_s <=> b.to_s }.each do |field, field_value|
204
209
  describe field do
@@ -360,7 +365,8 @@ describe Chef::Cookbook::Metadata do
360
365
  "recipes" => [ "mysql::server", "mysql::master" ],
361
366
  "default" => [ ],
362
367
  "source_url" => "http://example.com",
363
- "issues_url" => "http://example.com/issues"
368
+ "issues_url" => "http://example.com/issues",
369
+ "privacy" => true
364
370
  }
365
371
  expect(metadata.attribute("/db/mysql/databases", attrs)).to eq(attrs)
366
372
  end
@@ -401,6 +407,18 @@ describe Chef::Cookbook::Metadata do
401
407
  }.to raise_error(ArgumentError)
402
408
  end
403
409
 
410
+ it "should not accept anything but true or false for the privacy flag" do
411
+ expect {
412
+ metadata.attribute("db/mysql/databases", :privacy => true)
413
+ }.not_to raise_error
414
+ expect {
415
+ metadata.attribute("db/mysql/databases", :privacy => false)
416
+ }.not_to raise_error
417
+ expect {
418
+ metadata.attribute("db/mysql/databases", :privacy => 'true')
419
+ }.to raise_error(ArgumentError)
420
+ end
421
+
404
422
  it "should not accept anything but an array of strings for choice" do
405
423
  expect {
406
424
  metadata.attribute("db/mysql/databases", :choice => ['dedicated', 'shared'])
@@ -699,6 +717,7 @@ describe Chef::Cookbook::Metadata do
699
717
  version
700
718
  source_url
701
719
  issues_url
720
+ privacy
702
721
  }.each do |t|
703
722
  it "should include '#{t}'" do
704
723
  expect(deserialized_metadata[t]).to eq(metadata.send(t.to_sym))
@@ -734,6 +753,7 @@ describe Chef::Cookbook::Metadata do
734
753
  version
735
754
  source_url
736
755
  issues_url
756
+ privacy
737
757
  }.each do |t|
738
758
  it "should match '#{t}'" do
739
759
  expect(deserialized_metadata.send(t.to_sym)).to eq(metadata.send(t.to_sym))
@@ -53,7 +53,10 @@ describe Chef::Cookbook::SyntaxCheck do
53
53
  @ruby_files = @attr_files + @libr_files + @defn_files + @recipes + [File.join(cookbook_path, "metadata.rb")]
54
54
  basenames = %w{ helpers_via_partial_test.erb
55
55
  helper_test.erb
56
+ helpers.erb
56
57
  openldap_stuff.conf.erb
58
+ nested_openldap_partials.erb
59
+ nested_partial.erb
57
60
  openldap_variable_stuff.conf.erb
58
61
  test.erb
59
62
  some_windows_line_endings.erb
@@ -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
@@ -32,10 +32,6 @@ describe Chef::EventDispatch::DSL do
32
32
  Chef.set_run_context(run_context)
33
33
  end
34
34
 
35
- after do
36
- Chef.reset!
37
- end
38
-
39
35
  subject{ described_class.new('test') }
40
36
 
41
37
  it 'set handler name' do
@@ -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