Search code examples
chef-infralwrp

Error with Custom LWRP when upgrading from Chef 12.3.0 to 12.7.2


I'd really appreciate if someone could explain to me why i'm having a specific issue with a custom LWRP i've created a while back.

With Chef 12.3.0, my custom LWRP attributes work perfectly fine defined this way:

attribute 'name',               'kind_of' => String, 'name_attribute' => true
attribute 'older_than',         'kind_of' => Integer, 'default' => 60
attribute 'cron_month',         'kind_of' => String, 'default' => '*'
attribute 'cron_day',           'kind_of' => String, 'default' => '*'
attribute 'cron_minute',        'kind_of' => String, 'default' => '1'
attribute 'cron_hour',          'kind_of' => String, 'default' => '3'
attribute 'log_file',           'kind_of' => String, 'default' => '/var/log/curator.log'
....

With Chef 12.7.2, Attempting to specify "properties" the same way causes the following error:

Chef::Exceptions::ValidationFailed
----------------------------------
Property older_than must be one of: {"kind_of"=>Integer, "default"=>60}!  You passed 7.

The LWRP properties (previously attributes) don't work when defined like the previous example. It appears symbols must be used instead of strings. If I covert the code to the following format, it works fine:

property 'name',               kind_of: String, name_attribute: true
property 'older_than',         kind_of: Integer, default: 60
property 'cron_month',         kind_of: String, default: '*'
property 'cron_day',           kind_of: String, default: '*'
property 'cron_minute',        kind_of: String, default: '1'
property 'cron_hour',          kind_of: String, default: '3'
property 'log_file',           kind_of: String, default: '/var/log/curator.log'
....

I can't seem to figure out why this is a problem nor can I find anything in the Chef changelog that would indicate this method of defining properties/attributes is no longer supported. From my understanding of Ruby, although I'm far from being an expert, strings can be used the place of symbols and vice versa. Is there a simple reason for this or is this potentially a bug in Chef?


Solution

  • As answered on IRC (please don't cross-post), the fact that strings used to work was accidental and was not part of the API. Using symbols for keyword arguments is the standard in Ruby and we adhere to that. This was probably changed in 12.5 when we rewrote the internals of resource property handling to be a bit more self-contained, along with introducing the new action-in-resource syntax and a few other things.