sous-chefs / chef-splunk

Development repository for the chef-splunk cookbook
https://supermarket.chef.io/cookbooks/chef-splunk
Apache License 2.0
75 stars 122 forks source link

undefined local variable or method `node' for Chef::Provider::Service::Systemd:Class #212

Closed ecottom closed 3 years ago

ecottom commented 3 years ago

Brief Description

Any service resource with this cookbook as a dependency that is not action nothing throws NameError undefined local variable or method 'node' for Chef::Provider::Service::Systemd:Class

Potential Cause

systemd? in Chef::Provider::Service::Systemd:Class seem to conflict with ::ChefSplunk::Helpers.systemd?.

Steps To Reproduce

Run the following recipe with chef-splunk as a dependency on rhel8 with chef-client v17.1.35

service 'chronyd' do
  action :stop
end

service 'chronyd' do
  action :start
end

Chef Run Output

       Recipe: test::default
         * service[chronyd] action stop

           ================================================================================
           Error executing action `stop` on resource 'service[chronyd]'
           ================================================================================

           NameError
           ---------
           undefined local variable or method `node' for Chef::Provider::Service::Systemd:Class

           Cookbook Trace: (most recent call first)
           ----------------------------------------
           /tmp/kitchen/cache/cookbooks/chef-splunk/libraries/helpers.rb:272:in `systemd?'

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cache/cookbooks/test/recipes/default.rb

             7: service 'chronyd' do
             8:   action :stop
             9: end
            10: 

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cache/cookbooks/test/recipes/default.rb:7:in `from_file'

           service("chronyd") do
             action [:stop]
             default_guard_interpreter :default
             declared_type :service
             cookbook_name "test"
             recipe_name "default"
             supports {:restart=>nil, :reload=>nil, :status=>nil}
           end

           System Info:
           ------------
           chef_version=17.1.35
           platform=redhat
           platform_version=7.9
           ruby=ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
           program_name=/opt/chef/bin/chef-client
           executable=/opt/chef/bin/chef-client

       Running handlers:
       [2021-06-08T15:39:18-04:00] ERROR: Running exception handlers
       Running handlers complete
       [2021-06-08T15:39:18-04:00] ERROR: Exception handlers complete
       Chef Infra Client failed. 0 resources updated in 04 seconds
       [2021-06-08T15:39:18-04:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       [2021-06-08T15:39:18-04:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2021-06-08T15:39:18-04:00] FATAL: NameError: service[chronyd] (test::default line 7) had an error: NameError: undefined local variable or method `node' for Chef::Provider::Service::Systemd:Class
eheydrick commented 3 years ago

I think chef-splunk's systemd? helper should be removed in favor of the one included with chef-client. In the meantime there is a workaround over at https://github.com/chef/chef/issues/11528#issuecomment-833701887.

haidangwa commented 3 years ago

Although, chef-splunk's metadata states chef_version, >= 13, this declaration hadn't been updated for a long time and was made long before Chef 17 was released. This issue and a few other issues should be taken up as a single PR in chef-splunk to upgrade the cookbook for chef17, IMHO.

eheydrick commented 3 years ago

I think this can be closed now that 8.0.0 is out with the systemd? helper removed.