summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-03-03 11:37:44 +0000
committerThom May <thom@chef.io>2016-03-04 14:47:58 +0000
commitff539423f067ee83c07dcf73cbf688c6a07f64ae (patch)
tree5472f234d9df0892df49313f8407b4c003fab1fe /lib
parent788ec4597c9f1517c26d85703bdc79ea01e5ff53 (diff)
downloadchef-ff539423f067ee83c07dcf73cbf688c6a07f64ae.tar.gz
Enable progress output to be configuredtm/remote_file_download_progress
Add tests around progress output and tidy up
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/event_dispatch/base.rb12
-rw-r--r--lib/chef/formatters/doc.rb4
-rw-r--r--lib/chef/http.rb8
-rw-r--r--lib/chef/provider/remote_file/http.rb8
-rw-r--r--lib/chef/resource/remote_file.rb11
5 files changed, 17 insertions, 26 deletions
diff --git a/lib/chef/event_dispatch/base.rb b/lib/chef/event_dispatch/base.rb
index 65cb519dc7..e6bbbc929f 100644
--- a/lib/chef/event_dispatch/base.rb
+++ b/lib/chef/event_dispatch/base.rb
@@ -297,12 +297,6 @@ class Chef
# - resource_completed
#
- # Called when a progress notification should be sent to the user to
- # indicate the overall progress of a long running operation, such as
- # a large file download.
- def resource_action_progress(resource, current, total, interval)
- end
-
# Called before action is executed on a resource.
def resource_action_start(resource, action, notification_type = nil, notifier = nil)
end
@@ -330,6 +324,12 @@ class Chef
def resource_update_applied(resource, action, update)
end
+ # Called when a progress notification should be sent to the user to
+ # indicate the overall progress of a long running operation, such as
+ # a large file download.
+ def resource_update_progress(resource, current, total, interval)
+ end
+
# Called when a resource fails, but will retry.
def resource_failed_retriable(resource, action, retry_count, exception)
end
diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb
index 31732066a8..bad22370ae 100644
--- a/lib/chef/formatters/doc.rb
+++ b/lib/chef/formatters/doc.rb
@@ -259,7 +259,7 @@ class Chef
indent
end
- def resource_action_progress(resource, current, total, interval)
+ def resource_update_progress(resource, current, total, interval)
@progress[resource] ||= 0
percent_complete = (current.to_f / total.to_f * 100).to_i
@@ -269,7 +269,7 @@ class Chef
@progress[resource] = percent_complete
if percent_complete % interval == 0
- start_line " - Progress: #{percent_complete}/100 %", :green
+ start_line " - Progress: #{percent_complete}%", :green
end
end
end
diff --git a/lib/chef/http.rb b/lib/chef/http.rb
index c90f799cd9..4a3b0bc85e 100644
--- a/lib/chef/http.rb
+++ b/lib/chef/http.rb
@@ -74,8 +74,6 @@ class Chef
attr_reader :redirect_limit
attr_reader :options
- attr_reader :show_progress
- attr_reader :progress_interval
attr_reader :middlewares
@@ -156,8 +154,7 @@ class Chef
raise
end
-
- def streaming_request_with_progress(path, headers={}, &progress_block)
+ def streaming_request_with_progress(path, headers = {}, &progress_block)
url = create_url(path)
response, rest_request, return_value = nil, nil, nil
tempfile = nil
@@ -421,7 +418,7 @@ class Chef
end
def stream_to_tempfile(url, response, &progress_block)
- content_length = response['Content-Length']
+ content_length = response["Content-Length"]
tf = Tempfile.open("chef-rest")
if Chef::Platform.windows?
tf.binmode # required for binary files on Windows platforms
@@ -458,4 +455,3 @@ class Chef
end
end
-
diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb
index 3b97d116aa..d4f2446e27 100644
--- a/lib/chef/provider/remote_file/http.rb
+++ b/lib/chef/provider/remote_file/http.rb
@@ -63,7 +63,7 @@ class Chef
http = Chef::HTTP::Simple.new(uri, http_client_opts)
if want_progress?
tempfile = http.streaming_request_with_progress(uri, headers) do |size, total|
- events.resource_action_progress(new_resource, size, total, new_resource.progress_interval)
+ events.resource_update_progress(new_resource, size, total, progress_interval)
end
else
tempfile = http.streaming_request(uri, headers)
@@ -89,7 +89,11 @@ class Chef
end
def want_progress?
- new_resource.show_progress
+ events.formatter? && (Chef::Config[:show_download_progress] || !!new_resource.show_progress)
+ end
+
+ def progress_interval
+ Chef::Config[:download_progress_interval]
end
def want_mtime_cache_control?
diff --git a/lib/chef/resource/remote_file.rb b/lib/chef/resource/remote_file.rb
index b615297c24..321c3fcf4d 100644
--- a/lib/chef/resource/remote_file.rb
+++ b/lib/chef/resource/remote_file.rb
@@ -122,7 +122,7 @@ class Chef
)
end
- def show_progress(args=nil)
+ def show_progress(args = nil)
set_or_return(
:show_progress,
args,
@@ -131,15 +131,6 @@ class Chef
)
end
- def progress_interval(args=nil)
- set_or_return(
- :progress_interval,
- args,
- :default => 10,
- :equal_to => [1, 5, 10, 20, 25]
- )
- end
-
private
include Chef::Mixin::Uris