-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
(PUP-10861) Don't JSON.dump single fact values #8500
(PUP-10861) Don't JSON.dump single fact values #8500
Conversation
Use squiggly heredoc so it's clearer what output we're expecting.
result | ||
else | ||
Puppet::Util::Json.dump(result, :pretty => true) | ||
end |
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.
It looks like facter can emit [Integer, Float, TrueClass, FalseClass, NilClass, Symbol, String, Array, Hash]
, so I'm thinking we only want to call Json.dump
for Array
and Hash
, and rely on to_s
for the other types?
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.
@joshcooper I think for NilClass
JSON.dump
and to_s
behave differently
JSON.dump(nil) #=> "null"
nil.to_s #=> ""
But i'm not sure if Facter will return any nil
value, or it will convert it before.
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.
Facter can return nil
, so I updated this (including other types in https://github.com/puppetlabs/facter/blob/0654f8f6858ca0163680b3d8dfc53d90345f0f35/lib/facter/custom_facts/util/normalization.rb#L8)
I filed https://tickets.puppetlabs.com/browse/FACT-2930 as it seems facter can emit a Date
(which seems like a mistake), but the error message about VALID_TYPES
is inconsistent.
6c53d26
to
60d0d22
Compare
grr... JRuby output is different, I'll update that. |
The `puppet facts show --value-only` option prints just the value for a single fact. Previously, the value was pretty printed using JSON.dump, which emitted a quoted string. Now just print the string, so that the value can be parsed via automation, like export OSFAMILY=`puppet facts show os.family --value-only` Also add a test for multiple fact names as the `--value-only` option.
60d0d22
to
0de8cfc
Compare
@joshcooper Differing output may be grounds for a JRuby bug. If whatever it was seems like it should match CRuby, could you please open a JRuby issue? https://github.com/jruby/jruby/issues |
Thanks @headius! FWIW, JRuby output has an extra empty line when pretty printing, but the output is still correct, so I think it's ok? If you want it to be exactly the same, I can file a ticket?
|
@joshcooper Aha, now that does ring a bell.
So assuming this is the same issue, I think it will be resolved once the updated json gem is being used everywhere. |
JRuby 9.2.15.0 and 9.3.0.0 will ship the updated json. |
The
puppet facts show --value-only
option prints just the value for a singlefact. Previously, the value was pretty printed using JSON.dump, which emitted a
quoted string. Now just print the string, so that the value can be parsed via
automation, like export OSFAMILY=
puppet facts show os.family --value-only
Also add a test for multiple fact names as the
--value-only
option.