chef 11.18.12 → 12.0.0.alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +10 -0
- data/README.md +1 -1
- data/distro/common/html/_sources/index.txt +5 -2
- data/distro/common/html/_sources/knife_serve.txt +19 -0
- data/distro/common/html/_sources/knife_ssl_check.txt +2 -2
- data/distro/common/html/_sources/knife_ssl_fetch.txt +2 -2
- data/distro/common/html/_static/basic.css +1 -1
- data/distro/common/html/_static/doctools.js +1 -1
- data/distro/common/html/_static/searchtools.js +1 -1
- data/distro/common/html/_static/websupport.js +1 -1
- data/distro/common/html/ctl_chef_client.html +19 -9
- data/distro/common/html/ctl_chef_server.html +7 -1
- data/distro/common/html/ctl_chef_shell.html +3 -4
- data/distro/common/html/ctl_chef_solo.html +12 -7
- data/distro/common/html/index.html +19 -12
- data/distro/common/html/knife.html +1 -2
- data/distro/common/html/knife_bootstrap.html +16 -5
- data/distro/common/html/knife_client.html +8 -5
- data/distro/common/html/knife_common_options.html +11 -12
- data/distro/common/html/knife_configure.html +2 -3
- data/distro/common/html/knife_cookbook.html +16 -17
- data/distro/common/html/knife_cookbook_site.html +19 -18
- data/distro/common/html/knife_data_bag.html +6 -7
- data/distro/common/html/knife_delete.html +2 -3
- data/distro/common/html/knife_deps.html +2 -3
- data/distro/common/html/knife_diff.html +3 -4
- data/distro/common/html/knife_download.html +6 -7
- data/distro/common/html/knife_edit.html +0 -1
- data/distro/common/html/knife_environment.html +3 -4
- data/distro/common/html/knife_exec.html +0 -1
- data/distro/common/html/knife_index_rebuild.html +0 -1
- data/distro/common/html/knife_list.html +5 -6
- data/distro/common/html/knife_node.html +13 -6
- data/distro/common/html/knife_raw.html +0 -1
- data/distro/common/html/knife_recipe_list.html +0 -1
- data/distro/common/html/knife_role.html +1 -2
- data/distro/common/html/knife_search.html +2 -3
- data/distro/common/html/knife_serve.html +79 -0
- data/distro/common/html/knife_show.html +1 -2
- data/distro/common/html/knife_ssh.html +2 -3
- data/distro/common/html/knife_ssl_check.html +12 -9
- data/distro/common/html/knife_ssl_fetch.html +9 -10
- data/distro/common/html/knife_status.html +2 -3
- data/distro/common/html/knife_tag.html +0 -1
- data/distro/common/html/knife_upload.html +3 -4
- data/distro/common/html/knife_user.html +2 -3
- data/distro/common/html/knife_using.html +0 -1
- data/distro/common/html/knife_xargs.html +3 -4
- data/distro/common/html/search.html +0 -1
- data/distro/common/html/searchindex.js +1 -1
- data/lib/chef/api_client.rb +1 -1
- data/lib/chef/application.rb +24 -67
- data/lib/chef/application/client.rb +1 -1
- data/lib/chef/application/knife.rb +1 -1
- data/lib/chef/chef_fs/chef_fs_data_store.rb +2 -3
- data/lib/chef/chef_fs/command_line.rb +2 -3
- data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -5
- data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -2
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -2
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -3
- data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -5
- data/lib/chef/config.rb +26 -2
- data/lib/chef/config_fetcher.rb +1 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +4 -4
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/synchronizer.rb +50 -8
- data/lib/chef/cookbook_uploader.rb +9 -23
- data/lib/chef/cookbook_version.rb +3 -2
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/dsl/recipe.rb +1 -14
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +3 -3
- data/lib/chef/environment.rb +1 -1
- data/lib/chef/exceptions.rb +2 -24
- data/lib/chef/file_content_management/tempfile.rb +8 -1
- data/lib/chef/formatters/base.rb +0 -7
- data/lib/chef/http.rb +12 -19
- data/lib/chef/http/json_input.rb +12 -1
- data/lib/chef/json_compat.rb +45 -64
- data/lib/chef/knife.rb +2 -5
- data/lib/chef/knife/bootstrap.rb +2 -2
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +2 -2
- data/lib/chef/knife/bootstrap/centos5-gems.erb +2 -2
- data/lib/chef/knife/bootstrap/chef-aix.erb +2 -2
- data/lib/chef/knife/bootstrap/chef-full.erb +2 -2
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +2 -2
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +2 -2
- data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +2 -2
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_install.rb +10 -34
- data/lib/chef/knife/cookbook_site_list.rb +1 -1
- data/lib/chef/knife/cookbook_site_search.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +3 -3
- data/lib/chef/knife/cookbook_site_show.rb +3 -3
- data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
- data/lib/chef/knife/cookbook_upload.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +0 -24
- data/lib/chef/knife/core/ui.rb +8 -7
- data/lib/chef/knife/deps.rb +2 -3
- data/lib/chef/knife/serve.rb +2 -1
- data/lib/chef/local_mode.rb +105 -0
- data/lib/chef/mixin/file_class.rb +1 -4
- data/lib/chef/mixin/shell_out.rb +15 -0
- data/lib/chef/mixin/windows_architecture_helper.rb +0 -16
- data/lib/chef/node.rb +1 -1
- data/lib/chef/platform/query_helpers.rb +1 -5
- data/lib/chef/policy_builder/expand_node_object.rb +3 -0
- data/lib/chef/provider.rb +2 -0
- data/lib/chef/provider/cookbook_file.rb +0 -1
- data/lib/chef/provider/deploy.rb +0 -1
- data/lib/chef/provider/deploy/revision.rb +1 -1
- data/lib/chef/provider/env.rb +10 -25
- data/lib/chef/provider/env/windows.rb +23 -10
- data/lib/chef/provider/execute.rb +0 -3
- data/lib/chef/provider/file.rb +0 -3
- data/lib/chef/provider/git.rb +0 -6
- data/lib/chef/provider/group/dscl.rb +9 -27
- data/lib/chef/provider/group/gpasswd.rb +0 -3
- data/lib/chef/provider/group/groupmod.rb +0 -4
- data/lib/chef/provider/group/suse.rb +0 -3
- data/lib/chef/provider/group/usermod.rb +0 -3
- data/lib/chef/provider/link.rb +22 -5
- data/lib/chef/provider/log.rb +15 -4
- data/lib/chef/provider/mdadm.rb +0 -3
- data/lib/chef/provider/mount/mount.rb +0 -2
- data/lib/chef/provider/mount/solaris.rb +0 -2
- data/lib/chef/provider/package.rb +0 -1
- data/lib/chef/provider/package/apt.rb +0 -3
- data/lib/chef/provider/package/dpkg.rb +0 -1
- data/lib/chef/provider/package/easy_install.rb +0 -4
- data/lib/chef/provider/package/freebsd/base.rb +0 -3
- data/lib/chef/provider/package/freebsd/pkgng.rb +0 -2
- data/lib/chef/provider/package/freebsd/port.rb +0 -2
- data/lib/chef/provider/package/ips.rb +0 -3
- data/lib/chef/provider/package/paludis.rb +0 -5
- data/lib/chef/provider/package/portage.rb +0 -2
- data/lib/chef/provider/package/rpm.rb +2 -4
- data/lib/chef/provider/package/rubygems.rb +0 -4
- data/lib/chef/provider/package/smartos.rb +0 -3
- data/lib/chef/provider/package/windows/msi.rb +0 -2
- data/lib/chef/provider/package/yum.rb +0 -4
- data/lib/chef/provider/package/zypper.rb +0 -3
- data/lib/chef/provider/registry_key.rb +0 -2
- data/lib/chef/provider/remote_directory.rb +0 -1
- data/lib/chef/provider/remote_file.rb +0 -1
- data/lib/chef/provider/remote_file/cache_control_data.rb +1 -3
- data/lib/chef/provider/remote_file/content.rb +0 -1
- data/lib/chef/provider/remote_file/fetcher.rb +0 -2
- data/lib/chef/provider/remote_file/ftp.rb +0 -1
- data/lib/chef/provider/resource_update.rb +0 -3
- data/lib/chef/provider/service/freebsd.rb +0 -3
- data/lib/chef/provider/service/init.rb +0 -3
- data/lib/chef/provider/service/macosx.rb +0 -1
- data/lib/chef/provider/service/redhat.rb +0 -2
- data/lib/chef/provider/service/simple.rb +0 -3
- data/lib/chef/provider/service/solaris.rb +0 -3
- data/lib/chef/provider/service/systemd.rb +15 -14
- data/lib/chef/provider/service/windows.rb +0 -3
- data/lib/chef/provider/subversion.rb +0 -2
- data/lib/chef/provider/template.rb +0 -2
- data/lib/chef/provider/template/content.rb +0 -1
- data/lib/chef/provider/user/dscl.rb +156 -549
- data/lib/chef/provider/user/solaris.rb +0 -1
- data/lib/chef/provider/user/useradd.rb +0 -3
- data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
- data/lib/chef/providers.rb +0 -1
- data/lib/chef/resource.rb +1 -4
- data/lib/chef/resource/freebsd_package.rb +2 -10
- data/lib/chef/resource/lwrp_base.rb +1 -12
- data/lib/chef/resource/user.rb +0 -18
- data/lib/chef/resource_collection.rb +1 -1
- data/lib/chef/resource_reporter.rb +10 -10
- data/lib/chef/resources.rb +0 -1
- data/lib/chef/role.rb +3 -3
- data/lib/chef/run_list.rb +1 -1
- data/lib/chef/tasks/chef_repo.rake +131 -264
- data/lib/chef/user.rb +1 -1
- data/lib/chef/util/path_helper.rb +2 -2
- data/lib/chef/version.rb +9 -1
- data/lib/chef/win32/api/system.rb +0 -9
- data/spec/data/bootstrap/test-hints.erb +1 -1
- data/spec/data/bootstrap/test.erb +1 -1
- data/spec/functional/dsl/reboot_pending_spec.rb +53 -58
- data/spec/functional/knife/cookbook_delete_spec.rb +3 -3
- data/spec/functional/knife/exec_spec.rb +1 -1
- data/spec/functional/mixin/shell_out_spec.rb +48 -0
- data/spec/functional/resource/base.rb +0 -10
- data/spec/functional/resource/group_spec.rb +1 -5
- data/spec/functional/resource/link_spec.rb +8 -0
- data/spec/functional/resource/{user/useradd_spec.rb → user_spec.rb} +1 -1
- data/spec/integration/knife/chef_fs_data_store_spec.rb +3 -3
- data/spec/integration/knife/chef_repo_path_spec.rb +1 -6
- data/spec/integration/knife/chef_repository_file_system_spec.rb +1 -1
- data/spec/integration/knife/chefignore_spec.rb +1 -1
- data/spec/integration/knife/common_options_spec.rb +50 -3
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +1 -1
- data/spec/integration/knife/delete_spec.rb +1 -1
- data/spec/integration/knife/deps_spec.rb +1 -1
- data/spec/integration/knife/diff_spec.rb +3 -3
- data/spec/integration/knife/download_spec.rb +3 -3
- data/spec/integration/knife/list_spec.rb +1 -1
- data/spec/integration/knife/raw_spec.rb +1 -11
- data/spec/integration/knife/redirection_spec.rb +1 -1
- data/spec/integration/knife/serve_spec.rb +2 -2
- data/spec/integration/knife/show_spec.rb +1 -1
- data/spec/integration/knife/upload_spec.rb +9 -9
- data/spec/spec_helper.rb +0 -9
- data/spec/support/pedant/pedant_config.rb +2 -1
- data/spec/support/pedant/run_pedant.rb +2 -1
- data/spec/support/platform_helpers.rb +5 -24
- data/spec/support/shared/integration/integration_helper.rb +2 -1
- data/spec/support/shared/matchers.rb +17 -0
- data/spec/tiny_server.rb +1 -2
- data/spec/unit/api_client_spec.rb +3 -3
- data/spec/unit/application_spec.rb +9 -32
- data/spec/unit/config_fetcher_spec.rb +1 -1
- data/spec/unit/cookbook/metadata_spec.rb +3 -7
- data/spec/unit/cookbook/synchronizer_spec.rb +441 -226
- data/spec/unit/cookbook_loader_spec.rb +1 -1
- data/spec/unit/cookbook_uploader_spec.rb +160 -0
- data/spec/unit/cookbook_version_spec.rb +0 -4
- data/spec/unit/data_bag_item_spec.rb +1 -5
- data/spec/unit/data_bag_spec.rb +1 -5
- data/spec/unit/deprecation_spec.rb +1 -1
- data/spec/unit/dsl/recipe_spec.rb +12 -0
- data/spec/unit/encrypted_data_bag_item_spec.rb +7 -14
- data/spec/unit/environment_spec.rb +3 -7
- data/spec/unit/exceptions_spec.rb +0 -6
- data/spec/unit/http/json_input_spec.rb +128 -0
- data/spec/unit/json_compat_spec.rb +17 -58
- data/spec/unit/knife/client_create_spec.rb +3 -3
- data/spec/unit/knife/configure_client_spec.rb +6 -5
- data/spec/unit/knife/cookbook_delete_spec.rb +1 -1
- data/spec/unit/knife/cookbook_download_spec.rb +5 -5
- data/spec/unit/knife/cookbook_metadata_from_file_spec.rb +1 -0
- data/spec/unit/knife/cookbook_metadata_spec.rb +1 -1
- data/spec/unit/knife/cookbook_site_download_spec.rb +10 -11
- data/spec/unit/knife/cookbook_site_install_spec.rb +116 -161
- data/spec/unit/knife/cookbook_site_share_spec.rb +8 -8
- data/spec/unit/knife/cookbook_upload_spec.rb +3 -2
- data/spec/unit/knife/core/bootstrap_context_spec.rb +3 -3
- data/spec/unit/knife/core/subcommand_loader_spec.rb +1 -66
- data/spec/unit/knife/data_bag_from_file_spec.rb +2 -1
- data/spec/unit/knife/tag_create_spec.rb +3 -3
- data/spec/unit/knife/tag_delete_spec.rb +3 -3
- data/spec/unit/knife/user_create_spec.rb +1 -1
- data/spec/unit/knife_spec.rb +14 -14
- data/spec/unit/lwrp_spec.rb +1 -21
- data/spec/unit/mixin/shell_out_spec.rb +92 -0
- data/spec/unit/node_spec.rb +0 -4
- data/spec/unit/platform/query_helpers_spec.rb +0 -23
- data/spec/unit/provider/env/windows_spec.rb +34 -70
- data/spec/unit/provider/env_spec.rb +11 -76
- data/spec/unit/provider/group/dscl_spec.rb +1 -38
- data/spec/unit/provider/log_spec.rb +18 -0
- data/spec/unit/provider/package/rpm_spec.rb +0 -12
- data/spec/unit/provider/remote_file/cache_control_data_spec.rb +1 -1
- data/spec/unit/provider/service/systemd_service_spec.rb +44 -27
- data/spec/unit/provider/user/dscl_spec.rb +264 -660
- data/spec/unit/provider/user/useradd_spec.rb +0 -1
- data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
- data/spec/unit/provider_spec.rb +12 -0
- data/spec/unit/recipe_spec.rb +0 -41
- data/spec/unit/resource_collection_spec.rb +1 -5
- data/spec/unit/resource_reporter_spec.rb +3 -51
- data/spec/unit/resource_spec.rb +3 -14
- data/spec/unit/rest_spec.rb +1 -4
- data/spec/unit/role_spec.rb +0 -10
- data/spec/unit/run_list_spec.rb +1 -5
- data/spec/unit/user_spec.rb +1 -5
- metadata +20 -100
- data/lib/chef/mixin/windows_env_helper.rb +0 -56
- data/lib/chef/provider/dsc_script.rb +0 -175
- data/lib/chef/resource/dsc_script.rb +0 -126
- data/lib/chef/streaming_cookbook_uploader.rb +0 -205
- data/lib/chef/util/dsc/configuration_generator.rb +0 -115
- data/lib/chef/util/dsc/lcm_output_parser.rb +0 -133
- data/lib/chef/util/dsc/local_configuration_manager.rb +0 -141
- data/lib/chef/util/dsc/resource_info.rb +0 -26
- data/lib/chef/util/powershell/cmdlet.rb +0 -136
- data/lib/chef/util/powershell/cmdlet_result.rb +0 -46
- data/spec/data/mac_users/10.7-8.plist.xml +0 -559
- data/spec/data/mac_users/10.7-8.shadow.xml +0 -11
- data/spec/data/mac_users/10.7.plist.xml +0 -559
- data/spec/data/mac_users/10.7.shadow.xml +0 -11
- data/spec/data/mac_users/10.8.plist.xml +0 -559
- data/spec/data/mac_users/10.8.shadow.xml +0 -21
- data/spec/data/mac_users/10.9.plist.xml +0 -560
- data/spec/data/mac_users/10.9.shadow.xml +0 -21
- data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +0 -51
- data/spec/functional/resource/dsc_script_spec.rb +0 -382
- data/spec/functional/resource/env_spec.rb +0 -182
- data/spec/functional/resource/user/dscl_spec.rb +0 -199
- data/spec/functional/util/powershell/cmdlet_spec.rb +0 -113
- data/spec/support/lib/chef/resource/zen_follower.rb +0 -46
- data/spec/support/shared/shared_examples.rb +0 -10
- data/spec/unit/chef_fs/data_handler/group_handler_spec.rb +0 -63
- data/spec/unit/formatters/base_spec.rb +0 -48
- data/spec/unit/provider/dsc_script_spec.rb +0 -174
- data/spec/unit/resource/dsc_script_spec.rb +0 -98
- data/spec/unit/util/dsc/configuration_generator_spec.rb +0 -171
- data/spec/unit/util/dsc/lcm_output_parser_spec.rb +0 -169
- data/spec/unit/util/dsc/local_configuration_manager_spec.rb +0 -139
- data/spec/unit/util/powershell/cmdlet_spec.rb +0 -106
@@ -21,6 +21,7 @@ require 'tmpdir'
|
|
21
21
|
require 'fileutils'
|
22
22
|
require 'chef/config'
|
23
23
|
require 'chef_zero/rspec'
|
24
|
+
require 'json'
|
24
25
|
require 'support/shared/integration/knife_support'
|
25
26
|
require 'support/shared/integration/app_server_support'
|
26
27
|
require 'spec_helper'
|
@@ -68,7 +69,7 @@ module IntegrationSupport
|
|
68
69
|
File.open(filename, 'w') do |file|
|
69
70
|
raw = case contents
|
70
71
|
when Hash
|
71
|
-
|
72
|
+
JSON.pretty_generate(contents)
|
72
73
|
when Array
|
73
74
|
contents.join("\n")
|
74
75
|
else
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require 'rspec/expectations'
|
3
|
+
require 'spec/support/platform_helpers'
|
4
|
+
|
5
|
+
RSpec::Matchers.define :match_environment_variable do |varname|
|
6
|
+
match do |actual|
|
7
|
+
expected = if windows? && ENV[varname].nil?
|
8
|
+
# On Windows, if an environment variable is not set, the command
|
9
|
+
# `echo %VARNAME%` outputs %VARNAME%
|
10
|
+
"%#{varname}%"
|
11
|
+
else
|
12
|
+
ENV[varname].to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
actual == expected
|
16
|
+
end
|
17
|
+
end
|
data/spec/tiny_server.rb
CHANGED
@@ -25,7 +25,6 @@ require 'singleton'
|
|
25
25
|
require 'chef/json_compat'
|
26
26
|
require 'open-uri'
|
27
27
|
require 'chef/config'
|
28
|
-
require 'chef/json_compat'
|
29
28
|
|
30
29
|
module TinyServer
|
31
30
|
|
@@ -153,7 +152,7 @@ module TinyServer
|
|
153
152
|
:available_routes => @routes, :request => env}
|
154
153
|
# Uncomment me for glorious debugging
|
155
154
|
# pp :not_found => debug_info
|
156
|
-
[404, {'Content-Type' => 'application/json'}, [
|
155
|
+
[404, {'Content-Type' => 'application/json'}, [ debug_info.to_json ]]
|
157
156
|
end
|
158
157
|
end
|
159
158
|
|
@@ -92,7 +92,7 @@ describe Chef::ApiClient do
|
|
92
92
|
before(:each) do
|
93
93
|
@client.name("black")
|
94
94
|
@client.public_key("crowes")
|
95
|
-
@json =
|
95
|
+
@json = @client.to_json
|
96
96
|
end
|
97
97
|
|
98
98
|
it "serializes as a JSON object" do
|
@@ -117,7 +117,7 @@ describe Chef::ApiClient do
|
|
117
117
|
|
118
118
|
it "includes the private key when present" do
|
119
119
|
@client.private_key("monkeypants")
|
120
|
-
|
120
|
+
@client.to_json.should include(%q{"private_key":"monkeypants"})
|
121
121
|
end
|
122
122
|
|
123
123
|
it "does not include the private key if not present" do
|
@@ -135,7 +135,7 @@ describe Chef::ApiClient do
|
|
135
135
|
"validator" => true,
|
136
136
|
"json_class" => "Chef::ApiClient"
|
137
137
|
}
|
138
|
-
@client = Chef::JSONCompat.from_json(
|
138
|
+
@client = Chef::JSONCompat.from_json(client.to_json)
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should deserialize to a Chef::ApiClient object" do
|
@@ -255,12 +255,7 @@ describe Chef::Application do
|
|
255
255
|
|
256
256
|
it "should set ENV['http_proxy']" do
|
257
257
|
@app.configure_proxy_environment_variables
|
258
|
-
@env['http_proxy'].should == "
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should set ENV['HTTP_PROXY']" do
|
262
|
-
@app.configure_proxy_environment_variables
|
263
|
-
@env['HTTP_PROXY'].should == "#{scheme}://#{address}:#{port}"
|
258
|
+
@env['http_proxy'].should == "http://#{address}:#{port}"
|
264
259
|
end
|
265
260
|
|
266
261
|
describe "when Chef::Config[:http_proxy_user] is set" do
|
@@ -270,8 +265,7 @@ describe Chef::Application do
|
|
270
265
|
|
271
266
|
it "should set ENV['http_proxy'] with the username" do
|
272
267
|
@app.configure_proxy_environment_variables
|
273
|
-
@env['http_proxy'].should == "
|
274
|
-
@env['HTTP_PROXY'].should == "#{scheme}://username@#{address}:#{port}"
|
268
|
+
@env['http_proxy'].should == "http://username@#{address}:#{port}"
|
275
269
|
end
|
276
270
|
|
277
271
|
context "when :http_proxy_user contains '@' and/or ':'" do
|
@@ -281,8 +275,7 @@ describe Chef::Application do
|
|
281
275
|
|
282
276
|
it "should set ENV['http_proxy'] with the escaped username" do
|
283
277
|
@app.configure_proxy_environment_variables
|
284
|
-
@env['http_proxy'].should == "
|
285
|
-
@env['HTTP_PROXY'].should == "#{scheme}://my%3Ausern%40me@#{address}:#{port}"
|
278
|
+
@env['http_proxy'].should == "http://my%3Ausern%40me@#{address}:#{port}"
|
286
279
|
end
|
287
280
|
end
|
288
281
|
|
@@ -293,8 +286,7 @@ describe Chef::Application do
|
|
293
286
|
|
294
287
|
it "should set ENV['http_proxy'] with the password" do
|
295
288
|
@app.configure_proxy_environment_variables
|
296
|
-
@env['http_proxy'].should == "
|
297
|
-
@env['HTTP_PROXY'].should == "#{scheme}://username:password@#{address}:#{port}"
|
289
|
+
@env['http_proxy'].should == "http://username:password@#{address}:#{port}"
|
298
290
|
end
|
299
291
|
|
300
292
|
context "when :http_proxy_pass contains '@' and/or ':'" do
|
@@ -304,8 +296,7 @@ describe Chef::Application do
|
|
304
296
|
|
305
297
|
it "should set ENV['http_proxy'] with the escaped password" do
|
306
298
|
@app.configure_proxy_environment_variables
|
307
|
-
@env['http_proxy'].should == "
|
308
|
-
@env['HTTP_PROXY'].should == "#{scheme}://username:%3AP%40ssword101@#{address}:#{port}"
|
299
|
+
@env['http_proxy'].should == "http://username:%3AP%40ssword101@#{address}:#{port}"
|
309
300
|
end
|
310
301
|
end
|
311
302
|
end
|
@@ -319,8 +310,7 @@ describe Chef::Application do
|
|
319
310
|
|
320
311
|
it "should set ENV['http_proxy']" do
|
321
312
|
@app.configure_proxy_environment_variables
|
322
|
-
@env['http_proxy'].should == "
|
323
|
-
@env['HTTP_PROXY'].should == "#{scheme}://#{address}:#{port}"
|
313
|
+
@env['http_proxy'].should == "http://#{address}:#{port}"
|
324
314
|
end
|
325
315
|
end
|
326
316
|
end
|
@@ -348,43 +338,30 @@ describe Chef::Application do
|
|
348
338
|
|
349
339
|
describe "when Chef::Config[:http_proxy] is set" do
|
350
340
|
context "when given an FQDN" do
|
351
|
-
let(:scheme) { "http" }
|
352
|
-
let(:address) { "proxy.example.org" }
|
353
|
-
let(:port) { 8080 }
|
354
|
-
let(:http_proxy) { "#{scheme}://#{address}:#{port}" }
|
355
|
-
|
356
|
-
it_should_behave_like "setting ENV['http_proxy']"
|
357
|
-
end
|
358
|
-
|
359
|
-
context "when given an HTTPS URL" do
|
360
|
-
let(:scheme) { "https" }
|
361
341
|
let(:address) { "proxy.example.org" }
|
362
342
|
let(:port) { 8080 }
|
363
|
-
let(:http_proxy) { "
|
343
|
+
let(:http_proxy) { "http://#{address}:#{port}" }
|
364
344
|
|
365
345
|
it_should_behave_like "setting ENV['http_proxy']"
|
366
346
|
end
|
367
347
|
|
368
348
|
context "when given an IP" do
|
369
|
-
let(:scheme) { "http" }
|
370
349
|
let(:address) { "127.0.0.1" }
|
371
350
|
let(:port) { 22 }
|
372
|
-
let(:http_proxy) { "
|
351
|
+
let(:http_proxy) { "http://#{address}:#{port}" }
|
373
352
|
|
374
353
|
it_should_behave_like "setting ENV['http_proxy']"
|
375
354
|
end
|
376
355
|
|
377
356
|
context "when given an IPv6" do
|
378
|
-
let(:scheme) { "http" }
|
379
357
|
let(:address) { "[2001:db8::1]" }
|
380
358
|
let(:port) { 80 }
|
381
|
-
let(:http_proxy) { "
|
359
|
+
let(:http_proxy) { "http://#{address}:#{port}" }
|
382
360
|
|
383
361
|
it_should_behave_like "setting ENV['http_proxy']"
|
384
362
|
end
|
385
363
|
|
386
364
|
context "when given without including http://" do
|
387
|
-
let(:scheme) { "http" }
|
388
365
|
let(:address) { "proxy.example.org" }
|
389
366
|
let(:port) { 8181 }
|
390
367
|
let(:http_proxy) { "#{address}:#{port}" }
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'chef/config_fetcher'
|
3
3
|
describe Chef::ConfigFetcher do
|
4
|
-
let(:valid_json) {
|
4
|
+
let(:valid_json) { {:a=>"b"}.to_json }
|
5
5
|
let(:invalid_json) { %q[{"syntax-error": "missing quote}] }
|
6
6
|
let(:http) { double("Chef::HTTP::Simple") }
|
7
7
|
|
@@ -582,7 +582,7 @@ describe Chef::Cookbook::Metadata do
|
|
582
582
|
@meta.version "1.2.3"
|
583
583
|
end
|
584
584
|
|
585
|
-
describe "
|
585
|
+
describe "serialize" do
|
586
586
|
before(:each) do
|
587
587
|
@serial = Chef::JSONCompat.from_json(@meta.to_json)
|
588
588
|
end
|
@@ -613,15 +613,11 @@ describe Chef::Cookbook::Metadata do
|
|
613
613
|
@serial[t].should == @meta.send(t.to_sym)
|
614
614
|
end
|
615
615
|
end
|
616
|
-
|
617
|
-
it "should produce the same output from to_json and Chef::JSONCompat" do
|
618
|
-
expect(@meta.to_json).to eq(Chef::JSONCompat.to_json(@meta))
|
619
|
-
end
|
620
616
|
end
|
621
617
|
|
622
|
-
describe "
|
618
|
+
describe "deserialize" do
|
623
619
|
before(:each) do
|
624
|
-
@deserial = Chef::Cookbook::Metadata.from_json(
|
620
|
+
@deserial = Chef::Cookbook::Metadata.from_json(@meta.to_json)
|
625
621
|
end
|
626
622
|
|
627
623
|
it "should deserialize to a Chef::Cookbook::Metadata object" do
|
@@ -5,302 +5,517 @@ require 'chef/cookbook_version'
|
|
5
5
|
describe Chef::CookbookCacheCleaner do
|
6
6
|
describe "when cleaning up unused cookbook components" do
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
let(:cleaner) do
|
9
|
+
cleaner = Chef::CookbookCacheCleaner.instance
|
10
|
+
cleaner.reset!
|
11
|
+
cleaner
|
11
12
|
end
|
12
13
|
|
13
|
-
|
14
|
-
end
|
14
|
+
let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@cleaner.mark_file_as_valid('cookbooks/valid2/recipes/default.rb')
|
22
|
-
file_cache.should_receive(:find).with(File.join(%w{cookbooks ** *})).and_return(valid_cached_cb_files + unused_template_files)
|
23
|
-
file_cache.should_receive(:delete).with('cookbooks/unused/templates/default/foo.conf.erb')
|
24
|
-
file_cache.should_receive(:delete).with('cookbooks/unused/tempaltes/default/bar.conf.erb')
|
25
|
-
cookbook_hash = {"valid1"=> {}, "valid2" => {}}
|
26
|
-
@cleaner.stub(:cache).and_return(file_cache)
|
27
|
-
@cleaner.cleanup_file_cache
|
16
|
+
let(:unused_template_files) do
|
17
|
+
%w{
|
18
|
+
cookbooks/unused/templates/default/foo.conf.erb
|
19
|
+
cookbooks/unused/tempaltes/default/bar.conf.erb
|
20
|
+
}
|
28
21
|
end
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
let(:valid_cached_cb_files) do
|
24
|
+
%w{
|
25
|
+
cookbooks/valid1/recipes/default.rb
|
26
|
+
cookbooks/valid2/recipes/default.rb
|
27
|
+
}
|
28
|
+
end
|
34
29
|
|
35
|
-
|
36
|
-
|
30
|
+
before do
|
31
|
+
valid_cached_cb_files.each do |cbf|
|
32
|
+
cleaner.mark_file_as_valid(cbf)
|
37
33
|
end
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
it "removes all files not validated during the chef run" do
|
37
|
+
expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(valid_cached_cb_files + unused_template_files)
|
38
|
+
unused_template_files.each do |cbf|
|
39
|
+
expect(file_cache).to receive(:delete).with(cbf)
|
43
40
|
end
|
41
|
+
cookbook_hash = {"valid1"=> {}, "valid2" => {}}
|
42
|
+
allow(cleaner).to receive(:cache).and_return(file_cache)
|
43
|
+
cleaner.cleanup_file_cache
|
44
|
+
end
|
44
45
|
|
46
|
+
it "does not remove anything when skip_removal is true" do
|
47
|
+
cleaner.skip_removal = true
|
48
|
+
allow(cleaner.cache).to receive(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
|
49
|
+
expect(cleaner.cache).not_to receive(:delete)
|
50
|
+
cleaner.cleanup_file_cache
|
45
51
|
end
|
46
52
|
|
53
|
+
it "does not remove anything on chef-solo" do
|
54
|
+
Chef::Config[:solo] = true
|
55
|
+
allow(cleaner.cache).to receive(:find).and_return(%w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb})
|
56
|
+
expect(cleaner.cache).not_to receive(:delete)
|
57
|
+
cleaner.cleanup_file_cache
|
58
|
+
end
|
47
59
|
end
|
48
60
|
end
|
49
61
|
|
50
62
|
describe Chef::CookbookSynchronizer do
|
51
|
-
|
63
|
+
let(:cookbook_a_default_recipe) do
|
64
|
+
{
|
65
|
+
"path" => "recipes/default.rb",
|
66
|
+
"url" => "http://chef.example.com/abc123",
|
67
|
+
"checksum" => "abc123",
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
let(:cookbook_a_default_attrs) do
|
72
|
+
{
|
73
|
+
"path" => "attributes/default.rb",
|
74
|
+
"url" => "http://chef.example.com/abc456",
|
75
|
+
"checksum" => "abc456",
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:cookbook_a_template) do
|
80
|
+
{
|
81
|
+
"path" => "templates/default/apache2.conf.erb",
|
82
|
+
"url" => "http://chef.example.com/ffffff",
|
83
|
+
"checksum" => "abc125",
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:cookbook_a_file) do
|
88
|
+
{
|
89
|
+
"path" => "files/default/megaman.conf",
|
90
|
+
"url" => "http://chef.example.com/megaman.conf",
|
91
|
+
"checksum" => "abc124",
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
let(:cookbook_a_manifest) do
|
52
96
|
segments = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
97
|
+
cookbook_a_manifest = segments.inject({}) {|h, segment| h[segment.to_s] = []; h}
|
98
|
+
cookbook_a_manifest["recipes"] = [ cookbook_a_default_recipe ]
|
99
|
+
cookbook_a_manifest["attributes"] = [ cookbook_a_default_attrs ]
|
100
|
+
cookbook_a_manifest["templates"] = [ cookbook_a_template ]
|
101
|
+
cookbook_a_manifest["files"] = [ cookbook_a_file ]
|
102
|
+
cookbook_a_manifest
|
103
|
+
end
|
104
|
+
|
105
|
+
let(:cookbook_a) do
|
106
|
+
cookbook_a = Chef::CookbookVersion.new("cookbook_a")
|
107
|
+
cookbook_a.manifest = cookbook_a_manifest
|
108
|
+
cookbook_a
|
109
|
+
end
|
110
|
+
|
111
|
+
let(:cookbook_manifest) do
|
112
|
+
{
|
113
|
+
"cookbook_a" => cookbook_a
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
118
|
+
|
119
|
+
let(:no_lazy_load) { true }
|
120
|
+
|
121
|
+
let(:synchronizer) do
|
122
|
+
Chef::Config[:no_lazy_load] = no_lazy_load
|
123
|
+
Chef::CookbookSynchronizer.new(cookbook_manifest, events)
|
72
124
|
end
|
73
125
|
|
74
126
|
it "lists the cookbook names" do
|
75
|
-
|
127
|
+
expect(synchronizer.cookbook_names).to eq(%w[cookbook_a])
|
76
128
|
end
|
77
129
|
|
78
130
|
it "lists the cookbook manifests" do
|
79
|
-
|
131
|
+
expect(synchronizer.cookbooks).to eq([cookbook_a])
|
80
132
|
end
|
81
133
|
|
82
|
-
context "
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
134
|
+
context "#clear_obsoleted_cookbooks" do
|
135
|
+
after do
|
136
|
+
# Singletons == Global State == Bad
|
137
|
+
Chef::CookbookCacheCleaner.instance.skip_removal = nil
|
138
|
+
end
|
87
139
|
|
88
|
-
|
140
|
+
it "behaves correctly when remove_obsoleted_files is false" do
|
141
|
+
synchronizer.remove_obsoleted_files = false
|
142
|
+
expect(synchronizer).not_to receive(:remove_old_cookbooks)
|
143
|
+
expect(synchronizer).to receive(:remove_deleted_files)
|
144
|
+
synchronizer.clear_obsoleted_cookbooks
|
145
|
+
expect(Chef::CookbookCacheCleaner.instance.skip_removal).to be true
|
146
|
+
end
|
147
|
+
|
148
|
+
it "behaves correctly when remove_obsoleted_files is true" do
|
149
|
+
synchronizer.remove_obsoleted_files = true
|
150
|
+
expect(synchronizer).to receive(:remove_old_cookbooks)
|
151
|
+
expect(synchronizer).to receive(:remove_deleted_files)
|
152
|
+
synchronizer.clear_obsoleted_cookbooks
|
153
|
+
expect(Chef::CookbookCacheCleaner.instance.skip_removal).to be nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "#remove_old_cookbooks" do
|
158
|
+
let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
|
89
159
|
|
90
|
-
|
160
|
+
let(:cookbook_manifest) do
|
161
|
+
{"valid1"=> {}, "valid2" => {}}
|
91
162
|
end
|
92
163
|
|
93
164
|
it "removes unneeded cookbooks" do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
165
|
+
valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
|
166
|
+
obsolete_cb_files = %w{cookbooks/old1/recipes/default.rb cookbooks/old2/recipes/default.rb}
|
167
|
+
expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(valid_cached_cb_files + obsolete_cb_files)
|
168
|
+
expect(file_cache).to receive(:delete).with('cookbooks/old1/recipes/default.rb')
|
169
|
+
expect(file_cache).to receive(:delete).with('cookbooks/old2/recipes/default.rb')
|
170
|
+
allow(synchronizer).to receive(:cache).and_return(file_cache)
|
171
|
+
synchronizer.remove_old_cookbooks
|
99
172
|
end
|
100
173
|
end
|
101
174
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
175
|
+
context "#remove_deleted_files" do
|
176
|
+
let(:file_cache) { double("Chef::FileCache with files from unused cookbooks") }
|
177
|
+
|
178
|
+
let(:cookbook_manifest) do
|
179
|
+
{"valid1"=> {}, "valid2" => {}}
|
180
|
+
end
|
181
|
+
|
182
|
+
it "removes only deleted files" do
|
183
|
+
valid_cached_cb_files = %w{cookbooks/valid1/recipes/default.rb cookbooks/valid2/recipes/default.rb}
|
184
|
+
obsolete_cb_files = %w{cookbooks/valid1/recipes/deleted.rb cookbooks/valid2/recipes/deleted.rb}
|
185
|
+
expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(valid_cached_cb_files + obsolete_cb_files)
|
186
|
+
# valid1 is a cookbook in our run_list
|
187
|
+
expect(synchronizer).to receive(:have_cookbook?).with("valid1").at_least(:once).and_return(true)
|
188
|
+
# valid2 is a cookbook not in our run_list (we're simulating an override run_list where valid2 needs to be preserved)
|
189
|
+
expect(synchronizer).to receive(:have_cookbook?).with("valid2").at_least(:once).and_return(false)
|
190
|
+
expect(file_cache).to receive(:delete).with('cookbooks/valid1/recipes/deleted.rb')
|
191
|
+
expect(synchronizer).to receive(:cookbook_segment).with("valid1", "recipes").at_least(:once).and_return([ { "path" => "recipes/default.rb" }])
|
192
|
+
allow(synchronizer).to receive(:cache).and_return(file_cache)
|
193
|
+
synchronizer.remove_deleted_files
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
let(:cookbook_a_default_recipe_tempfile) do
|
198
|
+
double("Tempfile for cookbook_a default.rb recipe",
|
199
|
+
:path => "/tmp/cookbook_a_recipes_default_rb")
|
200
|
+
end
|
107
201
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
202
|
+
let(:cookbook_a_default_attribute_tempfile) do
|
203
|
+
double("Tempfile for cookbook_a default.rb attr file",
|
204
|
+
:path => "/tmp/cookbook_a_attributes_default_rb")
|
205
|
+
end
|
112
206
|
|
207
|
+
let(:cookbook_a_file_default_tempfile) do
|
208
|
+
double("Tempfile for cookbook_a megaman.conf file",
|
209
|
+
:path => "/tmp/cookbook_a_file_default_tempfile")
|
210
|
+
end
|
113
211
|
|
114
|
-
|
115
|
-
|
212
|
+
let(:cookbook_a_template_default_tempfile) do
|
213
|
+
double("Tempfile for cookbook_a apache.conf.erb template",
|
214
|
+
:path => "/tmp/cookbook_a_template_default_tempfile")
|
215
|
+
end
|
116
216
|
|
117
|
-
|
118
|
-
|
217
|
+
def setup_common_files_missing_expectations
|
218
|
+
# Files are not in the cache:
|
219
|
+
expect(file_cache).to receive(:has_key?).
|
220
|
+
with("cookbooks/cookbook_a/recipes/default.rb").
|
221
|
+
and_return(false)
|
222
|
+
expect(file_cache).to receive(:has_key?).
|
223
|
+
with("cookbooks/cookbook_a/attributes/default.rb").
|
224
|
+
and_return(false)
|
225
|
+
|
226
|
+
# Fetch and copy default.rb recipe
|
227
|
+
expect(server_api).to receive(:get_rest).
|
228
|
+
with('http://chef.example.com/abc123', true).
|
229
|
+
and_return(cookbook_a_default_recipe_tempfile)
|
230
|
+
expect(file_cache).to receive(:move_to).
|
231
|
+
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
|
232
|
+
expect(file_cache).to receive(:load).
|
233
|
+
with("cookbooks/cookbook_a/recipes/default.rb", false).
|
234
|
+
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
|
235
|
+
|
236
|
+
# Fetch and copy default.rb attribute file
|
237
|
+
expect(server_api).to receive(:get_rest).
|
238
|
+
with('http://chef.example.com/abc456', true).
|
239
|
+
and_return(cookbook_a_default_attribute_tempfile)
|
240
|
+
expect(file_cache).to receive(:move_to).
|
241
|
+
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
|
242
|
+
expect(file_cache).to receive(:load).
|
243
|
+
with("cookbooks/cookbook_a/attributes/default.rb", false).
|
244
|
+
and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
|
245
|
+
end
|
119
246
|
|
247
|
+
def setup_no_lazy_files_and_templates_missing_expectations
|
248
|
+
expect(file_cache).to receive(:has_key?).
|
249
|
+
with("cookbooks/cookbook_a/files/default/megaman.conf").
|
250
|
+
and_return(false)
|
251
|
+
expect(file_cache).to receive(:has_key?).
|
252
|
+
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
|
253
|
+
and_return(false)
|
254
|
+
|
255
|
+
expect(server_api).to receive(:get_rest).
|
256
|
+
with('http://chef.example.com/megaman.conf', true).
|
257
|
+
and_return(cookbook_a_file_default_tempfile)
|
258
|
+
expect(file_cache).to receive(:move_to).
|
259
|
+
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
|
260
|
+
expect(file_cache).to receive(:load).
|
261
|
+
with("cookbooks/cookbook_a/files/default/megaman.conf", false).
|
262
|
+
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
|
263
|
+
|
264
|
+
expect(server_api).to receive(:get_rest).
|
265
|
+
with('http://chef.example.com/ffffff', true).
|
266
|
+
and_return(cookbook_a_template_default_tempfile)
|
267
|
+
expect(file_cache).to receive(:move_to).
|
268
|
+
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
269
|
+
expect(file_cache).to receive(:load).
|
270
|
+
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
|
271
|
+
and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
272
|
+
end
|
273
|
+
|
274
|
+
def setup_common_files_chksum_mismatch_expectations
|
275
|
+
# Files are in the cache:
|
276
|
+
expect(file_cache).to receive(:has_key?).
|
277
|
+
with("cookbooks/cookbook_a/recipes/default.rb").
|
278
|
+
and_return(true)
|
279
|
+
expect(file_cache).to receive(:has_key?).
|
280
|
+
with("cookbooks/cookbook_a/attributes/default.rb").
|
281
|
+
and_return(true)
|
282
|
+
|
283
|
+
# Fetch and copy default.rb recipe
|
284
|
+
expect(server_api).to receive(:get_rest).
|
285
|
+
with('http://chef.example.com/abc123', true).
|
286
|
+
and_return(cookbook_a_default_recipe_tempfile)
|
287
|
+
expect(file_cache).to receive(:move_to).
|
288
|
+
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
|
289
|
+
expect(file_cache).to receive(:load).
|
290
|
+
with("cookbooks/cookbook_a/recipes/default.rb", false).
|
291
|
+
twice.
|
292
|
+
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
|
293
|
+
|
294
|
+
# Current file has fff000, want abc123
|
295
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
296
|
+
with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
|
297
|
+
and_return("fff000")
|
298
|
+
|
299
|
+
# Fetch and copy default.rb attribute file
|
300
|
+
expect(server_api).to receive(:get_rest).
|
301
|
+
with('http://chef.example.com/abc456', true).
|
302
|
+
and_return(cookbook_a_default_attribute_tempfile)
|
303
|
+
expect(file_cache).to receive(:move_to).
|
304
|
+
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
|
305
|
+
expect(file_cache).to receive(:load).
|
306
|
+
with("cookbooks/cookbook_a/attributes/default.rb", false).
|
307
|
+
twice.
|
308
|
+
and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
|
309
|
+
|
310
|
+
# Current file has fff000, want abc456
|
311
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
312
|
+
with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
|
313
|
+
and_return("fff000")
|
314
|
+
end
|
315
|
+
|
316
|
+
def setup_no_lazy_files_and_templates_chksum_mismatch_expectations
|
317
|
+
# Files are in the cache:
|
318
|
+
expect(file_cache).to receive(:has_key?).
|
319
|
+
with("cookbooks/cookbook_a/files/default/megaman.conf").
|
320
|
+
and_return(true)
|
321
|
+
expect(file_cache).to receive(:has_key?).
|
322
|
+
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
|
323
|
+
and_return(true)
|
324
|
+
|
325
|
+
# Fetch and copy megaman.conf
|
326
|
+
expect(server_api).to receive(:get_rest).
|
327
|
+
with('http://chef.example.com/megaman.conf', true).
|
328
|
+
and_return(cookbook_a_file_default_tempfile)
|
329
|
+
expect(file_cache).to receive(:move_to).
|
330
|
+
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
|
331
|
+
expect(file_cache).to receive(:load).
|
332
|
+
with("cookbooks/cookbook_a/files/default/megaman.conf", false).
|
333
|
+
twice.
|
334
|
+
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
|
335
|
+
|
336
|
+
# Fetch and copy apache2.conf template
|
337
|
+
expect(server_api).to receive(:get_rest).
|
338
|
+
with('http://chef.example.com/ffffff', true).
|
339
|
+
and_return(cookbook_a_template_default_tempfile)
|
340
|
+
expect(file_cache).to receive(:move_to).
|
341
|
+
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
342
|
+
expect(file_cache).to receive(:load).
|
343
|
+
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
|
344
|
+
twice.
|
345
|
+
and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
346
|
+
|
347
|
+
# Current file has fff000
|
348
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
349
|
+
with("/file-cache/cookbooks/cookbook_a/default/megaman.conf").
|
350
|
+
and_return("fff000")
|
351
|
+
|
352
|
+
# Current file has fff000
|
353
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
354
|
+
with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb").
|
355
|
+
and_return("fff000")
|
356
|
+
end
|
357
|
+
|
358
|
+
def setup_common_files_present_expectations
|
359
|
+
# Files are in the cache:
|
360
|
+
expect(file_cache).to receive(:has_key?).
|
361
|
+
with("cookbooks/cookbook_a/recipes/default.rb").
|
362
|
+
and_return(true)
|
363
|
+
expect(file_cache).to receive(:has_key?).
|
364
|
+
with("cookbooks/cookbook_a/attributes/default.rb").
|
365
|
+
and_return(true)
|
366
|
+
|
367
|
+
# Current file has abc123, want abc123
|
368
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
369
|
+
with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
|
370
|
+
and_return("abc123")
|
371
|
+
|
372
|
+
# Current file has abc456, want abc456
|
373
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
374
|
+
with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
|
375
|
+
and_return("abc456")
|
376
|
+
|
377
|
+
# :load called twice
|
378
|
+
expect(file_cache).to receive(:load).
|
379
|
+
with("cookbooks/cookbook_a/recipes/default.rb", false).
|
380
|
+
twice.
|
381
|
+
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
|
382
|
+
expect(file_cache).to receive(:load).
|
383
|
+
with("cookbooks/cookbook_a/attributes/default.rb", false).
|
384
|
+
twice.
|
385
|
+
and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
|
386
|
+
end
|
387
|
+
|
388
|
+
def setup_no_lazy_files_and_templates_present_expectations
|
389
|
+
# Files are in the cache:
|
390
|
+
expect(file_cache).to receive(:has_key?).
|
391
|
+
with("cookbooks/cookbook_a/files/default/megaman.conf").
|
392
|
+
and_return(true)
|
393
|
+
expect(file_cache).to receive(:has_key?).
|
394
|
+
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
|
395
|
+
and_return(true)
|
396
|
+
|
397
|
+
# Current file has abc124, want abc124
|
398
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
399
|
+
with("/file-cache/cookbooks/cookbook_a/default/megaman.conf").
|
400
|
+
and_return("abc124")
|
401
|
+
|
402
|
+
# Current file has abc125, want abc125
|
403
|
+
expect(Chef::CookbookVersion).to receive(:checksum_cookbook_file).
|
404
|
+
with("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb").
|
405
|
+
and_return("abc125")
|
406
|
+
|
407
|
+
# :load called twice
|
408
|
+
expect(file_cache).to receive(:load).
|
409
|
+
with("cookbooks/cookbook_a/files/default/megaman.conf", false).
|
410
|
+
twice.
|
411
|
+
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
|
412
|
+
expect(file_cache).to receive(:load).
|
413
|
+
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
|
414
|
+
twice.
|
415
|
+
and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
416
|
+
end
|
417
|
+
|
418
|
+
describe "when syncing cookbooks with the server" do
|
419
|
+
let(:server_api) { double("Chef::REST (mock)") }
|
420
|
+
|
421
|
+
let(:file_cache) { double("Chef::FileCache (mock)") }
|
422
|
+
|
423
|
+
before do
|
424
|
+
# Would rather not stub out methods on the test subject, but setting up
|
425
|
+
# the state is a PITA and tests for this behavior are above.
|
426
|
+
allow(synchronizer).to receive(:clear_obsoleted_cookbooks)
|
427
|
+
allow(synchronizer).to receive(:server_api).and_return(server_api)
|
428
|
+
allow(synchronizer).to receive(:cache).and_return(file_cache)
|
120
429
|
end
|
121
430
|
|
122
431
|
context "when the cache does not contain the desired files" do
|
123
432
|
before do
|
124
|
-
|
125
|
-
# Files are not in the cache:
|
126
|
-
@file_cache.should_receive(:has_key?).
|
127
|
-
with("cookbooks/cookbook_a/recipes/default.rb").
|
128
|
-
and_return(false)
|
129
|
-
@file_cache.should_receive(:has_key?).
|
130
|
-
with("cookbooks/cookbook_a/attributes/default.rb").
|
131
|
-
and_return(false)
|
132
|
-
|
133
|
-
# Fetch and copy default.rb recipe
|
134
|
-
@server_api.should_receive(:get_rest).
|
135
|
-
with('http://chef.example.com/abc123', true).
|
136
|
-
and_return(@cookbook_a_default_recipe_tempfile)
|
137
|
-
@file_cache.should_receive(:move_to).
|
138
|
-
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
|
139
|
-
@file_cache.should_receive(:load).
|
140
|
-
with("cookbooks/cookbook_a/recipes/default.rb", false).
|
141
|
-
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
|
142
|
-
|
143
|
-
# Fetch and copy default.rb attribute file
|
144
|
-
@server_api.should_receive(:get_rest).
|
145
|
-
with('http://chef.example.com/abc456', true).
|
146
|
-
and_return(@cookbook_a_default_attribute_tempfile)
|
147
|
-
@file_cache.should_receive(:move_to).
|
148
|
-
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
|
149
|
-
@file_cache.should_receive(:load).
|
150
|
-
with("cookbooks/cookbook_a/attributes/default.rb", false).
|
151
|
-
and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
|
433
|
+
setup_common_files_missing_expectations
|
152
434
|
end
|
153
435
|
|
154
|
-
|
155
|
-
|
156
|
-
end
|
436
|
+
context "Chef::Config[:no_lazy_load] is false" do
|
437
|
+
let(:no_lazy_load) { false }
|
157
438
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
439
|
+
it "fetches eagerly loaded files" do
|
440
|
+
synchronizer.sync_cookbooks
|
441
|
+
end
|
442
|
+
|
443
|
+
it "does not fetch templates or cookbook files" do
|
444
|
+
# Implicitly tested in previous test; this test is just for behavior specification.
|
445
|
+
expect(server_api).not_to receive(:get_rest).
|
446
|
+
with('http://chef.example.com/ffffff', true)
|
162
447
|
|
163
|
-
|
448
|
+
synchronizer.sync_cookbooks
|
449
|
+
end
|
164
450
|
end
|
165
451
|
|
166
452
|
context "Chef::Config[:no_lazy_load] is true" do
|
167
|
-
|
168
|
-
Chef::Config[:no_lazy_load] = true
|
169
|
-
@synchronizer = Chef::CookbookSynchronizer.new(@cookbook_manifest, @events)
|
170
|
-
@synchronizer.stub(:server_api).and_return(@server_api)
|
171
|
-
@synchronizer.stub(:cache).and_return(@file_cache)
|
172
|
-
@synchronizer.stub(:clear_obsoleted_cookbooks)
|
173
|
-
|
174
|
-
@cookbook_a_file_default_tempfile = double("Tempfile for cookbook_a megaman.conf file",
|
175
|
-
:path => "/tmp/cookbook_a_file_default_tempfile")
|
176
|
-
@cookbook_a_template_default_tempfile = double("Tempfile for cookbook_a apache.conf.erb template",
|
177
|
-
:path => "/tmp/cookbook_a_template_default_tempfile")
|
178
|
-
end
|
453
|
+
let(:no_lazy_load) { true }
|
179
454
|
|
180
|
-
|
181
|
-
|
455
|
+
before do
|
456
|
+
setup_no_lazy_files_and_templates_missing_expectations
|
182
457
|
end
|
183
458
|
|
184
459
|
it "fetches templates and cookbook files" do
|
185
|
-
|
186
|
-
with("cookbooks/cookbook_a/files/default/megaman.conf").
|
187
|
-
and_return(false)
|
188
|
-
@file_cache.should_receive(:has_key?).
|
189
|
-
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb").
|
190
|
-
and_return(false)
|
191
|
-
|
192
|
-
@server_api.should_receive(:get_rest).
|
193
|
-
with('http://chef.example.com/megaman.conf', true).
|
194
|
-
and_return(@cookbook_a_file_default_tempfile)
|
195
|
-
@file_cache.should_receive(:move_to).
|
196
|
-
with("/tmp/cookbook_a_file_default_tempfile", "cookbooks/cookbook_a/files/default/megaman.conf")
|
197
|
-
@file_cache.should_receive(:load).
|
198
|
-
with("cookbooks/cookbook_a/files/default/megaman.conf", false).
|
199
|
-
and_return("/file-cache/cookbooks/cookbook_a/default/megaman.conf")
|
200
|
-
|
201
|
-
@server_api.should_receive(:get_rest).
|
202
|
-
with('http://chef.example.com/ffffff', true).
|
203
|
-
and_return(@cookbook_a_template_default_tempfile)
|
204
|
-
@file_cache.should_receive(:move_to).
|
205
|
-
with("/tmp/cookbook_a_template_default_tempfile", "cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
206
|
-
@file_cache.should_receive(:load).
|
207
|
-
with("cookbooks/cookbook_a/templates/default/apache2.conf.erb", false).
|
208
|
-
and_return("/file-cache/cookbooks/cookbook_a/templates/default/apache2.conf.erb")
|
209
|
-
|
210
|
-
@synchronizer.sync_cookbooks
|
460
|
+
synchronizer.sync_cookbooks
|
211
461
|
end
|
212
462
|
end
|
213
463
|
end
|
214
464
|
|
215
465
|
context "when the cache contains outdated files" do
|
216
466
|
before do
|
217
|
-
|
218
|
-
@file_cache.should_receive(:has_key?).
|
219
|
-
with("cookbooks/cookbook_a/recipes/default.rb").
|
220
|
-
and_return(true)
|
221
|
-
@file_cache.should_receive(:has_key?).
|
222
|
-
with("cookbooks/cookbook_a/attributes/default.rb").
|
223
|
-
and_return(true)
|
224
|
-
|
225
|
-
|
226
|
-
# Fetch and copy default.rb recipe
|
227
|
-
@server_api.should_receive(:get_rest).
|
228
|
-
with('http://chef.example.com/abc123', true).
|
229
|
-
and_return(@cookbook_a_default_recipe_tempfile)
|
230
|
-
@file_cache.should_receive(:move_to).
|
231
|
-
with("/tmp/cookbook_a_recipes_default_rb", "cookbooks/cookbook_a/recipes/default.rb")
|
232
|
-
@file_cache.should_receive(:load).
|
233
|
-
with("cookbooks/cookbook_a/recipes/default.rb", false).
|
234
|
-
twice.
|
235
|
-
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
|
236
|
-
|
237
|
-
# Current file has fff000, want abc123
|
238
|
-
Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
|
239
|
-
with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
|
240
|
-
and_return("fff000")
|
241
|
-
|
242
|
-
# Fetch and copy default.rb attribute file
|
243
|
-
@server_api.should_receive(:get_rest).
|
244
|
-
with('http://chef.example.com/abc456', true).
|
245
|
-
and_return(@cookbook_a_default_attribute_tempfile)
|
246
|
-
@file_cache.should_receive(:move_to).
|
247
|
-
with("/tmp/cookbook_a_attributes_default_rb", "cookbooks/cookbook_a/attributes/default.rb")
|
248
|
-
@file_cache.should_receive(:load).
|
249
|
-
with("cookbooks/cookbook_a/attributes/default.rb", false).
|
250
|
-
twice.
|
251
|
-
and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
|
252
|
-
|
253
|
-
# Current file has fff000, want abc456
|
254
|
-
Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
|
255
|
-
with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
|
256
|
-
and_return("fff000")
|
467
|
+
setup_common_files_chksum_mismatch_expectations
|
257
468
|
end
|
258
469
|
|
259
|
-
|
260
|
-
|
470
|
+
context "Chef::Config[:no_lazy_load] is true" do
|
471
|
+
let(:no_lazy_load) { true }
|
472
|
+
|
473
|
+
before do
|
474
|
+
setup_no_lazy_files_and_templates_chksum_mismatch_expectations
|
475
|
+
end
|
476
|
+
|
477
|
+
it "updates the outdated files" do
|
478
|
+
synchronizer.sync_cookbooks
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
context "Chef::Config[:no_lazy_load] is false" do
|
483
|
+
let(:no_lazy_load) { false }
|
484
|
+
|
485
|
+
it "updates the outdated files" do
|
486
|
+
synchronizer.sync_cookbooks
|
487
|
+
end
|
261
488
|
end
|
262
489
|
end
|
263
490
|
|
264
491
|
context "when the cache is up to date" do
|
265
492
|
before do
|
266
|
-
|
267
|
-
@file_cache.should_receive(:has_key?).
|
268
|
-
with("cookbooks/cookbook_a/recipes/default.rb").
|
269
|
-
and_return(true)
|
270
|
-
@file_cache.should_receive(:has_key?).
|
271
|
-
with("cookbooks/cookbook_a/attributes/default.rb").
|
272
|
-
and_return(true)
|
273
|
-
|
274
|
-
# Current file has abc123, want abc123
|
275
|
-
Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
|
276
|
-
with("/file-cache/cookbooks/cookbook_a/recipes/default.rb").
|
277
|
-
and_return("abc123")
|
278
|
-
|
279
|
-
# Current file has abc456, want abc456
|
280
|
-
Chef::CookbookVersion.should_receive(:checksum_cookbook_file).
|
281
|
-
with("/file-cache/cookbooks/cookbook_a/attributes/default.rb").
|
282
|
-
and_return("abc456")
|
283
|
-
|
284
|
-
@file_cache.should_receive(:load).
|
285
|
-
with("cookbooks/cookbook_a/recipes/default.rb", false).
|
286
|
-
twice.
|
287
|
-
and_return("/file-cache/cookbooks/cookbook_a/recipes/default.rb")
|
288
|
-
|
289
|
-
@file_cache.should_receive(:load).
|
290
|
-
with("cookbooks/cookbook_a/attributes/default.rb", false).
|
291
|
-
twice.
|
292
|
-
and_return("/file-cache/cookbooks/cookbook_a/attributes/default.rb")
|
493
|
+
setup_common_files_present_expectations
|
293
494
|
end
|
294
495
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
496
|
+
context "Chef::Config[:no_lazy_load] is true" do
|
497
|
+
let(:no_lazy_load) { true }
|
498
|
+
|
499
|
+
before do
|
500
|
+
setup_no_lazy_files_and_templates_present_expectations
|
501
|
+
end
|
502
|
+
|
503
|
+
it "does not update files" do
|
504
|
+
expect(file_cache).not_to receive(:move_to)
|
505
|
+
expect(server_api).not_to receive(:get_rest)
|
506
|
+
synchronizer.sync_cookbooks
|
507
|
+
end
|
299
508
|
end
|
300
509
|
|
301
|
-
|
510
|
+
context "Chef::Config[:no_lazy_load] is false" do
|
511
|
+
let(:no_lazy_load) { false }
|
302
512
|
|
513
|
+
it "does not update files" do
|
514
|
+
expect(file_cache).not_to receive(:move_to)
|
515
|
+
expect(server_api).not_to receive(:get_rest)
|
516
|
+
synchronizer.sync_cookbooks
|
517
|
+
end
|
518
|
+
end
|
519
|
+
end
|
303
520
|
end
|
304
|
-
|
305
521
|
end
|
306
|
-
|