Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

rubygems undefined method `activate' for nil:NilClass #411

Closed
btm opened this issue Jun 4, 2015 · 13 comments
Closed

rubygems undefined method `activate' for nil:NilClass #411

btm opened this issue Jun 4, 2015 · 13 comments

Comments

@btm
Copy link
Contributor

btm commented Jun 4, 2015

PS C:\Users\Administrator> chef exec knife windows cert generate
C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:198:in `rescue in try_activate': undefined method `activate' for nil:NilClass (NoMethodError)
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:195:in `try_activate'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from C:/Users/Administrator/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.0.0.rc.0/lib/chef/knife/bootstrap_windows_base.rb:22:in `<top (required)>'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `block in load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `each'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:127:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:208:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/application/knife.rb:142:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/bin/knife:25:in `<top (required)>'
        from C:/opscode/chefdk/bin/knife:63:in `load'
        from C:/opscode/chefdk/bin/knife:63:in `<main>'
PS C:\Users\Administrator> chef gem list knife-windows

*** LOCAL GEMS ***

knife-windows (1.0.0.rc.0)
PS C:\Users\Administrator> chef --version
Chef Development Kit Version: 0.6.0
chef-client version: 12.3.0
berks version: 3.2.4
kitchen version: 1.4.0
PS C:\Users\Administrator> chef verify
Running verification for component 'berkshelf'
Running verification for component 'test-kitchen'
Running verification for component 'chef-client'
Running verification for component 'chef-dk'
Running verification for component 'chefspec'
Running verification for component 'rubocop'
Running verification for component 'fauxhai'
Running verification for component 'knife-spork'
Running verification for component 'kitchen-vagrant'
Running verification for component 'package installation'
.......................................

C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:198:in `rescue in try_activate': undefined method `activ
ate' for nil:NilClass (NoMethodError)
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:195:in `try_activate'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from C:/Users/Administrator/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.0.0.rc.0/lib/chef/knife/bootstrap_windows_base.rb:22:in `<top (required)>'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `block in load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `each'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:127:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:208:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/application/knife.rb:142:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/bin/knife:25:in `<top (required)>'
        from C:/opscode/chefdk/bin/knife:63:in `load'
        from C:/opscode/chefdk/bin/knife:63:in `<main>'


---------------------------------------------
Verification of component 'rubocop' succeeded.
Verification of component 'package installation' succeeded.
Verification of component 'berkshelf' succeeded.
Verification of component 'chef-client' succeeded.
Verification of component 'chefspec' succeeded.
Verification of component 'knife-spork' failed.
Verification of component 'test-kitchen' succeeded.
Verification of component 'fauxhai' succeeded.
Verification of component 'chef-dk' succeeded.
Verification of component 'kitchen-vagrant' succeeded.
@siddheshwar-more
Copy link

yes, am also facing same issue.

@btm
Copy link
Contributor Author

btm commented Jun 10, 2015

There's a Chef DK 0.7.0 RC that has the knife-windows RC in it. I'm curious if it would reproduce this issue as well.

@siddheshwar-more
Copy link

@btm -
There is no Chef- DK 0.7.0 RC version available, we have v0.6.1 latest https://rubygems.org/gems/chef-dk .
We don't have omnibus pkg for 0.6.1 https://downloads.chef.io/chef-dk/ .

Also tried to build chef-dk using omnibus-chef but got some error during build.

@siddheshwar-more
Copy link

@btm -
We tried below things -

  1. Installed chef-dk by using https://github.com/adamedx/getchef/blob/master/getchefdk.sh
  2. Above script installs chef-dk v0.7.0.rc.0 and it comes with knife-windows 0.8.5
  3. Tried $ knife winrm --help with knife-windows 0.8.5 and it worked fine.
  4. sudo chef gem uninstall knife-windows
  5. sudo chef gem install knife-windows -v '1.0.0.rc.0' --no-ri --no-rdco
  6. Tried $chef exec knife windows cert generate -H sidnsd -VV - It also worked fine.

Note- chef-dk v0.7.rc.0 doesn't contains knife-windows RC, it contains 0.8.5

@siddheshwar-more
Copy link

@btm @adamedx -
We have tried below things to debug this issue -

  1. Manually installed gem by using chefdk goes under ~/.chefdk/gem/ruby/2.1.0/gems . So we have two different location for GEM_PATHS i.e /opt/chefdk/embedded/lib/ruby/gems/2.1.0 and /home/USER/.chefdk/gem/ruby/2.1.0

  2. To verify knife-windows 1.0.0.rc.0 version and ruby $LOAD_PATH , tried-
    2.1 $ chef gem install knife-windows -v '1.0.0.rc.0'
    2.2 $ chef exec knife windows cert generate
    So, here we got $LOAD_PATH . It missing these entries. If we add manually these entries in $LOAD_PATH then above command #2.2 works fine.
    2.3 Installed $chef gem install knife-ec2 and verified $LOAD_PATH and it has knife-ec2 lib entries.
    I'm trying to understand why its not adding knife-windows 1.0.0.rc.0 versions lib in $LOAD_PATH ?

  3. To verify knife-windows 1.0.0.rc.0 versions .gemspec file, tried-
    3.1 git clone https://github.com/chef/knife-windows
    3.2 git checkout v1.0.0.rc.0
    3.3 Apply below patch to remove winrm and update winrm-s version -

    diff --git a/knife-windows.gemspec b/knife-windows.gemspec
    index e0b3da0..c6fcbb3 100644
    --- a/knife-windows.gemspec
    +++ b/knife-windows.gemspec
    @@ -14,8 +14,8 @@ Gem::Specification.new do |s|
    s.description = s.summary
    s.required_ruby_version = ">= 1.9.1"
    - s.add_dependency "winrm", "~> 1.3"
    - s.add_dependency "winrm-s", "~> 0.3.0.dev.0"
    + s.add_dependency "winrm-s", "~> 0.2.4"
    s.add_dependency "nokogiri"

    3.4 chef gem build knife-windows.gemspec
    3.5 chef gem install knife-windows-1.0.0.rc.0.gem
    3.6 chef exec knife windows cert generate - And it worked fine.
    Here my finding is knife-windows doesn't works with chef-dk if it has winrm > 1.2.0 dependency.
    I also observed chef-provisioning-1.1.1 depends on winrm (~> 1.2.0) and winrm-transport-1.0.1 depends on winrm (~> 1.3). We have to take care of these kind of gem dependency in chef-dk, where multiple gems using one gems(i.e winrm in our case) different versions.
    3.7 With below patch(i.e to remove winrm-s) and reinstall knife-windows 1.0.0.rc.0 version
    but still we have same issue for $chef exec knife windows cert generate

    diff --git a/knife-windows.gemspec b/knife-windows.gemspec
    index e0b3da0..7e1d056 100644
    --- a/knife-windows.gemspec
    +++ b/knife-windows.gemspec
    @@ -15,7 +15,6 @@ Gem::Specification.new do |s|
    s.required_ruby_version      = ">= 1.9.1"
    s.add_dependency "winrm", "~> 1.3"
    -  s.add_dependency "winrm-s", "~> 0.3.0.dev.0"
    s.add_dependency "nokogiri"
    s.add_development_dependency 'pry'
    

    So, that's means there are some issue with chef-dk + knife-windows 1.0.0.rc.0 version + winrm combo. Currently am working on these issues.

Please let us know if you guys have any idea about these dependency issues.

Thank you !

@danielsdeleo
Copy link
Contributor

@siddheshwar-more the dependency issues are a separate bug. I think they're resolve by the pull requests @btm just linked. This bug is specifically for errors like

C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:198:in `rescue in try_activate': undefined method `activate' for nil:NilClass (NoMethodError)

And

/opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/specification.rb:762:in `block in _resort!': undefined method `name' for nil:NilClass (NoMethodError)
    from /opt/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/specification.rb:761:in `sort!'

@danielsdeleo
Copy link
Contributor

I've been trying to get more information about what's going on in rubygems here by doing ad-hoc Ci builds with a patched rubygems. See the last 2 commits on this: danielsdeleo/rubygems#1

@danielsdeleo
Copy link
Contributor

Also rubygems/rubygems#1287

@btm
Copy link
Contributor Author

btm commented Jun 29, 2015

On a fresh install of a chefdk 0.7 nightly, running chef gem install knife-windows -v 1.0.0.rc.1 --no-user-install produces a usable install of the knife windows plugin, tested using knife windows cert generate -H blah

@btm
Copy link
Contributor Author

btm commented Jun 29, 2015

edit, this message was from using 0.7.0rc, which was a different issue, filed as #443.

@btm
Copy link
Contributor Author

btm commented Jun 29, 2015

For google, this is the error you get with ChefDK 0.6.2, after you install knife-windows 1.0.0.rc.1 but you have not removed knife-windows 0.8.5:

PS C:\Users\btm_000> chef exec knife windows cert generate
C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:128:in `require': cannot load such file -- chef/knife/winrm_knife_base (LoadError)
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from C:/Users/btm_000/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.0.0.rc.1/lib/chef/knife/bootstrap_windows_winrm.rb:22:in `<top (required)>'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `block in load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `each'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:127:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:208:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/application/knife.rb:142:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/bin/knife:25:in `<top (required)>'
        from C:/opscode/chefdk/bin/knife:63:in `load'
        from C:/opscode/chefdk/bin/knife:63:in `<main>'

Then after I uninstall knife-windows 0.8.5 I get this which was the original error:

PS C:\Users\btm_000> chef exec knife windows cert generate
C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:198:in `rescue in try_activate': undefined method `activate' for nil:NilClass (NoMethodError)

        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems.rb:195:in `try_activate'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:126:in `rescue in require'
        from C:/opscode/chefdk/embedded/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from C:/Users/btm_000/.chefdk/gem/ruby/2.1.0/gems/knife-windows-1.0.0.rc.1/lib/chef/knife/bootstrap_windows_base.rb:22:in `<top (required)>'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `block in load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `each'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife/core/subcommand_loader.rb:44:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:127:in `load_commands'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:208:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/application/knife.rb:142:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/bin/knife:25:in `<top (required)>'
        from C:/opscode/chefdk/bin/knife:63:in `load'

@btm
Copy link
Contributor Author

btm commented Jun 29, 2015

irb(main):006:0> Gem::Specification.find_by_name("knife-windows")
=> nil
irb(main):007:0>  Gem::Specification.find_all_by_name("knife-windows")
=> [#<Gem::Specification:0x14dc618 knife-windows-1.0.0.rc.1>]

I guess find_by_name doesn't like prereleases? maybe unless you have a "gem" line specifying the prerelease? rubygems/rubygems@84e8d9f

irb(main):001:0> Gem::Specification.find_by_name("knife-windows")
=> #<Gem::Specification:0x1435ad0 knife-windows-100.0.0>

That nil for find_by_name is what's causing the exception. It doesn't seem like it's supposed to be expected behavior: rubygems/rubygems#988

@btm
Copy link
Contributor Author

btm commented Jun 29, 2015

Okay, this is all dependency issues, which one thing ChefDK 0.7.0 is meant to bump.

To get knife-windows 1.0.0+ working on ChefDK 0.6.2:

  1. chef gem install knife-windows --pre
  2. chef gem install chef-provisioning --pre
  3. Edit C:/opscode/chefdk/bin/chef and remove this line: gem "chef-provisioning", "= 1.1.1"

Ultimately there's still some kind of rubygems bug, because this was a really non-obvious path.

@btm btm closed this as completed Jun 29, 2015
jtimberman pushed a commit to chef-boneyard/pcb that referenced this issue Jul 7, 2015
There is a bug in the ChefDK release installed on the build nodes that
causes an exception when running the unit tests. Reference:

- chef-boneyard/chef-dk#411
- rubygems/rubygems#1287

We think we can run unit phase again after ChefDK 0.7.0 (final
release) is installed on the build nodes.
@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants