flexera-public / right_aws

RightScale Amazon Web Services Ruby Gems
MIT License
451 stars 175 forks source link

ruby 2.0 incompatibility #167

Open smostovoy opened 11 years ago

smostovoy commented 11 years ago

Hey, Can't give more details for now but generally problem is next: capistrano-ec2group + right_aws don't work after moving to ruby 2.0. Looks like it has something to do with Ec2#describe_resources_with_list_and_options which passes to block something different in ruby1.9.3. In result @ec2_api.describe_instances always returns []. Gem version - 3.0.5 I will continue research if you have no idea why is it happening

unorthodoxgeek commented 10 years ago

happens because in Ruby 2.0 Net::HTTP doesn't automatically unzip gzip responses. I've solved this on my project by monkey patching the code like this:

module RightAws
  class RightAWSParser
    alias_method :old_parse, :parse
    def parse(xml_text, params={})
      if !xml_text.is_a?(String) && xml_text.to_hash["content-encoding"].include?("gzip")
        body = StringIO.new(xml_text.body)
        xml_text = Zlib::GzipReader.new(body).read
      end
      old_parse(xml_text, params)
    end
  end
end

should be handled by the gem, I guess... if this is a valid solution, I'd be happy to issue a Pull Request.

stormsilver commented 10 years ago

This monkey patch worked for me on gem version 3.1.0. Thank you!

hammer65 commented 10 years ago

The problem I'm having is that in using S3 and simpleDB. S3 works fine, but simpleDB returns a blank result no matter what I query. It will raise the proper error when I access something I don't have permission for, and there is no error when I query something I do have access to, it just won't return results. I checked with a desktop simpleDB client and it works. Switching using RVM back to 1.8.7 works fine.

rb2k commented 10 years ago

I would appreciate this fix going in. Ruby 2.0 has been out for a while...

unorthodoxgeek commented 10 years ago

this isn't a right_aws thing. http://avi.io/blog/2013/12/17/do-not-upgrade-your-rails-project-to-ruby-2-before-you-read-this/

seems like whoever is maintaining Net::HTTP just went to sleep. the patch in this post is a must, regardless of which gem you're using. this is relevant for koala, aws, and many many more gems

rb2k commented 10 years ago

It seems like this would fix it:

https://github.com/ruby/ruby/commit/f58d39807541d8f50ba682183ab9097ddcb52698

?

unorthodoxgeek commented 10 years ago

@rb2k - yup

rb2k commented 10 years ago

Weirdly enough, I still had to apply the manual fix to right_aws running on 2.1.0. Just looking through the parser class.

grahamlyus commented 10 years ago

@rb2k - It seems that the problem is actually in the right_http_connection gem, which overrides the request method and doesn't set decode_content on the response object.

Until that gem is updated, my workaround is to add the following to my Gemfile:

gem 'right_http_connection', git: 'git://github.com/rightscale/right_http_connection.git', ref: '3359524d81'

https://github.com/rightscale/right_http_connection/pull/20