diff options
20 files changed, 48 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore index 30a3bd6531..ecba9f4030 100644 --- a/.gitignore +++ b/.gitignore @@ -39,5 +39,5 @@ Berksfile.lock Vagrantfile .vagrant/ -# Dev Repo Local Mode Data -dev-repo/nodes/* +# Kitchen Tests Local Mode Data +kitchen-tests/nodes/* diff --git a/dev-repo/README.md b/dev-repo/README.md deleted file mode 100644 index 84fe5f77df..0000000000 --- a/dev-repo/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Chef Developer Repo - -This repository contains some basic cookbooks to test chef while you're hacking away. You can provision a VM using the kitchen configuration and run these tests like below: - -``` -$ kitchen converge chef-ubuntu-1210 -$ kitchen login chef-ubuntu-1210 -$ export PATH=/opt/chef/bin:/opt/chef/embedded/bin:$PATH -$ cd ~/chef -$ bundle install -$ bundle exec chef-client -z -o "recipe[audit_test::default]" -c dev-repo/dev-config.rb - -``` diff --git a/dev-repo/dev-config.rb b/dev-repo/dev-config.rb deleted file mode 100644 index 4ac411c832..0000000000 --- a/dev-repo/dev-config.rb +++ /dev/null @@ -1,2 +0,0 @@ -cookbook_path "/home/vagrant/chef/dev-repo/cookbooks" -cache_path "/home/vagrant/.cache/chef" diff --git a/dev-repo/nodes/chef-ubuntu-1210.vagrantup.com.json b/dev-repo/nodes/chef-ubuntu-1210.vagrantup.com.json deleted file mode 100644 index 17e7b8d173..0000000000 --- a/dev-repo/nodes/chef-ubuntu-1210.vagrantup.com.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "chef-ubuntu-1210.vagrantup.com" -}
\ No newline at end of file diff --git a/kitchen-tests/.chef/client.rb b/kitchen-tests/.chef/client.rb index 5eb200a939..98f773d691 100644 --- a/kitchen-tests/.chef/client.rb +++ b/kitchen-tests/.chef/client.rb @@ -1,7 +1,8 @@ -chef_dir = File.expand_path(File.dirame(__FILE__)) -repo_dir = File.expand_path(Fild.join(chef_dir, '..')) +chef_dir = File.expand_path(File.dirname(__FILE__)) +repo_dir = File.expand_path(File.join(chef_dir, '..')) -log_level :info +log_level :info chef_repo_path repo_dir -local_mode true +local_mode true +cache_path "#{ENV['HOME']}/.cache/chef" diff --git a/dev-repo/cookbooks/audit_test/.gitignore b/kitchen-tests/cookbooks/audit_test/.gitignore index ec2a890bd3..ec2a890bd3 100644 --- a/dev-repo/cookbooks/audit_test/.gitignore +++ b/kitchen-tests/cookbooks/audit_test/.gitignore diff --git a/dev-repo/cookbooks/audit_test/.kitchen.yml b/kitchen-tests/cookbooks/audit_test/.kitchen.yml index 3775752da2..3775752da2 100644 --- a/dev-repo/cookbooks/audit_test/.kitchen.yml +++ b/kitchen-tests/cookbooks/audit_test/.kitchen.yml diff --git a/dev-repo/cookbooks/audit_test/Berksfile b/kitchen-tests/cookbooks/audit_test/Berksfile index 0ac9b78cf7..0ac9b78cf7 100644 --- a/dev-repo/cookbooks/audit_test/Berksfile +++ b/kitchen-tests/cookbooks/audit_test/Berksfile diff --git a/dev-repo/cookbooks/audit_test/README.md b/kitchen-tests/cookbooks/audit_test/README.md index 31fb97a12d..31fb97a12d 100644 --- a/dev-repo/cookbooks/audit_test/README.md +++ b/kitchen-tests/cookbooks/audit_test/README.md diff --git a/dev-repo/cookbooks/audit_test/chefignore b/kitchen-tests/cookbooks/audit_test/chefignore index 80dc2d20ef..80dc2d20ef 100644 --- a/dev-repo/cookbooks/audit_test/chefignore +++ b/kitchen-tests/cookbooks/audit_test/chefignore diff --git a/dev-repo/cookbooks/audit_test/metadata.rb b/kitchen-tests/cookbooks/audit_test/metadata.rb index 4a60104e92..4a60104e92 100644 --- a/dev-repo/cookbooks/audit_test/metadata.rb +++ b/kitchen-tests/cookbooks/audit_test/metadata.rb diff --git a/dev-repo/cookbooks/audit_test/recipes/default.rb b/kitchen-tests/cookbooks/audit_test/recipes/default.rb index f02f24c2c9..f02f24c2c9 100644 --- a/dev-repo/cookbooks/audit_test/recipes/default.rb +++ b/kitchen-tests/cookbooks/audit_test/recipes/default.rb diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb index b1c9d30bfc..a671ce2221 100644 --- a/lib/chef/audit/audit_reporter.rb +++ b/lib/chef/audit/audit_reporter.rb @@ -53,15 +53,9 @@ class Chef post_auditing_data end - # If the audit phase failed, its because there was some kind of error in the framework - # that runs tests - normal errors are interpreted as EXAMPLE failures and captured. def audit_phase_failed(error) - # The stacktrace information has already been logged elsewhere - Chef::Log.error("Audit Reporter failed - sending error to server with available example information") - ordered_control_groups.each do |name, control_group| - audit_data.add_control_group(control_group) - end - post_auditing_data(error) + # TODO + raise error end def control_group_started(name) @@ -87,16 +81,13 @@ class Chef private - def post_auditing_data(error = nil) + def post_auditing_data if auditing_enabled? - audit_history_url = "controls" - Chef::Log.info("Sending audit report (run-id: #{audit_data.run_id})") + node_name = audit_data.node_name + run_id = audit_data.run_id + audit_history_url = "audits/nodes/#{node_name}/runs/#{run_id}" + Chef::Log.info("Sending audit report (run-id: #{run_id})") run_data = audit_data.to_hash - - if error - run_data[:error] = "#{error.class.to_s}: #{error.message}\n#{error.backtrace.join("\n")}" - end - Chef::Log.debug run_data.inspect compressed_data = encode_gzip(Chef::JSONCompat.to_json(run_data)) Chef::Log.debug("Sending compressed audit data...") diff --git a/lib/chef/audit/rspec_formatter.rb b/lib/chef/audit/rspec_formatter.rb new file mode 100644 index 0000000000..990c1cd780 --- /dev/null +++ b/lib/chef/audit/rspec_formatter.rb @@ -0,0 +1,19 @@ +require 'rspec/core' + +class Chef + class Audit + class RspecFormatter < RSpec::Core::Formatters::DocumentationFormatter + RSpec::Core::Formatters.register self, :close + + # @api public + # + # Invoked at the very end, `close` allows the formatter to clean + # up resources, e.g. open streams, etc. + # + # @param _notification [NullNotification] (Ignored) + def close(_notification) + # Normally Rspec closes the streams it's given. We don't want it for Chef. + end + end + end +end diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb index 4059741359..e20c8b3810 100644 --- a/lib/chef/audit/runner.rb +++ b/lib/chef/audit/runner.rb @@ -71,7 +71,6 @@ class Chef configuration.backtrace_exclusion_patterns.push(Regexp.new("/Users".gsub("/", File::SEPARATOR))) configuration.backtrace_exclusion_patterns.push(Regexp.new("(eval)")) configuration.color = Chef::Config[:color] - configuration.expose_dsl_globally = false add_formatters disable_should_syntax diff --git a/lib/chef/client.rb b/lib/chef/client.rb index b27a2b693d..8cadd43878 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -330,7 +330,6 @@ class Chef runner.converge @events.converge_complete rescue Exception => e - Chef::Log.error("Converge failed with error message #{e.message}") @events.converge_failed(e) converge_exception = e end @@ -351,16 +350,15 @@ class Chef converge_exception end + # TODO are failed audits going to raise exceptions, or only be handled by the reporters? def run_audits(run_context) audit_exception = nil begin @events.audit_phase_start(run_status) - Chef::Log.info("Starting audit phase") auditor = Chef::Audit::Runner.new(run_context) auditor.run @events.audit_phase_complete rescue Exception => e - Chef::Log.error("Audit phase failed with error message #{e.message}") @events.audit_phase_failed(e) audit_exception = e end @@ -441,8 +439,8 @@ class Chef run_context = setup_run_context - converge_error = converge_and_save(run_context) unless (Chef::Config[:audit_mode] == true) - audit_error = run_audits(run_context) unless (Chef::Config[:audit_mode] == false) + converge_error = converge_and_save(run_context) + audit_error = run_audits(run_context) if converge_error || audit_error e = Chef::Exceptions::RunFailedWrappingError.new(converge_error, audit_error) diff --git a/lib/chef/config.rb b/lib/chef/config.rb index 4b83a0eca3..be31be937a 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -320,6 +320,7 @@ class Chef default :ez, false default :enable_reporting, true default :enable_reporting_url_fatals, false + default :audit_mode, nil # Policyfile is an experimental feature where a node gets its run list and # cookbook version set from a single document on the server instead of diff --git a/lib/chef/monologger.rb b/lib/chef/monologger.rb index 464b21bdd3..f7d226f82e 100644 --- a/lib/chef/monologger.rb +++ b/lib/chef/monologger.rb @@ -1,5 +1,4 @@ require 'logger' - require 'pp' #== MonoLogger @@ -89,4 +88,3 @@ class MonoLogger < Logger end - diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 1816fc857d..a673f4aa58 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -20,7 +20,8 @@ # require 'uri' -require 'securerandom' +require 'zlib' +require 'chef/monkey_patches/securerandom' require 'chef/event_dispatch/base' class Chef diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 0999ae57c1..41fd11e6eb 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -18,6 +18,7 @@ # limitations under the License. require 'chef/resource_collection' +require 'chef/provider_resolver' require 'chef/cookbook_version' require 'chef/node' require 'chef/role' @@ -53,6 +54,9 @@ class Chef # The list of control groups to execute during the audit phase attr_accessor :controls_groups + # Chef::ProviderResolver for this run + attr_accessor :provider_resolver + # A Hash containing the immediate notifications triggered by resources # during the converge phase of the chef run. attr_accessor :immediate_notification_collection @@ -87,6 +91,7 @@ class Chef @node.run_context = self @cookbook_compiler = nil + @provider_resolver = Chef::ProviderResolver.new(@node) end # Triggers the compile phase of the chef run. Implemented by @@ -104,7 +109,7 @@ class Chef if nr.instance_of?(Chef::Resource) @immediate_notification_collection[nr.name] << notification else - @immediate_notification_collection[nr.declared_key] << notification + @immediate_notification_collection[nr.to_s] << notification end end @@ -115,7 +120,7 @@ class Chef if nr.instance_of?(Chef::Resource) @delayed_notification_collection[nr.name] << notification else - @delayed_notification_collection[nr.declared_key] << notification + @delayed_notification_collection[nr.to_s] << notification end end @@ -123,7 +128,7 @@ class Chef if resource.instance_of?(Chef::Resource) return @immediate_notification_collection[resource.name] else - return @immediate_notification_collection[resource.declared_key] + return @immediate_notification_collection[resource.to_s] end end @@ -131,7 +136,7 @@ class Chef if resource.instance_of?(Chef::Resource) return @delayed_notification_collection[resource.name] else - return @delayed_notification_collection[resource.declared_key] + return @delayed_notification_collection[resource.to_s] end end |