1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# 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 = "#{tmpdir}/chef-solo-features-dna.json"
File.open(dna_file, "w") do |fp|
fp.write("{ \"run_list\": [\"#{recipe_name}\"] }")
end
cleanup_files << "#{tmpdir}/chef-solo-features-dna.json"
# Set up the cache dir.
cache_dir = "#{tmpdir}/chef-solo-cache-features"
system("mkdir -p #{cache_dir}")
cleanup_dirs << cache_dir
# Cookbook dir
cookbook_dir ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'data', 'cookbooks'))
system("cp -r #{cookbook_dir} #{cache_dir}")
# Config file
config_file = "#{tmpdir}/chef-solo-config-features.rb"
File.open(config_file, "w") do |fp|
fp.write("cookbook_path \"#{cache_dir}/cookbooks\"\n")
fp.write("file_cache_path \"#{cache_dir}/cookbooks\"\n")
end
cleanup_files << config_file
binary_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'chef', 'bin', 'chef-solo'))
command = "#{binary_path} -c #{config_file} -j #{dna_file}"
command += " -l debug" if ENV['LOG_LEVEL'] == 'debug'
# 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
# This is kind of a crazy-ass setup, but it works.
When /^I run chef-solo without cookbooks$/ do
# Set up the cache dir.
cache_dir = "#{tmpdir}/chef-solo-cache-features"
system("mkdir -p #{cache_dir}")
cleanup_dirs << cache_dir
# Empty Cookbook dir
system("mkdir #{cache_dir}/cookbooks")
# Config file
config_file = "#{tmpdir}/chef-solo-config-features.rb"
File.open(config_file, "w") do |fp|
fp.write("cookbook_path \"#{cache_dir}/cookbooks\"\n")
fp.write("file_cache_path \"#{cache_dir}/cookbooks\"\n")
end
cleanup_files << config_file
binary_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'chef', 'bin', 'chef-solo'))
command = "#{binary_path} -c #{config_file}"
command += " -l debug" if ENV['LOG_LEVEL'] == 'debug'
# 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
|