diff options
author | John Keiser <jkeiser@opscode.com> | 2013-05-19 22:35:37 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2013-06-07 13:12:34 -0700 |
commit | b908cc22ad1439f116967b729ae5f078585d91ee (patch) | |
tree | abcca45b94c8492e8a8472bd45bef0a32da8c19e /spec/support | |
parent | 92590696b7b11775850d0c1a025646f20c143f58 (diff) | |
download | chef-b908cc22ad1439f116967b729ae5f078585d91ee.tar.gz |
Set cache dir to tmp for systems where we don't own /var
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/shared/integration/knife_support.rb | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb index f041e4efef..7f4078f591 100644 --- a/spec/support/shared/integration/knife_support.rb +++ b/spec/support/shared/integration/knife_support.rb @@ -1,3 +1,4 @@ +require 'chef/config' require 'chef/knife' require 'chef/application/knife' require 'logger' @@ -18,43 +19,53 @@ module KnifeSupport # Make output stable Chef::Config[:concurrency] = 1 - # This is Chef::Knife.run without load_commands and load_deps--we'll - # load stuff ourselves, thank you very much - stdout = StringIO.new - stderr = StringIO.new - old_loggers = Chef::Log.loggers - old_log_level = Chef::Log.level - begin - puts "knife: #{args.join(' ')}" if DEBUG - subcommand_class = Chef::Knife.subcommand_class_from(args) - subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options) - instance = subcommand_class.new(args) - - # Capture stdout/stderr - instance.ui = Chef::Knife::UI.new(stdout, stderr, STDIN, {}) - - # Don't print stuff - Chef::Config[:verbosity] = ( DEBUG ? 2 : 0 ) - instance.configure_chef - logger = Logger.new(stderr) - logger.formatter = proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" } - Chef::Log.use_log_devices([logger]) - Chef::Log.level = ( DEBUG ? :debug : :warn ) - Chef::Log::Formatter.show_time = false - - instance.run - - exit_code = 0 - - # This is how rspec catches exit() - rescue SystemExit => e - exit_code = e.status - ensure - Chef::Log.use_log_devices(old_loggers) - Chef::Log.level = old_log_level - end + # Work on machines where we can't access /var + checksums_cache_dir = Dir.mktmpdir('checksums') do |checksums_cache_dir| + old_cache_options = Chef::Config[:cache_options] + Chef::Config[:cache_options] = { + :path => checksums_cache_dir, + :skip_expires => true + } + + # This is Chef::Knife.run without load_commands and load_deps--we'll + # load stuff ourselves, thank you very much + stdout = StringIO.new + stderr = StringIO.new + old_loggers = Chef::Log.loggers + old_log_level = Chef::Log.level + begin + puts "knife: #{args.join(' ')}" if DEBUG + subcommand_class = Chef::Knife.subcommand_class_from(args) + subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options) + instance = subcommand_class.new(args) + + # Capture stdout/stderr + instance.ui = Chef::Knife::UI.new(stdout, stderr, STDIN, {}) + + # Don't print stuff + Chef::Config[:verbosity] = ( DEBUG ? 2 : 0 ) + instance.configure_chef + logger = Logger.new(stderr) + logger.formatter = proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" } + Chef::Log.use_log_devices([logger]) + Chef::Log.level = ( DEBUG ? :debug : :warn ) + Chef::Log::Formatter.show_time = false + + instance.run + + exit_code = 0 + + # This is how rspec catches exit() + rescue SystemExit => e + exit_code = e.status + ensure + Chef::Log.use_log_devices(old_loggers) + Chef::Log.level = old_log_level + Chef::Config[:cache_options] = old_cache_options + end - KnifeResult.new(stdout.string, stderr.string, exit_code) + KnifeResult.new(stdout.string, stderr.string, exit_code) + end end private |