Skip to content

Allow pick() to work with strict variables#890

Merged
david22swan merged 4 commits intopuppetlabs:masterfrom
binford2k:pick_undefined_vars
Jun 22, 2018
Merged

Allow pick() to work with strict variables#890
david22swan merged 4 commits intopuppetlabs:masterfrom
binford2k:pick_undefined_vars

Conversation

@binford2k
Copy link
Copy Markdown
Contributor

If strict_variables is enabled, then the standard usage of pick()
will fail. This simply adds the calling convention that strings that
look like variables will be resolved if they exist and ignored if they
don't.

If `strict_variables` is enabled, then the standard usage of `pick()`
will fail. This simply adds the calling convention that strings that
look like variables will be resolved if they exist and ignored if they
don't.
Comment thread lib/puppet/parser/functions/pick.rb Outdated
# look up the values of any strings that look like '$variables'
args.map! do |item|
next unless item.is_a? String
item.start_with?('$') ? function_getvar([item.slice(1..-1)]) : item
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use call_function instead of calling with function_xxx as that only works for 3.x functions.

@david22swan
Copy link
Copy Markdown
Member

@hlindberg Are you satisfied that the changes that you requested have been made??

Comment thread lib/puppet/parser/functions/pick.rb Outdated
args = args.compact

# look up the values of any strings that look like '$variables'
args.map! do |item|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should absolutely not mutate the given args!! Must work on a copy. earlier the args.compact provided the copy now this logic will destroy the caller's array of arguments.

@david22swan
Copy link
Copy Markdown
Member

@binford2k This is currently failing unit and syntax test's

@david22swan david22swan merged commit 81b95de into puppetlabs:master Jun 22, 2018
Copy link
Copy Markdown
Contributor

@mwhahaha mwhahaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to breaks the pick function if you're using '$variable' as a string option. https://bugs.launchpad.net/tripleo/+bug/1778201

@hlindberg
Copy link
Copy Markdown
Contributor

sigh - I think this should be reverted as the change is not backwards compatible.

@mwhahaha
Copy link
Copy Markdown
Contributor

revert #927

@mwhahaha
Copy link
Copy Markdown
Contributor

Simple test to exhibit the issue is:

$g = pick('$something', '$somethingelse')

Will fail with,
Error: Evaluation Error: Error while evaluating a Function Call, pick(): must receive at least one non empty value at /home/aschultz/foo.pp:1:6 on node aschultz.localdomain

apevec pushed a commit to redhat-openstack/rdoinfo that referenced this pull request Jun 22, 2018
[1] is breaking TripleO deployments, see
https://bugs.launchpad.net/tripleo/+bug/1778201

[1] - puppetlabs/puppetlabs-stdlib#890

Change-Id: I7cb4eeb7360ac458803a2926bd15183f69f9a35e
@hlindberg
Copy link
Copy Markdown
Contributor

For those that want to avoid errors with strict variables, there are other functions to use besides pick. For example the getvar function which will return undef for a variable that does not exist - simply combine that with pick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants