chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -1
  3. data/lib/chef/api_client.rb +130 -26
  4. data/lib/chef/application.rb +0 -1
  5. data/lib/chef/application/client.rb +8 -19
  6. data/lib/chef/audit/audit_reporter.rb +12 -7
  7. data/lib/chef/audit/logger.rb +36 -0
  8. data/lib/chef/audit/runner.rb +4 -2
  9. data/lib/chef/chef_class.rb +62 -11
  10. data/lib/chef/client.rb +587 -207
  11. data/lib/chef/config.rb +0 -1
  12. data/lib/chef/dsl/recipe.rb +45 -56
  13. data/lib/chef/dsl/resources.rb +3 -2
  14. data/lib/chef/event_dispatch/base.rb +7 -2
  15. data/lib/chef/exceptions.rb +4 -1
  16. data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
  17. data/lib/chef/formatters/doc.rb +15 -7
  18. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
  19. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
  20. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
  21. data/lib/chef/http/authenticator.rb +7 -2
  22. data/lib/chef/knife.rb +16 -4
  23. data/lib/chef/knife/client_create.rb +55 -31
  24. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  25. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  26. data/lib/chef/knife/osc_user_create.rb +97 -0
  27. data/lib/chef/knife/osc_user_delete.rb +51 -0
  28. data/lib/chef/knife/osc_user_edit.rb +58 -0
  29. data/lib/chef/knife/osc_user_list.rb +47 -0
  30. data/lib/chef/knife/osc_user_reregister.rb +64 -0
  31. data/lib/chef/knife/osc_user_show.rb +54 -0
  32. data/lib/chef/knife/user_create.rb +95 -36
  33. data/lib/chef/knife/user_delete.rb +52 -2
  34. data/lib/chef/knife/user_edit.rb +37 -7
  35. data/lib/chef/knife/user_list.rb +3 -0
  36. data/lib/chef/knife/user_reregister.rb +39 -8
  37. data/lib/chef/knife/user_show.rb +30 -1
  38. data/lib/chef/mixin/api_version_request_handling.rb +66 -0
  39. data/lib/chef/mixin/convert_to_class_name.rb +10 -4
  40. data/lib/chef/mixin/deprecation.rb +24 -0
  41. data/lib/chef/mixin/powershell_out.rb +98 -0
  42. data/lib/chef/mixin/provides.rb +5 -18
  43. data/lib/chef/mixin/uris.rb +11 -0
  44. data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
  45. data/lib/chef/mixin/windows_env_helper.rb +11 -2
  46. data/lib/chef/node_map.rb +130 -75
  47. data/lib/chef/osc_user.rb +194 -0
  48. data/lib/chef/platform/provider_mapping.rb +2 -269
  49. data/lib/chef/platform/provider_priority_map.rb +6 -69
  50. data/lib/chef/platform/query_helpers.rb +5 -0
  51. data/lib/chef/platform/resource_priority_map.rb +12 -15
  52. data/lib/chef/policy_builder/policyfile.rb +1 -0
  53. data/lib/chef/provider.rb +19 -0
  54. data/lib/chef/provider/directory.rb +3 -0
  55. data/lib/chef/provider/dsc_resource.rb +8 -1
  56. data/lib/chef/provider/file.rb +1 -0
  57. data/lib/chef/provider/group/aix.rb +1 -0
  58. data/lib/chef/provider/group/dscl.rb +1 -1
  59. data/lib/chef/provider/group/gpasswd.rb +1 -0
  60. data/lib/chef/provider/group/groupmod.rb +1 -1
  61. data/lib/chef/provider/group/pw.rb +1 -0
  62. data/lib/chef/provider/group/suse.rb +2 -0
  63. data/lib/chef/provider/group/usermod.rb +2 -1
  64. data/lib/chef/provider/group/windows.rb +1 -1
  65. data/lib/chef/provider/ifconfig.rb +2 -0
  66. data/lib/chef/provider/ifconfig/aix.rb +1 -0
  67. data/lib/chef/provider/ifconfig/debian.rb +2 -0
  68. data/lib/chef/provider/ifconfig/redhat.rb +1 -0
  69. data/lib/chef/provider/lwrp_base.rb +4 -0
  70. data/lib/chef/provider/mount.rb +0 -1
  71. data/lib/chef/provider/mount/aix.rb +1 -0
  72. data/lib/chef/provider/mount/mount.rb +2 -0
  73. data/lib/chef/provider/mount/solaris.rb +2 -0
  74. data/lib/chef/provider/package.rb +55 -0
  75. data/lib/chef/provider/package/aix.rb +7 -7
  76. data/lib/chef/provider/package/apt.rb +3 -3
  77. data/lib/chef/provider/package/dpkg.rb +4 -4
  78. data/lib/chef/provider/package/easy_install.rb +5 -5
  79. data/lib/chef/provider/package/freebsd/base.rb +2 -2
  80. data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
  81. data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
  82. data/lib/chef/provider/package/freebsd/port.rb +4 -4
  83. data/lib/chef/provider/package/homebrew.rb +2 -2
  84. data/lib/chef/provider/package/ips.rb +4 -4
  85. data/lib/chef/provider/package/macports.rb +5 -6
  86. data/lib/chef/provider/package/openbsd.rb +4 -5
  87. data/lib/chef/provider/package/pacman.rb +4 -4
  88. data/lib/chef/provider/package/portage.rb +2 -0
  89. data/lib/chef/provider/package/rpm.rb +7 -8
  90. data/lib/chef/provider/package/rubygems.rb +5 -12
  91. data/lib/chef/provider/package/smartos.rb +4 -4
  92. data/lib/chef/provider/package/solaris.rb +7 -7
  93. data/lib/chef/provider/package/windows/msi.rb +1 -1
  94. data/lib/chef/provider/package/yum.rb +4 -6
  95. data/lib/chef/provider/package/zypper.rb +16 -14
  96. data/lib/chef/provider/powershell_script.rb +129 -47
  97. data/lib/chef/provider/remote_file/content.rb +4 -1
  98. data/lib/chef/provider/remote_file/local_file.rb +10 -4
  99. data/lib/chef/provider/service.rb +44 -0
  100. data/lib/chef/provider/service/freebsd.rb +1 -1
  101. data/lib/chef/provider/service/init.rb +1 -0
  102. data/lib/chef/provider/service/macosx.rb +1 -1
  103. data/lib/chef/provider/service/windows.rb +0 -1
  104. data/lib/chef/provider/user.rb +1 -1
  105. data/lib/chef/provider/user/aix.rb +3 -2
  106. data/lib/chef/provider/user/pw.rb +1 -0
  107. data/lib/chef/provider/user/solaris.rb +2 -0
  108. data/lib/chef/provider/user/useradd.rb +1 -0
  109. data/lib/chef/provider_resolver.rb +87 -134
  110. data/lib/chef/resource.rb +274 -68
  111. data/lib/chef/resource/apt_package.rb +0 -2
  112. data/lib/chef/resource/bash.rb +0 -2
  113. data/lib/chef/resource/batch.rb +1 -1
  114. data/lib/chef/resource/bff_package.rb +0 -7
  115. data/lib/chef/resource/breakpoint.rb +3 -6
  116. data/lib/chef/resource/chef_gem.rb +0 -3
  117. data/lib/chef/resource/cookbook_file.rb +1 -3
  118. data/lib/chef/resource/cron.rb +2 -4
  119. data/lib/chef/resource/csh.rb +0 -2
  120. data/lib/chef/resource/deploy.rb +9 -6
  121. data/lib/chef/resource/deploy_revision.rb +0 -14
  122. data/lib/chef/resource/directory.rb +2 -4
  123. data/lib/chef/resource/dpkg_package.rb +0 -5
  124. data/lib/chef/resource/dsc_resource.rb +2 -3
  125. data/lib/chef/resource/dsc_script.rb +2 -3
  126. data/lib/chef/resource/easy_install_package.rb +0 -7
  127. data/lib/chef/resource/env.rb +3 -3
  128. data/lib/chef/resource/erl_call.rb +2 -5
  129. data/lib/chef/resource/execute.rb +2 -4
  130. data/lib/chef/resource/file.rb +2 -4
  131. data/lib/chef/resource/freebsd_package.rb +0 -5
  132. data/lib/chef/resource/gem_package.rb +0 -3
  133. data/lib/chef/resource/git.rb +0 -3
  134. data/lib/chef/resource/group.rb +2 -4
  135. data/lib/chef/resource/homebrew_package.rb +0 -2
  136. data/lib/chef/resource/http_request.rb +3 -4
  137. data/lib/chef/resource/ifconfig.rb +3 -4
  138. data/lib/chef/resource/ips_package.rb +2 -2
  139. data/lib/chef/resource/link.rb +3 -5
  140. data/lib/chef/resource/log.rb +2 -4
  141. data/lib/chef/resource/lwrp_base.rb +10 -61
  142. data/lib/chef/resource/macosx_service.rb +1 -2
  143. data/lib/chef/resource/macports_package.rb +0 -7
  144. data/lib/chef/resource/mdadm.rb +2 -5
  145. data/lib/chef/resource/mount.rb +2 -4
  146. data/lib/chef/resource/ohai.rb +2 -4
  147. data/lib/chef/resource/openbsd_package.rb +0 -6
  148. data/lib/chef/resource/package.rb +9 -6
  149. data/lib/chef/resource/pacman_package.rb +0 -7
  150. data/lib/chef/resource/paludis_package.rb +2 -3
  151. data/lib/chef/resource/perl.rb +0 -3
  152. data/lib/chef/resource/portage_package.rb +0 -3
  153. data/lib/chef/resource/powershell_script.rb +1 -2
  154. data/lib/chef/resource/python.rb +0 -3
  155. data/lib/chef/resource/reboot.rb +1 -3
  156. data/lib/chef/resource/registry_key.rb +3 -5
  157. data/lib/chef/resource/remote_directory.rb +3 -5
  158. data/lib/chef/resource/remote_file.rb +4 -5
  159. data/lib/chef/resource/route.rb +3 -5
  160. data/lib/chef/resource/rpm_package.rb +0 -2
  161. data/lib/chef/resource/ruby.rb +0 -4
  162. data/lib/chef/resource/ruby_block.rb +2 -4
  163. data/lib/chef/resource/scm.rb +3 -5
  164. data/lib/chef/resource/script.rb +0 -3
  165. data/lib/chef/resource/service.rb +3 -5
  166. data/lib/chef/resource/smartos_package.rb +0 -9
  167. data/lib/chef/resource/solaris_package.rb +0 -10
  168. data/lib/chef/resource/subversion.rb +1 -3
  169. data/lib/chef/resource/template.rb +0 -4
  170. data/lib/chef/resource/timestamped_deploy.rb +0 -4
  171. data/lib/chef/resource/user.rb +2 -5
  172. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
  173. data/lib/chef/resource/windows_package.rb +3 -3
  174. data/lib/chef/resource/windows_script.rb +2 -2
  175. data/lib/chef/resource/windows_service.rb +3 -3
  176. data/lib/chef/resource/yum_package.rb +0 -3
  177. data/lib/chef/resource/zypper_package.rb +27 -0
  178. data/lib/chef/resource_builder.rb +7 -0
  179. data/lib/chef/resource_reporter.rb +1 -1
  180. data/lib/chef/resource_resolver.rb +108 -62
  181. data/lib/chef/resources.rb +1 -0
  182. data/lib/chef/rest.rb +1 -0
  183. data/lib/chef/server_api.rb +2 -0
  184. data/lib/chef/user.rb +193 -42
  185. data/lib/chef/util/backup.rb +9 -1
  186. data/lib/chef/util/path_helper.rb +0 -1
  187. data/lib/chef/version.rb +1 -1
  188. data/spec/functional/audit/runner_spec.rb +22 -42
  189. data/spec/functional/mixin/powershell_out_spec.rb +43 -0
  190. data/spec/functional/resource/execute_spec.rb +9 -2
  191. data/spec/functional/resource/file_spec.rb +25 -0
  192. data/spec/functional/resource/group_spec.rb +5 -0
  193. data/spec/functional/resource/link_spec.rb +5 -11
  194. data/spec/functional/resource/powershell_spec.rb +40 -5
  195. data/spec/functional/resource/user/useradd_spec.rb +10 -18
  196. data/spec/integration/recipes/lwrp_spec.rb +57 -0
  197. data/spec/integration/recipes/provider_choice.rb +2 -7
  198. data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
  199. data/spec/spec_helper.rb +1 -1
  200. data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
  201. data/spec/support/lib/chef/resource/cat.rb +0 -2
  202. data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
  203. data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
  204. data/spec/support/lib/chef/resource/with_state.rb +0 -9
  205. data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
  206. data/spec/support/lib/chef/resource/zen_master.rb +1 -6
  207. data/spec/support/shared/context/client.rb +277 -0
  208. data/spec/support/shared/examples/client.rb +53 -0
  209. data/spec/support/shared/functional/file_resource.rb +0 -4
  210. data/spec/support/shared/functional/securable_resource.rb +0 -24
  211. data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
  212. data/spec/support/shared/functional/windows_script.rb +1 -1
  213. data/spec/support/shared/unit/api_versioning.rb +77 -0
  214. data/spec/support/shared/unit/knife_shared.rb +40 -0
  215. data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
  216. data/spec/unit/api_client_spec.rb +189 -14
  217. data/spec/unit/application/client_spec.rb +0 -5
  218. data/spec/unit/audit/audit_reporter_spec.rb +58 -14
  219. data/spec/unit/audit/logger_spec.rb +42 -0
  220. data/spec/unit/audit/runner_spec.rb +2 -2
  221. data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
  222. data/spec/unit/client_spec.rb +58 -374
  223. data/spec/unit/cookbook_spec.rb +0 -9
  224. data/spec/unit/cookbook_version_spec.rb +0 -20
  225. data/spec/unit/deprecation_spec.rb +55 -0
  226. data/spec/unit/dsl/resources_spec.rb +85 -0
  227. data/spec/unit/exceptions_spec.rb +2 -2
  228. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
  229. data/spec/unit/formatters/doc_spec.rb +46 -0
  230. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
  231. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
  232. data/spec/unit/http/authenticator_spec.rb +11 -2
  233. data/spec/unit/knife/client_create_spec.rb +122 -51
  234. data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
  235. data/spec/unit/knife/core/ui_spec.rb +14 -0
  236. data/spec/unit/knife/osc_user_create_spec.rb +93 -0
  237. data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
  238. data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
  239. data/spec/unit/knife/osc_user_list_spec.rb +37 -0
  240. data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
  241. data/spec/unit/knife/osc_user_show_spec.rb +46 -0
  242. data/spec/unit/knife/user_create_spec.rb +177 -51
  243. data/spec/unit/knife/user_delete_spec.rb +34 -8
  244. data/spec/unit/knife/user_edit_spec.rb +31 -12
  245. data/spec/unit/knife/user_list_spec.rb +7 -3
  246. data/spec/unit/knife/user_reregister_spec.rb +38 -17
  247. data/spec/unit/knife/user_show_spec.rb +35 -11
  248. data/spec/unit/knife_spec.rb +10 -4
  249. data/spec/unit/lwrp_spec.rb +228 -54
  250. data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
  251. data/spec/unit/mixin/command_spec.rb +1 -2
  252. data/spec/unit/mixin/powershell_out_spec.rb +70 -0
  253. data/spec/unit/mixin/uris_spec.rb +23 -11
  254. data/spec/unit/node_map_spec.rb +4 -1
  255. data/spec/unit/osc_user_spec.rb +276 -0
  256. data/spec/unit/platform_spec.rb +0 -60
  257. data/spec/unit/provider/deploy_spec.rb +1 -1
  258. data/spec/unit/provider/directory_spec.rb +199 -135
  259. data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
  260. data/spec/unit/provider/package/aix_spec.rb +16 -16
  261. data/spec/unit/provider/package/dpkg_spec.rb +2 -2
  262. data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
  263. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  264. data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
  265. data/spec/unit/provider/package/ips_spec.rb +22 -22
  266. data/spec/unit/provider/package/macports_spec.rb +10 -10
  267. data/spec/unit/provider/package/openbsd_spec.rb +4 -26
  268. data/spec/unit/provider/package/pacman_spec.rb +5 -5
  269. data/spec/unit/provider/package/rpm_spec.rb +14 -14
  270. data/spec/unit/provider/package/rubygems_spec.rb +10 -44
  271. data/spec/unit/provider/package/smartos_spec.rb +4 -4
  272. data/spec/unit/provider/package/solaris_spec.rb +11 -11
  273. data/spec/unit/provider/package/zypper_spec.rb +125 -90
  274. data/spec/unit/provider/package_spec.rb +34 -0
  275. data/spec/unit/provider/powershell_spec.rb +53 -11
  276. data/spec/unit/provider/remote_directory_spec.rb +2 -2
  277. data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
  278. data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
  279. data/spec/unit/provider/user_spec.rb +3 -3
  280. data/spec/unit/provider_resolver_spec.rb +463 -327
  281. data/spec/unit/recipe_spec.rb +42 -15
  282. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  283. data/spec/unit/resource/erl_call_spec.rb +1 -1
  284. data/spec/unit/resource/file_spec.rb +1 -1
  285. data/spec/unit/resource/ifconfig_spec.rb +10 -6
  286. data/spec/unit/resource/remote_file_spec.rb +5 -0
  287. data/spec/unit/resource/route_spec.rb +1 -1
  288. data/spec/unit/resource/ruby_block_spec.rb +2 -2
  289. data/spec/unit/resource/template_spec.rb +1 -1
  290. data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
  291. data/spec/unit/resource/windows_service_spec.rb +1 -1
  292. data/spec/unit/resource_spec.rb +99 -13
  293. data/spec/unit/rest_spec.rb +5 -5
  294. data/spec/unit/run_context_spec.rb +41 -0
  295. data/spec/unit/runner_spec.rb +2 -2
  296. data/spec/unit/user_spec.rb +406 -93
  297. data/tasks/maintainers.rb +69 -0
  298. metadata +37 -4
@@ -56,7 +56,7 @@ class Chef
56
56
  Chef::Log.debug("#{@new_resource} installing MSI package '#{@new_resource.source}'")
57
57
  shell_out!("msiexec /qn /i \"#{@new_resource.source}\" #{expand_options(@new_resource.options)}", {:timeout => @new_resource.timeout, :returns => @new_resource.returns})
58
58
  end
59
-
59
+
60
60
  def remove_package(name, version)
61
61
  # We could use MsiConfigureProduct here, but we'll start off with msiexec
62
62
  Chef::Log.debug("#{@new_resource} removing MSI package '#{@new_resource.source}'")
@@ -1,4 +1,4 @@
1
- #
1
+
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
4
  # License:: Apache License, Version 2.0
@@ -18,7 +18,6 @@
18
18
 
19
19
  require 'chef/config'
20
20
  require 'chef/provider/package'
21
- require 'chef/mixin/shell_out'
22
21
  require 'chef/mixin/which'
23
22
  require 'chef/resource/package'
24
23
  require 'singleton'
@@ -647,7 +646,6 @@ class Chef
647
646
 
648
647
  # Cache for our installed and available packages, pulled in from yum-dump.py
649
648
  class YumCache
650
- include Chef::Mixin::Command
651
649
  include Chef::Mixin::Which
652
650
  include Chef::Mixin::ShellOut
653
651
  include Singleton
@@ -1028,7 +1026,7 @@ class Chef
1028
1026
 
1029
1027
  def yum_command(command)
1030
1028
  Chef::Log.debug("#{@new_resource}: yum command: \"#{command}\"")
1031
- status = shell_out(command, {:timeout => Chef::Config[:yum_timeout]})
1029
+ status = shell_out_with_timeout(command, {:timeout => Chef::Config[:yum_timeout]})
1032
1030
 
1033
1031
  # This is fun: rpm can encounter errors in the %post/%postun scripts which aren't
1034
1032
  # considered fatal - meaning the rpm is still successfully installed. These issue
@@ -1045,7 +1043,7 @@ class Chef
1045
1043
  if l =~ %r{^error: %(post|postun)\(.*\) scriptlet failed, exit status \d+$}
1046
1044
  Chef::Log.warn("#{@new_resource} caught non-fatal scriptlet issue: \"#{l}\". Can't trust yum exit status " +
1047
1045
  "so running install again to verify.")
1048
- status = shell_out(command, {:timeout => Chef::Config[:yum_timeout]})
1046
+ status = shell_out_with_timeout(command, {:timeout => Chef::Config[:yum_timeout]})
1049
1047
  break
1050
1048
  end
1051
1049
  end
@@ -1118,7 +1116,7 @@ class Chef
1118
1116
  end
1119
1117
 
1120
1118
  Chef::Log.debug("#{@new_resource} checking rpm status")
1121
- shell_out!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}", :timeout => Chef::Config[:yum_timeout]).stdout.each_line do |line|
1119
+ shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}", :timeout => Chef::Config[:yum_timeout]).stdout.each_line do |line|
1122
1120
  case line
1123
1121
  when /([\w\d_.-]+)\s([\w\d_.-]+)/
1124
1122
  @current_resource.package_name($1)
@@ -29,46 +29,48 @@ class Chef
29
29
  class Package
30
30
  class Zypper < Chef::Provider::Package
31
31
 
32
+ provides :zypper_package, os: "linux"
33
+
32
34
  def load_current_resource
33
- @current_resource = Chef::Resource::Package.new(@new_resource.name)
34
- @current_resource.package_name(@new_resource.package_name)
35
+ @current_resource = Chef::Resource::ZypperPackage.new(new_resource.name)
36
+ current_resource.package_name(new_resource.package_name)
35
37
 
36
38
  is_installed=false
37
39
  is_out_of_date=false
38
40
  version=''
39
41
  oud_version=''
40
- Chef::Log.debug("#{@new_resource} checking zypper")
41
- status = shell_out("zypper --non-interactive info #{@new_resource.package_name}")
42
+ Chef::Log.debug("#{new_resource} checking zypper")
43
+ status = shell_out_with_timeout("zypper --non-interactive info #{new_resource.package_name}")
42
44
  status.stdout.each_line do |line|
43
45
  case line
44
46
  when /^Version: (.+)$/
45
47
  version = $1
46
- Chef::Log.debug("#{@new_resource} version #{$1}")
48
+ Chef::Log.debug("#{new_resource} version #{$1}")
47
49
  when /^Installed: Yes$/
48
50
  is_installed=true
49
- Chef::Log.debug("#{@new_resource} is installed")
51
+ Chef::Log.debug("#{new_resource} is installed")
50
52
 
51
53
  when /^Installed: No$/
52
54
  is_installed=false
53
- Chef::Log.debug("#{@new_resource} is not installed")
55
+ Chef::Log.debug("#{new_resource} is not installed")
54
56
  when /^Status: out-of-date \(version (.+) installed\)$/
55
57
  is_out_of_date=true
56
58
  oud_version=$1
57
- Chef::Log.debug("#{@new_resource} out of date version #{$1}")
59
+ Chef::Log.debug("#{new_resource} out of date version #{$1}")
58
60
  end
59
61
  end
60
62
 
61
63
  if is_installed==false
62
64
  @candidate_version=version
63
- @current_resource.version(nil)
65
+ current_resource.version(nil)
64
66
  end
65
67
 
66
68
  if is_installed==true
67
69
  if is_out_of_date==true
68
- @current_resource.version(oud_version)
70
+ current_resource.version(oud_version)
69
71
  @candidate_version=version
70
72
  else
71
- @current_resource.version(version)
73
+ current_resource.version(version)
72
74
  @candidate_version=version
73
75
  end
74
76
  end
@@ -77,7 +79,7 @@ class Chef
77
79
  raise Chef::Exceptions::Package, "zypper failed - #{status.inspect}!"
78
80
  end
79
81
 
80
- @current_resource
82
+ current_resource
81
83
  end
82
84
 
83
85
  def zypper_version()
@@ -104,9 +106,9 @@ class Chef
104
106
  def zypper_package(command, pkgname, version)
105
107
  version = "=#{version}" unless version.nil? || version.empty?
106
108
  if zypper_version < 1.0
107
- shell_out!("zypper#{gpg_checks} #{command} -y #{pkgname}")
109
+ shell_out_with_timeout!("zypper#{gpg_checks} #{command} -y #{pkgname}")
108
110
  else
109
- shell_out!("zypper --non-interactive#{gpg_checks} "+
111
+ shell_out_with_timeout!("zypper --non-interactive#{gpg_checks} "+
110
112
  "#{command} #{pkgname}#{version}")
111
113
  end
112
114
  end
@@ -24,71 +24,153 @@ class Chef
24
24
 
25
25
  provides :powershell_script, os: "windows"
26
26
 
27
+ def initialize (new_resource, run_context)
28
+ super(new_resource, run_context, '.ps1')
29
+ add_exit_status_wrapper
30
+ end
31
+
32
+ def action_run
33
+ valid_syntax = validate_script_syntax!
34
+ super if valid_syntax
35
+ end
36
+
37
+ def flags
38
+ # Must use -File rather than -Command to launch the script
39
+ # file created by the base class that contains the script
40
+ # code -- otherwise, powershell.exe does not propagate the
41
+ # error status of a failed Windows process that ran at the
42
+ # end of the script, it gets changed to '1'.
43
+ interpreter_flags = [default_interpreter_flags, '-File'].join(' ')
44
+
45
+ if ! (@new_resource.flags.nil?)
46
+ interpreter_flags = [@new_resource.flags, interpreter_flags].join(' ')
47
+ end
48
+
49
+ interpreter_flags
50
+ end
51
+
27
52
  protected
28
- EXIT_STATUS_EXCEPTION_HANDLER = "\ntrap [Exception] {write-error -exception ($_.Exception.Message);exit 1}".freeze
29
- EXIT_STATUS_NORMALIZATION_SCRIPT = "\nif ($? -ne $true) { if ( $LASTEXITCODE ) {exit $LASTEXITCODE} else { exit 1 }}".freeze
30
- EXIT_STATUS_RESET_SCRIPT = "\n$global:LASTEXITCODE=$null".freeze
31
53
 
32
- # Process exit codes are strange with PowerShell. Unless you
33
- # explicitly call exit in Powershell, the powershell.exe
34
- # interpreter returns only 0 for success or 1 for failure. Since
35
- # we'd like to get specific exit codes from executable tools run
36
- # with Powershell, we do some work using the automatic variables
37
- # $? and $LASTEXITCODE to return the process exit code of the
38
- # last process run in the script if it is the last command
39
- # executed, otherwise 0 or 1 based on whether $? is set to true
40
- # (success, where we return 0) or false (where we return 1).
41
- def normalize_script_exit_status( code )
42
- target_code = ( EXIT_STATUS_EXCEPTION_HANDLER +
43
- EXIT_STATUS_RESET_SCRIPT +
44
- "\n" +
45
- code.to_s +
46
- EXIT_STATUS_NORMALIZATION_SCRIPT )
47
- convert_boolean_return = @new_resource.convert_boolean_return
48
- self.code = <<EOH
49
- new-variable -name interpolatedexitcode -visibility private -value $#{convert_boolean_return}
50
- new-variable -name chefscriptresult -visibility private
51
- $chefscriptresult = {
52
- #{target_code}
53
- }.invokereturnasis()
54
- if ($interpolatedexitcode -and $chefscriptresult.gettype().name -eq 'boolean') { exit [int32](!$chefscriptresult) } else { exit 0 }
55
- EOH
56
- Chef::Log.debug("powershell_script provider called with script code:\n\n#{code}\n")
54
+ # Process exit codes are strange with PowerShell and require
55
+ # special handling to cover common use cases.
56
+ def add_exit_status_wrapper
57
+ self.code = wrapper_script
58
+ Chef::Log.debug("powershell_script provider called with script code:\n\n#{@new_resource.code}\n")
57
59
  Chef::Log.debug("powershell_script provider will execute transformed code:\n\n#{self.code}\n")
58
60
  end
59
61
 
60
- public
62
+ def validate_script_syntax!
63
+ interpreter_arguments = default_interpreter_flags.join(' ')
64
+ Tempfile.open(['chef_powershell_script-user-code', '.ps1']) do | user_script_file |
65
+ user_script_file.puts("{#{@new_resource.code}}")
66
+ user_script_file.close
61
67
 
62
- def initialize (new_resource, run_context)
63
- super(new_resource, run_context, '.ps1')
64
- normalize_script_exit_status(new_resource.code)
68
+ validation_command = "\"#{interpreter}\" #{interpreter_arguments} -Command #{user_script_file.path}"
69
+
70
+ # For consistency with other script resources, allow even syntax errors
71
+ # to be suppressed if the returns attribute would have suppressed it
72
+ # at converge.
73
+ valid_returns = [0]
74
+ specified_returns = @new_resource.returns.is_a?(Integer) ?
75
+ [@new_resource.returns] :
76
+ @new_resource.returns
77
+ valid_returns.concat([1]) if specified_returns.include?(1)
78
+
79
+ result = shell_out!(validation_command, {returns: valid_returns})
80
+ result.exitstatus == 0
81
+ end
65
82
  end
66
83
 
67
- def flags
68
- default_flags = [
84
+ def default_interpreter_flags
85
+ # 'Bypass' is preferable since it doesn't require user input confirmation
86
+ # for files such as PowerShell modules downloaded from the
87
+ # Internet. However, 'Bypass' is not supported prior to
88
+ # PowerShell 3.0, so the fallback is 'Unrestricted'
89
+ execution_policy = Chef::Platform.supports_powershell_execution_bypass?(run_context.node) ? 'Bypass' : 'Unrestricted'
90
+
91
+ [
69
92
  "-NoLogo",
70
93
  "-NonInteractive",
71
94
  "-NoProfile",
72
- "-ExecutionPolicy Unrestricted",
95
+ "-ExecutionPolicy #{execution_policy}",
73
96
  # Powershell will hang if STDIN is redirected
74
97
  # http://connect.microsoft.com/PowerShell/feedback/details/572313/powershell-exe-can-hang-if-stdin-is-redirected
75
- "-InputFormat None",
76
- # Must use -File rather than -Command to launch the script
77
- # file created by the base class that contains the script
78
- # code -- otherwise, powershell.exe does not propagate the
79
- # error status of a failed Windows process that ran at the
80
- # end of the script, it gets changed to '1'.
81
- "-File"
98
+ "-InputFormat None"
82
99
  ]
100
+ end
83
101
 
84
- interpreter_flags = default_flags.join(' ')
102
+ # A wrapper script is used to launch user-supplied script while
103
+ # still obtaining useful process exit codes. Unless you
104
+ # explicitly call exit in Powershell, the powershell.exe
105
+ # interpreter returns only 0 for success or 1 for failure. Since
106
+ # we'd like to get specific exit codes from executable tools run
107
+ # with Powershell, we do some work using the automatic variables
108
+ # $? and $LASTEXITCODE to return the process exit code of the
109
+ # last process run in the script if it is the last command
110
+ # executed, otherwise 0 or 1 based on whether $? is set to true
111
+ # (success, where we return 0) or false (where we return 1).
112
+ def wrapper_script
113
+ <<-EOH
114
+ # Chef Client wrapper for powershell_script resources
85
115
 
86
- if ! (@new_resource.flags.nil?)
87
- interpreter_flags = [@new_resource.flags, interpreter_flags].join(' ')
88
- end
116
+ # LASTEXITCODE can be uninitialized -- make it explictly 0
117
+ # to avoid incorrect detection of failure (non-zero) codes
118
+ $global:LASTEXITCODE = 0
89
119
 
90
- interpreter_flags
120
+ # Catch any exceptions -- without this, exceptions will result
121
+ # In a zero return code instead of the desired non-zero code
122
+ # that indicates a failure
123
+ trap [Exception] {write-error ($_.Exception.Message);exit 1}
124
+
125
+ # Variable state that should not be accessible to the user code
126
+ new-variable -name interpolatedexitcode -visibility private -value $#{@new_resource.convert_boolean_return}
127
+ new-variable -name chefscriptresult -visibility private
128
+
129
+ # Initialize a variable we use to capture $? inside a block
130
+ $global:lastcmdlet = $null
131
+
132
+ # Execute the user's code in a script block --
133
+ $chefscriptresult =
134
+ {
135
+ #{@new_resource.code}
136
+
137
+ # This assignment doesn't affect the block's return value
138
+ $global:lastcmdlet = $?
139
+ }.invokereturnasis()
140
+
141
+ # Assume failure status of 1 -- success cases
142
+ # will have to override this
143
+ $exitstatus = 1
144
+
145
+ # If convert_boolean_return is enabled, the block's return value
146
+ # gets precedence in determining our exit status
147
+ if ($interpolatedexitcode -and $chefscriptresult -ne $null -and $chefscriptresult.gettype().name -eq 'boolean')
148
+ {
149
+ $exitstatus = [int32](!$chefscriptresult)
150
+ }
151
+ elseif ($lastcmdlet)
152
+ {
153
+ # Otherwise, a successful cmdlet execution defines the status
154
+ $exitstatus = 0
155
+ }
156
+ elseif ( $LASTEXITCODE -ne $null -and $LASTEXITCODE -ne 0 )
157
+ {
158
+ # If the cmdlet status is failed, allow the Win32 status
159
+ # in $LASTEXITCODE to define exit status. This handles the case
160
+ # where no cmdlets, only Win32 processes have run since $?
161
+ # will be set to $false whenever a Win32 process returns a non-zero
162
+ # status.
163
+ $exitstatus = $LASTEXITCODE
164
+ }
165
+
166
+ # If this script is launched with -File, the process exit
167
+ # status of PowerShell.exe will be $exitstatus. If it was
168
+ # launched with -Command, it will be 0 if $exitstatus was 0,
169
+ # 1 (i.e. failed) otherwise.
170
+ exit $exitstatus
171
+ EOH
91
172
  end
173
+
92
174
  end
93
175
  end
94
176
  end
@@ -20,6 +20,7 @@
20
20
  require 'uri'
21
21
  require 'tempfile'
22
22
  require 'chef/file_content_management/content_base'
23
+ require 'chef/mixin/uris'
23
24
 
24
25
  class Chef
25
26
  class Provider
@@ -28,6 +29,8 @@ class Chef
28
29
 
29
30
  private
30
31
 
32
+ include Chef::Mixin::Uris
33
+
31
34
  def file_for_provider
32
35
  Chef::Log.debug("#{@new_resource} checking for changes")
33
36
 
@@ -48,7 +51,7 @@ class Chef
48
51
  uri = if Chef::Provider::RemoteFile::Fetcher.network_share?(source)
49
52
  source
50
53
  else
51
- URI.parse(source)
54
+ as_uri(source)
52
55
  end
53
56
  raw_file = grab_file_from_uri(uri)
54
57
  rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPServerException, Net::HTTPFatalError, Net::FTPError => e
@@ -32,15 +32,21 @@ class Chef
32
32
  @new_resource = new_resource
33
33
  @uri = uri
34
34
  end
35
-
35
+
36
36
  # CHEF-4472: Remove the leading slash from windows paths that we receive from a file:// URI
37
- def fix_windows_path(path)
38
- path.gsub(/^\/([a-zA-Z]:)/,'\1')
37
+ def fix_windows_path(path)
38
+ path.gsub(/^\/([a-zA-Z]:)/,'\1')
39
+ end
40
+
41
+ def source_path
42
+ @source_path ||= begin
43
+ path = URI.unescape(uri.path)
44
+ Chef::Platform.windows? ? fix_windows_path(path) : path
45
+ end
39
46
  end
40
47
 
41
48
  # Fetches the file at uri, returning a Tempfile-like File handle
42
49
  def fetch
43
- source_path = Chef::Platform.windows? ? fix_windows_path(uri.path) : uri.path
44
50
  tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
45
51
  Chef::Log.debug("#{new_resource} staging #{source_path} to #{tempfile.path}")
46
52
  FileUtils.cp(source_path, tempfile.path)
@@ -168,6 +168,50 @@ class Chef
168
168
  @new_resource.respond_to?(method_name) &&
169
169
  !!@new_resource.send(method_name)
170
170
  end
171
+
172
+ module ServicePriorityInit
173
+
174
+ #
175
+ # Platform-specific versions
176
+ #
177
+
178
+ #
179
+ # Linux
180
+ #
181
+
182
+ require 'chef/chef_class'
183
+ require 'chef/provider/service/systemd'
184
+ require 'chef/provider/service/insserv'
185
+ require 'chef/provider/service/redhat'
186
+ require 'chef/provider/service/arch'
187
+ require 'chef/provider/service/gentoo'
188
+ require 'chef/provider/service/upstart'
189
+ require 'chef/provider/service/debian'
190
+ require 'chef/provider/service/invokercd'
191
+ require 'chef/provider/service/freebsd'
192
+ require 'chef/provider/service/openbsd'
193
+ require 'chef/provider/service/solaris'
194
+ require 'chef/provider/service/macosx'
195
+
196
+ def self.os(os, *providers)
197
+ Chef.set_provider_priority_array(:service, providers, os: os)
198
+ end
199
+ def self.platform_family(platform_family, *providers)
200
+ Chef.set_provider_priority_array(:service, providers, platform_family: platform_family)
201
+ end
202
+
203
+ os %w(freebsd netbsd), Freebsd
204
+ os %w(openbsd), Openbsd
205
+ os %w(solaris2), Solaris
206
+ os %w(darwin), Macosx
207
+ os %w(linux), Systemd, Insserv, Redhat
208
+
209
+ platform_family %w(arch), Systemd, Arch
210
+ platform_family %w(gentoo), Systemd, Gentoo
211
+ platform_family %w(debian), Systemd, Upstart, Insserv, Debian, Invokercd
212
+ platform_family %w(rhel fedora suse), Systemd, Insserv, Redhat
213
+
214
+ end
171
215
  end
172
216
  end
173
217
  end
@@ -147,7 +147,7 @@ class Chef
147
147
  # some scripts support multiple instances through symlinks such as openvpn.
148
148
  # We should get the service name from rcvar.
149
149
  Chef::Log.debug("name=\"service\" not found at #{init_command}. falling back to rcvar")
150
- sn = shell_out!("#{init_command} rcvar").stdout[/(\w+_enable)=/, 1]
150
+ shell_out!("#{init_command} rcvar").stdout[/(\w+_enable)=/, 1]
151
151
  else
152
152
  # for why-run mode when the rcd_script is not there yet
153
153
  new_resource.service_name