From eceebb76d74a07039d68231c669ea82913cff3bc Mon Sep 17 00:00:00 2001 From: David Balatero Date: Fri, 1 May 2009 15:49:23 -0700 Subject: * Made some annoying print statements only occur in ENV['LOG_LEVEL'] == "debug" for run_client.rb * Added the ability to run chef-solo in Cucumber tests for more lightweight features --- features/steps/run_client.rb | 7 +++++-- features/steps/run_solo.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 features/steps/run_solo.rb diff --git a/features/steps/run_client.rb b/features/steps/run_client.rb index 62249daa7d..0fdf6663be 100644 --- a/features/steps/run_client.rb +++ b/features/steps/run_client.rb @@ -98,8 +98,11 @@ end # Then ### Then /^the run should exit '(.+)'$/ do |exit_code| - puts @status.inspect - puts @status.exitstatus + if ENV['LOG_LEVEL'] == 'debug' + puts @status.inspect + puts @status.exitstatus + end + begin @status.exitstatus.should eql(exit_code.to_i) rescue diff --git a/features/steps/run_solo.rb b/features/steps/run_solo.rb new file mode 100644 index 0000000000..f31749f524 --- /dev/null +++ b/features/steps/run_solo.rb @@ -0,0 +1,36 @@ +# This is kind of a crazy-ass setup, but it works. +When /^I run chef-solo with the '(.+)' recipe$/ do |recipe_name| + # Set up the JSON file with the recipe we want to run. + dna_file = "/tmp/chef-solo-features-dna.json" + File.open(dna_file, "w") do |fp| + fp.write("{ \"recipes\": [\"#{recipe_name}\"] }") + end + + # Set up the cache dir. + cache_dir = "/tmp/chef-solo-cache-features" + result = `rm -fr #{cache_dir}; mkdir #{cache_dir}; chmod 777 #{cache_dir}` + + # Cookbook dir + cookbook_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'cookbooks')) + result = `ln -sf #{cookbook_dir} #{cache_dir}/cookbooks` + + # Config file + config_file = "/tmp/chef-solo-config-features.rb" + File.open(config_file, "w") do |fp| + fp.write("file_cache_path \"#{cache_dir}\"\n") + end + + binary_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'chef', 'bin', 'chef-solo')) + command = "#{binary_path} -c #{config_file} -j #{dna_file}" + + # Run it + puts "Running solo: #{command}" if ENV['LOG_LEVEL'] == 'debug' + + status = Chef::Mixin::Command.popen4(command) do |p, i, o, e| + @stdout = o.gets(nil) + @stderr = o.gets(nil) + end + @status = status + + print_output if ENV['LOG_LEVEL'] == 'debug' +end -- cgit v1.2.1