|
23 | 23 |
|
24 | 24 | CHEF_CLIENT=File.join(CHEF_PROJECT_ROOT,"chef","bin","chef-client") |
25 | 25 |
|
| 26 | +defchef_client_command_string |
| 27 | +@log_level ||= ENV["LOG_LEVEL"] ? ENV["LOG_LEVEL"] : "error" |
| 28 | +@chef_args ||= "" |
| 29 | +@config_file ||= File.expand_path(File.join(configdir,'client.rb')) |
| 30 | + |
| 31 | +"#{File.join(File.dirname(__FILE__),"..","..","chef","bin","chef-client")} -l #{@log_level} -c #{@config_file}#{@chef_args}" |
| 32 | +end |
26 | 33 |
|
27 | 34 | ### |
28 | 35 | # When |
29 | 36 | ### |
30 | 37 | When/^I run the chef\-client$/do |
31 | | -@log_level ||= ENV["LOG_LEVEL"] ? ENV["LOG_LEVEL"] : "error" |
32 | | -@chef_args ||= "" |
33 | | -@config_file ||= File.expand_path(File.join(configdir,'client.rb')) |
34 | | -status=Chef::Mixin::Command.popen4( |
35 | | -"#{File.join(File.dirname(__FILE__),"..","..","chef","bin","chef-client")} -l #{@log_level} -c #{@config_file}#{@chef_args}")do |p,i,o,e| |
| 38 | +status=Chef::Mixin::Command.popen4(chef_client_command_string())do |p,i,o,e| |
36 | 39 | @stdout=o.gets(nil) |
37 | 40 | @stderr=e.gets(nil) |
38 | 41 | end |
|
65 | 68 | end |
66 | 69 |
|
67 | 70 | When/^I run the chef\-client for '(.+)' seconds$/do |run_for| |
68 | | -cid=Process.fork{ |
69 | | -sleeprun_for.to_i |
70 | | - |
71 | | -client_pid=`ps ax | grep chef-client | grep -v grep | grep -v rake | grep -v cucumber | awk '{print $1 }'`.to_i |
72 | | - |
73 | | -# Send a SIGINT to the child process so it has a chance to cleanly exit, |
74 | | -# including flushing its stdout. |
75 | | -Process.kill("INT",client_pid) |
76 | | - |
77 | | -sleep1 |
78 | | - |
79 | | -# Send KILL to the child chef-client. Due to OHAI-223, where ohai sometimes |
80 | | -# ignores/doesn't exit correctly on receipt of SIGINT, brutally kill the |
81 | | -# subprocess. |
82 | | -begin |
83 | | -Process.kill("KILL",client_pid) |
84 | | -rescueErrno::ESRCH |
85 | | -# SIGINT worked above, so the KILL failed. Ignore it as this means things |
86 | | -# are working the way they're supposed to. |
| 71 | +# Normal behavior depends on the run_interval/recipes/default.rb to count down |
| 72 | +# and exit subordinate chef-client after two runs. However, we will forcably |
| 73 | +# kill the client if that didn't work. |
| 74 | +begin |
| 75 | +stdout_filename="/tmp/chef.run_interval.stdout.#{$$}.txt" |
| 76 | +stderr_filename="/tmp/chef.run_interval.stderr.#{$$}.txt" |
| 77 | +client_pid=Process.forkdo |
| 78 | +STDOUT.reopen(File.open(stdout_filename,"w")) |
| 79 | +STDERR.reopen(File.open(stderr_filename,"w")) |
| 80 | +execchef_client_command_string() |
| 81 | +exit2 |
87 | 82 | end |
88 | | -} |
89 | | -When'I run the chef-client' |
90 | | -Process.waitpid2(cid) |
| 83 | + |
| 84 | +killer_pid=Process.fork{ |
| 85 | +sleeprun_for.to_i |
| 86 | + |
| 87 | +# Send KILL to the child chef-client. Due to OHAI-223, where ohai sometimes |
| 88 | +# ignores/doesn't exit correctly on receipt of SIGINT, brutally kill the |
| 89 | +# subprocess. |
| 90 | +begin |
| 91 | +Process.kill("KILL",client_pid) |
| 92 | +rescueErrno::ESRCH |
| 93 | +# Kill didn't work; the process exited while we were waiting, like |
| 94 | +# it's supposed to. |
| 95 | +end |
| 96 | +} |
| 97 | + |
| 98 | +Process.waitpid2(killer_pid) |
| 99 | +@status=Process.waitpid2(client_pid).last |
| 100 | + |
| 101 | +# Read these in so they can be used in later steps. |
| 102 | +@stdout=IO.read(stdout_filename) |
| 103 | +@stderr=IO.read(stderr_filename) |
| 104 | +ensure |
| 105 | +# clean up after ourselves. |
| 106 | +File.delete(stdout_filename) |
| 107 | +File.delete(stderr_filename) |
| 108 | +end |
91 | 109 | end |
92 | 110 |
|
93 | 111 | When/^I run the chef\-client at log level '(.+)'$/do |log_level| |
|
0 commit comments