From: <jh...@us...> - 2011-01-14 23:56:59
|
Revision: 253 http://etch.svn.sourceforge.net/etch/?rev=253&view=rev Author: jheiss Date: 2011-01-14 23:56:52 +0000 (Fri, 14 Jan 2011) Log Message: ----------- Add support for a detailed_results setting in the client config file, allowing users to log detailed results to a local file in addition to or instead of sending them to the server. Modified Paths: -------------- trunk/client/etch.conf trunk/client/etchclient.rb trunk/test/test_conf.rb Modified: trunk/client/etch.conf =================================================================== --- trunk/client/etch.conf 2011-01-14 23:54:16 UTC (rev 252) +++ trunk/client/etch.conf 2011-01-14 23:56:52 UTC (rev 253) @@ -11,8 +11,15 @@ #local = /var/etch/configs # Etch will try to find an SSH host key and use it to sign all requests to the -# etch server. Several standard locations for SSH keys are searched by -# default, if your key is not in a standard location you can point etch to it. -# See https://sourceforge.net/apps/trac/etch/wiki/ClientAuthentication +# etch server. Several standard locations for host keys are searched by +# default. If your host key is not in a standard location then you can point +# etch to it. +# See http://sourceforge.net/apps/trac/etch/wiki/ClientAuthentication #key = /etc/ssh/ssh_host_rsa_key +# Etch can send detailed results back to the server for viewing in the web UI +# and/or to a local log file. They are sent to the server by default. +# Note that SERVER is ignored when etch is running in local mode. +#detailed_results = SERVER +#detailed_results = /var/etch/results.log + Modified: trunk/client/etchclient.rb =================================================================== --- trunk/client/etchclient.rb 2011-01-14 23:54:16 UTC (rev 252) +++ trunk/client/etchclient.rb 2011-01-14 23:56:52 UTC (rev 253) @@ -43,6 +43,7 @@ PRIVATE_KEY_PATHS = ["/etc/ssh/ssh_host_rsa_key", "/etc/ssh_host_rsa_key"] DEFAULT_CONFIGDIR = '/etc' DEFAULT_VARBASE = '/var/etch' + DEFAULT_DETAILED_RESULTS = ['SERVER'] # We need these in relation to the output capturing ORIG_STDOUT = STDOUT.dup @@ -75,6 +76,7 @@ end @configfile = File.join(@configdir, 'etch.conf') + @detailed_results = [] if File.exist?(@configfile) IO.foreach(@configfile) do |line| @@ -119,6 +121,9 @@ end elsif key == 'path' ENV['PATH'] = value + elsif key == 'detailed_results' + warn "Adding detailed results destination '#{value}'" if @debug + @detailed_results << value end end end @@ -130,6 +135,10 @@ warn "No readable private key found, messages to server will not be signed and may be rejected depending on server configuration" end + if @detailed_results.empty? + @detailed_results = DEFAULT_DETAILED_RESULTS + end + @origbase = File.join(@varbase, 'orig') @historybase = File.join(@varbase, 'history') @lockbase = File.join(@varbase, 'locks') @@ -480,13 +489,15 @@ rails_results << "fqdn=#{CGI.escape(@facts['fqdn'])}" rails_results << "status=#{CGI.escape(status.to_s)}" rails_results << "message=#{CGI.escape(message)}" - @results.each do |result| - # Strangely enough this works. Even though the key is not unique to - # each result the Rails parameter parsing code keeps track of keys it - # has seen, and if it sees a duplicate it starts a new hash. - rails_results << "results[][file]=#{CGI.escape(result['file'])}" - rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" - rails_results << "results[][message]=#{CGI.escape(result['message'])}" + if @detailed_results.include?('SERVER') + @results.each do |result| + # Strangely enough this works. Even though the key is not unique to + # each result the Rails parameter parsing code keeps track of keys it + # has seen, and if it sees a duplicate it starts a new hash. + rails_results << "results[][file]=#{CGI.escape(result['file'])}" + rails_results << "results[][success]=#{CGI.escape(result['success'].to_s)}" + rails_results << "results[][message]=#{CGI.escape(result['message'])}" + end end puts "Sending results to server #{@resultsuri}" if (@debug) resultspost = Net::HTTP::Post.new(@resultsuri.path) @@ -507,6 +518,27 @@ end end + @detailed_results.each do |detail_dest| + # If any of the destinations look like a file (start with a /) then we + # log to that file + if detail_dest =~ %r{^/} + FileUtils.mkpath(File.dirname(detail_dest)) + File.open(detail_dest, 'a') do |file| + # Add a header for the overall status of the run + file.puts "Etch run at #{Time.now}" + file.puts "Status: #{status}" + if !message.empty? + file.puts "Message:\n#{message}\n" + end + # Then the detailed results + @results.each do |result| + file.puts "File #{result['file']}, result #{result['success']}:\n" + file.puts result['message'] + end + end + end + end + status end Modified: trunk/test/test_conf.rb =================================================================== --- trunk/test/test_conf.rb 2011-01-14 23:54:16 UTC (rev 252) +++ trunk/test/test_conf.rb 2011-01-14 23:56:52 UTC (rev 253) @@ -308,6 +308,102 @@ assert(File.exist?("#{@repodir}/pathtest/testpost.output")) end + def test_conf_detailed_results + # + # Test the detailed_results setting in etch.conf + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file></warning_file> + <source> + <plain>source</plain> + </source> + </file> + </config> + EOF + end + + # No setting, should log to server by default + testname = 'etch.conf detailed_results setting, not set' + # We add a random component to the contents so that we can distinguish + # our test run from others in the server database + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, latest_result_message, testname) + + # Configure logging to server + testname = 'etch.conf detailed_results setting, log to server' + # We add a random component to the contents so that we can distinguish + # our test run from others in the server database + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results = SERVER" + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, latest_result_message, testname) + + # Configure logging to file + logfile = Tempfile.new('etchlog') + testname = 'etch.conf detailed_results setting, log to file' + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results = #{logfile.path}" + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, File.read(logfile.path), testname) + # Check that details weren't sent to server + # Odd that assert_no_match requires a Regexp when assert_match accepts a String + assert_no_match(Regexp.new(Regexp.escape(sourcecontents)), latest_result_message, testname) + + # Configure logging to server and file + logfile = Tempfile.new('etchlog') + testname = 'etch.conf detailed_results setting, log to server and file' + # We add a random component to the contents so that we can distinguish + # our test run from others in the server database + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results = SERVER" + file.puts "detailed_results = #{logfile.path}" + end + run_etch(@server, @testroot, :testname => testname) + assert_match(sourcecontents, latest_result_message, testname) + assert_match(sourcecontents, File.read(logfile.path), testname) + + # Configure no logging + testname = 'etch.conf detailed_results setting, log nowhere' + sourcecontents = "Test #{testname}, #{rand}\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + FileUtils.mkdir_p("#{@testroot}/etc") + File.open("#{@testroot}/etc/etch.conf", 'w') do |file| + file.puts "detailed_results =" + end + run_etch(@server, @testroot, :testname => testname) + # Check that details weren't sent to server + # Odd that assert_no_match requires a Regexp when assert_match accepts a String + assert_no_match(Regexp.new(Regexp.escape(sourcecontents)), latest_result_message, testname) + end + def teardown remove_repository(@repodir) FileUtils.rm_rf(@testroot) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |