chef 12.5.1-universal-mingw32 → 12.6.0-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 (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -1
  3. data/README.md +6 -4
  4. data/Rakefile +1 -4
  5. data/chef-windows.gemspec +21 -0
  6. data/chef.gemspec +58 -0
  7. data/lib/chef/api_client/registration.rb +9 -4
  8. data/lib/chef/application.rb +3 -84
  9. data/lib/chef/application/apply.rb +9 -2
  10. data/lib/chef/application/client.rb +8 -3
  11. data/lib/chef/application/solo.rb +7 -1
  12. data/lib/chef/application/windows_service.rb +21 -6
  13. data/lib/chef/application/windows_service_manager.rb +2 -3
  14. data/lib/chef/audit/runner.rb +1 -0
  15. data/lib/chef/chef_class.rb +1 -11
  16. data/lib/chef/chef_fs/chef_fs_data_store.rb +181 -2
  17. data/lib/chef/chef_fs/file_system/cookbook_subdir.rb +5 -0
  18. data/lib/chef/chef_fs/file_system/file_system_entry.rb +11 -7
  19. data/lib/chef/client.rb +28 -1
  20. data/lib/chef/cookbook/cookbook_collection.rb +14 -1
  21. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  22. data/lib/chef/cookbook/metadata.rb +115 -9
  23. data/lib/chef/cookbook/remote_file_vendor.rb +1 -1
  24. data/lib/chef/cookbook_version.rb +6 -2
  25. data/lib/chef/data_bag.rb +1 -1
  26. data/lib/chef/data_bag_item.rb +1 -1
  27. data/lib/chef/digester.rb +5 -1
  28. data/lib/chef/dsl/chef_provisioning.rb +57 -0
  29. data/lib/chef/dsl/cheffish.rb +64 -0
  30. data/lib/chef/dsl/declare_resource.rb +108 -0
  31. data/lib/chef/dsl/platform_introspection.rb +3 -3
  32. data/lib/chef/dsl/recipe.rb +3 -73
  33. data/lib/chef/dsl/resources.rb +27 -1
  34. data/lib/chef/event_dispatch/base.rb +3 -0
  35. data/lib/chef/event_dispatch/dispatcher.rb +5 -0
  36. data/lib/chef/event_dispatch/events_output_stream.rb +8 -0
  37. data/lib/chef/exceptions.rb +21 -1
  38. data/lib/chef/file_access_control/unix.rb +12 -12
  39. data/lib/chef/file_content_management/deploy/cp.rb +2 -2
  40. data/lib/chef/file_content_management/deploy/mv_unix.rb +4 -4
  41. data/lib/chef/file_content_management/deploy/mv_windows.rb +1 -1
  42. data/lib/chef/formatters/base.rb +7 -0
  43. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +2 -2
  44. data/lib/chef/formatters/indentable_output_stream.rb +5 -0
  45. data/lib/chef/http.rb +19 -3
  46. data/lib/chef/http/decompressor.rb +2 -2
  47. data/lib/chef/json_compat.rb +1 -0
  48. data/lib/chef/knife.rb +16 -2
  49. data/lib/chef/knife/bootstrap.rb +55 -10
  50. data/lib/chef/knife/cookbook_site_install.rb +5 -1
  51. data/lib/chef/knife/core/bootstrap_context.rb +2 -1
  52. data/lib/chef/knife/core/node_presenter.rb +1 -1
  53. data/lib/chef/knife/ssh.rb +30 -16
  54. data/lib/chef/knife/ssl_check.rb +4 -2
  55. data/lib/chef/knife/ssl_fetch.rb +3 -2
  56. data/lib/chef/knife/status.rb +14 -1
  57. data/lib/chef/log.rb +14 -0
  58. data/lib/chef/mixin/get_source_from_package.rb +7 -2
  59. data/lib/chef/mixin/properties.rb +302 -0
  60. data/lib/chef/mixin/proxified_socket.rb +38 -0
  61. data/lib/chef/mixin/subclass_directive.rb +37 -0
  62. data/lib/chef/node.rb +13 -5
  63. data/lib/chef/platform/query_helpers.rb +14 -3
  64. data/lib/chef/platform/service_helpers.rb +20 -38
  65. data/lib/chef/policy_builder/expand_node_object.rb +3 -0
  66. data/lib/chef/policy_builder/policyfile.rb +1 -0
  67. data/lib/chef/property.rb +51 -12
  68. data/lib/chef/provider.rb +40 -35
  69. data/lib/chef/provider/deploy.rb +1 -1
  70. data/lib/chef/provider/dsc_resource.rb +54 -20
  71. data/lib/chef/provider/execute.rb +25 -4
  72. data/lib/chef/provider/group.rb +1 -1
  73. data/lib/chef/provider/lwrp_base.rb +1 -0
  74. data/lib/chef/provider/package.rb +76 -30
  75. data/lib/chef/provider/package/dpkg.rb +152 -69
  76. data/lib/chef/provider/package/openbsd.rb +6 -8
  77. data/lib/chef/provider/package/solaris.rb +2 -0
  78. data/lib/chef/provider/package/windows.rb +95 -14
  79. data/lib/chef/provider/package/windows/exe.rb +129 -0
  80. data/lib/chef/provider/package/windows/msi.rb +37 -13
  81. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +89 -0
  82. data/lib/chef/provider/package/yum.rb +13 -3
  83. data/lib/chef/provider/powershell_script.rb +3 -0
  84. data/lib/chef/provider/remote_file/cache_control_data.rb +37 -4
  85. data/lib/chef/provider/remote_file/http.rb +1 -1
  86. data/lib/chef/provider/script.rb +1 -0
  87. data/lib/chef/provider/service.rb +13 -10
  88. data/lib/chef/provider/service/solaris.rb +43 -17
  89. data/lib/chef/provider/service/upstart.rb +3 -3
  90. data/lib/chef/provider/user.rb +1 -1
  91. data/lib/chef/provider/user/dscl.rb +111 -100
  92. data/lib/chef/provider/user/windows.rb +5 -3
  93. data/lib/chef/recipe.rb +3 -5
  94. data/lib/chef/resource.rb +77 -320
  95. data/lib/chef/resource/action_class.rb +4 -0
  96. data/lib/chef/resource/dpkg_package.rb +4 -3
  97. data/lib/chef/resource/dsc_resource.rb +40 -2
  98. data/lib/chef/resource/execute.rb +9 -1
  99. data/lib/chef/resource/ksh.rb +32 -0
  100. data/lib/chef/resource/lwrp_base.rb +6 -10
  101. data/lib/chef/resource/package.rb +8 -9
  102. data/lib/chef/resource/registry_key.rb +1 -1
  103. data/lib/chef/resource/resource_notification.rb +14 -1
  104. data/lib/chef/resource/script.rb +1 -1
  105. data/lib/chef/resource/windows_package.rb +1 -1
  106. data/lib/chef/resource_builder.rb +14 -7
  107. data/lib/chef/resource_reporter.rb +6 -0
  108. data/lib/chef/resources.rb +1 -7
  109. data/lib/chef/rest.rb +1 -1
  110. data/lib/chef/run_context.rb +45 -2
  111. data/lib/chef/run_list/run_list_expansion.rb +47 -0
  112. data/lib/chef/runner.rb +25 -0
  113. data/lib/chef/search/query.rb +16 -2
  114. data/lib/chef/util/diff.rb +2 -2
  115. data/lib/chef/util/powershell/ps_credential.rb +2 -3
  116. data/lib/chef/version.rb +1 -1
  117. data/lib/chef/win32/api/file.rb +51 -1
  118. data/lib/chef/win32/file.rb +5 -0
  119. data/lib/chef/win32/file/version_info.rb +93 -0
  120. data/lib/chef/win32/mutex.rb +1 -1
  121. data/spec/data/apt/chef-integration-test2-1.0/debian/changelog +5 -0
  122. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.debhelper.log +45 -0
  123. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2.substvars +1 -0
  124. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/conffiles +1 -0
  125. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/control +10 -0
  126. data/spec/data/apt/chef-integration-test2-1.0/debian/chef-integration-test2/DEBIAN/md5sums +1 -0
  127. data/spec/data/apt/chef-integration-test2-1.0/debian/compat +1 -0
  128. data/spec/data/apt/chef-integration-test2-1.0/debian/conffiles +1 -0
  129. data/spec/data/apt/chef-integration-test2-1.0/debian/control +13 -0
  130. data/spec/data/apt/chef-integration-test2-1.0/debian/copyright +34 -0
  131. data/spec/data/apt/chef-integration-test2-1.0/debian/files +1 -0
  132. data/spec/data/apt/chef-integration-test2-1.0/debian/rules +13 -0
  133. data/spec/data/apt/chef-integration-test2-1.0/debian/source/format +1 -0
  134. data/spec/data/apt/chef-integration-test2_1.0-1.debian.tar.gz +0 -0
  135. data/spec/data/apt/chef-integration-test2_1.0-1.dsc +18 -0
  136. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.build +91 -0
  137. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.changes +31 -0
  138. data/spec/data/apt/chef-integration-test2_1.0-1_amd64.deb +0 -0
  139. data/spec/data/apt/chef-integration-test2_1.0.orig.tar.gz +0 -0
  140. data/spec/functional/application_spec.rb +1 -1
  141. data/spec/functional/audit/runner_spec.rb +4 -0
  142. data/spec/functional/knife/ssh_spec.rb +5 -5
  143. data/spec/functional/notifications_spec.rb +74 -4
  144. data/spec/functional/resource/aix_service_spec.rb +2 -2
  145. data/spec/functional/resource/dpkg_package_spec.rb +339 -0
  146. data/spec/functional/resource/ifconfig_spec.rb +3 -1
  147. data/spec/functional/resource/mount_spec.rb +5 -2
  148. data/spec/functional/resource/package_spec.rb +1 -1
  149. data/spec/functional/resource/user/windows_spec.rb +8 -0
  150. data/spec/functional/resource/windows_package_spec.rb +177 -0
  151. data/spec/functional/win32/version_info_spec.rb +50 -0
  152. data/spec/integration/client/client_spec.rb +80 -0
  153. data/spec/integration/knife/download_spec.rb +9 -0
  154. data/spec/integration/knife/upload_spec.rb +28 -1
  155. data/spec/integration/recipes/lwrp_inline_resources_spec.rb +93 -23
  156. data/spec/integration/recipes/resource_action_spec.rb +211 -116
  157. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +72 -0
  158. data/spec/integration/solo/solo_spec.rb +34 -0
  159. data/spec/spec_helper.rb +11 -1
  160. data/spec/support/platform_helpers.rb +8 -0
  161. data/spec/support/shared/integration/integration_helper.rb +6 -0
  162. data/spec/support/shared/unit/execute_resource.rb +5 -0
  163. data/spec/support/shared/unit/platform_introspector.rb +7 -0
  164. data/spec/tiny_server.rb +6 -2
  165. data/spec/unit/api_client/registration_spec.rb +5 -4
  166. data/spec/unit/application_spec.rb +1 -181
  167. data/spec/unit/chef_fs/file_system/cookbook_subdir_spec.rb +34 -0
  168. data/spec/unit/cookbook/metadata_spec.rb +122 -2
  169. data/spec/unit/http_spec.rb +102 -0
  170. data/spec/unit/knife/bootstrap_spec.rb +55 -13
  171. data/spec/unit/knife/core/bootstrap_context_spec.rb +10 -3
  172. data/spec/unit/knife/ssl_check_spec.rb +7 -3
  173. data/spec/unit/knife/ssl_fetch_spec.rb +2 -2
  174. data/spec/unit/knife/status_spec.rb +13 -13
  175. data/spec/unit/knife_spec.rb +26 -2
  176. data/spec/unit/lwrp_spec.rb +1 -1
  177. data/spec/unit/mixin/properties_spec.rb +97 -0
  178. data/spec/unit/mixin/proxified_socket_spec.rb +94 -0
  179. data/spec/unit/mixin/subclass_directive_spec.rb +45 -0
  180. data/spec/unit/node_spec.rb +9 -1
  181. data/spec/unit/policy_builder/policyfile_spec.rb +2 -0
  182. data/spec/unit/property/validation_spec.rb +14 -12
  183. data/spec/unit/property_spec.rb +56 -0
  184. data/spec/unit/provider/deploy_spec.rb +1 -1
  185. data/spec/unit/provider/dsc_resource_spec.rb +63 -24
  186. data/spec/unit/provider/execute_spec.rb +95 -28
  187. data/spec/unit/provider/package/dpkg_spec.rb +185 -96
  188. data/spec/unit/provider/package/windows/exe_spec.rb +251 -0
  189. data/spec/unit/provider/package/windows/msi_spec.rb +94 -10
  190. data/spec/unit/provider/package/windows_spec.rb +227 -26
  191. data/spec/unit/provider/package/yum_spec.rb +6 -0
  192. data/spec/unit/provider/package_spec.rb +495 -366
  193. data/spec/unit/provider/remote_file/cache_control_data_spec.rb +62 -36
  194. data/spec/unit/provider/script_spec.rb +2 -2
  195. data/spec/unit/provider/service/solaris_smf_service_spec.rb +110 -39
  196. data/spec/unit/provider/service/upstart_service_spec.rb +19 -0
  197. data/spec/unit/provider/user/dscl_spec.rb +14 -0
  198. data/spec/unit/provider/user/windows_spec.rb +2 -2
  199. data/spec/unit/provider/user_spec.rb +9 -0
  200. data/spec/unit/provider_resolver_spec.rb +6 -30
  201. data/spec/unit/recipe_spec.rb +46 -20
  202. data/spec/unit/resource/chef_gem_spec.rb +1 -1
  203. data/spec/unit/resource/dsc_resource_spec.rb +14 -3
  204. data/spec/unit/resource/ksh_spec.rb +40 -0
  205. data/spec/unit/resource/registry_key_spec.rb +2 -2
  206. data/spec/unit/resource/resource_notification_spec.rb +44 -45
  207. data/spec/unit/resource_reporter_spec.rb +7 -0
  208. data/spec/unit/resource_spec.rb +268 -253
  209. data/spec/unit/rest_spec.rb +2 -2
  210. data/spec/unit/run_list/run_list_expansion_spec.rb +18 -3
  211. data/spec/unit/search/query_spec.rb +19 -1
  212. data/spec/unit/util/powershell/ps_credential_spec.rb +8 -1
  213. data/spec/unit/windows_service_spec.rb +83 -38
  214. data/tasks/external_tests.rb +19 -9
  215. data/tasks/rspec.rb +1 -1
  216. metadata +70 -21
  217. data/spec/support/pedant/Gemfile +0 -3
  218. data/spec/support/pedant/pedant_config.rb +0 -129
  219. data/spec/support/pedant/run_pedant.rb +0 -63
  220. data/spec/support/pedant/stickywicket.pem +0 -27
  221. data/spec/unit/provider/package_spec.rbe +0 -0
@@ -384,6 +384,9 @@ class Chef
384
384
  def deprecation(message, location=caller(2..2)[0])
385
385
  end
386
386
 
387
+ def run_list_expanded(run_list_expansion)
388
+ end
389
+
387
390
  # An uncategorized message. This supports the case that a user needs to
388
391
  # pass output that doesn't fit into one of the callbacks above. Note that
389
392
  # there's no semantic information about the content or importance of the
@@ -20,6 +20,11 @@ class Chef
20
20
  @subscribers << subscriber
21
21
  end
22
22
 
23
+ # Check to see if we are dispatching to a formatter
24
+ def formatter?
25
+ @subscribers.any? { |s| s.respond_to?(:is_formatter?) && s.is_formatter? }
26
+ end
27
+
23
28
  ####
24
29
  # All messages are unconditionally forwarded to all subscribers, so just
25
30
  # define the forwarding in one go:
@@ -21,6 +21,14 @@ class Chef
21
21
  events.stream_output(self, str, options)
22
22
  end
23
23
 
24
+ def <<(str)
25
+ events.stream_output(self, str, options)
26
+ end
27
+
28
+ def write(str)
29
+ events.stream_output(self, str, options)
30
+ end
31
+
24
32
  def close
25
33
  events.stream_closed(self, options)
26
34
  end
@@ -2,7 +2,7 @@
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
3
  # Author:: Seth Falcon (<seth@opscode.com>)
4
4
  # Author:: Kyle Goodwin (<kgoodwin@primerevenue.com>)
5
- # Copyright:: Copyright 2008-2010 Opscode, Inc.
5
+ # Copyright:: Copyright 2008-2015 Chef Software, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -74,6 +74,11 @@ class Chef
74
74
  class InvalidPrivateKey < ArgumentError; end
75
75
  class MissingKeyAttribute < ArgumentError; end
76
76
  class KeyCommandInputError < ArgumentError; end
77
+ class BootstrapCommandInputError < ArgumentError
78
+ def initialize
79
+ super "You cannot pass both --json-attributes and --json-attribute-file. Please pass one or none."
80
+ end
81
+ end
77
82
  class InvalidKeyArgument < ArgumentError; end
78
83
  class InvalidKeyAttribute < ArgumentError; end
79
84
  class InvalidUserAttribute < ArgumentError; end
@@ -164,6 +169,7 @@ class Chef
164
169
  class LCMParser < RuntimeError; end
165
170
 
166
171
  class CannotDetermineHomebrewOwner < Package; end
172
+ class CannotDetermineWindowsInstallerType < Package; end
167
173
 
168
174
  # Can not create staging file during file deployment
169
175
  class FileContentStagingError < RuntimeError
@@ -477,6 +483,20 @@ class Chef
477
483
  end
478
484
  end
479
485
 
486
+ class CookbookChefVersionMismatch < RuntimeError
487
+ def initialize(chef_version, cookbook_name, cookbook_version, *constraints)
488
+ constraint_str = constraints.map { |c| c.requirement.as_list.to_s }.join(', ')
489
+ super "Cookbook '#{cookbook_name}' version '#{cookbook_version}' depends on chef version #{constraint_str}, but the running chef version is #{chef_version}"
490
+ end
491
+ end
492
+
493
+ class CookbookOhaiVersionMismatch < RuntimeError
494
+ def initialize(ohai_version, cookbook_name, cookbook_version, *constraints)
495
+ constraint_str = constraints.map { |c| c.requirement.as_list.to_s }.join(', ')
496
+ super "Cookbook '#{cookbook_name}' version '#{cookbook_version}' depends on ohai version #{constraint_str}, but the running ohai version is #{ohai_version}"
497
+ end
498
+ end
499
+
480
500
  class MultipleDscResourcesFound < RuntimeError
481
501
  attr_reader :resources_found
482
502
  def initialize(resources_found)
@@ -79,18 +79,18 @@ class Chef
79
79
  def should_update_owner?
80
80
  if target_uid.nil?
81
81
  # the user has not specified a permission on the new resource, so we never manage it with FAC
82
- Chef::Log.debug("found target_uid == nil, so no owner was specified on resource, not managing owner")
82
+ Chef::Log.debug("Found target_uid == nil, so no owner was specified on resource, not managing owner")
83
83
  return false
84
84
  elsif current_uid.nil?
85
85
  # the user has specified a permission, and we are creating a file, so always enforce permissions
86
- Chef::Log.debug("found current_uid == nil, so we are creating a new file, updating owner")
86
+ Chef::Log.debug("Found current_uid == nil, so we are creating a new file, updating owner")
87
87
  return true
88
88
  elsif target_uid != current_uid
89
89
  # the user has specified a permission, and it does not match the file, so fix the permission
90
- Chef::Log.debug("found target_uid != current_uid, updating owner")
90
+ Chef::Log.debug("Found target_uid != current_uid, updating owner")
91
91
  return true
92
92
  else
93
- Chef::Log.debug("found target_uid == current_uid, not updating owner")
93
+ Chef::Log.debug("Found target_uid == current_uid, not updating owner")
94
94
  # the user has specified a permission, but it matches the file, so behave idempotently
95
95
  return false
96
96
  end
@@ -138,18 +138,18 @@ class Chef
138
138
  def should_update_group?
139
139
  if target_gid.nil?
140
140
  # the user has not specified a permission on the new resource, so we never manage it with FAC
141
- Chef::Log.debug("found target_gid == nil, so no group was specified on resource, not managing group")
141
+ Chef::Log.debug("Found target_gid == nil, so no group was specified on resource, not managing group")
142
142
  return false
143
143
  elsif current_gid.nil?
144
144
  # the user has specified a permission, and we are creating a file, so always enforce permissions
145
- Chef::Log.debug("found current_gid == nil, so we are creating a new file, updating group")
145
+ Chef::Log.debug("Found current_gid == nil, so we are creating a new file, updating group")
146
146
  return true
147
147
  elsif target_gid != current_gid
148
148
  # the user has specified a permission, and it does not match the file, so fix the permission
149
- Chef::Log.debug("found target_gid != current_gid, updating group")
149
+ Chef::Log.debug("Found target_gid != current_gid, updating group")
150
150
  return true
151
151
  else
152
- Chef::Log.debug("found target_gid == current_gid, not updating group")
152
+ Chef::Log.debug("Found target_gid == current_gid, not updating group")
153
153
  # the user has specified a permission, but it matches the file, so behave idempotently
154
154
  return false
155
155
  end
@@ -187,20 +187,20 @@ class Chef
187
187
  def should_update_mode?
188
188
  if target_mode.nil?
189
189
  # the user has not specified a permission on the new resource, so we never manage it with FAC
190
- Chef::Log.debug("found target_mode == nil, so no mode was specified on resource, not managing mode")
190
+ Chef::Log.debug("Found target_mode == nil, so no mode was specified on resource, not managing mode")
191
191
  return false
192
192
  elsif current_mode.nil?
193
193
  # the user has specified a permission, and we are creating a file, so always enforce permissions
194
- Chef::Log.debug("found current_mode == nil, so we are creating a new file, updating mode")
194
+ Chef::Log.debug("Found current_mode == nil, so we are creating a new file, updating mode")
195
195
  return true
196
196
  elsif target_mode != current_mode
197
197
  # the user has specified a permission, and it does not match the file, so fix the permission
198
- Chef::Log.debug("found target_mode != current_mode, updating mode")
198
+ Chef::Log.debug("Found target_mode != current_mode, updating mode")
199
199
  return true
200
200
  elsif suid_bit_set? and (should_update_group? or should_update_owner?)
201
201
  return true
202
202
  else
203
- Chef::Log.debug("found target_mode == current_mode, not updating mode")
203
+ Chef::Log.debug("Found target_mode == current_mode, not updating mode")
204
204
  # the user has specified a permission, but it matches the file, so behave idempotently
205
205
  return false
206
206
  end
@@ -34,12 +34,12 @@ class Chef
34
34
  #
35
35
  class Cp
36
36
  def create(file)
37
- Chef::Log.debug("touching #{file} to create it")
37
+ Chef::Log.debug("Touching #{file} to create it")
38
38
  FileUtils.touch(file)
39
39
  end
40
40
 
41
41
  def deploy(src, dst)
42
- Chef::Log.debug("copying temporary file #{src} into place at #{dst}")
42
+ Chef::Log.debug("Copying temporary file #{src} into place at #{dst}")
43
43
  FileUtils.cp(src, dst)
44
44
  end
45
45
  end
@@ -30,19 +30,19 @@ class Chef
30
30
  def create(file)
31
31
  # this is very simple, but it ensures that ownership and file modes take
32
32
  # good defaults, in particular mode needs to obey umask on create
33
- Chef::Log.debug("touching #{file} to create it")
33
+ Chef::Log.debug("Touching #{file} to create it")
34
34
  FileUtils.touch(file)
35
35
  end
36
36
 
37
37
  def deploy(src, dst)
38
38
  # we are only responsible for content so restore the dst files perms
39
- Chef::Log.debug("reading modes from #{dst} file")
39
+ Chef::Log.debug("Reading modes from #{dst} file")
40
40
  stat = ::File.stat(dst)
41
41
  mode = stat.mode & 07777
42
42
  uid = stat.uid
43
43
  gid = stat.gid
44
44
 
45
- Chef::Log.debug("applying mode = #{mode.to_s(8)}, uid = #{uid}, gid = #{gid} to #{src}")
45
+ Chef::Log.debug("Applying mode = #{mode.to_s(8)}, uid = #{uid}, gid = #{gid} to #{src}")
46
46
 
47
47
  # i own the inode, so should be able to at least chmod it
48
48
  ::File.chmod(mode, src)
@@ -67,7 +67,7 @@ class Chef
67
67
  Chef::Log.warn("Could not set gid = #{gid} on #{src}, file modes not preserved")
68
68
  end
69
69
 
70
- Chef::Log.debug("moving temporary file #{src} into place at #{dst}")
70
+ Chef::Log.debug("Moving temporary file #{src} into place at #{dst}")
71
71
  FileUtils.mv(src, dst)
72
72
  end
73
73
  end
@@ -35,7 +35,7 @@ class Chef
35
35
  ACL = Security::ACL
36
36
 
37
37
  def create(file)
38
- Chef::Log.debug("touching #{file} to create it")
38
+ Chef::Log.debug("Touching #{file} to create it")
39
39
  FileUtils.touch(file)
40
40
  end
41
41
 
@@ -215,6 +215,10 @@ class Chef
215
215
  def deprecation(message, location=caller(2..2)[0])
216
216
  Chef::Log.deprecation("#{message} at #{location}")
217
217
  end
218
+
219
+ def is_formatter?
220
+ true
221
+ end
218
222
  end
219
223
 
220
224
 
@@ -225,6 +229,9 @@ class Chef
225
229
 
226
230
  cli_name(:null)
227
231
 
232
+ def is_formatter?
233
+ false
234
+ end
228
235
  end
229
236
 
230
237
  end
@@ -108,7 +108,7 @@ class Chef
108
108
  def culprit_backtrace_entry
109
109
  @culprit_backtrace_entry ||= begin
110
110
  bt_entry = filtered_bt.first
111
- Chef::Log.debug("backtrace entry for compile error: '#{bt_entry}'")
111
+ Chef::Log.debug("Backtrace entry for compile error: '#{bt_entry}'")
112
112
  bt_entry
113
113
  end
114
114
  end
@@ -138,7 +138,7 @@ class Chef
138
138
  begin
139
139
  filters = Array(Chef::Config.cookbook_path).map {|p| /^#{Regexp.escape(p)}/i }
140
140
  r = exception.backtrace.select {|line| filters.any? {|filter| line =~ filter }}
141
- Chef::Log.debug("filtered backtrace of compile error: #{r.join(",")}")
141
+ Chef::Log.debug("Filtered backtrace of compile error: #{r.join(",")}")
142
142
  r
143
143
  end
144
144
  end
@@ -50,6 +50,11 @@ class Chef
50
50
  print(string, from_args(args, :start_line => true, :end_line => true))
51
51
  end
52
52
 
53
+ # Print a raw chunk
54
+ def <<(obj)
55
+ print(obj)
56
+ end
57
+
53
58
  # Print a string.
54
59
  #
55
60
  # == Arguments
@@ -5,7 +5,7 @@
5
5
  # Author:: Christopher Brown (<cb@opscode.com>)
6
6
  # Author:: Christopher Walters (<cw@opscode.com>)
7
7
  # Author:: Daniel DeLeo (<dan@opscode.com>)
8
- # Copyright:: Copyright (c) 2009, 2010, 2013 Opscode, Inc.
8
+ # Copyright:: Copyright (c) 2009, 2010, 2013-2015 Chef Software, Inc.
9
9
  # License:: Apache License, Version 2.0
10
10
  #
11
11
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,7 +25,6 @@ require 'tempfile'
25
25
  require 'net/https'
26
26
  require 'uri'
27
27
  require 'chef/http/basic_client'
28
- require 'chef/http/socketless_chef_zero_client'
29
28
  require 'chef/monkey_patches/net_http'
30
29
  require 'chef/config'
31
30
  require 'chef/platform/query_helpers'
@@ -75,6 +74,7 @@ class Chef
75
74
  attr_reader :sign_on_redirect
76
75
  attr_reader :redirect_limit
77
76
 
77
+ attr_reader :options
78
78
  attr_reader :middlewares
79
79
 
80
80
  # Create a HTTP client object. The supplied +url+ is used as the base for
@@ -87,6 +87,7 @@ class Chef
87
87
  @sign_on_redirect = true
88
88
  @redirects_followed = 0
89
89
  @redirect_limit = 10
90
+ @options = options
90
91
 
91
92
  @middlewares = []
92
93
  self.class.middlewares.each do |middleware_class|
@@ -198,6 +199,14 @@ class Chef
198
199
  def http_client(base_url=nil)
199
200
  base_url ||= url
200
201
  if chef_zero_uri?(base_url)
202
+ # PERFORMANCE CRITICAL: *MUST* lazy require here otherwise we load up webrick
203
+ # via chef-zero and that hits DNS (at *require* time) which may timeout,
204
+ # when for most knife/chef-client work we never need/want this loaded.
205
+ Thread.exclusive {
206
+ unless defined?(SocketlessChefZeroClient)
207
+ require 'chef/http/socketless_chef_zero_client'
208
+ end
209
+ }
201
210
  SocketlessChefZeroClient.new(base_url)
202
211
  else
203
212
  BasicClient.new(base_url, :ssl_policy => Chef::HTTP::APISSLPolicy)
@@ -307,7 +316,7 @@ class Chef
307
316
  end
308
317
  return [response, request, return_value]
309
318
  end
310
- rescue SocketError, Errno::ETIMEDOUT => e
319
+ rescue SocketError, Errno::ETIMEDOUT, Errno::ECONNRESET => e
311
320
  if http_retry_count - http_attempts + 1 > 0
312
321
  Chef::Log.error("Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
313
322
  sleep(http_retry_delay)
@@ -329,6 +338,13 @@ class Chef
329
338
  retry
330
339
  end
331
340
  raise Timeout::Error, "Timeout connecting to #{url}, giving up"
341
+ rescue OpenSSL::SSL::SSLError => e
342
+ if (http_retry_count - http_attempts + 1 > 0) && !e.message.include?("certificate verify failed")
343
+ Chef::Log.error("SSL Error connecting to #{url}, retry #{http_attempts}/#{http_retry_count}")
344
+ sleep(http_retry_delay)
345
+ retry
346
+ end
347
+ raise OpenSSL::SSL::SSLError, "SSL Error connecting to #{url} - #{e.message}"
332
348
  end
333
349
  end
334
350
 
@@ -79,10 +79,10 @@ class Chef
79
79
  else
80
80
  case response[CONTENT_ENCODING]
81
81
  when GZIP
82
- Chef::Log.debug "decompressing gzip response"
82
+ Chef::Log.debug "Decompressing gzip response"
83
83
  Zlib::Inflate.new(Zlib::MAX_WBITS + 16).inflate(response.body)
84
84
  when DEFLATE
85
- Chef::Log.debug "decompressing deflate response"
85
+ Chef::Log.debug "Decompressing deflate response"
86
86
  Zlib::Inflate.inflate(response.body)
87
87
  else
88
88
  response.body
@@ -41,6 +41,7 @@ class Chef
41
41
  CHEF_RESOURCECOLLECTION = "Chef::ResourceCollection".freeze
42
42
  CHEF_RESOURCESET = "Chef::ResourceCollection::ResourceSet".freeze
43
43
  CHEF_RESOURCELIST = "Chef::ResourceCollection::ResourceList".freeze
44
+ CHEF_RUNLISTEXPANSION = "Chef::RunListExpansion".freeze
44
45
 
45
46
  class <<self
46
47
 
@@ -87,7 +87,16 @@ class Chef
87
87
  def self.inherited(subclass)
88
88
  unless subclass.unnamed?
89
89
  subcommands[subclass.snake_case_name] = subclass
90
- subcommand_files[subclass.snake_case_name] += [caller[0].split(/:\d+/).first]
90
+ subcommand_files[subclass.snake_case_name] +=
91
+ if subclass.superclass.to_s == "Chef::ChefFS::Knife"
92
+ # ChefFS-based commands have a superclass that defines an
93
+ # inhereited method which calls super. This means that the
94
+ # top of the call stack is not the class definition for
95
+ # our subcommand. Try the second entry in the call stack.
96
+ [path_from_caller(caller[1])]
97
+ else
98
+ [path_from_caller(caller[0])]
99
+ end
91
100
  end
92
101
  end
93
102
 
@@ -221,6 +230,10 @@ class Chef
221
230
 
222
231
  OFFICIAL_PLUGINS = %w[ec2 rackspace windows openstack terremark bluebox]
223
232
 
233
+ def self.path_from_caller(caller_line)
234
+ caller_line.split(/:\d+/).first
235
+ end
236
+
224
237
  # :nodoc:
225
238
  # Error out and print usage. probably because the arguments given by the
226
239
  # user could not be resolved to a subcommand.
@@ -293,7 +306,7 @@ class Chef
293
306
 
294
307
  # copy Mixlib::CLI over so that it can be configured in knife.rb
295
308
  # config file
296
- Chef::Config[:verbosity] = config[:verbosity]
309
+ Chef::Config[:verbosity] = config[:verbosity] if config[:verbosity]
297
310
  end
298
311
 
299
312
  def parse_options(args)
@@ -388,6 +401,7 @@ class Chef
388
401
 
389
402
  merge_configs
390
403
  apply_computed_config
404
+ Chef::Config.export_proxies
391
405
  # This has to be after apply_computed_config so that Mixlib::Log is configured
392
406
  Chef::Log.info("Using configuration from #{config[:config_file]}") if config[:config_file]
393
407
  end
@@ -42,7 +42,7 @@ class Chef
42
42
  Chef::Knife::Ssh.load_deps
43
43
  end
44
44
 
45
- banner "knife bootstrap FQDN (options)"
45
+ banner "knife bootstrap [SSH_USER@]FQDN (options)"
46
46
 
47
47
  option :ssh_user,
48
48
  :short => "-x USERNAME",
@@ -74,8 +74,12 @@ class Chef
74
74
  :boolean => true
75
75
 
76
76
  option :identity_file,
77
- :short => "-i IDENTITY_FILE",
78
77
  :long => "--identity-file IDENTITY_FILE",
78
+ :description => "The SSH identity file used for authentication. [DEPRECATED] Use --ssh-identity-file instead."
79
+
80
+ option :ssh_identity_file,
81
+ :short => "-i IDENTITY_FILE",
82
+ :long => "--ssh-identity-file IDENTITY_FILE",
79
83
  :description => "The SSH identity file used for authentication"
80
84
 
81
85
  option :chef_node_name,
@@ -122,6 +126,11 @@ class Chef
122
126
  :description => "Execute the bootstrap via sudo",
123
127
  :boolean => true
124
128
 
129
+ option :preserve_home,
130
+ :long => "--sudo-preserve-home",
131
+ :description => "Preserve non-root user HOME environment variable with sudo",
132
+ :boolean => true
133
+
125
134
  option :use_sudo_password,
126
135
  :long => "--use-sudo-password",
127
136
  :description => "Execute the bootstrap via sudo with password",
@@ -164,7 +173,13 @@ class Chef
164
173
  :long => "--json-attributes",
165
174
  :description => "A JSON string to be added to the first run of chef-client",
166
175
  :proc => lambda { |o| Chef::JSONCompat.parse(o) },
167
- :default => {}
176
+ :default => nil
177
+
178
+ option :first_boot_attributes_from_file,
179
+ :long => "--json-attribute-file FILE",
180
+ :description => "A JSON file to be used to the first run of chef-client",
181
+ :proc => lambda { |o| Chef::JSONCompat.parse(File.read(o)) },
182
+ :default => nil
168
183
 
169
184
  option :host_key_verify,
170
185
  :long => "--[no-]host-key-verify",
@@ -256,13 +271,25 @@ class Chef
256
271
  "chef-full"
257
272
  end
258
273
 
274
+ def host_descriptor
275
+ Array(@name_args).first
276
+ end
277
+
259
278
  # The server_name is the DNS or IP we are going to connect to, it is not necessarily
260
279
  # the node name, the fqdn, or the hostname of the server. This is a public API hook
261
280
  # which knife plugins use or inherit and override.
262
281
  #
263
282
  # @return [String] The DNS or IP that bootstrap will connect to
264
283
  def server_name
265
- Array(@name_args).first
284
+ if host_descriptor
285
+ @server_name ||= host_descriptor.split('@').reverse[0]
286
+ end
287
+ end
288
+
289
+ def user_name
290
+ if host_descriptor
291
+ @user_name ||= host_descriptor.split('@').reverse[1]
292
+ end
266
293
  end
267
294
 
268
295
  def bootstrap_template
@@ -317,13 +344,22 @@ class Chef
317
344
  )
318
345
  end
319
346
 
347
+ def first_boot_attributes
348
+ @config[:first_boot_attributes] || @config[:first_boot_attributes_from_file] || {}
349
+ end
350
+
320
351
  def render_template
352
+ @config[:first_boot_attributes] = first_boot_attributes
321
353
  template_file = find_template
322
354
  template = IO.read(template_file).chomp
323
355
  Erubis::Eruby.new(template).evaluate(bootstrap_context)
324
356
  end
325
357
 
326
358
  def run
359
+ if @config[:first_boot_attributes] && @config[:first_boot_attributes_from_file]
360
+ raise Chef::Exceptions::BootstrapCommandInputError
361
+ end
362
+
327
363
  validate_name_args!
328
364
  validate_options!
329
365
 
@@ -358,7 +394,7 @@ class Chef
358
394
  if config[:ssh_password]
359
395
  raise
360
396
  else
361
- ui.info("Failed to authenticate #{config[:ssh_user]} - trying password auth")
397
+ ui.info("Failed to authenticate #{knife_ssh.config[:ssh_user]} - trying password auth")
362
398
  knife_ssh_with_password_auth.run
363
399
  end
364
400
  end
@@ -389,12 +425,12 @@ class Chef
389
425
  ssh = Chef::Knife::Ssh.new
390
426
  ssh.ui = ui
391
427
  ssh.name_args = [ server_name, ssh_command ]
392
- ssh.config[:ssh_user] = config[:ssh_user]
428
+ ssh.config[:ssh_user] = user_name || config[:ssh_user]
393
429
  ssh.config[:ssh_password] = config[:ssh_password]
394
430
  ssh.config[:ssh_port] = config[:ssh_port]
395
431
  ssh.config[:ssh_gateway] = config[:ssh_gateway]
396
432
  ssh.config[:forward_agent] = config[:forward_agent]
397
- ssh.config[:identity_file] = config[:identity_file]
433
+ ssh.config[:ssh_identity_file] = config[:ssh_identity_file] || config[:identity_file]
398
434
  ssh.config[:manual] = true
399
435
  ssh.config[:host_key_verify] = config[:host_key_verify]
400
436
  ssh.config[:on_error] = :raise
@@ -403,7 +439,7 @@ class Chef
403
439
 
404
440
  def knife_ssh_with_password_auth
405
441
  ssh = knife_ssh
406
- ssh.config[:identity_file] = nil
442
+ ssh.config[:ssh_identity_file] = nil
407
443
  ssh.config[:ssh_password] = ssh.get_password
408
444
  ssh
409
445
  end
@@ -412,7 +448,8 @@ class Chef
412
448
  command = render_template
413
449
 
414
450
  if config[:use_sudo]
415
- command = config[:use_sudo_password] ? "echo '#{config[:ssh_password]}' | sudo -SH #{command}" : "sudo -H #{command}"
451
+ sudo_prefix = config[:use_sudo_password] ? "echo '#{config[:ssh_password]}' | sudo -S " : "sudo "
452
+ command = config[:preserve_home] ? "#{sudo_prefix} #{command}" : "#{sudo_prefix} -H #{command}"
416
453
  end
417
454
 
418
455
  command
@@ -422,7 +459,15 @@ class Chef
422
459
 
423
460
  # True if policy_name and run_list are both given
424
461
  def policyfile_and_run_list_given?
425
- !config[:run_list].empty? && !!config[:policy_name]
462
+ run_list_given? && policyfile_options_given?
463
+ end
464
+
465
+ def run_list_given?
466
+ !config[:run_list].nil? && !config[:run_list].empty?
467
+ end
468
+
469
+ def policyfile_options_given?
470
+ !!config[:policy_name]
426
471
  end
427
472
 
428
473
  # True if one of policy_name or policy_group was given, but not both