-
Notifications
You must be signed in to change notification settings - Fork 303
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
Check if $is_pe exists before using it #270
Conversation
$is_pe is not a standard fact, so the current code fails with strict_variables on.
|
@mhaskel @cmurphy This is to fix #261 (comment) |
|
+1 |
|
There has to be a better solution to this than sprinkling more |
|
Hopefully there is, I can't think of one right now. |
|
imo, it should be part of the language (even c99 got that by now;) that if (!foo) { /* error handling */ }if if $::is_pe {
# do stuff
}shows the intent of the programmer to check whether |
|
In Ruby, |
|
What if we use ping @hunner @mhaskel @cyberious |
|
@cmurphy I'm fine with |
If the system is not running PE, the $::is_pe fact will be undefined, causing errors when run under strict variables mode. This patch uses the getvar() function to look up the fact so that it won't fail if not defined. Alternative to puppetlabs#270 This should fix the broken CI for the postgresql module.
|
We've merged #273 which should fix the issue, so closing this one. |
|
LGTM, thanks |
|
Actually, this solution seems to fail with the future parser: |
|
@hlindberg Care to posit an opinion here? |
|
There is a method called A better solution in Puppet code is to use the |
|
The reason it fails with future parser is because it should fail. You cannot determine the existence by simply returning a value - so the function is flawed. |
|
@hlindberg so would you recommend using |
|
hm, so it requires turning on other options (structured_facts IIRC). So, maybe you end up with two problems instead of two. Let me look at the defined function.... |
|
The |
|
The code works for me on stable (3.7.5) - which puppet version was used when it failed? @raphink ? Going forward (from puppet 4.0) I think it is best to use Hope that helps. |
|
Reverted #273 in order to merge this. |
Check if $is_pe exists before using it
|
There is yet another option, which is to provide an |
|
Or yet another possibility: keep all PE specific logic out of concat and use parameters+defaults to setup concat in PE. |
|
@hlindberg going forward, with puppet 4 being strict by default, i think we really need a workable solution for this pattern. i agree with @daenney that sprinkling our code with |
|
@igalic Puppet 4.0 does not have strict variables turned on by default - it is recommended to turn it on if you can, but generally too many existing modules break if it is on by default. When you say "native to puppet" what do you mean? Do you want an operator for this purpose? Since the only really valid use case is to check if a fact is present then this should be done with The other use case is to mix in arbitrary data, that should be done with data in modules and looked up, not by checking if a variable is defined or not. |
|
Upon thinking about it more, I really wonder if it is relevant to have PE-specific settings in generic modules like |
|
@raphink I think you are on to something there - having a module that depends on a fact without introducing it or declaring a dependency on the module that introduces it is quite smelly. |
@hlindberg looking up an hash with a key that might not exist is acceptable (and even encouraged) in the puppet ecosystem ? |
|
@PierreR How can anyone like that ? :) |
|
The convention that it is ok to lookup and get nil/undef/null/unit (or however undefined is encoded) is common in many programming languages for an open ended construct such as a Hash. If it feels smelly that keys may be missing, then do a type assertion on the Hash using the Puppet type Struct before accessing keys. |
|
@hlindberg Only joking ;) It turns out that missing keys are always a bug in my manifests, but I understand it's very different for other people. |
Sorry in advance for expressing my personal opinion here ;-) As a specialized DSL I would expect Puppet to be closer to the end user than the library authors. In that spirit the most logical default for Instead we force the end user to write expensive behavior tests so that they can get a minimum of confidence from their manifest (or we ask him to use a rather involved new syntax If you look at it, many current usage of this idiom come (from library authors) out of laziness (the feature is half baked downstream) or out of a lack of a better solution (another primitive function that would silently fail when it is really what you want to do). Anyhow thanks for the feedback. I do understand that such a change would break compatibility and might not be suitable, at least now. |
You're mix-matching user as in 'end user of the module' and library author/developer across your argument which makes it rather difficult to follow what you mean. As far as |
|
I think the meaning of @PierreR is that you are forced to choose between brittle and verbose for no perceived gain. I personally never took advantage of the fact that you silently get |
|
i very, very, very frequently use # Aggressive network behaviour: Use multiple TCP connections when
# writing archives. Use of this option is recommended only in
# cases where TCP congestion control is known to be the limiting
# factor in upload performance.
<%- if @aggresssive_networking.nil? -%>
#aggressive-networking
<%- elsif !@aggressive_networking -%>
no-aggressive-networking
<%- else -%>
aggressive-networking
<%- end -%>to only render absolutely minimal changes in files. |
If the system is not running PE, the $::is_pe fact will be undefined, causing errors when run under strict variables mode. This patch uses the getvar() function to look up the fact so that it won't fail if not defined. Alternative to puppetlabs/puppetlabs-concat#270 This should fix the broken CI for the postgresql module.
$is_pe is not a standard fact, so the
current code fails with strict_variables on.