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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -40,20 +40,30 @@ describe Chef::Knife::CookbookDelete do
40
40
  end
41
41
 
42
42
  context "when the cookbook doesn't exist" do
43
- before do
44
- @log_output = StringIO.new
45
-
46
- Chef::Log.logger = Logger.new(@log_output)
47
- Chef::Log.level = :debug
43
+ let(:log_output) { StringIO.new }
48
44
 
45
+ before do
49
46
  @knife.name_args = %w{no-such-cookbook}
50
47
  @api.get("/cookbooks/no-such-cookbook", 404, Chef::JSONCompat.to_json({'error'=>'dear Tim, no. -Sent from my iPad'}))
51
48
  end
52
49
 
50
+ around do |ex|
51
+ old_logger = Chef::Log.logger
52
+ old_level = Chef::Log.level
53
+ begin
54
+ Chef::Log.logger = Logger.new(log_output)
55
+ Chef::Log.level = :debug
56
+ ex.run
57
+ ensure
58
+ Chef::Log.logger = old_logger
59
+ Chef::Log.level = old_level
60
+ end
61
+ end
62
+
53
63
  it "logs an error and exits" do
54
- allow(@knife.ui).to receive(:stderr).and_return(@log_output)
64
+ allow(@knife.ui).to receive(:stderr).and_return(log_output)
55
65
  expect {@knife.run}.to raise_error(SystemExit)
56
- expect(@log_output.string).to match(/Cannot find a cookbook named no-such-cookbook to delete/)
66
+ expect(log_output.string).to match(/Cannot find a cookbook named no-such-cookbook to delete/)
57
67
  end
58
68
 
59
69
  end
@@ -31,6 +31,22 @@ describe Chef::Knife::Ssh do
31
31
  @server.stop
32
32
  end
33
33
 
34
+ let(:ssh_config) { Hash.new }
35
+ before do
36
+ allow(Net::SSH).to receive(:configuration_for).and_return(ssh_config)
37
+ end
38
+
39
+ # Force log level to info.
40
+ around do |ex|
41
+ old_level = Chef::Log.level
42
+ begin
43
+ Chef::Log.level = :info
44
+ ex.run
45
+ ensure
46
+ Chef::Log.level = old_level
47
+ end
48
+ end
49
+
34
50
  describe "identity file" do
35
51
  context "when knife[:ssh_identity_file] is set" do
36
52
  before do
@@ -43,7 +43,7 @@ describe Chef::Platform::Rebooter do
43
43
 
44
44
  let(:expected) do
45
45
  {
46
- :windows => 'shutdown /r /t 5 /c "rebooter spec test"',
46
+ :windows => 'shutdown /r /t 300 /c "rebooter spec test"',
47
47
  :linux => 'shutdown -r +5 "rebooter spec test"'
48
48
  }
49
49
  end
@@ -819,7 +819,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do
819
819
  end
820
820
 
821
821
  before do
822
- expect { deploy_that_fails.run_action(:deploy) }.to raise_error(Chef::Exceptions::Exec)
822
+ expect { deploy_that_fails.run_action(:deploy) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
823
823
  deploy_to_latest_with_callback_tracking.run_action(:deploy)
824
824
  end
825
825
 
@@ -43,6 +43,8 @@ describe Chef::Resource::DscResource, :windows_powershell_dsc_only do
43
43
  before do
44
44
  if !Chef::Platform.supports_dsc_invoke_resource?(node)
45
45
  skip 'Requires Powershell >= 5.0.10018.0'
46
+ elsif !Chef::Platform.dsc_refresh_mode_disabled?(node)
47
+ skip 'Requires LCM RefreshMode is Disabled'
46
48
  end
47
49
  end
48
50
  context 'with an invalid dsc resource' do
@@ -19,6 +19,7 @@
19
19
  require 'spec_helper'
20
20
  require 'chef/mixin/shell_out'
21
21
  require 'chef/mixin/windows_architecture_helper'
22
+ require 'support/shared/integration/integration_helper'
22
23
 
23
24
  describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
24
25
  include Chef::Mixin::WindowsArchitectureHelper
@@ -67,8 +68,7 @@ describe Chef::Resource::DscScript, :windows_powershell_dsc_only do
67
68
  node = Chef::Node.new
68
69
  node.automatic['platform'] = 'windows'
69
70
  node.automatic['platform_version'] = '6.1'
70
- node.automatic['kernel'][:machine] =
71
- is_i386_process_on_x86_64_windows? ? :x86_64 : :i386
71
+ node.automatic['kernel'][:machine] = :x86_64 # Only 64-bit architecture is supported
72
72
  node.automatic[:languages][:powershell][:version] = '4.0'
73
73
  empty_events = Chef::EventDispatch::Dispatcher.new
74
74
  Chef::RunContext.new(node, {}, empty_events)
@@ -379,4 +379,93 @@ EOH
379
379
  it_behaves_like 'a dsc_script with configuration data that takes parameters'
380
380
  it_behaves_like 'a dsc_script without configuration data that takes parameters'
381
381
  end
382
+
383
+ context 'when using ps_credential' do
384
+ include IntegrationSupport
385
+
386
+ before(:each) do
387
+ delete_user(dsc_user)
388
+ ohai_reader = Ohai::System.new
389
+ ohai_reader.all_plugins(["platform", "os", "languages/powershell"])
390
+ dsc_test_run_context.node.consume_external_attrs(ohai_reader.data,{})
391
+ end
392
+
393
+ let(:configuration_data_path) { 'C:\\configurationdata.psd1' }
394
+
395
+ let(:self_signed_cert_path) do
396
+ File.join(CHEF_SPEC_DATA, 'dsc_lcm.pfx')
397
+ end
398
+
399
+ let(:dsc_configuration_script) do
400
+ <<-MYCODE
401
+ cd c:\\
402
+ configuration LCM
403
+ {
404
+ param ($thumbprint)
405
+ localconfigurationmanager
406
+ {
407
+ RebootNodeIfNeeded = $false
408
+ ConfigurationMode = 'ApplyOnly'
409
+ CertificateID = $thumbprint
410
+ }
411
+ }
412
+ $cert = ls Cert:\\LocalMachine\\My\\ |
413
+ Where-Object {$_.Subject -match "ChefTest"} |
414
+ Select -first 1
415
+
416
+ if($cert -eq $null) {
417
+ $pfxpath = '#{self_signed_cert_path}'
418
+ $password = ''
419
+ $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($pfxpath, $password, ([System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::PersistKeySet -bor [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::MachineKeyset))
420
+ $store = New-Object System.Security.Cryptography.X509Certificates.X509Store "My", ([System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine)
421
+ $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
422
+ $store.Add($cert)
423
+ $store.Close()
424
+ }
425
+
426
+ lcm -thumbprint $cert.thumbprint
427
+ set-dsclocalconfigurationmanager -path ./LCM
428
+ $ConfigurationData = @"
429
+ @{
430
+ AllNodes = @(
431
+ @{
432
+ NodeName = "localhost";
433
+ CertificateID = '$($cert.thumbprint)';
434
+ };
435
+ );
436
+ }
437
+ "@
438
+ $ConfigurationData | out-file '#{configuration_data_path}' -force
439
+ MYCODE
440
+ end
441
+
442
+ let(:powershell_script_resource) do
443
+ Chef::Resource::PowershellScript.new('configure-lcm', dsc_test_run_context).tap do |r|
444
+ r.code(dsc_configuration_script)
445
+ r.architecture(:x86_64)
446
+ end
447
+ end
448
+
449
+ let(:dsc_script_resource) do
450
+ dsc_test_resource_base.tap do |r|
451
+ r.code <<-EOF
452
+ User dsctestusercreate
453
+ {
454
+ UserName = '#{dsc_user}'
455
+ Password = #{r.ps_credential('jf9a8m49jrajf4#')}
456
+ Ensure = "Present"
457
+ }
458
+ EOF
459
+ r.configuration_data_script(configuration_data_path)
460
+ end
461
+ end
462
+
463
+ it 'allows the use of ps_credential' do
464
+ expect(user_exists?(dsc_user)).to eq(false)
465
+ powershell_script_resource.run_action(:run)
466
+ expect(File).to exist(configuration_data_path)
467
+ dsc_script_resource.run_action(:run)
468
+ expect(user_exists?(dsc_user)).to eq(true)
469
+ end
470
+ end
382
471
  end
@@ -95,7 +95,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
95
95
 
96
96
  def create_user(username)
97
97
  user(username).run_action(:create) if ! windows_domain_user?(username)
98
- # TODO: User shouldn't exist
98
+ # TODO: User should exist
99
99
  end
100
100
 
101
101
  def remove_user(username)
@@ -135,44 +135,75 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
135
135
  group_should_not_exist(group_name)
136
136
  end
137
137
 
138
- describe "when append is not set" do
139
- let(:included_members) { [spec_members[1]] }
140
-
141
- before do
142
- create_user(spec_members[1])
143
- create_user(spec_members[0])
144
- add_members_to_group([spec_members[0]])
145
- end
138
+ # dscl doesn't perform any error checking and will let you add users that don't exist.
139
+ describe "when no users exist", :not_supported_on_mac_osx do
140
+ describe "when append is not set" do
141
+ # excluded_members can only be used when append is set. It is ignored otherwise.
142
+ let(:excluded_members) { [] }
146
143
 
147
- after do
148
- remove_user(spec_members[1])
149
- remove_user(spec_members[0])
144
+ it "should raise an error" do
145
+ expect { group_resource.run_action(tested_action) }.to raise_error()
146
+ end
150
147
  end
151
148
 
152
- it "should remove the existing users and add the new users to the group" do
153
- group_resource.run_action(tested_action)
149
+ describe "when append is set" do
150
+ before do
151
+ group_resource.append(true)
152
+ end
154
153
 
155
- expect(user_exist_in_group?(spec_members[1])).to eq(true)
156
- expect(user_exist_in_group?(spec_members[0])).to eq(false)
154
+ it "should raise an error" do
155
+ expect { group_resource.run_action(tested_action) }.to raise_error()
156
+ end
157
157
  end
158
158
  end
159
159
 
160
- describe "when append is set" do
161
- before(:each) do
162
- group_resource.append(true)
160
+ describe "when the users exist" do
161
+ before do
162
+ (spec_members).each do |member|
163
+ create_user(member)
164
+ end
163
165
  end
164
166
 
165
- describe "when the users exist" do
166
- before do
167
- (included_members + excluded_members).each do |member|
168
- create_user(member)
167
+ after do
168
+ (spec_members).each do |member|
169
+ remove_user(member)
170
+ end
171
+ end
172
+
173
+ describe "when append is not set" do
174
+ it "should set the group to to contain given members" do
175
+ group_resource.run_action(tested_action)
176
+
177
+ included_members.each do |member|
178
+ expect(user_exist_in_group?(member)).to eq(true)
179
+ end
180
+ (spec_members - included_members).each do |member|
181
+ expect(user_exist_in_group?(member)).to eq(false)
169
182
  end
170
183
  end
171
184
 
172
- after do
173
- (included_members + excluded_members).each do |member|
174
- remove_user(member)
185
+ describe "when group already contains some users" do
186
+ before do
187
+ add_members_to_group([included_members[0]])
188
+ add_members_to_group(spec_members - included_members)
175
189
  end
190
+
191
+ it "should remove all existing users and only add the new users to the group" do
192
+ group_resource.run_action(tested_action)
193
+
194
+ included_members.each do |member|
195
+ expect(user_exist_in_group?(member)).to eq(true)
196
+ end
197
+ (spec_members - included_members).each do |member|
198
+ expect(user_exist_in_group?(member)).to eq(false)
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ describe "when append is set" do
205
+ before(:each) do
206
+ group_resource.append(true)
176
207
  end
177
208
 
178
209
  it "should add included members to the group" do
@@ -186,9 +217,9 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
186
217
  end
187
218
  end
188
219
 
189
- describe "when group contains some users" do
220
+ describe "when group already contains some users" do
190
221
  before(:each) do
191
- add_members_to_group([ spec_members[0], spec_members[2] ])
222
+ add_members_to_group([included_members[0], excluded_members[0]])
192
223
  end
193
224
 
194
225
  it "should add the included users and remove excluded users" do
@@ -203,20 +234,6 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
203
234
  end
204
235
  end
205
236
  end
206
-
207
- describe "when the users doesn't exist" do
208
- describe "when append is not set" do
209
- it "should raise an error" do
210
- expect { @grp_resource.run_action(tested_action) }.to raise_error
211
- end
212
- end
213
-
214
- describe "when append is set" do
215
- it "should raise an error" do
216
- expect { @grp_resource.run_action(tested_action) }.to raise_error
217
- end
218
- end
219
- end
220
237
  end
221
238
  end
222
239
 
@@ -231,6 +248,12 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
231
248
  group_should_exist(group_name)
232
249
  end
233
250
 
251
+ after(:each) do
252
+ group_resource.run_action(:remove)
253
+ end
254
+
255
+ # TODO: The ones below might actually return ArgumentError now - but I don't have
256
+ # a way to verify that. Change it and delete this comment if that's the case.
234
257
  describe "when updating membership" do
235
258
  it "raises an error for a non well-formed domain name" do
236
259
  group_resource.members [invalid_domain_user_name]
@@ -256,7 +279,7 @@ describe Chef::Resource::Group, :requires_root_or_running_windows, :not_supporte
256
279
  end
257
280
  end
258
281
 
259
- let(:group_name) { "t-#{SecureRandom.random_number(9999)}" }
282
+ let(:group_name) { "group#{SecureRandom.random_number(9999)}" }
260
283
  let(:included_members) { nil }
261
284
  let(:excluded_members) { nil }
262
285
  let(:group_resource) {
@@ -300,7 +323,7 @@ theoldmanwalkingdownthestreetalwayshadagoodsmileonhisfacetheoldmanwalking\
300
323
  downthestreetalwayshadagoodsmileonhisfacetheoldmanwalkingdownthestreeQQQQQQ" }
301
324
 
302
325
  it "should not create a group" do
303
- expect { group_resource.run_action(:create) }.to raise_error
326
+ expect { group_resource.run_action(:create) }.to raise_error(ArgumentError)
304
327
  group_should_not_exist(group_name)
305
328
  end
306
329
  end
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'chef/platform/query_helpers'
19
20
  require 'spec_helper'
20
21
 
21
22
  describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
@@ -27,7 +28,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
27
28
 
28
29
  it_behaves_like "a Windows script running on Windows"
29
30
 
30
-
31
31
  let(:successful_executable_script_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe $env:systemroot" }
32
32
  let(:failed_executable_script_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe /badargument" }
33
33
  let(:processor_architecture_script_content) { "echo $env:PROCESSOR_ARCHITECTURE" }
@@ -57,6 +57,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
57
57
  end
58
58
 
59
59
  it "returns the exit status 27 for a powershell script that exits with 27" do
60
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
61
+
60
62
  file = Tempfile.new(['foo', '.ps1'])
61
63
  begin
62
64
  file.write "exit 27"
@@ -73,6 +75,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
73
75
  let (:negative_exit_status) { -27 }
74
76
  let (:unsigned_exit_status) { (-negative_exit_status ^ 65535) + 1 }
75
77
  it "returns the exit status -27 as a signed integer or an unsigned 16-bit 2's complement value of 65509 for a powershell script that exits with -27" do
78
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
79
+
76
80
  # Versions of PowerShell prior to 4.0 return a 16-bit unsigned value --
77
81
  # PowerShell 4.0 and later versions return a 32-bit signed value.
78
82
  file = Tempfile.new(['foo', '.ps1'])
@@ -96,6 +100,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
96
100
  end
97
101
 
98
102
  it "returns the process exit code" do
103
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
104
+
99
105
  resource.code(arbitrary_nonzero_process_exit_code_content)
100
106
  resource.returns(arbitrary_nonzero_process_exit_code)
101
107
  resource.run_action(:run)
@@ -114,27 +120,37 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
114
120
  end
115
121
 
116
122
  it "returns 1 if the last command was a cmdlet that failed" do
123
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
124
+
117
125
  resource.code(cmdlet_exit_code_not_found_content)
118
126
  resource.returns(1)
119
127
  resource.run_action(:run)
120
128
  end
121
129
 
122
130
  it "returns 1 if the last command was a cmdlet that failed and was preceded by a successfully executed non-cmdlet Windows binary" do
131
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
132
+
123
133
  resource.code([windows_process_exit_code_success_content, cmdlet_exit_code_not_found_content].join(';'))
124
134
  resource.returns(1)
125
135
  expect { resource.run_action(:run) }.not_to raise_error
126
136
  end
127
137
 
128
- it "raises an error if the script is not syntactically correct and returns is not set to 1" do
138
+ it "raises a Mixlib::ShellOut::ShellCommandFailed error if the script is not syntactically correct" do
139
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
140
+
129
141
  resource.code('if({)')
130
142
  resource.returns(0)
131
143
  expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
132
144
  end
133
145
 
134
- it "returns 1 if the script provided to the code attribute is not syntactically correct" do
146
+ it "raises an error if the script is not syntactically correct even if returns is set to 1 which is what powershell.exe returns for syntactically invalid scripts" do
147
+ # This test fails because shell_out expects the exit status to be 1, but it is actually 0
148
+ # The error is a false-positive.
149
+ skip "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
150
+
135
151
  resource.code('if({)')
136
152
  resource.returns(1)
137
- expect { resource.run_action(:run) }.not_to raise_error
153
+ expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
138
154
  end
139
155
 
140
156
  # This somewhat ambiguous case, two failures of different types,
@@ -146,24 +162,32 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
146
162
  # errors than 0 or 1, we return that instead, which is acceptable
147
163
  # since callers can test for nonzero rather than testing for 1.
148
164
  it "returns 1 if the last command was a cmdlet that failed and was preceded by an unsuccessfully executed non-cmdlet Windows binary" do
165
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
166
+
149
167
  resource.code([arbitrary_nonzero_process_exit_code_content,cmdlet_exit_code_not_found_content].join(';'))
150
168
  resource.returns(arbitrary_nonzero_process_exit_code)
151
169
  resource.run_action(:run)
152
170
  end
153
171
 
154
172
  it "returns 0 if the last command was a non-cmdlet Windows binary that succeeded and was preceded by a failed cmdlet" do
173
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
174
+
155
175
  resource.code([cmdlet_exit_code_success_content, arbitrary_nonzero_process_exit_code_content].join(';'))
156
176
  resource.returns(arbitrary_nonzero_process_exit_code)
157
177
  resource.run_action(:run)
158
178
  end
159
179
 
160
180
  it "returns a specific error code if the last command was a non-cmdlet Windows binary that failed and was preceded by cmdlet that succeeded" do
181
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
182
+
161
183
  resource.code([cmdlet_exit_code_success_content, arbitrary_nonzero_process_exit_code_content].join(';'))
162
184
  resource.returns(arbitrary_nonzero_process_exit_code)
163
185
  resource.run_action(:run)
164
186
  end
165
187
 
166
188
  it "returns a specific error code if the last command was a non-cmdlet Windows binary that failed and was preceded by cmdlet that failed" do
189
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
190
+
167
191
  resource.code([cmdlet_exit_code_not_found_content, arbitrary_nonzero_process_exit_code_content].join(';'))
168
192
  resource.returns(arbitrary_nonzero_process_exit_code)
169
193
  resource.run_action(:run)
@@ -182,6 +206,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
182
206
  end
183
207
 
184
208
  it "returns 1 for $false as the last line of the script when convert_boolean_return is true" do
209
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
210
+
185
211
  resource.convert_boolean_return true
186
212
  resource.code "$false"
187
213
  resource.returns(1)
@@ -208,6 +234,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
208
234
  end
209
235
 
210
236
  it "returns 1 if an invalid flag is passed to the interpreter" do
237
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
238
+
211
239
  resource.code(cmdlet_exit_code_success_content)
212
240
  resource.flags(invalid_powershell_interpreter_flag)
213
241
  resource.returns(1)
@@ -227,10 +255,25 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
227
255
  expect { resource.should_skip?(:run) }.to raise_error(ArgumentError, /guard_interpreter does not support blocks/)
228
256
  end
229
257
 
258
+ context "when dsc is supported", :windows_powershell_dsc_only do
259
+ it "can execute LCM configuration code" do
260
+ resource.code <<-EOF
261
+ configuration LCM
262
+ {
263
+ param ($thumbprint)
264
+ localconfigurationmanager
265
+ {
266
+ RebootNodeIfNeeded = $false
267
+ ConfigurationMode = 'ApplyOnly'
268
+ }
269
+ }
270
+ EOF
271
+ expect { resource.run_action(:run) }.not_to raise_error
272
+ end
273
+ end
230
274
  end
231
275
 
232
- context "when running on a 32-bit version of Windows", :windows32_only do
233
-
276
+ context "when running on a 32-bit version of Ruby", :ruby32_only do
234
277
  it "executes a script with a 32-bit process if process architecture :i386 is specified" do
235
278
  resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
236
279
  resource.architecture(:i386)
@@ -240,15 +283,28 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
240
283
  expect(source_contains_case_insensitive_content?( get_script_output, 'x86' )).to eq(true)
241
284
  end
242
285
 
243
- it "raises an exception if :x86_64 process architecture is specified" do
244
- begin
245
- expect(resource.architecture(:x86_64)).to raise_error Chef::Exceptions::Win32ArchitectureIncorrect
246
- rescue Chef::Exceptions::Win32ArchitectureIncorrect
286
+ context "when running on a 64-bit version of Windows", :windows64_only do
287
+ it "executes a script with a 64-bit process if :x86_64 arch is specified" do
288
+ resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
289
+ resource.architecture(:x86_64)
290
+ resource.returns(0)
291
+ resource.run_action(:run)
292
+
293
+ expect(source_contains_case_insensitive_content?( get_script_output, 'AMD64' )).to eq(true)
294
+ end
295
+ end
296
+
297
+ context "when running on a 32-bit version of Windows", :windows32_only do
298
+ it "raises an exception if :x86_64 process architecture is specified" do
299
+ begin
300
+ expect(resource.architecture(:x86_64)).to raise_error Chef::Exceptions::Win32ArchitectureIncorrect
301
+ rescue Chef::Exceptions::Win32ArchitectureIncorrect
302
+ end
247
303
  end
248
304
  end
249
305
  end
250
306
 
251
- context "when running on a 64-bit version of Windows", :windows64_only do
307
+ context "when running on a 64-bit version of Ruby", :ruby64_only do
252
308
  it "executes a script with a 64-bit process if :x86_64 arch is specified" do
253
309
  resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
254
310
  resource.architecture(:x86_64)
@@ -258,7 +314,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
258
314
  expect(source_contains_case_insensitive_content?( get_script_output, 'AMD64' )).to eq(true)
259
315
  end
260
316
 
261
- it "executes a script with a 32-bit process if :i386 arch is specified" do
317
+ it "executes a script with a 32-bit process if :i386 arch is specified", :not_supported_on_nano do
262
318
  resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
263
319
  resource.architecture(:i386)
264
320
  resource.returns(0)
@@ -266,6 +322,12 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
266
322
 
267
323
  expect(source_contains_case_insensitive_content?( get_script_output, 'x86' )).to eq(true)
268
324
  end
325
+
326
+ it "raises an error when executing a script with a 32-bit process on Windows Nano Server", :windows_nano_only do
327
+ resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}")
328
+ expect{ resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect,
329
+ "cannot execute script with requested architecture 'i386' on Windows Nano Server")
330
+ end
269
331
  end
270
332
 
271
333
  describe "when executing guards" do
@@ -319,6 +381,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
319
381
  end
320
382
 
321
383
  it "evaluates a powershell $false for a not_if block as true" do
384
+ pending "powershell.exe always exits with $true on nano" if Chef::Platform.windows_nano_server?
385
+
322
386
  resource.not_if "$false"
323
387
  expect(resource.should_skip?(:run)).to be_falsey
324
388
  end
@@ -329,6 +393,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
329
393
  end
330
394
 
331
395
  it "evaluates a powershell $false for an only_if block as false" do
396
+ pending "powershell.exe always exits with $true on nano" if Chef::Platform.windows_nano_server?
397
+
332
398
  resource.only_if "$false"
333
399
  expect(resource.should_skip?(:run)).to be_truthy
334
400
  end
@@ -349,6 +415,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
349
415
  end
350
416
 
351
417
  it "evaluates a non-zero powershell exit status for not_if as true" do
418
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
419
+
352
420
  resource.not_if "exit 37"
353
421
  expect(resource.should_skip?(:run)).to be_falsey
354
422
  end
@@ -359,6 +427,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
359
427
  end
360
428
 
361
429
  it "evaluates a failed executable exit status for not_if as false" do
430
+ pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
431
+
362
432
  resource.not_if windows_process_exit_code_not_found_content
363
433
  expect(resource.should_skip?(:run)).to be_falsey
364
434
  end
@@ -369,6 +439,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
369
439
  end
370
440
 
371
441
  it "evaluates a failed executable exit status for only_if as false" do
442
+ pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
443
+
372
444
  resource.only_if windows_process_exit_code_not_found_content
373
445
  expect(resource.should_skip?(:run)).to be_truthy
374
446
  end
@@ -379,6 +451,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
379
451
  end
380
452
 
381
453
  it "evaluates a failed cmdlet exit status for not_if as true" do
454
+ pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
455
+
382
456
  resource.not_if "throw 'up'"
383
457
  expect(resource.should_skip?(:run)).to be_falsey
384
458
  end
@@ -389,6 +463,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
389
463
  end
390
464
 
391
465
  it "evaluates a failed cmdlet exit status for only_if as false" do
466
+ pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server?
467
+
392
468
  resource.only_if "throw 'up'"
393
469
  expect(resource.should_skip?(:run)).to be_truthy
394
470
  end
@@ -431,30 +507,36 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
431
507
  end
432
508
 
433
509
  it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean true as nonzero status code", :windows64_only do
510
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
511
+
434
512
  resource.architecture :x86_64
435
513
  resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'AMD64')"
436
514
  expect(resource.should_skip?(:run)).to be_truthy
437
515
  end
438
516
 
439
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" do
517
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code", :not_supported_on_nano do
440
518
  resource.architecture :i386
441
519
  resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'X86')"
442
520
  expect(resource.should_skip?(:run)).to be_falsey
443
521
  end
444
522
 
445
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" do
523
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code", :not_supported_on_nano do
446
524
  resource.architecture :i386
447
525
  resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'X86')"
448
526
  expect(resource.should_skip?(:run)).to be_truthy
449
527
  end
450
528
 
451
529
  it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for only_if" do
530
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
531
+
452
532
  resource.convert_boolean_return true
453
533
  resource.only_if "$false"
454
534
  expect(resource.should_skip?(:run)).to be_truthy
455
535
  end
456
536
 
457
537
  it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for not_if" do
538
+ pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server?
539
+
458
540
  resource.convert_boolean_return true
459
541
  resource.not_if "$false"
460
542
  expect(resource.should_skip?(:run)).to be_falsey
@@ -472,33 +554,40 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do
472
554
  expect(resource.should_skip?(:run)).to be_truthy
473
555
  end
474
556
 
475
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if" do
557
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if", :not_supported_on_nano do
476
558
  resource.convert_boolean_return true
477
559
  resource.architecture :i386
478
560
  resource.only_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
479
561
  expect(resource.should_skip?(:run)).to be_falsey
480
562
  end
481
563
 
482
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if" do
564
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if", :not_supported_on_nano do
483
565
  resource.convert_boolean_return true
484
566
  resource.architecture :i386
485
567
  resource.not_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
486
568
  expect(resource.should_skip?(:run)).to be_falsey
487
569
  end
488
570
 
489
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if" do
571
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if", :not_supported_on_nano do
490
572
  resource.convert_boolean_return true
491
573
  resource.architecture :i386
492
574
  resource.only_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'"
493
575
  expect(resource.should_skip?(:run)).to be_truthy
494
576
  end
495
577
 
496
- it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if" do
578
+ it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if", :not_supported_on_nano do
497
579
  resource.convert_boolean_return true
498
580
  resource.architecture :i386
499
581
  resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'"
500
582
  expect(resource.should_skip?(:run)).to be_truthy
501
583
  end
584
+
585
+ it "raises an error when a 32-bit guard is used on Windows Nano Server", :windows_nano_only do
586
+ resource.only_if "$true", :architecture => :i386
587
+ expect{resource.run_action(:run)}.to raise_error(
588
+ Chef::Exceptions::Win32ArchitectureIncorrect,
589
+ /cannot execute script with requested architecture 'i386' on Windows Nano Server/)
590
+ end
502
591
  end
503
592
  end
504
593