chef 12.5.1 → 12.6.0

Sign up to get free protection for your applications and to get access to all the features.
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 +64 -15
  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
@@ -70,6 +70,40 @@ EOM
70
70
  end
71
71
  end
72
72
 
73
+ when_the_repository "has a cookbook with an incompatible chef_version" do
74
+ before do
75
+ file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0', "\nchef_version '~> 999.0'")
76
+ file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"'
77
+ file 'config/solo.rb', <<EOM
78
+ cookbook_path "#{path_to('cookbooks')}"
79
+ file_cache_path "#{path_to('config/cache')}"
80
+ EOM
81
+ end
82
+
83
+ it "should exit with an error" do
84
+ result = shell_out("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug", :cwd => chef_dir)
85
+ expect(result.exitstatus).to eq(1)
86
+ expect(result.stdout).to include("Chef::Exceptions::CookbookChefVersionMismatch")
87
+ end
88
+ end
89
+
90
+ when_the_repository "has a cookbook with an incompatible ohai_version" do
91
+ before do
92
+ file 'cookbooks/x/metadata.rb', cb_metadata('x', '1.0.0', "\nohai_version '~> 999.0'")
93
+ file 'cookbooks/x/recipes/default.rb', 'puts "ITWORKS"'
94
+ file 'config/solo.rb', <<EOM
95
+ cookbook_path "#{path_to('cookbooks')}"
96
+ file_cache_path "#{path_to('config/cache')}"
97
+ EOM
98
+ end
99
+
100
+ it "should exit with an error" do
101
+ result = shell_out("#{chef_solo} -c \"#{path_to('config/solo.rb')}\" -o 'x::default' -l debug", :cwd => chef_dir)
102
+ expect(result.exitstatus).to eq(1)
103
+ expect(result.stdout).to include("Chef::Exceptions::CookbookOhaiVersionMismatch")
104
+ end
105
+ end
106
+
73
107
 
74
108
  when_the_repository "has a cookbook with a recipe with sleep" do
75
109
  before do
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -94,8 +94,10 @@ test_node.automatic['platform_family'] = (OHAI_SYSTEM['platform_family'] || 'unk
94
94
  test_node.automatic['platform'] = (OHAI_SYSTEM['platform'] || 'unknown_platform').dup.freeze
95
95
  test_node.automatic['platform_version'] = (OHAI_SYSTEM['platform_version'] || 'unknown_platform_version').dup.freeze
96
96
  TEST_NODE = test_node.freeze
97
+ TEST_OS = TEST_NODE['os']
97
98
  TEST_PLATFORM = TEST_NODE['platform']
98
99
  TEST_PLATFORM_VERSION = TEST_NODE['platform_version']
100
+ TEST_PLATFORM_FAMILY = TEST_NODE['platform_family']
99
101
 
100
102
  RSpec.configure do |config|
101
103
  config.include(Matchers)
@@ -121,6 +123,7 @@ RSpec.configure do |config|
121
123
 
122
124
  config.filter_run_excluding :skip_appveyor => true if ENV["APPVEYOR"]
123
125
  config.filter_run_excluding :appveyor_only => true unless ENV["APPVEYOR"]
126
+ config.filter_run_excluding :skip_travis => true if ENV["TRAVIS"]
124
127
 
125
128
  config.filter_run_excluding :windows_only => true unless windows?
126
129
  config.filter_run_excluding :not_supported_on_mac_osx_106 => true if mac_osx_106?
@@ -144,6 +147,7 @@ RSpec.configure do |config|
144
147
  config.filter_run_excluding :system_windows_service_gem_only => true unless system_windows_service_gem?
145
148
  config.filter_run_excluding :unix_only => true unless unix?
146
149
  config.filter_run_excluding :aix_only => true unless aix?
150
+ config.filter_run_excluding :debian_family_only => true unless debian_family?
147
151
  config.filter_run_excluding :supports_cloexec => true unless supports_cloexec?
148
152
  config.filter_run_excluding :selinux_only => true unless selinux_enabled?
149
153
  config.filter_run_excluding :ruby_20_only => true unless ruby_20?
@@ -159,6 +163,7 @@ RSpec.configure do |config|
159
163
  config.filter_run_excluding :openssl_lt_101 => true unless openssl_lt_101?
160
164
  config.filter_run_excluding :aes_256_gcm_only => true unless aes_256_gcm?
161
165
  config.filter_run_excluding :broken => true
166
+ config.filter_run_excluding :not_wpar => true unless wpar?
162
167
 
163
168
  running_platform_arch = `uname -m`.strip unless windows?
164
169
 
@@ -200,6 +205,11 @@ RSpec.configure do |config|
200
205
  ENV['CHEF_TREAT_DEPRECATION_WARNINGS_AS_ERRORS'] = "1"
201
206
  end
202
207
 
208
+ # raise if anyone commits any test to CI with :focus set on it
209
+ config.before(:example, :focus) do
210
+ raise 'This example was committed with `:focus` and should not have been'
211
+ end if ENV['CI']
212
+
203
213
  config.before(:suite) do
204
214
  ARGV.clear
205
215
  end
@@ -143,10 +143,18 @@ def freebsd?
143
143
  !!(RUBY_PLATFORM =~ /freebsd/)
144
144
  end
145
145
 
146
+ def debian_family?
147
+ !!(ohai[:platform_family] == "debian")
148
+ end
149
+
146
150
  def aix?
147
151
  !!(RUBY_PLATFORM =~ /aix/)
148
152
  end
149
153
 
154
+ def wpar?
155
+ !((ohai[:virtualization] || {})[:wpar_no].nil?)
156
+ end
157
+
150
158
  def supports_cloexec?
151
159
  Fcntl.const_defined?('F_SETFD') && Fcntl.const_defined?('FD_CLOEXEC')
152
160
  end
@@ -27,6 +27,12 @@ require 'support/shared/integration/app_server_support'
27
27
  require 'cheffish/rspec/chef_run_support'
28
28
  require 'spec_helper'
29
29
 
30
+ module Cheffish
31
+ class BasicChefClient
32
+ def_delegators :@run_context, :before_notifications
33
+ end
34
+ end
35
+
30
36
  module IntegrationSupport
31
37
  include ChefZero::RSpec
32
38
 
@@ -111,6 +111,11 @@ shared_examples_for "an execute resource" do
111
111
  expect(@resource.creates).to eql("something")
112
112
  end
113
113
 
114
+ it "should accept a boolean for live streaming" do
115
+ @resource.live_stream true
116
+ expect(@resource.live_stream).to be true
117
+ end
118
+
114
119
  describe "when it has cwd, environment, group, path, return value, and a user" do
115
120
  before do
116
121
  @resource.command("grep")
@@ -32,6 +32,7 @@ shared_examples_for "a platform introspector" do
32
32
  # The following @platform_hash keys are used for testing version constraints
33
33
  @platform_hash['exact_match'] = { '1.2.3' => 'exact', '>= 1.0' => 'not exact'}
34
34
  @platform_hash['multiple_matches'] = { '~> 2.3.4' => 'matched ~> 2.3.4', '>= 2.3' => 'matched >=2.3' }
35
+ @platform_hash['invalid_cookbook_version'] = {'>= 21' => 'Matches a single number'}
35
36
  @platform_hash['successful_matches'] = { '< 3.0' => 'matched < 3.0', '>= 3.0' => 'matched >= 3.0' }
36
37
 
37
38
  @platform_family_hash = {
@@ -95,6 +96,12 @@ shared_examples_for "a platform introspector" do
95
96
  expect {platform_introspector.value_for_platform(@platform_hash)}.to raise_error(RuntimeError)
96
97
  end
97
98
 
99
+ it 'should not require .0 to match >= 21.0' do
100
+ node.automatic_attrs[:platform] = 'invalid_cookbook_version'
101
+ node.automatic_attrs[:platform_version] = '21'
102
+ expect(platform_introspector.value_for_platform(@platform_hash)).to eq('Matches a single number')
103
+ end
104
+
98
105
  it 'should return the value for that match' do
99
106
  node.automatic_attrs[:platform] = 'successful_matches'
100
107
  node.automatic_attrs[:platform_version] = '2.9'
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Daniel DeLeo (<dan@opscode.com>)
3
- # Copyright:: Copyright (c) 2010 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2010-2015 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -66,9 +66,11 @@ module TinyServer
66
66
  @server = Server.setup(@options) do
67
67
  run API.instance
68
68
  end
69
+ @old_handler = trap(:INT, "EXIT")
69
70
  @server.start
70
71
  end
71
72
  block_until_started
73
+ trap(:INT, @old_handler)
72
74
  end
73
75
 
74
76
  def url
@@ -92,9 +94,11 @@ module TinyServer
92
94
  true
93
95
  rescue Errno::ECONNREFUSED, EOFError, Errno::ECONNRESET => e
94
96
  sleep 0.1
97
+ true
95
98
  # If the host has ":::1 localhost" in its hosts file and if IPv6
96
99
  # is not enabled we can get NetworkUnreachable exception...
97
- rescue Errno::ENETUNREACH => e
100
+ rescue Errno::ENETUNREACH, Net::ReadTimeout, IO::EAGAINWaitReadable,
101
+ Errno::EHOSTUNREACH => e
98
102
  sleep 0.1
99
103
  false
100
104
  end
@@ -35,7 +35,7 @@ describe Chef::ApiClient::Registration do
35
35
  File.open(Chef::Config[:validation_key], "r") {|f| f.read.chomp }
36
36
  end
37
37
 
38
- let(:http_mock) { double("Chef::REST mock") }
38
+ let(:http_mock) { double("Chef::ServerAPI mock") }
39
39
 
40
40
  let(:expected_post_data) do
41
41
  { :name => client_name, :admin => false, :public_key => generated_public_key.to_pem }
@@ -93,9 +93,10 @@ describe Chef::ApiClient::Registration do
93
93
  end
94
94
 
95
95
  it "has an HTTP client configured with validator credentials" do
96
- expect(registration.http_api).to be_a_kind_of(Chef::REST)
97
- expect(registration.http_api.client_name).to eq("test-validator")
98
- expect(registration.http_api.signing_key).to eq(private_key_data)
96
+ expect(registration.http_api).to be_a_kind_of(Chef::ServerAPI)
97
+ expect(registration.http_api.options[:client_name]).to eq("test-validator")
98
+ auth = registration.http_api.middlewares.select { |klass| klass.kind_of? Chef::HTTP::Authenticator }.first
99
+ expect(auth.client_name).to eq("test-validator")
99
100
  end
100
101
 
101
102
  describe "when creating/updating the client on the server" do
@@ -39,7 +39,6 @@ describe Chef::Application do
39
39
  @app = Chef::Application.new
40
40
  allow(@app).to receive(:configure_chef).and_return(true)
41
41
  allow(@app).to receive(:configure_logging).and_return(true)
42
- allow(@app).to receive(:configure_proxy_environment_variables).and_return(true)
43
42
  end
44
43
 
45
44
  it "should configure chef" do
@@ -52,11 +51,6 @@ describe Chef::Application do
52
51
  @app.reconfigure
53
52
  end
54
53
 
55
- it "should configure environment variables" do
56
- expect(@app).to receive(:configure_proxy_environment_variables).and_return(true)
57
- @app.reconfigure
58
- end
59
-
60
54
  it 'should not receive set_specific_recipes' do
61
55
  expect(@app).to_not receive(:set_specific_recipes)
62
56
  @app.reconfigure
@@ -101,6 +95,7 @@ describe Chef::Application do
101
95
  @app = Chef::Application.new
102
96
  #Chef::Config.stub(:merge!).and_return(true)
103
97
  allow(@app).to receive(:parse_options).and_return(true)
98
+ expect(Chef::Config).to receive(:export_proxies).and_return(true)
104
99
  end
105
100
 
106
101
  it "should parse the commandline options" do
@@ -245,181 +240,6 @@ describe Chef::Application do
245
240
  end
246
241
  end
247
242
 
248
- describe "when configuring environment variables" do
249
- def configure_proxy_environment_variables_stubs
250
- allow(@app).to receive(:configure_http_proxy).and_return(true)
251
- allow(@app).to receive(:configure_https_proxy).and_return(true)
252
- allow(@app).to receive(:configure_ftp_proxy).and_return(true)
253
- allow(@app).to receive(:configure_no_proxy).and_return(true)
254
- end
255
-
256
- shared_examples_for "setting ENV['http_proxy']" do
257
- before do
258
- Chef::Config[:http_proxy] = http_proxy
259
- end
260
-
261
- it "should set ENV['http_proxy']" do
262
- @app.configure_proxy_environment_variables
263
- expect(@env['http_proxy']).to eq("#{scheme}://#{address}:#{port}")
264
- end
265
-
266
- it "should set ENV['HTTP_PROXY']" do
267
- @app.configure_proxy_environment_variables
268
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://#{address}:#{port}")
269
- end
270
-
271
- describe "when Chef::Config[:http_proxy_user] is set" do
272
- before do
273
- Chef::Config[:http_proxy_user] = "username"
274
- end
275
-
276
- it "should set ENV['http_proxy'] with the username" do
277
- @app.configure_proxy_environment_variables
278
- expect(@env['http_proxy']).to eq("#{scheme}://username@#{address}:#{port}")
279
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://username@#{address}:#{port}")
280
- end
281
-
282
- context "when :http_proxy_user contains '@' and/or ':'" do
283
- before do
284
- Chef::Config[:http_proxy_user] = "my:usern@me"
285
- end
286
-
287
- it "should set ENV['http_proxy'] with the escaped username" do
288
- @app.configure_proxy_environment_variables
289
- expect(@env['http_proxy']).to eq("#{scheme}://my%3Ausern%40me@#{address}:#{port}")
290
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://my%3Ausern%40me@#{address}:#{port}")
291
- end
292
- end
293
-
294
- describe "when Chef::Config[:http_proxy_pass] is set" do
295
- before do
296
- Chef::Config[:http_proxy_pass] = "password"
297
- end
298
-
299
- it "should set ENV['http_proxy'] with the password" do
300
- @app.configure_proxy_environment_variables
301
- expect(@env['http_proxy']).to eq("#{scheme}://username:password@#{address}:#{port}")
302
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://username:password@#{address}:#{port}")
303
- end
304
-
305
- context "when :http_proxy_pass contains '@' and/or ':'" do
306
- before do
307
- Chef::Config[:http_proxy_pass] = ":P@ssword101"
308
- end
309
-
310
- it "should set ENV['http_proxy'] with the escaped password" do
311
- @app.configure_proxy_environment_variables
312
- expect(@env['http_proxy']).to eq("#{scheme}://username:%3AP%40ssword101@#{address}:#{port}")
313
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://username:%3AP%40ssword101@#{address}:#{port}")
314
- end
315
- end
316
- end
317
- end
318
-
319
- describe "when Chef::Config[:http_proxy_pass] is set (but not Chef::Config[:http_proxy_user])" do
320
- before do
321
- Chef::Config[:http_proxy_user] = nil
322
- Chef::Config[:http_proxy_pass] = "password"
323
- end
324
-
325
- it "should set ENV['http_proxy']" do
326
- @app.configure_proxy_environment_variables
327
- expect(@env['http_proxy']).to eq("#{scheme}://#{address}:#{port}")
328
- expect(@env['HTTP_PROXY']).to eq("#{scheme}://#{address}:#{port}")
329
- end
330
- end
331
- end
332
-
333
- describe "when configuring ENV['http_proxy']" do
334
- before do
335
- @env = {}
336
- allow(@app).to receive(:env).and_return(@env)
337
-
338
- allow(@app).to receive(:configure_https_proxy).and_return(true)
339
- allow(@app).to receive(:configure_ftp_proxy).and_return(true)
340
- allow(@app).to receive(:configure_no_proxy).and_return(true)
341
- end
342
-
343
- describe "when Chef::Config[:http_proxy] is not set" do
344
- before do
345
- Chef::Config[:http_proxy] = nil
346
- end
347
-
348
- it "should not set ENV['http_proxy']" do
349
- @app.configure_proxy_environment_variables
350
- expect(@env).to eq({})
351
- end
352
- end
353
-
354
- describe "when Chef::Config[:http_proxy] is set" do
355
- context "when given an FQDN" do
356
- let(:scheme) { "http" }
357
- let(:address) { "proxy.example.org" }
358
- let(:port) { 8080 }
359
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
360
-
361
- it_should_behave_like "setting ENV['http_proxy']"
362
- end
363
-
364
- context "when given an HTTPS URL" do
365
- let(:scheme) { "https" }
366
- let(:address) { "proxy.example.org" }
367
- let(:port) { 8080 }
368
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
369
-
370
- it_should_behave_like "setting ENV['http_proxy']"
371
- end
372
-
373
- context "when given an IP" do
374
- let(:scheme) { "http" }
375
- let(:address) { "127.0.0.1" }
376
- let(:port) { 22 }
377
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
378
-
379
- it_should_behave_like "setting ENV['http_proxy']"
380
- end
381
-
382
- context "when given an IPv6" do
383
- let(:scheme) { "http" }
384
- let(:address) { "[2001:db8::1]" }
385
- let(:port) { 80 }
386
- let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
387
-
388
- it_should_behave_like "setting ENV['http_proxy']"
389
- end
390
-
391
- context "when given without including http://" do
392
- let(:scheme) { "http" }
393
- let(:address) { "proxy.example.org" }
394
- let(:port) { 8181 }
395
- let(:http_proxy) { "#{address}:#{port}" }
396
-
397
- it_should_behave_like "setting ENV['http_proxy']"
398
- end
399
-
400
- context "when given the full proxy in :http_proxy only" do
401
- before do
402
- Chef::Config[:http_proxy] = "http://username:password@proxy.example.org:2222"
403
- Chef::Config[:http_proxy_user] = nil
404
- Chef::Config[:http_proxy_pass] = nil
405
- end
406
-
407
- it "should set ENV['http_proxy']" do
408
- @app.configure_proxy_environment_variables
409
- expect(@env['http_proxy']).to eq(Chef::Config[:http_proxy])
410
- end
411
- end
412
-
413
- context "when the config options aren't URI compliant" do
414
- it "raises Chef::Exceptions::BadProxyURI" do
415
- Chef::Config[:http_proxy] = "http://proxy.bad_example.org/:8080"
416
- expect { @app.configure_proxy_environment_variables }.to raise_error(Chef::Exceptions::BadProxyURI)
417
- end
418
- end
419
- end
420
- end
421
- end
422
-
423
243
  describe "class method: fatal!" do
424
244
  before do
425
245
  allow(STDERR).to receive(:puts).with("FATAL: blah").and_return(true)
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: John Keiser (<jkeiser@opscode.com>)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+ require 'chef/chef_fs/file_system/cookbook_subdir'
21
+
22
+ describe Chef::ChefFS::FileSystem::CookbookSubdir do
23
+ let(:root) do
24
+ Chef::ChefFS::FileSystem::BaseFSDir.new('', nil)
25
+ end
26
+
27
+ let(:cookbook_subdir) do
28
+ Chef::ChefFS::FileSystem::CookbookSubdir.new('test', root, false, true)
29
+ end
30
+
31
+ it 'can get child' do
32
+ cookbook_subdir.child('test')
33
+ end
34
+ end