Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing NoMethodError when using system wide rvm and the gem_package resource. #66

Merged
merged 1 commit into from
Mar 12, 2012

Conversation

kristopher
Copy link
Contributor

Today I updated the chef-rvm cookbook to head and started getting this error. It is repeatable for me in vagrant.

Error

NoMethodError: gem_package[god] (god::default line 22) had an error: undefined method `user' for Chef::Resource::GemPackage
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource.rb:145:in `method_missing'
/tmp/vagrant-chef-1/chef-solo-1/rvm/libraries/rvm_rubygems_package.rb:147:in `install_via_gem_command'
/tmp/vagrant-chef-1/chef-solo-1/rvm/libraries/rvm_rubygems_package.rb:134:in `install_package'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/provider/package.rb:60:in `action_install'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource.rb:417:in `send'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource.rb:417:in `run_action'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/runner.rb:45:in `run_action'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/runner.rb:78:in `converge'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/runner.rb:78:in `each'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/runner.rb:78:in `converge'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection.rb:94:in `execute_each_resource'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/resource_collection.rb:92:in `execute_each_resource'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/runner.rb:76:in `converge'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/client.rb:312:in `converge'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/client.rb:160:in `run'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/application/solo.rb:192:in `run_application'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/application/solo.rb:183:in `loop'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/application/solo.rb:183:in `run_application'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/../lib/chef/application.rb:66:in `run'
/opt/ruby/lib/ruby/gems/1.8/gems/chef-0.10.2/bin/chef-solo:25
/opt/ruby/bin/chef-solo:19:in `load'

Code that causes the error.

gem_package "god" do
  action :install
end

@TylerRick
Copy link

This was a problem for me as well.

I first ran into this when I added rvm::gem_package to my run_list/recipes so that the unicorn::default recipe would install its gem to my app's RVM gemset rather than to the system gem environment.

include_recipe 'rvm::gem_package'

Here is the error and backtrace:

INFO: Processing gem_package[unicorn] action install (unicorn::default line 21)
INFO: Processing rvm_environment[1.9.3-p125] action create (/etc/chef/cookbooks/rvm/libraries/rvm_rubygems_package.rb line 127)
ERROR: gem_package[unicorn] (unicorn::default line 21) has had an error
ERROR: gem_package[unicorn] (/etc/chef/cookbooks/unicorn/recipes/default.rb:21:in `from_file') had an error:
gem_package[unicorn] (unicorn::default line 21) had an error: NoMethodError: undefined method `user' for Chef::Resource::GemPackage
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource.rb:147:in `method_missing'
/etc/chef/cookbooks/rvm/libraries/rvm_rubygems_package.rb:147:in `install_via_gem_command'
/etc/chef/cookbooks/rvm/libraries/rvm_rubygems_package.rb:134:in `install_package'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/provider/package.rb:60:in `action_install'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource.rb:441:in `send'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource.rb:441:in `run_action'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:45:in `run_action'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:81:in `converge'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:81:in `each'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:81:in `converge'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection.rb:95:in `execute_each_resource'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection.rb:92:in `execute_each_resource'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:76:in `converge'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/client.rb:312:in `converge'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/client.rb:160:in `run'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/application/solo.rb:192:in `run_application'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/application/solo.rb:183:in `loop'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/application/solo.rb:183:in `run_application'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/application.rb:67:in `run'
/usr/lib/ruby/gems/1.8/gems/chef-0.10.8/bin/chef-solo:25
/usr/bin/chef-solo:19:in `load'
/usr/bin/chef-solo:19
ERROR: Running exception handlers
ERROR: Exception handlers complete
FATAL: Stacktrace dumped to /etc/chef/chef-stacktrace.out

I was also able to reproduce this problem with a simpler recipe, something like this:

include_recipe 'rvm::system'
include_recipe 'rvm::gem_package'
gem_package 'facets'

(the error and backtrace were identical)

Simply changing gem_package to rvm_gem fixed that problem:

gem_package 'facets'

but that isn't an option in my original problem, since that relies on a 3rd-party recipe from the unicorn cookbook. So I really need the rvm::gem_package monkey-patch to work!

Here is the context of where it was failing:

        def install_via_gem_command(name, version)
          ...

          cmd = %{rvm #{ruby_strings.join(',')} #{rvm_do(new_resource.user)} #{gem_binary_path}}
          cmd << %{ install #{name} -q --no-rdoc --no-ri -v "#{version}"}
          cmd << %{#{src}#{opts}}

          if new_resource.respond_to?("user") && new_resource.user
            ...
          else
            ...
          end
          ...
        end

It tries to call new_resource.user even though we're installing to a system-wide rvm install. I assume that is the reason why user is undefined? (and I assume it would be defined if this were a user rvm install?)

In any case, why is it unconditionally calling new_resource.user right there when a few lines later it checks if new_resource.respond_to?("user")?? That feels like a bug, even though I don't completely understand the code.

@TylerRick
Copy link

Thanks, @kristopher, for the fix! Your patch fixed the problem for me.

(I cherry-picked your commit into my fork of chef-rvm, applying it on top of the latest from upstream, bd3ff1f (Feb 23). Working great so far!)

@fnichol
Copy link
Contributor

fnichol commented Mar 12, 2012

Excellent catch, thank you @kristopher for the fix and @TylerRick for confirming! Sorry about the huge delay in pulling this in.

fnichol added a commit that referenced this pull request Mar 12, 2012
Fixing NoMethodError when using system wide rvm and the gem_package resource.
@fnichol fnichol merged commit 39390a4 into sous-chefs:master Mar 12, 2012
@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants