Skip to content

Commit eceebb7

Browse files
author
David Balatero
committed
* 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
1 parent 969a165 commit eceebb7

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

features/steps/run_client.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,11 @@
9898
# Then
9999
###
100100
Then /^the run should exit '(.+)'$/ do |exit_code|
101-
puts @status.inspect
102-
puts @status.exitstatus
101+
if ENV['LOG_LEVEL'] == 'debug'
102+
puts @status.inspect
103+
puts @status.exitstatus
104+
end
105+
103106
begin
104107
@status.exitstatus.should eql(exit_code.to_i)
105108
rescue

features/steps/run_solo.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This is kind of a crazy-ass setup, but it works.
2+
When /^I run chef-solo with the '(.+)' recipe$/ do |recipe_name|
3+
# Set up the JSON file with the recipe we want to run.
4+
dna_file = "/tmp/chef-solo-features-dna.json"
5+
File.open(dna_file, "w") do |fp|
6+
fp.write("{ \"recipes\": [\"#{recipe_name}\"] }")
7+
end
8+
9+
# Set up the cache dir.
10+
cache_dir = "/tmp/chef-solo-cache-features"
11+
result = `rm -fr #{cache_dir}; mkdir #{cache_dir}; chmod 777 #{cache_dir}`
12+
13+
# Cookbook dir
14+
cookbook_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'cookbooks'))
15+
result = `ln -sf #{cookbook_dir} #{cache_dir}/cookbooks`
16+
17+
# Config file
18+
config_file = "/tmp/chef-solo-config-features.rb"
19+
File.open(config_file, "w") do |fp|
20+
fp.write("file_cache_path \"#{cache_dir}\"\n")
21+
end
22+
23+
binary_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'chef', 'bin', 'chef-solo'))
24+
command = "#{binary_path} -c #{config_file} -j #{dna_file}"
25+
26+
# Run it
27+
puts "Running solo: #{command}" if ENV['LOG_LEVEL'] == 'debug'
28+
29+
status = Chef::Mixin::Command.popen4(command) do |p, i, o, e|
30+
@stdout = o.gets(nil)
31+
@stderr = o.gets(nil)
32+
end
33+
@status = status
34+
35+
print_output if ENV['LOG_LEVEL'] == 'debug'
36+
end

0 commit comments

Comments
 (0)