sous-chefs / cron

Development repository for the cron cookbook
https://supermarket.chef.io/cookbooks/cron
Apache License 2.0
78 stars 100 forks source link

Unclean exit when duplicate resource names #58

Closed spuder closed 8 years ago

spuder commented 9 years ago

If you accidentally create two LWRP's with the same name, you get a cryptic message that is hard to troubleshoot.

It would be nice if the LWRP could detect the duplicate name, and error gracefully.

cron_d "foo" do
  minute '0'
  hour '1'
  command 'echo foo'
end

cron_d "foo" do
  minute '0'
  hour '1'
  command 'echo foo'
end
           ================================================================================
           Error executing action `create` on resource 'template[/etc/cron.d/compresss_kafka_controller_log]'
           ================================================================================

           Chef::Exceptions::ChecksumMismatch
           ----------------------------------
           Checksum on resource (cb551a) does not match checksum on content (9a41a2)

           Resource Declaration:
           ---------------------
           # In /tmp/kitchen/cookbooks/cron/providers/d.rb

            36:   t = template "/etc/cron.d/#{new_resource.name}" do
            37:     cookbook new_resource.cookbook
            38:     source 'cron.d.erb'

            40:     variables(
            41:                 :name => new_resource.name,
            42:                 :predefined_value => new_resource.predefined_value,
            43:                 :minute => new_resource.minute,
            44:                 :hour => new_resource.hour,
            45:                 :day => new_resource.day,
            46:                 :month => new_resource.month,
            47:                 :weekday => new_resource.weekday,
            48:                 :command => new_resource.command,
            49:                 :user => new_resource.user,
            50:                 :mailto => new_resource.mailto,
            51:                 :path => new_resource.path,
            52:                 :home => new_resource.home,
            53:                 :shell => new_resource.shell,
            54:                 :comment => new_resource.comment,
            55:                 :environment => new_resource.environment
            56:       )
            57:     action :create
            58:   end
            59:   new_resource.updated_by_last_action(t.updated_by_last_action?)

           Compiled Resource:
           ------------------
           # Declared in /tmp/kitchen/cookbooks/cron/providers/d.rb:36:in `block in class_from_file'

           template("/etc/cron.d/compresss_kafka_controller_log") do
             action [:create]
             updated true
             retries 0
             retry_delay 2
             default_guard_interpreter :default
             path "/etc/cron.d/compresss_kafka_controller_log"
             backup 5
             atomic_update true
             source "cron.d.erb"
             cookbook "cron"
             variables {:name=>"compresss_kafka_controller_log", :predefined_value=>nil, :minute=>"6", :hour=>"1", :day=>"*", :month=>"*", :weekday=>"*", :command=>"/usr/bin/find /var/log/kafka -type f -name \"kafka-controller.log.*.tar.gz\" -mtime +30 -exec /bin/rm {} \\;", :user=>"root", :mailto=>nil, :path=>nil, :home=>nil, :shell=>nil, :comment=>nil, :environment=>{}}
             declared_type :template
             cookbook_name :"ND-Kafka"
             mode "0644"
             checksum "cb551a64fc961957b39ad6f2c5fbaabe1bfecb9de8955c95dd9195764058b7fe"
             owner "root"

           end

       Running handlers:
       [2015-06-01T22:52:36+00:00] ERROR: Running exception handlers
       Running handlers complete

       [2015-06-01T22:52:36+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
       Chef Client failed. 4 resources updated in 1.078846308 seconds
       [2015-06-01T22:52:36+00:00] ERROR: template[/etc/cron.d/compresss_kafka_controller_log] (/tmp/kitchen/cookbooks/cron/providers/d.rb line 36) had an error: Chef::Exceptions::ChecksumMismatch: Checksum on resource (cb551a) does not match checksum on content (9a41a2)
       [2015-06-01T22:52:36+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
tas50 commented 8 years ago

This should no longer be an issue with the latest cookbook now that we enable the inline resources in chef 11+. Feel free to open it back up if you still see the problem though.