diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-01-27 09:58:10 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-01-27 09:58:10 -0800 |
commit | c3f1021fc6107808826461279cfd6eb055aa6162 (patch) | |
tree | 528219d477aed08ad1df1dcef5e831c5471bab6d | |
parent | 3f3fbc8fb5eddf5bea28699bee358c9fb2dabc17 (diff) | |
parent | f7b3e6a0c2d3fdbbe5479df1e540e15111dc931e (diff) | |
download | chef-c3f1021fc6107808826461279cfd6eb055aa6162.tar.gz |
Merge pull request #4409 from chef/lcg/suppress-reporter-failures
Lcg/suppress reporter failures
-rw-r--r-- | lib/chef/client.rb | 24 | ||||
-rw-r--r-- | spec/support/shared/context/client.rb | 6 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 2 |
3 files changed, 29 insertions, 3 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index a524a9cd54..65df62ae5b 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -97,6 +97,14 @@ class Chef attr_reader :rest # + # A rest object with validate_utf8 set to false. This will not throw exceptions + # on non-UTF8 strings in JSON but will sanitize them so that e.g. POSTs will + # never fail. Cannot be configured on a request-by-request basis, so we carry + # around another rest object for it. + # + attr_reader :rest_clean + + # # The runner used to converge. # # @return [Chef::Runner] @@ -385,13 +393,23 @@ class Chef end end + # Rest client for use by API reporters. This rest client will not fail with an exception if + # it is fed non-UTF8 data. + # + # @api private + def rest_clean(client_name=node_name, config=Chef::Config) + @rest_clean ||= + Chef::ServerAPI.new(config[:chef_server_url], client_name: client_name, + signing_key_filename: config[:client_key], validate_utf8: false) + end + # Resource reporters send event information back to the chef server for # processing. Can only be called after we have a @rest object # @api private def register_reporters [ - Chef::ResourceReporter.new(rest), - Chef::Audit::AuditReporter.new(rest), + Chef::ResourceReporter.new(rest_clean), + Chef::Audit::AuditReporter.new(rest_clean), ].each do |r| events.register(r) end @@ -603,6 +621,8 @@ class Chef # We now have the client key, and should use it from now on. @rest = Chef::ServerAPI.new(config[:chef_server_url], client_name: client_name, signing_key_filename: config[:client_key]) + # force initialization of the rest_clean API object + rest_clean(client_name, config) register_reporters rescue Exception => e # TODO this should probably only ever fire if we *started* registration. diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb index 2089928618..3c88e36fbb 100644 --- a/spec/support/shared/context/client.rb +++ b/spec/support/shared/context/client.rb @@ -71,6 +71,7 @@ shared_context "a client run" do let(:http_cookbook_sync) { double("Chef::ServerAPI (cookbook sync)") } let(:http_node_load) { double("Chef::ServerAPI (node)") } let(:http_node_save) { double("Chef::ServerAPI (node save)") } + let(:reporting_rest_client) { double("Chef::ServerAPI (reporting client)") } let(:runner) { instance_double("Chef::Runner") } let(:audit_runner) { instance_double("Chef::Audit::Runner", :failed? => false) } @@ -111,6 +112,10 @@ shared_context "a client run" do expect_any_instance_of(Chef::ResourceReporter).to receive(:node_load_completed) end + def stub_rest_clean + allow(client).to receive(:rest_clean).and_return(reporting_rest_client) + end + def stub_for_sync_cookbooks # --Client#setup_run_context # ---Client#sync_cookbooks -- downloads the list of cookbooks to sync @@ -147,6 +152,7 @@ shared_context "a client run" do stub_const("Chef::Client::STDOUT_FD", stdout) stub_const("Chef::Client::STDERR_FD", stderr) + stub_rest_clean stub_for_register stub_for_node_load stub_for_sync_cookbooks diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 60b274a774..4c15145527 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -2,7 +2,7 @@ # Author:: Adam Jacob (<adam@opscode.com>) # Author:: Tim Hinderliter (<tim@opscode.com>) # Author:: Christopher Walters (<cw@opscode.com>) -# Copyright:: Copyright 2008-2010 Opscode, Inc. +# Copyright:: Copyright 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); |