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

yum.repo with should_not exist fails with NoMethodError: undefined method `[]' for nil:NilClass #1553

Closed
shoekstra opened this issue Mar 9, 2017 · 2 comments
Labels
Type: Bug Feature not working as expected

Comments

@shoekstra
Copy link
Contributor

Description

While converting a cookbook from Serverspec to Inspec I found testing for a yum repo using yum.repo that does not exist causes Inspec to break.

InSpec and Platform Version

1.11.0 (ChefDK 1.2.22)

Replication Case

Using the original resource from my serverspec test:

File:

describe yumrepo('internal') do
  it { should exist }
  it { should be_enabled }
end

describe yumrepo('epel') do
  it { should_not exist }
end

Output:

[DEPRECATION] `yumrepo(reponame)` is deprecated.  Please use `yum.repo(reponame)` instead.
[DEPRECATION] `yumrepo(reponame)` is deprecated.  Please use `yum.repo(reponame)` instead.
[DEPRECATION] `yumrepo(reponame)` is deprecated.  Please use `yum.repo(reponame)` instead.

Target:  docker://6f0853576e7fe411561c21959ea58963057ae63da3a7b539bda877bba8bd8933


  Yum Repository
     ✔  should exist
     ✔  should be enabled
  Yum Repository
     ✔  should not exist

Test Summary: 3 successful, 0 failures, 0 skipped

Using the new yum.repo('name') format.

File:

describe yum.repo('internal') do
  it { should exist }
  it { should be_enabled }
end

describe yum.repo('epel') do
  it { should_not exist }
end

Output:

[root@localhost /]# inspec exec test.rb
/opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/resources/yum.rb:139:in `to_s': undefined method `[]' for nil:NilClass (NoMethodError)
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/metadata.rb:180:in `build_description_from'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/metadata.rb:133:in `populate'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/metadata.rb:258:in `create'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:420:in `set_it_up'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:384:in `subclass'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/rspec-core-3.5.4/lib/rspec/core/example_group.rb:258:in `block in define_example_group_method'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner_rspec.rb:27:in `example_group'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:238:in `get_check_example'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:264:in `block in register_rule'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:263:in `each'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:263:in `flat_map'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:263:in `register_rule'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:94:in `block in load'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:93:in `each'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:93:in `load'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/runner.rb:100:in `run'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/base_cli.rb:82:in `run_tests'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/inspec/cli.rb:158:in `exec'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
        from /opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/bin/inspec:12:in `<top (required)>'
        from /usr/bin/inspec:22:in `load'
        from /usr/bin/inspec:22:in `<main>'

Confirmed using the shell:

inspec> describe yumrepo('epel') do
inspec>   it { should_not exist }
inspec> end
[DEPRECATION] `yumrepo(reponame)` is deprecated.  Please use `yum.repo(reponame)` instead.

Profile: inspec-shell
Version: (not specified)

  Yum Repository
     ✔  should not exist

Test Summary: 1 successful, 0 failures, 0 skipped

inspec> describe yum.repo('epel') do
inspec>   it { should_not exist }
inspec> end
after_eval hook failed: NoMethodError: undefined method `[]' for nil:NilClass
/opt/inspec/embedded/lib/ruby/gems/2.3.0/gems/inspec-1.16.1/lib/resources/yum.rb:139:in `to_s'
(see _pry_.hooks.errors to debug)
@adamleff
Copy link
Contributor

@shoekstra thanks for submitting this issue, and for your patience! I have submitted PR #1593 to fix this problem.

@adamleff adamleff added the Type: Bug Feature not working as expected label Mar 24, 2017
@shoekstra
Copy link
Contributor Author

@adamleff no worries, looks good! Thanks for picking this up 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Feature not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants