berkshelf / ridley

A reliable Chef API client with a clean syntax
Other
231 stars 85 forks source link

Backtrace when using with chef-guard #308

Closed iroller closed 9 years ago

iroller commented 9 years ago

When making changes to chef-server with chef-guard installed you can get "Ridley::Errors::HTTPPreconditionFailed" produced by Chef-Guard to protect the server. For example:

=== Cookbook Constraints errors found ===
 - test version 0.0.1 needs to be frozen
=========================================

The issue is with useful error message I'm getting a huge traceback:

$ ./ridley.rb
/Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/middleware/chef_response.rb:24:in `on_complete':  (Ridley::Errors::HTTPPreconditionFailed)
=== Cookbook Constraints errors found ===
 - test version 0.0.1 needs to be frozen
=========================================

        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:9:in `block in call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:57:in `on_complete'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:8:in `call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:8:in `call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/response.rb:8:in `call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/middleware/chef_auth.rb:74:in `call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/request/retry.rb:110:in `call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/rack_builder.rb:139:in `build_response'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/connection.rb:377:in `run_request'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/connection.rb:106:in `run_request'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/faraday-0.9.1/lib/faraday/connection.rb:177:in `post'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:63:in `dispatch'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_thread.rb:21:in `block in create'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/thread_handle.rb:13:in `block in initialize'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor_system.rb:32:in `block in get_thread'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/internal_pool.rb:130:in `block in create'
        from (celluloid):0:in `remote procedure call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:92:in `value'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/proxies/sync_proxy.rb:33:in `method_missing'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/proxies/cell_proxy.rb:17:in `_send_'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/pool_manager.rb:41:in `_send_'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/pool_manager.rb:140:in `method_missing'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:63:in `dispatch'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
        from (celluloid):0:in `remote procedure call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:92:in `value'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/proxies/sync_proxy.rb:33:in `method_missing'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/resource.rb:132:in `raw_request'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/resource.rb:123:in `request'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/resource.rb:87:in `create'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:63:in `dispatch'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
        from (celluloid):0:in `remote procedure call'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/calls.rb:92:in `value'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/celluloid-0.16.0/lib/celluloid/proxies/sync_proxy.rb:33:in `method_missing'
        from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/chef_object.rb:65:in `save'
        from ./ridley.rb:11:in `<main>'

Script to reproduce (when chef-guard is installed):

#!/usr/bin/env ruby
require 'ridley'

Ridley.logger = nil
Celluloid.logger.level = ::Logger::ERROR

r = Ridley.new(server_url: 'https://chef', client_name: 'username', client_key: '/Users/username/.chef/username.pem')
e = r.environment.find('production')
e.cookbook_versions['test'] = '0.0.1'
e.save

It looks like setting Ridley.logger to nil here does nothing. Any other ways to reduce the output?

Versions:

    ridley (4.1.2)
    ridley-connectors (2.3.1)
reset commented 9 years ago

@iroller the important bit of the stacktrace is the exception thrown based on the response back from the API which is precondition failed and a message regarding a cookbook called "test". This is an issue with Chef Guard and not Ridley. I'd post this on their issue tracker and see what comes up!

iroller commented 9 years ago

@reset The exception is 100% fine and expected. It's described here:

Chef-Guard will return with a 412 Precondition Failed error and some additional details about the error.

The issue is the amount of extra output produced by ridley in this case.

When I try to pin the version in production env with knife I'm getting nice and clear output:

$ knife environment edit production
ERROR: Precondition Failed
Response:
=== Cookbook Constraints errors found ===
 - test version 0.0.1 needs to be frozen
=========================================
$

Also I've just tried to run my script in pry and it somehow suppresses the output too:

[14] pry(main)> e.save
Ridley::Errors::HTTPPreconditionFailed:
=== Cookbook Constraints errors found ===
 - test version 0.0.1 needs to be frozen
=========================================

from /Users/username/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/ridley-4.1.2/lib/ridley/middleware/chef_response.rb:24:in `on_complete'
[15] pry(main)>

Ideally I'd like to find a way to make it output the same amount of information knife outputs. Or at least make it as short as the output produced in pry.

Huge output makes it impossible to do scripting using ridley when using chef-guard.

reset commented 9 years ago

@iroller it's just a plain Ruby library so you can rescue the exception and format the output however you'd like

iroller commented 9 years ago

Oh, I need to go home and have a rest for a bit :tired_face: Thanks @reset

reset commented 9 years ago

No problem man :smile: