jeudi 25 février 2016

RubyZip fails - closed stream

I have a chef-cookbook with following ruby code:

    class Chef::Recipe::Helpers
      def self.is_config?(filename)
        ['.lua', '.conf'].include?(File.extname(filename))
      end

      def self.out_filename(filename)
        File.extname(filename) == '.conf' ? 'nginx.conf' : filename
      end

      def self.unzip(data, dest_dir)
        ::Zip::File.open_buffer(data) do |fzip|
          fzip.each do |entry|
            next unless is_config?(entry.name)
            content = fzip.read(entry)
            filename = out_filename(entry.name)
            path = File.join(dest_dir, filename)
            File.write(path, content)
          end
        end
      end
      def self.fetch_from_url(url, dest_dir)
        response = HTTPClient.get(url, follows_redirect: true)
        if response.status == 200
             unzip(response.body, dest_dir)
        else
             raise 'Could not fetch files from 3scale'
         end
        end

I have a zip file in an artifact repository that is zipped and uploaded and I give that endpoint for this code to receive in :

ruby_block 'fetch configuration files from a URL' do
    block do
      Helpers.fetch_from_url(node['3scale']['config-url'], version_dir)
    end
    action :run
  end

and this uses the helper function mentioned in the post, but when I run it I get the following error:

 * ruby_block[fetch configuration files from a URL] action run
================================================================================
Error executing action `run` on resource 'ruby_block[fetch configuration files from a URL]'
================================================================================


IOError
-------
closed stream


Cookbook Trace:
---------------
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:23:in `block (2 levels) in unzip'
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:21:in `block in unzip'
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:20:in `unzip'
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:34:in `fetch_from_url'
/var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb:79:in `block (2 levels) in from_file'


Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb

 77:   ruby_block 'fetch configuration files from a URL' do
 78:     block do
 79:       Helpers.fetch_from_url(node['3scale']['config-url'], version_dir)
 80:     end
 81:     action :run
 82:   end
 83: elsif mode == 'local'



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb:77:in `from_file'

ruby_block("fetch configuration files from a URL") do
  action [:run]
  retries 0
  retry_delay 2
  block_name "fetch configuration files from a URL"
  cookbook_name "dj-chef-3scale"
  recipe_name "default"
  block #<Proc:0x0000000420e230@/var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb:78>
end

Not sure why I would be getting 'closed stream' here ?

Aucun commentaire:

Enregistrer un commentaire