-
Notifications
You must be signed in to change notification settings - Fork 40
Conversation
|
I need to edit this a little more... |
8c5d9ae
to
0b61c17
Compare
|
Something is off with my testing here... |
|
This error from Onceover is what I am trying to fix here. I am creating the list of masters and pdb servers via this in my manifest: $master_query = "inventory[certname] {
facts.classification.stage = '${facts['classification']['stage']}' and
resources {
type = 'Class' and
title = 'Profile::Pe::Master'
}
}"
$masters = puppetdb_query($master_query).map |$value| { $value["certname"] }
$mom_query = "inventory[certname] {
facts.classification.stage = '${facts['classification']['stage']}' and
resources {
type = 'Class' and
title = 'Profile::Pe::Mom'
}
}"
$moms = puppetdb_query($mom_query).map |$value| { $value["certname"] }In my Onceover test run those pdb queries but naturally don't find anything... I thought this was retuning an empty array but I guess something else is going on :( The same code works fine in production when pdb actually returns stuff. |
|
That is pretty weird. I am not sure how I suspect removing the This is given that |
|
Coincidently, I'd convert that Then, when you run the test you'll be able to see if it's picking up the right code by looking at the line number. |
|
(I have tracked down waaayy too many bugs in PHP code by adding lines to change the line number in the error message. (Sometimes I would get a line number, but not a file name.)) |
|
@genebean I had a moment to look into this this morning. Based on the output from onceover it looks like the code is calling the new unique function that we added in PUP-7620. You can see your output is hitting the code block here: I'm not sure how to solve this yet, though. I'm not familiar with onceover, would it somehow prefer the "native" unique function over the stdlib one? (I'm assuming when you run this in a puppet environment it uses the stdlib function still) |
|
Guess that is why namespacing is important @suckatrash ... too bad the stdlib one is not namespaced by default |
0a5ebc2
to
4212d11
Compare
The unless broke if an empty array was passed in. Also accounted for empty arrays before running unique against it.
4212d11
to
687c019
Compare
|
The oneceover issue was a PEBKAC one... aka, a local testing goof. This version passes tests. |
|
@genebean @danielparks Is there really anything to fix here? If the new unique function returns undef when passed an empty array, then that's a breaking change that will be introduced when the stdlib function is deprecated. I think we should submit a PUP ticket for that. I can pass an empty array to the (current) template and it will compile without errors as long as I use the stdlib function. |
|
@suckatrash We can't assume the user will be using the stdlib version though as best as I can tell. The module needs to work regardless of which is used, right? |
|
Oh, and that pebkac was just for the local onceover testing. |
|
Thanks! |
| @@ -12,15 +12,18 @@ | |||
| Array $master_list | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this Array[String] to avoid having to deal with bad stuff in the $master_list (later there are calls to split which will fail if there is garbage in $master_list
|
|
||
| $unique_serverarray = unique($serverarray) | ||
| if length(delete_undef_values($serverarray)) > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is meaningless if typing the input as suggested above, and you know that the map function called above always returns an Array because the input to it is known to be Array[String].
The only thing that can happen is that the input can be empty, in which case the $unique_serverarray is also empty.
Also, note that the removal of any undef values in $serverarray on this line does not alter the $serverarray, it just affects the calculated length, so below, the call to unique could return a set that incudes undef when
there is no protection against that from the start.
You can write the entire thing (lines 15-26) like this:
$unique_serverarray = $master_list.map |$host| {
$split = $host.split("[.]")
$server_tag = $split.map | $x | { "server" }.join('.')
$wildcards = $split.map | $x | { "*" }.join('.')
"puppetlabs.${wildcards}.placeholder .${server_tag}.measurement*"
}.unique()
The unless broke if an empty array was passed in. The modifications are per recommendations from @danielparks