chef-cookbooks / runit

Development repository for the Chef Runit Cookbook
https://supermarket.chef.io/cookbooks/runit
Apache License 2.0
106 stars 197 forks source link

Runit-5.0.0 breaks chefspec tests #242

Closed Tetha closed 5 years ago

Tetha commented 5 years ago

Cookbook version

runit-5.0.0

Chef-client version

13.8.5

Platform Details

We're running these tests on Fedora 29 and Centos 7.x. Both tests run with the chefdk 2.5.3, which provides chef 13.8.5 and chefspec 7.1.2.

Scenario:

Our CI has picked up failing unit tests in our cookbooks. Practically, this has hit internal cookbooks depending on the jenkins cookbook first, since the jenkins cookbook uses the runit cookbook for service management. However, I've created a reproduction cookbook which uses runit alone.

Steps to Reproduce:

Create the following test cookbook:

# ./Berksfile
source 'https://supermarket.chef.io'
metadata
# ./metadata.rb
name 'runit-reproduction'
depends 'runit'
# ./recipes/default.rb
include_recipe 'runit::default'

runit_service 'jenkins' do
end
# ./test/spec/default_spec.rb
require 'chefspec'
require 'chefspec/berkshelf'

describe 'runit-reproduction::default' do
  context 'When all attributes are default, on CentOS 7.2.1511' do
    let(:chef_run) do
      runner = ChefSpec::SoloRunner.new(platform: 'centos', version: '7.2.1511')
      runner.converge(described_recipe)
    end

    it 'converges successfully' do
      expect { chef_run }.to_not raise_error
    end
  end
end

At this point, run chef exec berks install followed by chef exec rspec test/spec.

Expected Result:

I'd expect this minimal example to pass the tests, especially given that there are zero assertions.

Actual Result:

This exception occurs:

Failures:

  1) runit-reproduction::default When all attributes are default, on CentOS 7.2.1511 converges successfully
     Failure/Error: expect { chef_run }.to_not raise_error

       expected no Exception, got #<NoMethodError: undefined method `find_resource' for Chef::Resource::RunitService> with backtrace:
         # /tmp/d20190205-18041-a913l1/cookbooks/runit/libraries/resource_runit_service.rb:97:in `after_created'
         # /tmp/d20190205-18041-a913l1/cookbooks/runit-reproduction/recipes/default.rb:3:in `from_file'
         # ./test/spec/default_spec.rb:8:in `block (3 levels) in <top (required)>'
         # ./test/spec/default_spec.rb:12:in `block (4 levels) in <top (required)>'
         # ./test/spec/default_spec.rb:12:in `block (3 levels) in <top (required)>'
     # ./test/spec/default_spec.rb:12:in `block (3 levels) in <top (required)>'

Finished in 0.22391 seconds (files took 1.29 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./test/spec/default_spec.rb:11 # runit-reproduction::default When all attributes are default, on CentOS 7.2.1511 converges successfully

Am I missing something horrible here?

welcomebot commented 5 years ago

Hey There It looks like this is the first issue you've filed against the chef-cookbooks project. I'm here to offer you a bit of extra help to make sure we can quickly get back to you. Make sure you've filled out all the fields in our issue template. Make sure you've provided us with the version of chef-client you're running, your operating system and the version of the cookbook. If you're not using the most up to date version of the cookbook then please make sure to update first. Lots of things change between versions even if you're issue isn't listed in the changelog. Finally please give us a detailed description of the issue you're having. The more we know about what you're trying to do, what actually happens, and how you can reproduce the problem, the better.

If you're looking for more immediate troubleshooting help make sure to check out #general on the Chef Community Slack. There's plenty of folks there willing to lend a helping hand. Thanks for the first issue. We hope we can get back to you soon with a solution.

tas50 commented 5 years ago

@Tetha Any chance you can try this on the latest ChefSpec?

Tetha commented 5 years ago

Yeah sure, I'll do some digging tomorrow or thursday depending on the maintenance work tonight. It shouldn't take too much time switching between a couple of chefdks on a VM to see if a specific version of chefspec broke something. I just didn't have time for further digging today.

amcappelli commented 5 years ago

I am running into this same error with runit 5.0.0 using chef-client 13.8.5 (not chefspec)

Error Log & Stacktrace

undefined method `find_resource' for Chef::Resource::RunitService

Backtrace
----------------------------------------------------
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/resource.rb:1297:in `method_missing'
/var/chef/cache/cookbooks/runit/libraries/resource_runit_service.rb:97:in `after_created'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/resource_builder.rb:73:in `build'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/dsl/declare_resource.rb:293:in `build_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/dsl/declare_resource.rb:250:in `declare_resource'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/dsl/resources.rb:38:in `runit_service'
/var/chef/cache/cookbooks/jenkins/recipes/_master_war.rb:70:in `from_file'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/mixin/from_file.rb:30:in `instance_eval'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/mixin/from_file.rb:30:in `from_file'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/cookbook_version.rb:205:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/run_context.rb:342:in `load_recipe'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:163:in `block in compile_recipes'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:160:in `each'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:160:in `compile_recipes'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/run_context/cookbook_compiler.rb:77:in `compile'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/run_context.rb:191:in `load'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/policy_builder/expand_node_object.rb:97:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/client.rb:513:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/client.rb:281:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application.rb:292:in `block in fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application.rb:280:in `fork'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application.rb:280:in `fork_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application.rb:245:in `block in run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/local_mode.rb:44:in `with_server_connectivity'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application.rb:233:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application/client.rb:469:in `sleep_then_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application/client.rb:458:in `block in interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application/client.rb:457:in `loop'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application/client.rb:457:in `interval_run_chef_client'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application/client.rb:441:in `run_application'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/lib/chef/application.rb:59:in `run'
/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/chef-13.8.5/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:59:in `load'
/usr/bin/chef-client:59:in `<main>'
tas50 commented 5 years ago

The fix here is to either pin on the 4.0 cookbook or to upgrade ChefDK to the latest version. It turns out the old ChefSpec had some bugs and couldn't handle this resource.

amcappelli commented 5 years ago

it doesn't seem right to close this issue when it's affecting chef-client as well, not just chefspec. The changelog says This cookbook now requires Chef 13 or later which 13.8.5 falls under. What version is required for this to work properly?

tas50 commented 5 years ago

@amcappelli 🤦‍♂️ yep. This cookbook now requires Chef 14. I've updated the metadata and released a 5.0.1 release. You'll need to stick with the previous major release or upgrade your chef-client. Keep in mind that Chef 13 goes EOL the first week or April and won't get security updates or bug fixes after that date.