chef 11.12.8 → 11.14.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -2
  3. data/distro/common/html/_sources/index.txt +6 -0
  4. data/distro/common/html/_sources/knife_ssl_check.txt +41 -0
  5. data/distro/common/html/_sources/knife_ssl_fetch.txt +41 -0
  6. data/distro/common/html/_static/basic.css +2 -5
  7. data/distro/common/html/_static/doctools.js +5 -14
  8. data/distro/common/html/_static/jquery.js +2 -154
  9. data/distro/common/html/_static/pygments.css +2 -2
  10. data/distro/common/html/_static/searchtools.js +212 -150
  11. data/distro/common/html/_static/underscore.js +29 -21
  12. data/distro/common/html/_static/websupport.js +1 -1
  13. data/distro/common/html/ctl_chef_client.html +15 -18
  14. data/distro/common/html/ctl_chef_server.html +7 -7
  15. data/distro/common/html/ctl_chef_shell.html +6 -6
  16. data/distro/common/html/ctl_chef_solo.html +7 -8
  17. data/distro/common/html/index.html +34 -24
  18. data/distro/common/html/knife.html +23 -24
  19. data/distro/common/html/knife_bootstrap.html +13 -9
  20. data/distro/common/html/knife_client.html +10 -11
  21. data/distro/common/html/knife_common_options.html +6 -7
  22. data/distro/common/html/knife_configure.html +3 -4
  23. data/distro/common/html/knife_cookbook.html +18 -11
  24. data/distro/common/html/knife_cookbook_site.html +14 -14
  25. data/distro/common/html/knife_data_bag.html +24 -23
  26. data/distro/common/html/knife_delete.html +4 -5
  27. data/distro/common/html/knife_deps.html +4 -5
  28. data/distro/common/html/knife_diff.html +6 -7
  29. data/distro/common/html/knife_download.html +12 -13
  30. data/distro/common/html/knife_edit.html +4 -5
  31. data/distro/common/html/knife_environment.html +8 -9
  32. data/distro/common/html/knife_exec.html +9 -10
  33. data/distro/common/html/knife_index_rebuild.html +4 -5
  34. data/distro/common/html/knife_list.html +8 -9
  35. data/distro/common/html/knife_node.html +34 -33
  36. data/distro/common/html/knife_raw.html +2 -3
  37. data/distro/common/html/knife_recipe_list.html +3 -4
  38. data/distro/common/html/knife_role.html +30 -29
  39. data/distro/common/html/knife_search.html +7 -7
  40. data/distro/common/html/knife_show.html +4 -5
  41. data/distro/common/html/knife_ssh.html +2 -3
  42. data/distro/common/html/knife_ssl_check.html +148 -0
  43. data/distro/common/html/knife_ssl_fetch.html +152 -0
  44. data/distro/common/html/knife_status.html +4 -5
  45. data/distro/common/html/knife_tag.html +2 -3
  46. data/distro/common/html/knife_upload.html +5 -6
  47. data/distro/common/html/knife_user.html +9 -10
  48. data/distro/common/html/knife_using.html +12 -12
  49. data/distro/common/html/knife_xargs.html +11 -12
  50. data/distro/common/html/search.html +1 -2
  51. data/distro/common/html/searchindex.js +1 -1
  52. data/distro/common/man/man1/chef-shell.1 +19 -11
  53. data/distro/common/man/man1/knife-bootstrap.1 +35 -19
  54. data/distro/common/man/man1/knife-client.1 +111 -28
  55. data/distro/common/man/man1/knife-configure.1 +30 -14
  56. data/distro/common/man/man1/knife-cookbook-site.1 +105 -22
  57. data/distro/common/man/man1/knife-cookbook.1 +164 -23
  58. data/distro/common/man/man1/knife-data-bag.1 +157 -33
  59. data/distro/common/man/man1/knife-delete.1 +21 -17
  60. data/distro/common/man/man1/knife-deps.1 +60 -16
  61. data/distro/common/man/man1/knife-diff.1 +37 -17
  62. data/distro/common/man/man1/knife-download.1 +68 -24
  63. data/distro/common/man/man1/knife-edit.1 +19 -15
  64. data/distro/common/man/man1/knife-environment.1 +105 -17
  65. data/distro/common/man/man1/knife-exec.1 +78 -18
  66. data/distro/common/man/man1/knife-index-rebuild.1 +16 -8
  67. data/distro/common/man/man1/knife-list.1 +39 -23
  68. data/distro/common/man/man1/knife-node.1 +170 -22
  69. data/distro/common/man/man1/knife-raw.1 +33 -13
  70. data/distro/common/man/man1/knife-recipe-list.1 +17 -5
  71. data/distro/common/man/man1/knife-role.1 +86 -18
  72. data/distro/common/man/man1/knife-search.1 +80 -16
  73. data/distro/common/man/man1/knife-show.1 +30 -14
  74. data/distro/common/man/man1/knife-ssh.1 +54 -14
  75. data/distro/common/man/man1/knife-ssl-check.1 +207 -0
  76. data/distro/common/man/man1/knife-ssl-fetch.1 +207 -0
  77. data/distro/common/man/man1/knife-status.1 +48 -12
  78. data/distro/common/man/man1/knife-tag.1 +30 -10
  79. data/distro/common/man/man1/knife-upload.1 +72 -20
  80. data/distro/common/man/man1/knife-user.1 +79 -23
  81. data/distro/common/man/man1/knife-xargs.1 +61 -53
  82. data/distro/common/man/man8/chef-client.8 +87 -29
  83. data/distro/common/man/man8/chef-solo.8 +36 -15
  84. data/lib/chef/application.rb +19 -14
  85. data/lib/chef/application/client.rb +5 -0
  86. data/lib/chef/application/solo.rb +5 -0
  87. data/lib/chef/application/windows_service_manager.rb +3 -0
  88. data/lib/chef/chef_fs/chef_fs_data_store.rb +72 -24
  89. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +20 -4
  90. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +20 -1
  91. data/lib/chef/chef_fs/file_system/file_system_entry.rb +10 -2
  92. data/lib/chef/client.rb +2 -3
  93. data/lib/chef/config.rb +34 -8
  94. data/lib/chef/cookbook/cookbook_version_loader.rb +45 -4
  95. data/lib/chef/cookbook_version.rb +38 -30
  96. data/lib/chef/dsl/recipe.rb +4 -1
  97. data/lib/chef/event_dispatch/base.rb +14 -0
  98. data/lib/chef/event_dispatch/events_output_stream.rb +29 -0
  99. data/lib/chef/exceptions.rb +8 -0
  100. data/lib/chef/formatters/base.rb +16 -45
  101. data/lib/chef/formatters/doc.rb +51 -26
  102. data/lib/chef/formatters/indentable_output_stream.rb +165 -0
  103. data/lib/chef/knife/node_environment_set.rb +54 -0
  104. data/lib/chef/knife/user_create.rb +1 -1
  105. data/lib/chef/monkey_patches/pathname.rb +32 -0
  106. data/lib/chef/node.rb +1 -1
  107. data/lib/chef/platform/provider_mapping.rb +345 -338
  108. data/lib/chef/policy_builder/expand_node_object.rb +1 -1
  109. data/lib/chef/policy_builder/policyfile.rb +1 -1
  110. data/lib/chef/provider.rb +1 -0
  111. data/lib/chef/provider/git.rb +1 -1
  112. data/lib/chef/provider/link.rb +2 -2
  113. data/lib/chef/provider/remote_file/content.rb +1 -1
  114. data/lib/chef/provider/remote_file/local_file.rb +8 -2
  115. data/lib/chef/provider/service/arch.rb +0 -1
  116. data/lib/chef/provider/service/debian.rb +0 -2
  117. data/lib/chef/provider/service/freebsd.rb +2 -1
  118. data/lib/chef/provider/service/gentoo.rb +1 -1
  119. data/lib/chef/provider/service/init.rb +0 -1
  120. data/lib/chef/provider/service/insserv.rb +0 -2
  121. data/lib/chef/provider/service/invokercd.rb +0 -2
  122. data/lib/chef/provider/service/macosx.rb +2 -1
  123. data/lib/chef/provider/service/redhat.rb +0 -1
  124. data/lib/chef/provider/service/simple.rb +1 -0
  125. data/lib/chef/provider/service/solaris.rb +1 -0
  126. data/lib/chef/provider/service/systemd.rb +1 -1
  127. data/lib/chef/provider/service/upstart.rb +1 -1
  128. data/lib/chef/provider/user.rb +9 -9
  129. data/lib/chef/provider/user/solaris.rb +2 -0
  130. data/lib/chef/resource.rb +1 -0
  131. data/lib/chef/resource/remote_file.rb +32 -6
  132. data/lib/chef/run_context.rb +22 -0
  133. data/lib/chef/run_lock.rb +43 -4
  134. data/lib/chef/version.rb +2 -2
  135. data/spec/functional/http/simple_spec.rb +84 -0
  136. data/spec/functional/resource/remote_file_spec.rb +107 -43
  137. data/spec/functional/rest_spec.rb +94 -0
  138. data/spec/functional/run_lock_spec.rb +1 -1
  139. data/spec/functional/win32/service_manager_spec.rb +6 -0
  140. data/spec/integration/knife/chef_fs_data_store_spec.rb +2 -0
  141. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +76 -0
  142. data/spec/spec_helper.rb +2 -0
  143. data/spec/support/mock/platform.rb +7 -0
  144. data/spec/support/pedant/pedant_config.rb +121 -0
  145. data/spec/support/pedant/run_pedant.rb +63 -0
  146. data/spec/support/pedant/stickywicket.pem +27 -0
  147. data/spec/support/shared/functional/http.rb +242 -0
  148. data/spec/support/shared/unit/api_error_inspector.rb +2 -2
  149. data/spec/unit/api_client_spec.rb +2 -2
  150. data/spec/unit/application/client_spec.rb +6 -1
  151. data/spec/unit/application/knife_spec.rb +4 -0
  152. data/spec/unit/application/solo_spec.rb +2 -0
  153. data/spec/unit/application_spec.rb +7 -0
  154. data/spec/unit/client_spec.rb +16 -0
  155. data/spec/unit/config_spec.rb +3 -20
  156. data/spec/unit/cookbook_version_spec.rb +224 -122
  157. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +2 -2
  158. data/spec/unit/formatters/error_inspectors/cookbook_resolve_error_inspector_spec.rb +2 -2
  159. data/spec/unit/formatters/error_inspectors/cookbook_sync_error_inspector_spec.rb +2 -2
  160. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +2 -2
  161. data/spec/unit/formatters/error_inspectors/run_list_expansion_error_inspector_spec.rb +2 -2
  162. data/spec/unit/handler_spec.rb +0 -1
  163. data/spec/unit/knife/client_bulk_delete_spec.rb +3 -0
  164. data/spec/unit/knife/cookbook_bulk_delete_spec.rb +2 -0
  165. data/spec/unit/knife/cookbook_metadata_spec.rb +2 -2
  166. data/spec/unit/knife/cookbook_site_install_spec.rb +3 -1
  167. data/spec/unit/knife/cookbook_upload_spec.rb +10 -10
  168. data/spec/unit/knife/node_environment_set_spec.rb +80 -0
  169. data/spec/unit/knife/user_create_spec.rb +6 -4
  170. data/spec/unit/knife/user_edit_spec.rb +5 -0
  171. data/spec/unit/knife_spec.rb +3 -0
  172. data/spec/unit/mixin/securable_spec.rb +18 -20
  173. data/spec/unit/node/attribute_spec.rb +15 -2
  174. data/spec/unit/node/immutable_collections_spec.rb +4 -4
  175. data/spec/unit/provider/cron_spec.rb +14 -14
  176. data/spec/unit/provider/git_spec.rb +4 -4
  177. data/spec/unit/provider/group_spec.rb +1 -1
  178. data/spec/unit/provider/ohai_spec.rb +2 -2
  179. data/spec/unit/provider/remote_file/content_spec.rb +58 -35
  180. data/spec/unit/provider/remote_file/local_file_spec.rb +23 -0
  181. data/spec/unit/provider/service/solaris_smf_service_spec.rb +13 -13
  182. data/spec/unit/resource/mount_spec.rb +0 -1
  183. data/spec/unit/resource/remote_file_spec.rb +29 -0
  184. data/spec/unit/resource_spec.rb +1 -1
  185. data/spec/unit/run_context_spec.rb +7 -0
  186. data/spec/unit/run_lock_spec.rb +98 -0
  187. data/spec/unit/version_constraint_spec.rb +1 -1
  188. metadata +164 -151
  189. data/distro/common/html/_static/chef.css +0 -507
  190. data/distro/common/html/_static/chef_logo.png +0 -0
  191. data/lib/chef/checksum/storage.rb +0 -18
  192. data/lib/chef/checksum/storage/filesystem.rb +0 -56
  193. data/spec/unit/checksum/storage/filesystem_spec.rb +0 -70
@@ -107,7 +107,7 @@ class Chef
107
107
  def build_node
108
108
  # Allow user to override the environment of a node by specifying
109
109
  # a config parameter.
110
- if Chef::Config[:environment] && !Chef::Config[:environment].chop.empty?
110
+ if Chef::Config[:environment] && !Chef::Config[:environment].chomp.empty?
111
111
  node.chef_environment(Chef::Config[:environment])
112
112
  end
113
113
 
@@ -82,7 +82,7 @@ class Chef
82
82
  raise UnsupportedFeature, "Policyfile does not support setting the run_list in json data at this time"
83
83
  end
84
84
 
85
- if Chef::Config[:environment] && !Chef::Config[:environment].chop.empty?
85
+ if Chef::Config[:environment] && !Chef::Config[:environment].chomp.empty?
86
86
  raise UnsupportedFeature, "Policyfile does not work with Chef Environments"
87
87
  end
88
88
  end
@@ -22,6 +22,7 @@ require 'chef/mixin/convert_to_class_name'
22
22
  require 'chef/dsl/recipe'
23
23
  require 'chef/mixin/enforce_ownership_and_permissions'
24
24
  require 'chef/mixin/why_run'
25
+
25
26
  class Chef
26
27
  class Provider
27
28
  include Chef::DSL::Recipe
@@ -247,7 +247,7 @@ class Chef
247
247
  else
248
248
  @new_resource.revision + '*'
249
249
  end
250
- command = git("ls-remote \"#{@new_resource.repository}\"", rev_pattern)
250
+ command = git("ls-remote \"#{@new_resource.repository}\" \"#{rev_pattern}\"")
251
251
  @resolved_reference = shell_out!(command, run_options).stdout
252
252
  ref_lines = @resolved_reference.split("\n")
253
253
  refs = ref_lines.map { |line| line.split("\t") }
@@ -99,13 +99,13 @@ class Chef
99
99
  if @new_resource.link_type == :symbolic
100
100
  converge_by("create symlink at #{@new_resource.target_file} to #{@new_resource.to}") do
101
101
  file_class.symlink(canonicalize(@new_resource.to),@new_resource.target_file)
102
- Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.to} -> #{@new_resource.target_file}")
102
+ Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.target_file} -> #{@new_resource.to}")
103
103
  Chef::Log.info("#{@new_resource} created")
104
104
  end
105
105
  elsif @new_resource.link_type == :hard
106
106
  converge_by("create hard link at #{@new_resource.target_file} to #{@new_resource.to}") do
107
107
  file_class.link(@new_resource.to, @new_resource.target_file)
108
- Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.to} -> #{@new_resource.target_file}")
108
+ Chef::Log.debug("#{@new_resource} created #{@new_resource.link_type} link from #{@new_resource.target_file} -> #{@new_resource.to}")
109
109
  Chef::Log.info("#{@new_resource} created")
110
110
  end
111
111
  end
@@ -48,7 +48,7 @@ class Chef
48
48
  begin
49
49
  uri = URI.parse(source)
50
50
  raw_file = grab_file_from_uri(uri)
51
- rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPFatalError, Net::FTPError => e
51
+ rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPServerException, Net::HTTPFatalError, Net::FTPError => e
52
52
  Chef::Log.warn("#{@new_resource} cannot be downloaded from #{source}: #{e.to_s}")
53
53
  if source = sources.shift
54
54
  Chef::Log.info("#{@new_resource} trying to download from another mirror")
@@ -32,12 +32,18 @@ class Chef
32
32
  @new_resource = new_resource
33
33
  @uri = uri
34
34
  end
35
+
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')
39
+ end
35
40
 
36
41
  # Fetches the file at uri, returning a Tempfile-like File handle
37
42
  def fetch
43
+ source_path = Chef::Platform.windows? ? fix_windows_path(uri.path) : uri.path
38
44
  tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
39
- Chef::Log.debug("#{new_resource} staging #{uri.path} to #{tempfile.path}")
40
- FileUtils.cp(uri.path, tempfile.path)
45
+ Chef::Log.debug("#{new_resource} staging #{source_path} to #{tempfile.path}")
46
+ FileUtils.cp(source_path, tempfile.path)
41
47
  tempfile.close if tempfile
42
48
  tempfile
43
49
  end
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require 'chef/provider/service/init'
20
- require 'chef/mixin/command'
21
20
 
22
21
  class Chef::Provider::Service::Arch < Chef::Provider::Service::Init
23
22
 
@@ -16,9 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
20
19
  require 'chef/provider/service/init'
21
- require 'chef/mixin/command'
22
20
 
23
21
  class Chef
24
22
  class Provider
@@ -17,7 +17,8 @@
17
17
  #
18
18
 
19
19
  require 'chef/mixin/shell_out'
20
- require 'chef/provider/service'
20
+ require 'chef/resource/service'
21
+ require 'chef/provider/service/init'
21
22
  require 'chef/mixin/command'
22
23
 
23
24
  class Chef
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/provider/service'
20
+ require 'chef/provider/service/init'
21
21
  require 'chef/mixin/command'
22
22
 
23
23
  class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require 'chef/mixin/shell_out'
20
- require 'chef/provider/service'
21
20
  require 'chef/provider/service/simple'
22
21
  require 'chef/mixin/command'
23
22
 
@@ -16,9 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
20
19
  require 'chef/provider/service/init'
21
- require 'chef/mixin/command'
22
20
 
23
21
  class Chef
24
22
  class Provider
@@ -16,9 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
20
19
  require 'chef/provider/service/init'
21
- require 'chef/mixin/command'
22
20
 
23
21
  class Chef
24
22
  class Provider
@@ -16,8 +16,9 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
20
19
  require 'rexml/document'
20
+ require 'chef/resource/service'
21
+ require 'chef/provider/service/simple'
21
22
 
22
23
  class Chef
23
24
  class Provider
@@ -16,7 +16,6 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
20
19
  require 'chef/provider/service/init'
21
20
  require 'chef/mixin/shell_out'
22
21
 
@@ -18,6 +18,7 @@
18
18
 
19
19
  require 'chef/mixin/shell_out'
20
20
  require 'chef/provider/service'
21
+ require 'chef/resource/service'
21
22
  require 'chef/mixin/command'
22
23
 
23
24
  class Chef
@@ -18,6 +18,7 @@
18
18
 
19
19
  require 'chef/mixin/shell_out'
20
20
  require 'chef/provider/service'
21
+ require 'chef/resource/service'
21
22
  require 'chef/mixin/command'
22
23
 
23
24
  class Chef
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
19
+ require 'chef/resource/service'
20
20
  require 'chef/provider/service/simple'
21
21
  require 'chef/mixin/command'
22
22
 
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/provider/service'
19
+ require 'chef/resource/service'
20
20
  require 'chef/provider/service/simple'
21
21
  require 'chef/mixin/command'
22
22
  require 'chef/util/file_edit'
@@ -103,8 +103,8 @@ class Chef
103
103
  end
104
104
  requirements.assert(:modify, :lock, :unlock) do |a|
105
105
  a.assertion { @user_exists }
106
- a.failure_message(Chef::Exceptions::User, "Cannot modify user #{@new_resource} - does not exist!")
107
- a.whyrun("Assuming user #{@new_resource} would have been created")
106
+ a.failure_message(Chef::Exceptions::User, "Cannot modify user #{@new_resource.username} - does not exist!")
107
+ a.whyrun("Assuming user #{@new_resource.username} would have been created")
108
108
  end
109
109
  end
110
110
 
@@ -128,12 +128,12 @@ class Chef
128
128
  def action_create
129
129
 
130
130
  if !@user_exists
131
- converge_by("create user #{@new_resource}") do
131
+ converge_by("create user #{@new_resource.username}") do
132
132
  create_user
133
133
  Chef::Log.info("#{@new_resource} created")
134
134
  end
135
135
  elsif compare_user
136
- converge_by("alter user #{@new_resource}") do
136
+ converge_by("alter user #{@new_resource.username}") do
137
137
  manage_user
138
138
  Chef::Log.info("#{@new_resource} altered")
139
139
  end
@@ -142,7 +142,7 @@ class Chef
142
142
 
143
143
  def action_remove
144
144
  if @user_exists
145
- converge_by("remove user #{@new_resource}") do
145
+ converge_by("remove user #{@new_resource.username}") do
146
146
  remove_user
147
147
  Chef::Log.info("#{@new_resource} removed")
148
148
  end
@@ -155,7 +155,7 @@ class Chef
155
155
 
156
156
  def action_manage
157
157
  if @user_exists && compare_user
158
- converge_by("manage user #{@new_resource}") do
158
+ converge_by("manage user #{@new_resource.username}") do
159
159
  manage_user
160
160
  Chef::Log.info("#{@new_resource} managed")
161
161
  end
@@ -168,7 +168,7 @@ class Chef
168
168
 
169
169
  def action_modify
170
170
  if compare_user
171
- converge_by("modify user #{@new_resource}") do
171
+ converge_by("modify user #{@new_resource.username}") do
172
172
  manage_user
173
173
  Chef::Log.info("#{@new_resource} modified")
174
174
  end
@@ -177,7 +177,7 @@ class Chef
177
177
 
178
178
  def action_lock
179
179
  if check_lock() == false
180
- converge_by("lock the user #{@new_resource}") do
180
+ converge_by("lock the user #{@new_resource.username}") do
181
181
  lock_user
182
182
  Chef::Log.info("#{@new_resource} locked")
183
183
  end
@@ -196,7 +196,7 @@ class Chef
196
196
 
197
197
  def action_unlock
198
198
  if check_lock() == true
199
- converge_by("unlock user #{@new_resource}") do
199
+ converge_by("unlock user #{@new_resource.username}") do
200
200
  unlock_user
201
201
  Chef::Log.info("#{@new_resource} unlocked")
202
202
  end
@@ -16,6 +16,8 @@
16
16
  # See the License for the specific language governing permissions and
17
17
  # limitations under the License.
18
18
 
19
+ require 'chef/provider/user/useradd'
20
+
19
21
  class Chef
20
22
  class Provider
21
23
  class User
@@ -29,6 +29,7 @@ require 'chef/resource/conditional_action_not_nothing'
29
29
  require 'chef/resource_collection'
30
30
  require 'chef/resource_platform_map'
31
31
  require 'chef/node'
32
+ require 'chef/platform'
32
33
 
33
34
  require 'chef/mixin/deprecation'
34
35
 
@@ -40,13 +40,37 @@ class Chef
40
40
  @provider = Chef::Provider::RemoteFile
41
41
  end
42
42
 
43
+ # source can take any of the following as arguments
44
+ # - A single string argument
45
+ # - Multiple string arguments
46
+ # - An array or strings
47
+ # - A delayed evaluator that evaluates to a string
48
+ # or array of strings
49
+ # All strings must be parsable as URIs.
50
+ # source returns an array of strings.
43
51
  def source(*args)
44
- if not args.empty?
45
- args = Array(args).flatten
46
- validate_source(args)
47
- @source = args
48
- elsif self.instance_variable_defined?(:@source) == true
49
- @source
52
+ arg = parse_source_args(args)
53
+ ret = set_or_return(:source,
54
+ arg,
55
+ { :callbacks => {
56
+ :validate_source => method(:validate_source)
57
+ }})
58
+ if ret.is_a? String
59
+ Array(ret)
60
+ else
61
+ ret
62
+ end
63
+ end
64
+
65
+ def parse_source_args(args)
66
+ if args.empty?
67
+ nil
68
+ elsif args[0].is_a?(Chef::DelayedEvaluator) && args.count == 1
69
+ args[0]
70
+ elsif args.any? {|a| a.is_a?(Chef::DelayedEvaluator)} && args.count > 1
71
+ raise Exceptions::InvalidRemoteFileURI, "Only 1 source argument allowed when using a lazy evaluator"
72
+ else
73
+ Array(args).flatten
50
74
  end
51
75
  end
52
76
 
@@ -107,6 +131,7 @@ class Chef
107
131
  private
108
132
 
109
133
  def validate_source(source)
134
+ source = Array(source).flatten
110
135
  raise ArgumentError, "#{resource_name} has an empty source" if source.empty?
111
136
  source.each do |src|
112
137
  unless absolute_uri?(src)
@@ -114,6 +139,7 @@ class Chef
114
139
  "#{src.inspect} is not a valid `source` parameter for #{resource_name}. `source` must be an absolute URI or an array of URIs."
115
140
  end
116
141
  end
142
+ true
117
143
  end
118
144
 
119
145
  def absolute_uri?(source)
@@ -24,6 +24,7 @@ require 'chef/role'
24
24
  require 'chef/log'
25
25
  require 'chef/recipe'
26
26
  require 'chef/run_context/cookbook_compiler'
27
+ require 'chef/event_dispatch/events_output_stream'
27
28
 
28
29
  class Chef
29
30
 
@@ -249,6 +250,27 @@ ERROR_MESSAGE
249
250
  @cookbook_compiler.unreachable_cookbook?(cookbook_name)
250
251
  end
251
252
 
253
+ # Open a stream object that can be printed into and will dispatch to events
254
+ #
255
+ # == Arguments
256
+ # options is a hash with these possible options:
257
+ # - name: a string that identifies the stream to the user. Preferably short.
258
+ #
259
+ # Pass a block and the stream will be yielded to it, and close on its own
260
+ # at the end of the block.
261
+ def open_stream(options = {})
262
+ stream = EventDispatch::EventsOutputStream.new(events, options)
263
+ if block_given?
264
+ begin
265
+ yield stream
266
+ ensure
267
+ stream.close
268
+ end
269
+ else
270
+ stream
271
+ end
272
+ end
273
+
252
274
  private
253
275
 
254
276
  def loaded_recipe(cookbook, recipe)
@@ -20,6 +20,9 @@ require 'fcntl'
20
20
  if Chef::Platform.windows?
21
21
  require 'chef/win32/mutex'
22
22
  end
23
+ require 'chef/config'
24
+ require 'chef/exceptions'
25
+ require 'timeout'
23
26
 
24
27
  class Chef
25
28
 
@@ -43,10 +46,13 @@ class Chef
43
46
  @runlock_file = lockfile
44
47
  @runlock = nil
45
48
  @mutex = nil
49
+ @runpid = nil
46
50
  end
47
51
 
48
52
  # Acquire the system-wide lock. Will block indefinitely if another process
49
- # already has the lock.
53
+ # already has the lock and Chef::Config[:run_lock_timeout] is
54
+ # not set. Otherwise will block for Chef::Config[:run_lock_timeout]
55
+ # seconds and exit if the lock is not acquired.
50
56
  #
51
57
  # Each call to acquire should have a corresponding call to #release.
52
58
  #
@@ -55,7 +61,23 @@ class Chef
55
61
  # Either acquire() or test() methods should be called in order to
56
62
  # get the ownership of run_lock.
57
63
  def acquire
58
- wait unless test
64
+ if timeout_given?
65
+ begin
66
+ Timeout::timeout(time_to_wait) do
67
+ unless test
68
+ if time_to_wait > 0.0
69
+ wait
70
+ else
71
+ exit_from_timeout
72
+ end
73
+ end
74
+ end
75
+ rescue Timeout::Error => e
76
+ exit_from_timeout
77
+ end
78
+ else
79
+ wait unless test
80
+ end
59
81
  end
60
82
 
61
83
  #
@@ -92,7 +114,6 @@ class Chef
92
114
  # Waits until acquiring the system-wide lock.
93
115
  #
94
116
  def wait
95
- runpid = runlock.read.strip.chomp
96
117
  Chef::Log.warn("Chef client #{runpid} is running, will wait for it to finish and then run.")
97
118
  if Chef::Platform.windows?
98
119
  mutex.wait
@@ -131,6 +152,7 @@ class Chef
131
152
  def reset
132
153
  @runlock = nil
133
154
  @mutex = nil
155
+ @runpid = nil
134
156
  end
135
157
 
136
158
  # Since flock mechanism doesn't exist on windows we are using
@@ -144,6 +166,23 @@ class Chef
144
166
  @mutex = Chef::ReservedNames::Win32::Mutex.new("Global\\#{runlock_file.gsub(/[\\]/, "/").downcase}")
145
167
  mutex.test
146
168
  end
169
+
170
+ def runpid
171
+ @runpid ||= runlock.read.strip
172
+ end
173
+
174
+ def timeout_given?
175
+ !time_to_wait.nil?
176
+ end
177
+
178
+ def time_to_wait
179
+ Chef::Config[:run_lock_timeout]
180
+ end
181
+
182
+ def exit_from_timeout
183
+ rp = runpid
184
+ release # Just to be on the safe side...
185
+ raise Chef::Exceptions::RunLockTimeout.new(time_to_wait, rp)
186
+ end
147
187
  end
148
188
  end
149
-