January 5, 2012

When trying to pip install large packages via Chef, we found that some of our packages were failing to install with the message: "command timed out:"

Turns out that python_pip is using the shell_out function which has a 60 second timeout when running commands. [See Also]

So the fix is to update python_pip to specify a larger timeout value.

First add the timeout attribute to the pip resource:

Changed file resources/pip.rb

22 22  
23 23  attribute :package_name, :kind_of => String, :name_attribute => true
24 24  attribute :version, :default => nil
  25  attribute :timeout, :default => nil
25 26  attribute :virtualenv, :kind_of => String
26 27  attribute :options, :kind_of => String
27 28 \ No newline at end of file

Then set the new timeout value and send pass that new timeout value to shell_out:

Changed file providers/pip.rb

35 35      install_version = candidate_version
36 36    end
37 37    
  38    # Set the timeout (units in seconds)
  39    timeout = 900
  40    if @new_resource.timeout
  41      timeout = @new_resource.timeout
  42    end
  43    
38 44    if install_version
39 45      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)
41 47      if status
42 48        @new_resource.updated_by_last_action(true)
43 49      end
121 139    end
122 140  end
123 141  
124    def install_package(name,version)
  142  def install_package(name, version, timeout)
125 143    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)
127 145  end
128 146  

(optional) Repeat for upgrade_package and remove_package.

You can view the full diff here.



blog comments powered by Disqus