[PUP-4709] Square braces in title confuse puppet 4 parser Created: 2015/06/08  Updated: 2016/07/13  Resolved: 2015/06/11

Status: Closed
Project: Puppet
Component/s: None
Affects Version/s: None
Fix Version/s: PUP 4.2.0

Type: Bug Priority: Major
Reporter: Jonny (JT) Tripathy Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: 0 minutes
Time Spent: 10 minutes
Original Estimate: Not Specified

Issue Links:
Blocks
Relates
relates to MODULES-3472 inifile: 1.5.0 breaks backwards compa... Resolved
Template:
Story Points: 1
Sprint: Language 2015-06-10, Language 2015-06-24
Release Notes: Bug Fix

 Description   

If we have two resources where the titles begin with an identical string enclosed in square braces, the puppet 4 parser throws an error that duplicate resources have been declared:

extern% PUPPET_GEM_VERSION='~> 4.0' be puppet apply -e 'notify { "[foo] bar": } ; notify { "[foo] baz": }'
Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Notify[[foo] baz] is already declared in file :1; cannot redeclare at line 1  at line 1:27 on node extern.local

It works fine without the square braces however:

extern% PUPPET_GEM_VERSION='~> 4.0' be puppet apply -e 'notify { "foo bar": } ; notify { "foo baz": }'
Notice: Compiled catalog for extern.local in environment production in 0.48 seconds
Notice: foo bar
Notice: /Stage[main]/Main/Notify[foo bar]/message: defined 'message' as 'foo bar'
Notice: foo baz
Notice: /Stage[main]/Main/Notify[foo baz]/message: defined 'message' as 'foo baz'
Notice: Applied catalog in 0.02 seconds

An example of a unit test failure is in puppetlabs-inifile when run against Puppet 4: https://travis-ci.org/puppetlabs/puppetlabs-inifile/jobs/65406398

UPDATE & WORKAROUND

The problem can manifest itself in different ways - even if not getting the error "duplicate resource", the catalog will record the name wrong and it may not be able to later find it, if something else depends on that resource. The underlying problem is a bug in the parsing of a combined type/title as the first right bracket is believed to be the end of the string - e.g. Notify[[foo]bar] ends up as ["Notify", "[foo"] instead of the expected ["Notify", "[foo]bar"]. (In the reported case, both resource end up with the same title as the part after the first right bracket is lost. Other cases may be that the notify is just not found).

As a workaround until the fix is released, for notify instances it is possible to use a different title and instead set the message e.g.

notify {'_foo_bar': message = '[foo]bar' }; notify {'_foo_baz': message => '[foo]baz' }



 Comments   
Comment by Kurt Wall [ 2015/06/08 ]

I've confirmed this in master at SHA=ab1ea395a4ca9333d43a0e64ed47d24c93a816e4:

$ gl | head -n1
ab1ea39 Merge branch 'stable'
$ be puppet apply -e "notify {'[foo]bar':}; notify {'[foo]baz':}"
Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Notify[[foo]baz] is already declared in file :1; cannot redeclare at line 1  at line 1:23 on node breve.local

Comment by Henrik Lindberg [ 2015/06/08 ]

This works with 3.x. and --parser=future

Comment by Henrik Lindberg [ 2015/06/08 ]

This is caused by the method Puppet::Resource::Catalog.title_key_for_ref(title_string) in 4.x where it seems an optimization causes computation of the title key to be [Notify", "[foo"] because it does not balance the brackets!

Comment by Henrik Lindberg [ 2015/06/08 ]

I have a fix for this... PR coming

Comment by Henrik Lindberg [ 2015/06/09 ]

PR available. As a workaround until the fix is released, for notify instances it is possible to use a different title and instead set the message e.g.

notify {'_foo_bar': message = '[foo]bar' }; notify {'_foo_baz': message => '[foo]baz' }

With that in mind, I changed the severity of the ticket to "major".

Comment by Thomas Hallgren [ 2015/06/09 ]

Merged to stable at 4276d29.

Comment by Thomas Hallgren [ 2015/06/09 ]

Merged to master at 7988b07

Comment by Shaigy Nixon [X] (Inactive) [ 2015/06/11 ]

Validated on redhat-7-x86_64 on stable at http://builds.puppetlabs.lan/puppet-agent/ab115b9a582aedfec7f7f87bf737bd9d0db5f9df/

[root@b8aafaw162aadff ~]# puppet apply -e 'notify { "[foo] bar": } ; notify { "[foo] baz": }'
Notice: Compiled catalog for b8aafaw162aadff.delivery.puppetlabs.net in environment production in 0.37 seconds
Notice: [foo] bar
Notice: /Stage[main]/Main/Notify[[foo] bar]/message: defined 'message' as '[foo] bar'
Notice: [foo] baz
Notice: /Stage[main]/Main/Notify[[foo] baz]/message: defined 'message' as '[foo] baz'
Notice: Applied catalog in 0.04 seconds

Validated on redhat-7-x86_64 on http://builds.puppetlabs.lan/puppet-agent/df8786db8e1eb50e11cc0864c532ee7125d30fd6/

[root@ch5wm67af3t9fvm ~]# puppet apply -e "notify {'[foo]bar':}; notify {'[foo]baz':}"
Notice: Compiled catalog for ch5wm67af3t9fvm.delivery.puppetlabs.net in environment production in 0.35 seconds
Notice: [foo]bar
Notice: /Stage[main]/Main/Notify[[foo]bar]/message: defined 'message' as '[foo]bar'
Notice: [foo]baz
Notice: /Stage[main]/Main/Notify[[foo]baz]/message: defined 'message' as '[foo]baz'
Notice: Applied catalog in 0.02 seconds

Generated at Thu Jun 27 05:41:48 PDT 2019 using JIRA 7.7.1#77002-sha1:e75ca93d5574d9409c0630b81c894d9065296414.