Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 64f8f50

Browse files
Dale Huijtimberman
Dale Hui
authored and
jtimberman
committed
Changing the default shell_out timeout from 1 minute to 15 minutes.
Add the ability to change the shell_out timeout. These changes are needed for pip packages that take more than 1 minute to install.
1 parent d5cbdbc commit 64f8f50

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

providers/pip.rb

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,49 @@
3434
elsif @current_resource.version == nil
3535
install_version = candidate_version
3636
end
37+
38+
# Set the timeout (units in seconds)
39+
timeout = 900
40+
if @new_resource.timeout
41+
timeout = @new_resource.timeout
42+
end
3743

3844
if install_version
3945
Chef::Log.info("Installing #{@new_resource} version #{install_version}")
40-
status = install_package(@new_resource.package_name, install_version)
46+
status = install_package(@new_resource.package_name, install_version, timeout)
4147
if status
4248
@new_resource.updated_by_last_action(true)
4349
end
4450
end
4551
end
4652

4753
action :upgrade do
54+
# Set the timeout (units in seconds)
55+
timeout = 900
56+
if @new_resource.timeout
57+
timeout = @new_resource.timeout
58+
end
59+
4860
if @current_resource.version != candidate_version
4961
orig_version = @current_resource.version || "uninstalled"
5062
Chef::Log.info("Upgrading #{@new_resource} version from #{orig_version} to #{candidate_version}")
51-
status = upgrade_package(@new_resource.package_name, candidate_version)
63+
status = upgrade_package(@new_resource.package_name, candidate_version, timeout)
5264
if status
5365
@new_resource.updated_by_last_action(true)
5466
end
5567
end
5668
end
5769

5870
action :remove do
71+
# Set the timeout (units in seconds)
72+
timeout = 900
73+
if @new_resource.timeout
74+
timeout = @new_resource.timeout
75+
end
76+
5977
if removing_package?
6078
Chef::Log.info("Removing #{@new_resource}")
61-
remove_package(@current_resource.package_name, @new_resource.version)
79+
remove_package(@current_resource.package_name, @new_resource.version, timeout)
6280
@new_resource.updated_by_last_action(true)
6381
else
6482
end
@@ -121,18 +139,18 @@ def candidate_version
121139
end
122140
end
123141

124-
def install_package(name,version)
142+
def install_package(name, version, timeout)
125143
v = "==#{version}" unless version.eql?('latest')
126-
shell_out!("pip install#{expand_options(@new_resource.options)}#{expand_virtualenv(can_haz_virtualenv(@new_resource))} #{name}#{v}")
144+
shell_out!("pip install#{expand_options(@new_resource.options)}#{expand_virtualenv(can_haz_virtualenv(@new_resource))} #{name}#{v}", :timeout => timeout)
127145
end
128146

129-
def upgrade_package(name, version)
147+
def upgrade_package(name, version, timeout)
130148
v = "==#{version}" unless version.eql?('latest')
131-
shell_out!("pip install --upgrade#{expand_options(@new_resource.options)}#{expand_virtualenv(can_haz_virtualenv(@new_resource))} #{@new_resource.name}#{v}")
149+
shell_out!("pip install --upgrade#{expand_options(@new_resource.options)}#{expand_virtualenv(can_haz_virtualenv(@new_resource))} #{@new_resource.name}#{v}", :timeout => timeout)
132150
end
133151

134-
def remove_package(name, version)
135-
shell_out!("pip uninstall -y#{expand_options(@new_resource.options)}#{expand_virtualenv(can_haz_virtualenv(@new_resource))} #{@new_resource.name}")
152+
def remove_package(name, version, timeout)
153+
shell_out!("pip uninstall -y#{expand_options(@new_resource.options)}#{expand_virtualenv(can_haz_virtualenv(@new_resource))} #{@new_resource.name}", :timeout => timeout)
136154
end
137155

138156
def expand_virtualenv(virtualenv)

resources/pip.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222

2323
attribute :package_name, :kind_of => String, :name_attribute => true
2424
attribute :version, :default => nil
25+
attribute :timeout, :default => nil
2526
attribute :virtualenv, :kind_of => String
26-
attribute :options, :kind_of => String
27+
attribute :options, :kind_of => String

0 commit comments

Comments
 (0)