diff options
author | Thom May <thom@may.lt> | 2016-02-09 16:27:30 -0800 |
---|---|---|
committer | Thom May <thom@may.lt> | 2016-02-09 16:27:30 -0800 |
commit | cec2303fdd6e24a76ee83abb2dc4044fd8e5e8b4 (patch) | |
tree | dfcda354e2248d5d544b32b53b3b8debc97db592 | |
parent | 7755b93c72ef33d5041b6a9c4b53bcf29814579d (diff) | |
parent | d17661e30c1e08a14d17dcfa6ce46f81086fc1ec (diff) | |
download | chef-cec2303fdd6e24a76ee83abb2dc4044fd8e5e8b4.tar.gz |
Merge pull request #4550 from chef/tm/site_download_regression
Use a streaming request to download cookbook
-rw-r--r-- | lib/chef/cookbook/remote_file_vendor.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_show.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_download.rb | 3 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_show_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_site_download_spec.rb | 10 |
5 files changed, 12 insertions, 15 deletions
diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb index 9155162c4c..e63d094dc4 100644 --- a/lib/chef/cookbook/remote_file_vendor.rb +++ b/lib/chef/cookbook/remote_file_vendor.rb @@ -63,7 +63,7 @@ class Chef # (remote, per manifest), do the update. This will also execute if there # is no current checksum. if current_checksum != found_manifest_record["checksum"] - raw_file = @rest.get(found_manifest_record[:url], true) + raw_file = @rest.streaming_request(found_manifest_record[:url]) Chef::Log.debug("Storing updated #{cache_filename} in the cache.") Chef::FileCache.move_to(raw_file.path, cache_filename) diff --git a/lib/chef/knife/cookbook_show.rb b/lib/chef/knife/cookbook_show.rb index 20013cea4b..5fab7c303f 100644 --- a/lib/chef/knife/cookbook_show.rb +++ b/lib/chef/knife/cookbook_show.rb @@ -69,7 +69,7 @@ class Chef cookbook = rest.get("cookbooks/#{cookbook_name}/#{cookbook_version}") manifest_entry = cookbook.preferred_manifest_record(node, segment, filename) - temp_file = rest.get(manifest_entry[:url], true) + temp_file = rest.streaming_request(manifest_entry[:url]) # the temp file is cleaned up elsewhere temp_file.open if temp_file.closed? diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index 7e4eda015f..2bdeea9781 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -86,8 +86,7 @@ class Chef def download_cookbook ui.info "Downloading #{@name_args[0]} from Supermarket at version #{version} to #{download_location}" - noauth_rest.sign_on_redirect = false - tf = noauth_rest.get desired_cookbook_data["file"], true + tf = noauth_rest.streaming_request(desired_cookbook_data["file"]) ::FileUtils.cp tf.path, download_location ui.info "Cookbook saved: #{download_location}" diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb index de6d569e1d..0183577ec1 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -126,7 +126,7 @@ describe Chef::Knife::CookbookShow do it "should print the raw result of the request (likely a file!)" do expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get).with("http://example.org/files/default.rb", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:streaming_request).with("http://example.org/files/default.rb").and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -178,7 +178,7 @@ describe Chef::Knife::CookbookShow do @knife.config[:platform_version] = "1.0" @knife.config[:fqdn] = "examplehost.example.org" expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get).with("http://example.org/files/1111", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:streaming_request).with("http://example.org/files/1111").and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -190,7 +190,7 @@ describe Chef::Knife::CookbookShow do @knife.config[:platform_version] = "1.0" @knife.config[:fqdn] = "differenthost.example.org" expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get).with("http://example.org/files/3333", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:streaming_request).with("http://example.org/files/3333").and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -202,7 +202,7 @@ describe Chef::Knife::CookbookShow do @knife.config[:platform_version] = "9.10" @knife.config[:fqdn] = "differenthost.example.org" expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get).with("http://example.org/files/2222", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:streaming_request).with("http://example.org/files/2222").and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end @@ -211,7 +211,7 @@ describe Chef::Knife::CookbookShow do describe "with none of the arguments, it should use the default" do it "should pass them all" do expect(@rest).to receive(:get).with("cookbooks/cookbook_name/0.1.0").and_return(@cookbook_response) - expect(@rest).to receive(:get).with("http://example.org/files/4444", true).and_return(StringIO.new(@response)) + expect(@rest).to receive(:streaming_request).with("http://example.org/files/4444").and_return(StringIO.new(@response)) expect(@knife).to receive(:pretty_print).with(@response) @knife.run end diff --git a/spec/unit/knife/cookbook_site_download_spec.rb b/spec/unit/knife/cookbook_site_download_spec.rb index 663ad1af74..d7f26f2f2e 100644 --- a/spec/unit/knife/cookbook_site_download_spec.rb +++ b/spec/unit/knife/cookbook_site_download_spec.rb @@ -60,8 +60,6 @@ describe Chef::Knife::CookbookSiteDownload do "file" => "http://example.com/apache2_#{@version_us}.tgz" } @temp_file = double( :path => "/tmp/apache2_#{@version_us}.tgz" ) @file = File.join(Dir.pwd, "apache2-#{@version}.tar.gz") - - expect(@noauth_rest).to receive(:sign_on_redirect=).with(false) end context "downloading the latest version" do @@ -69,8 +67,8 @@ describe Chef::Knife::CookbookSiteDownload do expect(@noauth_rest).to receive(:get). with(@current_data["latest_version"]). and_return(@cookbook_data) - expect(@noauth_rest).to receive(:get). - with(@cookbook_data["file"], true). + expect(@noauth_rest).to receive(:streaming_request). + with(@cookbook_data["file"]). and_return(@temp_file) end @@ -134,8 +132,8 @@ describe Chef::Knife::CookbookSiteDownload do expect(@noauth_rest).to receive(:get). with("#{@cookbook_api_url}/apache2/versions/#{@version_us}"). and_return(@cookbook_data) - expect(@noauth_rest).to receive(:get). - with(@cookbook_data["file"], true). + expect(@noauth_rest).to receive(:streaming_request). + with(@cookbook_data["file"]). and_return(@temp_file) expect(FileUtils).to receive(:cp).with(@temp_file.path, @file) @knife.run |