summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md11
-rw-r--r--Gemfile.lock12
-rw-r--r--VERSION2
-rw-r--r--chef-config/lib/chef-config/version.rb2
-rw-r--r--lib/chef/http.rb20
-rw-r--r--lib/chef/knife/cookbook_upload.rb8
-rw-r--r--lib/chef/provider/launchd.rb1
-rw-r--r--lib/chef/provider/remote_file/http.rb5
-rw-r--r--lib/chef/resource/launchd.rb6
-rw-r--r--lib/chef/version.rb2
-rw-r--r--spec/unit/http_spec.rb9
-rw-r--r--spec/unit/provider/remote_file/http_spec.rb42
12 files changed, 66 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01367732df..9174f2a52f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,17 +1,18 @@
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
-<!-- latest_release 13.6.49 -->
-## [v13.6.49](https://github.com/chef/chef/tree/v13.6.49) (2017-12-19)
+<!-- latest_release 13.6.52 -->
+## [v13.6.52](https://github.com/chef/chef/tree/v13.6.52) (2017-12-20)
#### Merged Pull Requests
-- Fix yum_repository allowing priority of 0 and remove string regexes [#6697](https://github.com/chef/chef/pull/6697) ([tas50](https://github.com/tas50))
-- Add descriptions and yard @since comments to all resources [#6696](https://github.com/chef/chef/pull/6696) ([tas50](https://github.com/tas50))
-- Cleanup to some of the resource specs [#6692](https://github.com/chef/chef/pull/6692) ([tas50](https://github.com/tas50))
+- Allow injecting tempfiles into Chef::HTTP [#6701](https://github.com/chef/chef/pull/6701) ([lamont-granquist](https://github.com/lamont-granquist))
<!-- latest_release -->
<!-- release_rollup since=13.6.4 -->
### Changes since 13.6.4 release
#### Merged Pull Requests
+- Allow injecting tempfiles into Chef::HTTP [#6701](https://github.com/chef/chef/pull/6701) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 13.6.52 -->
+- Modernize launchd resource [#6698](https://github.com/chef/chef/pull/6698) ([tas50](https://github.com/tas50)) <!-- 13.6.51 -->
+- Add an &#39;s&#39; for quantity of 0 cookbooks. [#6552](https://github.com/chef/chef/pull/6552) ([anoadragon453](https://github.com/anoadragon453)) <!-- 13.6.50 -->
- Fix yum_repository allowing priority of 0 and remove string regexes [#6697](https://github.com/chef/chef/pull/6697) ([tas50](https://github.com/tas50)) <!-- 13.6.49 -->
- Add descriptions and yard @since comments to all resources [#6696](https://github.com/chef/chef/pull/6696) ([tas50](https://github.com/tas50)) <!-- 13.6.48 -->
- Cleanup to some of the resource specs [#6692](https://github.com/chef/chef/pull/6692) ([tas50](https://github.com/tas50)) <!-- 13.6.48 -->
diff --git a/Gemfile.lock b/Gemfile.lock
index 59668a6721..afa5cec131 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -17,10 +17,10 @@ GIT
PATH
remote: .
specs:
- chef (13.6.49)
+ chef (13.6.52)
addressable
bundler (>= 1.10)
- chef-config (= 13.6.49)
+ chef-config (= 13.6.52)
chef-zero (>= 13.0)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -47,10 +47,10 @@ PATH
specinfra (~> 2.10)
syslog-logger (~> 1.6)
uuidtools (~> 2.1.5)
- chef (13.6.49-universal-mingw32)
+ chef (13.6.52-universal-mingw32)
addressable
bundler (>= 1.10)
- chef-config (= 13.6.49)
+ chef-config (= 13.6.52)
chef-zero (>= 13.0)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
@@ -92,7 +92,7 @@ PATH
PATH
remote: chef-config
specs:
- chef-config (13.6.49)
+ chef-config (13.6.52)
addressable
fuzzyurl
mixlib-config (~> 2.0)
@@ -309,7 +309,7 @@ GEM
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
slop (3.6.0)
- specinfra (2.72.1)
+ specinfra (2.73.0)
net-scp
net-ssh (>= 2.7, < 5.0)
net-telnet
diff --git a/VERSION b/VERSION
index e14833735d..fe937527df 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-13.6.49 \ No newline at end of file
+13.6.52 \ No newline at end of file
diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb
index ce3b8a2802..ba2c1e5f9c 100644
--- a/chef-config/lib/chef-config/version.rb
+++ b/chef-config/lib/chef-config/version.rb
@@ -21,7 +21,7 @@
module ChefConfig
CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__)
- VERSION = "13.6.49"
+ VERSION = "13.6.52"
end
#
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index 14dd8b93a5..c9df4e1235 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -170,11 +170,10 @@ class Chef
raise
end
- def streaming_request_with_progress(path, headers = {}, &progress_block)
+ def streaming_request_with_progress(path, headers = {}, tempfile = nil, &progress_block)
http_attempts ||= 0
url = create_url(path)
response, rest_request, return_value = nil, nil, nil
- tempfile = nil
data = nil
method = :GET
@@ -182,7 +181,7 @@ class Chef
response, rest_request, return_value = send_http_request(method, url, processed_headers, data) do |http_response|
if http_response.kind_of?(Net::HTTPSuccess)
- tempfile = stream_to_tempfile(url, http_response, &progress_block)
+ tempfile = stream_to_tempfile(url, http_response, tempfile, &progress_block)
end
apply_stream_complete_middleware(http_response, rest_request, return_value)
end
@@ -217,11 +216,10 @@ class Chef
#
# @yield [tempfile] block to process the tempfile
# @yieldparams [tempfile<Tempfile>] tempfile
- def streaming_request(path, headers = {})
+ def streaming_request(path, headers = {}, tempfile = nil)
http_attempts ||= 0
url = create_url(path)
response, rest_request, return_value = nil, nil, nil
- tempfile = nil
data = nil
method = :GET
@@ -229,7 +227,7 @@ class Chef
response, rest_request, return_value = send_http_request(method, url, processed_headers, data) do |http_response|
if http_response.kind_of?(Net::HTTPSuccess)
- tempfile = stream_to_tempfile(url, http_response)
+ tempfile = stream_to_tempfile(url, http_response, tempfile)
end
apply_stream_complete_middleware(http_response, rest_request, return_value)
end
@@ -500,11 +498,13 @@ class Chef
end
# @api private
- def stream_to_tempfile(url, response, &progress_block)
+ def stream_to_tempfile(url, response, tf = nil, &progress_block)
content_length = response["Content-Length"]
- tf = Tempfile.open("chef-rest")
- if Chef::Platform.windows?
- tf.binmode # required for binary files on Windows platforms
+ if tf.nil?
+ tf = Tempfile.open("chef-rest")
+ if Chef::Platform.windows?
+ tf.binmode # required for binary files on Windows platforms
+ end
end
Chef::Log.debug("Streaming download from #{url} to tempfile #{tf.path}")
# Stolen from http://www.ruby-forum.com/topic/166423
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index 6938ac280d..92084e7906 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -146,12 +146,12 @@ class Chef
end
if upload_failures == 0
- ui.info "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""}."
+ ui.info "Uploaded #{upload_ok} cookbook#{upload_ok == 1 ? "" : "s"}."
elsif upload_failures > 0 && upload_ok > 0
- ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok > 1 ? "s" : ""} ok but #{upload_failures} " +
- "cookbook#{upload_failures > 1 ? "s" : ""} upload failed."
+ ui.warn "Uploaded #{upload_ok} cookbook#{upload_ok == 1 ? "" : "s"} ok but #{upload_failures} " +
+ "cookbook#{upload_failures == 1 ? "" : "s"} upload failed."
elsif upload_failures > 0 && upload_ok == 0
- ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures > 1 ? "s" : ""}."
+ ui.error "Failed to upload #{upload_failures} cookbook#{upload_failures == 1 ? "" : "s"}."
exit 1
end
end
diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb
index 8281410d42..8d868784dd 100644
--- a/lib/chef/provider/launchd.rb
+++ b/lib/chef/provider/launchd.rb
@@ -17,7 +17,6 @@
#
require "chef/provider"
-require "chef/resource/launchd"
require "chef/resource/file"
require "chef/resource/cookbook_file"
require "chef/resource/macosx_service"
diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb
index ad044f9e3c..4732253e5b 100644
--- a/lib/chef/provider/remote_file/http.rb
+++ b/lib/chef/provider/remote_file/http.rb
@@ -61,12 +61,13 @@ class Chef
def fetch
http = Chef::HTTP::Simple.new(uri, http_client_opts)
+ tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile
if want_progress?
- tempfile = http.streaming_request_with_progress(uri, headers) do |size, total|
+ tempfile = http.streaming_request_with_progress(uri, headers, tempfile) do |size, total|
events.resource_update_progress(new_resource, size, total, progress_interval)
end
else
- tempfile = http.streaming_request(uri, headers)
+ tempfile = http.streaming_request(uri, headers, tempfile)
end
if tempfile
update_cache_control_data(tempfile, http.last_response)
diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb
index 358d5462bc..121af1555c 100644
--- a/lib/chef/resource/launchd.rb
+++ b/lib/chef/resource/launchd.rb
@@ -17,7 +17,6 @@
#
require "chef/resource"
-require "chef/provider/launchd"
class Chef
class Resource
@@ -25,14 +24,13 @@ class Chef
#
# @since 12.8
class Launchd < Chef::Resource
+ resource_name :launchd
provides :launchd, os: "darwin"
- identity_attr :label
-
default_action :create
allowed_actions :create, :create_if_missing, :delete, :enable, :disable, :restart
- property :label, String, default: lazy { name }, identity: true
+ property :label, String, identity: true, name_property: true
property :backup, [Integer, FalseClass]
property :cookbook, String
property :group, [String, Integer]
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index cd0691ca18..a26d60164d 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -23,7 +23,7 @@ require "chef/version_string"
class Chef
CHEF_ROOT = File.expand_path("../..", __FILE__)
- VERSION = Chef::VersionString.new("13.6.49")
+ VERSION = Chef::VersionString.new("13.6.52")
end
#
diff --git a/spec/unit/http_spec.rb b/spec/unit/http_spec.rb
index d58f07c417..bf873b8535 100644
--- a/spec/unit/http_spec.rb
+++ b/spec/unit/http_spec.rb
@@ -93,6 +93,15 @@ describe Chef::HTTP do
expect { http.send(:stream_to_tempfile, uri, resp) }.to raise_error("TestError")
end
+ it "accepts a tempfile" do
+ resp = Net::HTTPOK.new("1.1", 200, "OK")
+ http = Chef::HTTP.new(uri)
+ tempfile = Tempfile.open("tempy-mctempfile")
+ expect(Tempfile).not_to receive(:open)
+ expect(resp).to receive(:read_body).and_yield("conty-mccontent")
+ http.send(:stream_to_tempfile, uri, resp, tempfile)
+ expect(IO.read(tempfile.path)).to eql("conty-mccontent")
+ end
end
describe "head" do
diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb
index f58a3d3c14..ec9c0cf2e3 100644
--- a/spec/unit/provider/remote_file/http_spec.rb
+++ b/spec/unit/provider/remote_file/http_spec.rb
@@ -157,9 +157,9 @@ describe Chef::Provider::RemoteFile::HTTP do
let(:expected_http_opts) { {} }
let(:expected_http_args) { [uri, expected_http_opts] }
- let(:tempfile_path) { "/tmp/chef-mock-tempfile-abc123" }
+ let(:tempfile_path) { tempfile.path }
- let(:tempfile) { double(Tempfile, :path => tempfile_path, :close => nil) }
+ let(:tempfile) { Tempfile.open("muhtempfile") }
let(:last_response) { {} }
@@ -171,7 +171,7 @@ describe Chef::Provider::RemoteFile::HTTP do
let(:rest) do
rest = double(Chef::HTTP::Simple)
- allow(rest).to receive(:streaming_request).and_return(tempfile)
+ allow_any_instance_of(Chef::FileContentManagement::Tempfile).to receive(:tempfile).and_return(tempfile)
allow(rest).to receive(:last_response).and_return(last_response)
rest
end
@@ -189,17 +189,35 @@ describe Chef::Provider::RemoteFile::HTTP do
it "should return a nil tempfile for a 304 HTTPNotModifed" do
# Streaming request returns nil for 304 errors
- allow(rest).to receive(:streaming_request).and_return(nil)
+ expect(rest).to receive(:streaming_request).with(uri, {}, tempfile).and_return(nil)
expect(fetcher.fetch).to be_nil
end
end
- describe "and the request returns new content" do
+ context "with progress reports" do
+ let(:fetched_content_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" }
+
+ before do
+ expect(cache_control_data).to receive(:save)
+ expect(Chef::Digester).to receive(:checksum_for_file).with(tempfile_path).and_return(fetched_content_checksum)
+ Chef::Config[:show_download_progress] = true
+ end
+
+ it "should yield its progress" do
+ expect(rest).to receive(:streaming_request_with_progress).with(uri, {}, tempfile).and_yield(50, 100).and_yield(70, 100).and_return(tempfile)
+ expect(event_dispatcher).to receive(:formatter?).and_return(true)
+ expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 50, 100, 10).ordered
+ expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 70, 100, 10).ordered
+ fetcher.fetch
+ end
+ end
+ describe "and the request returns new content" do
let(:fetched_content_checksum) { "e2a8938cc31754f6c067b35aab1d0d4864272e9bf8504536ef3e79ebf8432305" }
before do
+ expect(rest).to receive(:streaming_request).with(uri, {}, tempfile).and_return(tempfile)
expect(cache_control_data).to receive(:save)
expect(Chef::Digester).to receive(:checksum_for_file).with(tempfile_path).and_return(fetched_content_checksum)
end
@@ -212,20 +230,6 @@ describe Chef::Provider::RemoteFile::HTTP do
expect(cache_control_data.checksum).to eq(fetched_content_checksum)
end
- context "with progress reports" do
- before do
- Chef::Config[:show_download_progress] = true
- end
-
- it "should yield its progress" do
- allow(rest).to receive(:streaming_request_with_progress).and_yield(50, 100).and_yield(70, 100).and_return(tempfile)
- expect(event_dispatcher).to receive(:formatter?).and_return(true)
- expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 50, 100, 10).ordered
- expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 70, 100, 10).ordered
- fetcher.fetch
- end
- end
-
context "and the response does not contain an etag" do
let(:last_response) { { "etag" => nil } }
it "does not include an etag in the result" do