Issue Details (XML | Word | Printable)

Key: OHAI-147
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Adam Jacob
Reporter: Joshua Timberman
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Ohai

exception on pretty_generate when specifying an attribute with json 1.2.0

Created: 01/Dec/09 11:54 PM   Updated: 28/Jan/10 01:31 AM   Resolved: 22/Jan/10 09:22 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 0.4.0


 Description  « Hide

$ ohai platform_version
/usr/lib/ruby/gems/1.8/gems/json-1.2.0/lib/json/common.rb:242:in `pretty_generate': only generation of JSON objects or arrays allowed (JSON::GeneratorError)
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/system.rb:215:in `attributes_print'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:93:in `run_application'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:92:in `each'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:92:in `run_application'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:67:in `run'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/bin/ohai:24
from /usr/bin/ohai:19:in `load'
from /usr/bin/ohai:19



Sort Order: Ascending order - Click to sort in descending order
Joshua Timberman added a comment - 01/Dec/09 11:55 PM

ohai w/o an attribute specified runs as normal.


Joshua Timberman added a comment - 09/Dec/09 05:15 PM

Additional information from an EC2 instance:

From chef run:
[Wed, 09 Dec 2009 17:03:09 +0000] ERROR: ArgumentError
[Wed, 09 Dec 2009 17:03:09 +0000] FATAL: Attribute domain is not defined!
/usr/lib/ruby/gems/1.8/gems/chef-0.8.0/bin/../lib/chef/node/attribute.rb:387:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.0/bin/../lib/chef/node.rb:247:in `send'
/usr/lib/ruby/gems/1.8/gems/chef-0.8.0/bin/../lib/chef/node.rb:247:in `method_missing'
/var/chef/cache/cookbooks/chef/attributes/chef.rb:57:in `from_file'

ubuntu@ip-10-243-31-223:~$ ohai | grep domain
"domain": "ec2.internal",
ubuntu@ip-10-243-31-223:~$ ohai domain
/usr/lib/ruby/gems/1.8/gems/json-1.2.0/lib/json/common.rb:242:in `pretty_generate': only generation of JSON objects or arrays allowed (JSON::GeneratorError)
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/system.rb:215:in `attributes_print'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:93:in `run_application'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:92:in `each'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:92:in `run_application'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/application.rb:67:in `run'
from /usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/bin/ohai:24
from /usr/bin/ohai:19:in `load'
from /usr/bin/ohai:19
ubuntu@ip-10-243-31-223:~$ irb -rrubygems -rohai -rjson
irb(main):001:0> o = Ohai::System.new
=> #<Ohai::System:0x7fe3b6b08cd0 @plugin_path="", @data={}, @providers={}, @seen_plugins={}>
irb(main):002:0> o.all_plugins
=> ["/usr/lib/ruby/gems/1.8/gems/ohai-0.3.6/lib/ohai/plugins"]
irb(main):003:0> o[:domain]
=> "ec2.internal"

chef/attributes/chef.rb:
set_unless[:chef][:server_fqdn] = domain ? "chef.#{domain}" : "chef"

ubuntu@ip-10-243-31-223:~$ gem list

      • LOCAL GEMS ***

abstract (1.0.0)
amqp (0.6.5)
chef (0.8.0)
deep_merge (0.1.0)
erubis (2.6.5)
eventmachine (0.12.10)
extlib (0.9.13)
json (1.2.0)
json_pure (1.2.0)
mixlib-authentication (1.0.0)
mixlib-cli (1.0.4)
mixlib-config (1.0.12)
mixlib-log (1.0.3)
moneta (0.6.0)
ohai (0.3.6)
ruby-hmac (0.3.2)
systemu (1.2.0)
thor (0.12.0)


Joshua Timberman added a comment - 23/Dec/09 11:42 PM

Until this bug is fixed, the resolution here for now is to downgrade JSON gems to 1.1.9:

% sudo gem install json json_pure -v 1.1.9 --no-ri --no-rdoc
Building native extensions. This could take a while...
Successfully installed json-1.1.9
Successfully installed json_pure-1.1.9
2 gems installed

% sudo gem uninstall json json_pure -v 1.2.0
Successfully uninstalled json-1.2.0
Successfully uninstalled json_pure-1.2.0

% sudo gem cleanup
Cleaning up installed gems...
Clean Up Complete

% ohai hostname
"webserver"


Sander van Zoest added a comment - 24/Dec/09 01:12 AM

I had this also pop up on a chef server:
/var/log/chef/server.log:
-------
~ Started request handling: Wed Dec 23 12:04:25 -0800 2009
~ Params: {"format"=>nil, "action"=>"show", "id"=>"mynode", "controller"=>"chef_server_slice/nodes"}
~ only generation of JSON objects or arrays allowed - (JSON::GeneratorError)
/usr/lib/ruby/gems/1.8/gems/json_pure-1.2.0/lib/json/common.rb:242:in `pretty_generate'
/usr/lib/ruby/gems/1.8/gems/chef-server-slice-0.7.16/app/helpers/application_helper.rb:105:in `append_tree'
---------


Joshua Timberman added a comment - 22/Jan/10 09:20 AM

When an attribute value is a string instead of an array or [hm]ash, the generator error occurs, as it is looking for this regular expression: /\A\s*(?:[.]|{.})\s*\Z/m - a string value won't match, so for example the following from irb:

% irb
irb(main):001:0> require 'ohai'
=> true
irb(main):002:0> o = Ohai::System.new
=> #<Ohai::System:0x1187788 @plugin_path="", @data={}, @providers={}, @seen_plugins={}>
irb(main):003:0> o.all_plugins
=> ["/Library/Ruby/Gems/1.8/gems/ohai-0.3.7/lib/ohai/plugins"]
irb(main):004:0> o.fqdn
=> "cider.local"
irb(main):005:0> JSON.pretty_generate(o.fqdn)
JSON::GeneratorError: only generation of JSON objects or arrays allowed
from /Library/Ruby/Gems/1.8/gems/json-2.0.0/lib/json/common.rb:261:in `generate'
from /Library/Ruby/Gems/1.8/gems/json-2.0.0/lib/json/common.rb:261:in `pretty_generate'
from (irb):5
irb(main):006:0> JSON.pretty_generate(o.fqdn.to_a)
=> "[\n \"cider.local\"\n]"


Joshua Timberman added a comment - 22/Jan/10 09:22 AM

Adam Jacob added a comment - 28/Jan/10 01:31 AM

Thanks for the fix, Joshua. Applied to opscode/master.