Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pick() to work with strict variables #890

Merged
merged 4 commits into from
Jun 22, 2018
Merged

Allow pick() to work with strict variables #890

merged 4 commits into from
Jun 22, 2018

Conversation

binford2k
Copy link
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.
# 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
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
Member

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

args = args.compact

# look up the values of any strings that look like '$variables'
args.map! do |item|
Copy link
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
Member

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

@david22swan david22swan merged commit 81b95de into puppetlabs:master Jun 22, 2018
Copy link
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
Contributor

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

@mwhahaha
Copy link
Contributor

revert #927

@mwhahaha
Copy link
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
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