From 78f2a41e666ed7a81a3db443a995118d199ed0de Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 26 Mar 2015 15:12:12 -0700 Subject: [PATCH] Add more logging when keys are selected or corrupt --- lib/chef/provider/private_key.rb | 1 + lib/cheffish.rb | 18 ++++++++++-------- lib/cheffish/rspec/chef_run_wrapper.rb | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/chef/provider/private_key.rb b/lib/chef/provider/private_key.rb index 3a36b20..a1261da 100644 --- a/lib/chef/provider/private_key.rb +++ b/lib/chef/provider/private_key.rb @@ -209,6 +209,7 @@ def load_current_resource end rescue # If there's an error reading, we assume format and type are wrong and don't futz with them + Chef::Log.warn("Error reading #{new_path}: #{$!}") end else resource.action :delete diff --git a/lib/cheffish.rb b/lib/cheffish.rb index ae608e6..2331e1b 100644 --- a/lib/cheffish.rb +++ b/lib/cheffish.rb @@ -1,11 +1,3 @@ -require 'chef/run_list/run_list_item' -require 'cheffish/basic_chef_client' -require 'cheffish/server_api' -require 'chef/knife' -require 'chef/config_fetcher' -require 'chef/log' -require 'chef/application' - module Cheffish NAME_REGEX = /^[.\-[:alnum:]_]+$/ @@ -92,8 +84,10 @@ def self.get_private_key(name, config = profiled_config) def self.get_private_key_with_path(name, config = profiled_config) if config[:private_keys] && config[:private_keys][name] if config[:private_keys][name].is_a?(String) + Chef::Log.info("Got key #{name} from Chef::Config.private_keys.#{name}, which points at #{config[:private_keys[name]]}. Reading key from there ...") return [ IO.read(config[:private_keys][name]), config[:private_keys][name] ] else + Chef::Log.info("Got key #{name} raw from Chef::Config.private_keys.#{name}.") return [ config[:private_keys][name].to_pem, nil ] end elsif config[:private_key_paths] @@ -104,6 +98,7 @@ def self.get_private_key_with_path(name, config = profiled_config) if ext == '' || ext == '.pem' key_name = key[0..-(ext.length+1)] if key_name == name + Chef::Log.info("Reading key #{name} from file #{private_key_path}/#{key}") return [ IO.read("#{private_key_path}/#{key}"), "#{private_key_path}/#{key}" ] end end @@ -223,4 +218,11 @@ def remove_role(*roles) # Include all recipe objects so require 'cheffish' brings in the whole recipe DSL +require 'chef/run_list/run_list_item' +require 'cheffish/basic_chef_client' +require 'cheffish/server_api' +require 'chef/knife' +require 'chef/config_fetcher' +require 'chef/log' +require 'chef/application' require 'cheffish/recipe_dsl' diff --git a/lib/cheffish/rspec/chef_run_wrapper.rb b/lib/cheffish/rspec/chef_run_wrapper.rb index b57ed56..2c6987f 100644 --- a/lib/cheffish/rspec/chef_run_wrapper.rb +++ b/lib/cheffish/rspec/chef_run_wrapper.rb @@ -103,7 +103,7 @@ def output_for_failure_message message << "--- ---\n" message << "--- Chef Client Logs ---\n" message << "--- ---\n" - message << logs.string + message << logs end message end