From 119db37463d1e42c47884d7fccac82f40aa453ca Mon Sep 17 00:00:00 2001 From: yarondbb Date: Sun, 8 Dec 2013 18:08:24 +0200 Subject: [PATCH 01/20] Added application file --- bin/daily_tests.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 bin/daily_tests.rb diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb new file mode 100644 index 0000000..99c43de --- /dev/null +++ b/bin/daily_tests.rb @@ -0,0 +1,48 @@ +# +#Unit Tests (Rake): +# Uninstall all Gems +# Retrieve the latest master from BBFS git repository +# Remove previous execution output file +# Create output Log Directory for test: +# /tmp/daily_tests/unit_test/log/ +# Create all needed Gems for tests (e.g. Bundler and Rake gem) +# Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log +# Parse log and generate report +# + +def uninstall_all_gems + `gem list --no-versions`.each_line {|gem| + puts "gem to uninstall #{gem}" + # `gem uninstall #{gem} -a -x -I` + # puts "removed gem #{gem}" + } +end + +def prepare_latest_bbfs +end + +def unit_test + uninstall_all_gems + prepare_latest_bbfs + # Retrieve the latest master from BBFS git repository + # Remove previous execution output file + # Create output Log Directory for test: + # /tmp/daily_tests/unit_test/log/ + # Create all needed Gems for tests (e.g. Bundler and Rake gem) + # Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log + # Parse log and generate report + +end + +begin + `dir`.each_line {|dir| + puts "puts:#{dir}" + `echo #{dir.to_s}` + break + } + unit_test +rescue => e + puts "Error caught. Msg:#{e.message}\nBack trace:#{e.backtrace}" +end + + From 91c6487e8e00f874b9ca6d8be63761e5decabd2c Mon Sep 17 00:00:00 2001 From: yarondbb Date: Sun, 8 Dec 2013 18:08:34 +0200 Subject: [PATCH 02/20] Added application file --- bin/daily_tests.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 99c43de..b033ac8 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -13,8 +13,8 @@ def uninstall_all_gems `gem list --no-versions`.each_line {|gem| puts "gem to uninstall #{gem}" - # `gem uninstall #{gem} -a -x -I` - # puts "removed gem #{gem}" + `gem uninstall #{gem} -a -x -I` + puts "removed gem #{gem}" } end From ba7ae3ec40e7305b474ef7b547565e31ab3be3e3 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 9 Dec 2013 17:03:32 +0200 Subject: [PATCH 03/20] Added unit tests methods --- bin/daily_tests.rb | 106 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 86 insertions(+), 20 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index b033ac8..2892679 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -1,3 +1,6 @@ +#TODO yarondbb Add time out for operations + +require 'FileUtils' # #Unit Tests (Rake): # Uninstall all Gems @@ -9,40 +12,103 @@ # Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log # Parse log and generate report # +BBFS_GIT_REPO = 'https://github.com/bbfsdev/bbfs' +DAILY_TEST_DIR = File.join('C:/Users/ydror1','daily_tests') +BBFS_DIR = File.join(DAILY_TEST_DIR, 'bbfs') + +UNIT_TEST_BASE_DIR = File.join(DAILY_TEST_DIR, 'unit_test') +UNIT_TEST_OUT_DIR = File.join(UNIT_TEST_BASE_DIR, 'log') +UNIT_TEST_OUT_FILE = File.join(UNIT_TEST_OUT_DIR, 'rake.log') + +#output = `grep hosts /private/etc/* 2>&1` +def execute_command(command) + puts "\n Running command:'#{command}'" + command_res = `#{command} 2>&1` # this will redirect both stdout and stderr to stdout + command_res.each_line { |line| + chomped_line = line.chomp + puts " #{chomped_line}" + } + raise("Error occurred in command:#{command}") if command_res.match(/fatal|fail|error|aborted/i) + command_res +end def uninstall_all_gems + puts "\n\nStart uninstall all gems" + puts "-------------------------------------------------------------------" `gem list --no-versions`.each_line {|gem| - puts "gem to uninstall #{gem}" - `gem uninstall #{gem} -a -x -I` - puts "removed gem #{gem}" + gem_new = gem.chomp + next if gem_new.length == 0 + execute_command("gem uninstall #{gem_new} -a -x -I") + puts " removed gem #{gem}" } + puts "\nDone uninstall all gems" end -def prepare_latest_bbfs +def prepare_latest_bbfs_repo + puts "\n\nStart removing bbfs dir:#{BBFS_DIR}" + puts "-------------------------------------------------------------------" + ::FileUtils.remove_dir(BBFS_DIR, true) # true will force delete + puts "\nDone removing bbfs dir:#{BBFS_DIR}" + Dir.chdir(DAILY_TEST_DIR) + puts "\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}" + puts "-------------------------------------------------------------------" + execute_command("git clone #{BBFS_GIT_REPO}") + puts "\nDone cloning bbfs from git repo:#{BBFS_GIT_REPO}" + end + +# Create all needed Gems for tests (Bundler and Rake) +def unit_test_create_gems + puts "\n\nStart install bundler gems" + puts "-------------------------------------------------------------------" + Dir.chdir(BBFS_DIR) + execute_command('gem install bundler') + execute_command('bundle install') + puts "\nDone install bundler gems" end -def unit_test - uninstall_all_gems - prepare_latest_bbfs - # Retrieve the latest master from BBFS git repository - # Remove previous execution output file - # Create output Log Directory for test: - # /tmp/daily_tests/unit_test/log/ - # Create all needed Gems for tests (e.g. Bundler and Rake gem) - # Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log - # Parse log and generate report + +def unit_test_prepare_prev_inout_paths + puts "\n\nUnit test: Start prepare prev inout paths" + puts "-------------------------------------------------------------------" + ::FileUtils.remove_dir(UNIT_TEST_OUT_DIR, true) # true will force delete + ::FileUtils.mkdir_p(UNIT_TEST_OUT_DIR) + puts " Cleared and Created out path:#{UNIT_TEST_OUT_DIR}" + puts "\nUnit test: Done prepare prev inout paths" end -begin - `dir`.each_line {|dir| - puts "puts:#{dir}" - `echo #{dir.to_s}` - break +# Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log +def unit_test_execute + puts "\n\nStart unit test execution" + puts "-------------------------------------------------------------------" + rake_output = execute_command("rake") + File.open(UNIT_TEST_OUT_FILE,'w') { |file| + file.puts(rake_output) } +end + +def unit_test_parse_log + +end + +def unit_test_generate_report + +end + +def unit_test + #uninstall_all_gems + #prepare_latest_bbfs_repo + #unit_test_prepare_prev_inout_paths + #unit_test_create_gems + unit_test_execute + unit_test_parse_log + unit_test_generate_report +end + +begin unit_test rescue => e - puts "Error caught. Msg:#{e.message}\nBack trace:#{e.backtrace}" + puts "\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}" end From 1d0dbd57f33498430825f64e15255434dfb63013 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 9 Dec 2013 17:08:52 +0200 Subject: [PATCH 04/20] . --- bin/daily_tests.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 2892679..9c55e28 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -13,7 +13,8 @@ # Parse log and generate report # BBFS_GIT_REPO = 'https://github.com/bbfsdev/bbfs' -DAILY_TEST_DIR = File.join('C:/Users/ydror1','daily_tests') +#DAILY_TEST_DIR = File.join('C:/Users/ydror1','daily_tests') +DAILY_TEST_DIR = File.join('tmp','daily_tests') BBFS_DIR = File.join(DAILY_TEST_DIR, 'bbfs') UNIT_TEST_BASE_DIR = File.join(DAILY_TEST_DIR, 'unit_test') From 7dd2fe93f9ab324250e04dd729fb3598e22f5efa Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 9 Dec 2013 17:25:03 +0200 Subject: [PATCH 05/20] added support for path for unix (under /tmp) and windows (under user dir) --- bin/daily_tests.rb | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 9c55e28..6e89c04 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -1,6 +1,6 @@ #TODO yarondbb Add time out for operations -require 'FileUtils' +require 'fileutils' # #Unit Tests (Rake): # Uninstall all Gems @@ -13,8 +13,12 @@ # Parse log and generate report # BBFS_GIT_REPO = 'https://github.com/bbfsdev/bbfs' -#DAILY_TEST_DIR = File.join('C:/Users/ydror1','daily_tests') -DAILY_TEST_DIR = File.join('tmp','daily_tests') +unless Gem::win_platform? + DAILY_TEST_DIR = File.join('tmp','daily_tests') +else + DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests') #for Windows +end + BBFS_DIR = File.join(DAILY_TEST_DIR, 'bbfs') UNIT_TEST_BASE_DIR = File.join(DAILY_TEST_DIR, 'unit_test') @@ -45,11 +49,14 @@ def uninstall_all_gems puts "\nDone uninstall all gems" end -def prepare_latest_bbfs_repo - puts "\n\nStart removing bbfs dir:#{BBFS_DIR}" + + +def prepare_daily_test_dirs + puts "\n\nStart removing and creating daily test dir:#{DAILY_TEST_DIR}" puts "-------------------------------------------------------------------" - ::FileUtils.remove_dir(BBFS_DIR, true) # true will force delete - puts "\nDone removing bbfs dir:#{BBFS_DIR}" + ::FileUtils.remove_dir(DAILY_TEST_DIR, true) # true will force delete + ::FileUtils.mkdir_p(DAILY_TEST_DIR) + puts "\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}" Dir.chdir(DAILY_TEST_DIR) puts "\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}" puts "-------------------------------------------------------------------" @@ -97,10 +104,10 @@ def unit_test_generate_report end def unit_test - #uninstall_all_gems - #prepare_latest_bbfs_repo - #unit_test_prepare_prev_inout_paths - #unit_test_create_gems + uninstall_all_gems + prepare_daily_test_dirs + unit_test_prepare_prev_inout_paths + unit_test_create_gems unit_test_execute unit_test_parse_log unit_test_generate_report From 1128cdcc2c07d03c64d0ba04783f430092c11304 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 9 Dec 2013 17:31:24 +0200 Subject: [PATCH 06/20] . --- bin/daily_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 6e89c04..2b4e839 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -14,7 +14,7 @@ # BBFS_GIT_REPO = 'https://github.com/bbfsdev/bbfs' unless Gem::win_platform? - DAILY_TEST_DIR = File.join('tmp','daily_tests') + DAILY_TEST_DIR = File.join('/tmp','daily_tests') else DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests') #for Windows end From 437692ff0508771b90cd4ad4edfa536b34a45f73 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 9 Dec 2013 17:45:41 +0200 Subject: [PATCH 07/20] for rake, do not raise error when 'error' string is returned from commnad since it does not necessarity indicated a real error but rather an indiation that no error had occurred --- bin/daily_tests.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 2b4e839..145249f 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -25,15 +25,23 @@ UNIT_TEST_OUT_DIR = File.join(UNIT_TEST_BASE_DIR, 'log') UNIT_TEST_OUT_FILE = File.join(UNIT_TEST_OUT_DIR, 'rake.log') -#output = `grep hosts /private/etc/* 2>&1` -def execute_command(command) +# Algorithm: +# executing shell commands. if stdout and\or stderr has the +# strings: fatal|fail|error|aborted an error will be raised +# Parameters: +# in: command - the comand to execute +# in: raise_error - if false then if stdout and\or stderr has the +# strings: fatal|fail|error|aborted they will not raise an error. +# Used for 'rake' command where the string error is used but it does not indicate an error +# Returns: Stdout and Stderr of the command +def execute_command(command, raise_error=ture) puts "\n Running command:'#{command}'" command_res = `#{command} 2>&1` # this will redirect both stdout and stderr to stdout command_res.each_line { |line| chomped_line = line.chomp puts " #{chomped_line}" } - raise("Error occurred in command:#{command}") if command_res.match(/fatal|fail|error|aborted/i) + raise("Error occurred in command:#{command}") if command_res.match(/fatal|fail|error|aborted/i) if raise_error command_res end @@ -89,7 +97,7 @@ def unit_test_prepare_prev_inout_paths def unit_test_execute puts "\n\nStart unit test execution" puts "-------------------------------------------------------------------" - rake_output = execute_command("rake") + rake_output = execute_command("rake", false) File.open(UNIT_TEST_OUT_FILE,'w') { |file| file.puts(rake_output) } From 1eb0b0bcebfd22c95dbdf770d02690aac46e3eb8 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 9 Dec 2013 17:46:58 +0200 Subject: [PATCH 08/20] for rake, do not raise error when 'error' string is returned from commnad since it does not necessarity indicated a real error but rather an indiation that no error had occurred --- bin/daily_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 145249f..626c377 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -34,7 +34,7 @@ # strings: fatal|fail|error|aborted they will not raise an error. # Used for 'rake' command where the string error is used but it does not indicate an error # Returns: Stdout and Stderr of the command -def execute_command(command, raise_error=ture) +def execute_command(command, raise_error=true) puts "\n Running command:'#{command}'" command_res = `#{command} 2>&1` # this will redirect both stdout and stderr to stdout command_res.each_line { |line| From 43e6505909135a26d17b85afe8fe121197d65353 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Tue, 10 Dec 2013 18:23:55 +0200 Subject: [PATCH 09/20] Added email suppport --- bin/daily_tests.rb | 61 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 626c377..cda31b1 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -1,5 +1,6 @@ #TODO yarondbb Add time out for operations +require 'email' require 'fileutils' # #Unit Tests (Rake): @@ -18,14 +19,22 @@ else DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests') #for Windows end - BBFS_DIR = File.join(DAILY_TEST_DIR, 'bbfs') - UNIT_TEST_BASE_DIR = File.join(DAILY_TEST_DIR, 'unit_test') UNIT_TEST_OUT_DIR = File.join(UNIT_TEST_BASE_DIR, 'log') UNIT_TEST_OUT_FILE = File.join(UNIT_TEST_OUT_DIR, 'rake.log') +FROM_EMAIL = ARGV[0] +FROM_EMAIL_PASSWORD = ARGV[1] +TO_EMAIL = ARGV[2] + +def send_email(report) + msg =< Date: Wed, 11 Dec 2013 19:27:47 +0200 Subject: [PATCH 10/20] mail support --- bin/daily_tests.rb | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index cda31b1..8a0bcd7 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -2,7 +2,8 @@ require 'email' require 'fileutils' -# + +################################################################# #Unit Tests (Rake): # Uninstall all Gems # Retrieve the latest master from BBFS git repository @@ -12,7 +13,9 @@ # Create all needed Gems for tests (e.g. Bundler and Rake gem) # Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log # Parse log and generate report -# +################################################################### + +# ------------------------------------------------- Definitions --------------------------- BBFS_GIT_REPO = 'https://github.com/bbfsdev/bbfs' unless Gem::win_platform? DAILY_TEST_DIR = File.join('/tmp','daily_tests') @@ -27,13 +30,6 @@ FROM_EMAIL_PASSWORD = ARGV[1] TO_EMAIL = ARGV[2] -def send_email(report) - msg =< e puts "\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}" end - - From d8bd7b501d8da091828444e3621b9cd0ac96dca4 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 19:49:51 +0200 Subject: [PATCH 11/20] Added main log support --- bin/daily_tests.rb | 57 ++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 8a0bcd7..9e59c2c 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -22,6 +22,8 @@ else DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests') #for Windows end +DAILY_TEST_LOG_DIR = File.join(DAILY_TEST_DIR, 'log') +DAILY_TEST_LOG_FILE = File.join(DAILY_TEST_LOG_DIR, 'daily_test.log') BBFS_DIR = File.join(DAILY_TEST_DIR, 'bbfs') UNIT_TEST_BASE_DIR = File.join(DAILY_TEST_DIR, 'unit_test') UNIT_TEST_OUT_DIR = File.join(UNIT_TEST_BASE_DIR, 'log') @@ -30,6 +32,8 @@ FROM_EMAIL_PASSWORD = ARGV[1] TO_EMAIL = ARGV[2] +$log_file = nil # will be initialized later + # execute_command Algorithm: # executing shell commands. if stdout and\or stderr has the # strings: fatal|fail|error|aborted an error will be raised @@ -65,43 +69,43 @@ def uninstall_all_gems def prepare_daily_test_dirs - puts "\n\nStart removing and creating daily test dir:#{DAILY_TEST_DIR}" - puts "-------------------------------------------------------------------" + $log_file.puts("\n\nStart removing and creating daily test dir:#{DAILY_TEST_DIR}") + $log_file.puts("-------------------------------------------------------------------") ::FileUtils.remove_dir(DAILY_TEST_DIR, true) # true will force delete ::FileUtils.mkdir_p(DAILY_TEST_DIR) - puts "\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}" + ::FileUtils.mkdir_p(DAILY_TEST_LOG_DIR) + $log_file.puts("\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}") Dir.chdir(DAILY_TEST_DIR) - puts "\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}" - puts "-------------------------------------------------------------------" + $log_file.puts("\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}") + $log_file.puts("-------------------------------------------------------------------") execute_command("git clone #{BBFS_GIT_REPO}") - puts "\nDone cloning bbfs from git repo:#{BBFS_GIT_REPO}" + $log_file.puts("\nDone cloning bbfs from git repo:#{BBFS_GIT_REPO}") end # Create all needed Gems for tests (Bundler and Rake) def unit_test_create_gems - puts "\n\nStart install bundler gems" - puts "-------------------------------------------------------------------" + $log_file.puts("\n\nStart install bundler gems") + $log_file.puts("-------------------------------------------------------------------") Dir.chdir(BBFS_DIR) execute_command('gem install bundler') execute_command('bundle install') - puts "\nDone install bundler gems" + $log_file.puts("\nDone install bundler gems") end def unit_test_prepare_prev_inout_paths - puts "\n\nUnit test: Start prepare prev inout paths" - puts "-------------------------------------------------------------------" + $log_file.puts("\n\nUnit test: Start prepare prev inout paths") + $log_file.puts("-------------------------------------------------------------------") ::FileUtils.remove_dir(UNIT_TEST_OUT_DIR, true) # true will force delete ::FileUtils.mkdir_p(UNIT_TEST_OUT_DIR) - puts " Cleared and Created out path:#{UNIT_TEST_OUT_DIR}" - puts "\nUnit test: Done prepare prev inout paths" - + $log_file.puts(" Cleared and Created out path:#{UNIT_TEST_OUT_DIR}") + $log_file.puts("\nUnit test: Done prepare prev inout paths") end # Run Rake and redirect to /tmp/daily_tests/unit_test/log/rake.log def unit_test_execute - puts "\n\nStart unit test execution" - puts "-------------------------------------------------------------------" + $log_file.puts("\n\nStart unit test execution") + $log_file.puts("-------------------------------------------------------------------") rake_output = execute_command("rake", false) File.open(UNIT_TEST_OUT_FILE,'w') { |file| file.puts(rake_output) @@ -134,35 +138,44 @@ def unit_test_parse_log(rake_output) end end } - puts "\n Rake report summary:\n -----------------------\n#{report}\n" + if report.each_line.length != 2 + $log_file.puts("\n Problem with parsing Rake log. Could not find status 2 lines") + else + $log_file.puts("\n Rake report summary:\n -----------------------\n#{report}") + end report end def unit_test_generate_report(report) mail_body =< e - puts "\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}" + puts("\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}") + $log_file.puts("\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}") + $log_file.close end From 4e402b6c987aade05aef21f7a8a2bccc6a5a8896 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 19:54:04 +0200 Subject: [PATCH 12/20] . --- bin/daily_tests.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 9e59c2c..032065f 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -69,13 +69,15 @@ def uninstall_all_gems def prepare_daily_test_dirs - $log_file.puts("\n\nStart removing and creating daily test dir:#{DAILY_TEST_DIR}") - $log_file.puts("-------------------------------------------------------------------") + puts("\n\nStart removing and creating daily test dir:#{DAILY_TEST_DIR}") + puts("-------------------------------------------------------------------") ::FileUtils.remove_dir(DAILY_TEST_DIR, true) # true will force delete ::FileUtils.mkdir_p(DAILY_TEST_DIR) ::FileUtils.mkdir_p(DAILY_TEST_LOG_DIR) - $log_file.puts("\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}") + puts("\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}") Dir.chdir(DAILY_TEST_DIR) + $log_file = File.open(DAILY_TEST_LOG_FILE, 'w') + puts("\nRest of log can be found in: #{DAILY_TEST_LOG_FILE}") $log_file.puts("\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}") $log_file.puts("-------------------------------------------------------------------") execute_command("git clone #{BBFS_GIT_REPO}") From 811ec7910b5bd3ccfef149ce621986a7bf647bfe Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 19:58:50 +0200 Subject: [PATCH 13/20] . --- bin/daily_tests.rb | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 032065f..a996b66 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -44,26 +44,26 @@ # Used for 'rake' command where the string error is used but it does not indicate an error # Returns: Stdout and Stderr of the command def execute_command(command, raise_error=true) - puts "\n Running command:'#{command}'" + $log_file.puts("\n Running command:'#{command}'") command_res = `#{command} 2>&1` # this will redirect both stdout and stderr to stdout command_res.each_line { |line| chomped_line = line.chomp - puts " #{chomped_line}" + $log_file.puts(" #{chomped_line}") } raise("Error occurred in command:#{command}") if command_res.match(/fatal|fail|error|aborted/i) if raise_error command_res end def uninstall_all_gems - puts "\n\nStart uninstall all gems" - puts "-------------------------------------------------------------------" + $log_file.puts("\n\nStart uninstall all gems") + $log_file.puts("-------------------------------------------------------------------") `gem list --no-versions`.each_line {|gem| gem_new = gem.chomp next if gem_new.length == 0 execute_command("gem uninstall #{gem_new} -a -x -I") - puts " removed gem #{gem}" + $log_file.puts(" removed gem #{gem}") } - puts "\nDone uninstall all gems" + $log_file.puts("\nDone uninstall all gems") end @@ -76,8 +76,9 @@ def prepare_daily_test_dirs ::FileUtils.mkdir_p(DAILY_TEST_LOG_DIR) puts("\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}") Dir.chdir(DAILY_TEST_DIR) - $log_file = File.open(DAILY_TEST_LOG_FILE, 'w') - puts("\nRest of log can be found in: #{DAILY_TEST_LOG_FILE}") +end + +def clone_bbfs_repo $log_file.puts("\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}") $log_file.puts("-------------------------------------------------------------------") execute_command("git clone #{BBFS_GIT_REPO}") @@ -162,10 +163,15 @@ def unit_test_generate_report(report) end def unit_test - uninstall_all_gems - prepare_daily_test_dirs + prepare_daily_test_dirs # this will use puts to console + # init log $log_file = File.open(DAILY_TEST_LOG_FILE, 'w') + puts("\nRest of log can be found in: #{DAILY_TEST_LOG_FILE}") + # from now on log file will be used by methods + + clone_bbfs_repo + uninstall_all_gems unit_test_prepare_prev_inout_paths unit_test_create_gems rake_output = unit_test_execute From 6791dca8b75f60d28b7f1def00da7b9fd121c6d5 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 21:21:10 +0200 Subject: [PATCH 14/20] . --- bin/daily_tests.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index a996b66..5d39fd2 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -123,10 +123,12 @@ def unit_test_parse_log(rake_output) # format of Spec is: # 42 examples, 0 failures report = '' + pass_counter = 0 rake_output.each_line { |line| chomped_line = line.chomp # Check Rake Test if chomped_line.match(/\d+ failures, \d+ errors, \d+ skips/) + pass_counter += 1 if chomped_line.match(/0 failures, 0 errors, 0 skips/) report += " Rake Test is OK. Description: #{chomped_line}\n" else @@ -134,6 +136,7 @@ def unit_test_parse_log(rake_output) end # Check Rake Spec elsif chomped_line.match(/examples, \d+ failures/) + pass_counter += 1 if chomped_line.match(/examples, 0 failures/) report += " Rake Spec is OK. Description: #{chomped_line}\n" else @@ -141,7 +144,7 @@ def unit_test_parse_log(rake_output) end end } - if report.each_line.length != 2 + if pass_counter != 2 $log_file.puts("\n Problem with parsing Rake log. Could not find status 2 lines") else $log_file.puts("\n Rake report summary:\n -----------------------\n#{report}") From b9c620e8998ac03b2572a938416ead81d892df93 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 22:32:43 +0200 Subject: [PATCH 15/20] Added scheduling code (start at midnight) --- bin/daily_tests.rb | 80 +++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 5d39fd2..4c280c8 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -17,17 +17,7 @@ # ------------------------------------------------- Definitions --------------------------- BBFS_GIT_REPO = 'https://github.com/bbfsdev/bbfs' -unless Gem::win_platform? - DAILY_TEST_DIR = File.join('/tmp','daily_tests') -else - DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests') #for Windows -end -DAILY_TEST_LOG_DIR = File.join(DAILY_TEST_DIR, 'log') -DAILY_TEST_LOG_FILE = File.join(DAILY_TEST_LOG_DIR, 'daily_test.log') -BBFS_DIR = File.join(DAILY_TEST_DIR, 'bbfs') -UNIT_TEST_BASE_DIR = File.join(DAILY_TEST_DIR, 'unit_test') -UNIT_TEST_OUT_DIR = File.join(UNIT_TEST_BASE_DIR, 'log') -UNIT_TEST_OUT_FILE = File.join(UNIT_TEST_OUT_DIR, 'rake.log') + FROM_EMAIL = ARGV[0] FROM_EMAIL_PASSWORD = ARGV[1] TO_EMAIL = ARGV[2] @@ -66,30 +56,42 @@ def uninstall_all_gems $log_file.puts("\nDone uninstall all gems") end - +def update_dirs(time) + unless Gem::win_platform? + $DAILY_TEST_DIR = File.join('/tmp','daily_tests', time.to_s) + else + $DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests', time.to_s) #for Windows + end + $DAILY_TEST_LOG_DIR = File.join($DAILY_TEST_DIR, 'log') + $DAILY_TEST_LOG_FILE = File.join($DAILY_TEST_LOG_DIR, 'daily_test.log') + $BBFS_DIR = File.join($DAILY_TEST_DIR, 'bbfs') + $UNIT_TEST_BASE_DIR = File.join($DAILY_TEST_DIR, 'unit_test') + $UNIT_TEST_OUT_DIR = File.join($UNIT_TEST_BASE_DIR, 'log') + $UNIT_TEST_OUT_FILE = File.join($UNIT_TEST_OUT_DIR, 'rake.log') +end def prepare_daily_test_dirs - puts("\n\nStart removing and creating daily test dir:#{DAILY_TEST_DIR}") + puts("\n\nStart preparing daily test dir:#{$DAILY_TEST_DIR}") puts("-------------------------------------------------------------------") - ::FileUtils.remove_dir(DAILY_TEST_DIR, true) # true will force delete - ::FileUtils.mkdir_p(DAILY_TEST_DIR) - ::FileUtils.mkdir_p(DAILY_TEST_LOG_DIR) - puts("\nDone removing and creating bbfs dir:#{DAILY_TEST_DIR}") - Dir.chdir(DAILY_TEST_DIR) + #::FileUtils.remove_dir($DAILY_TEST_DIR, true) # true will force delete + ::FileUtils.mkdir_p($DAILY_TEST_DIR) unless File.exist($DAILY_TEST_DIR) + ::FileUtils.mkdir_p($DAILY_TEST_LOG_DIR) + puts("\nDone removing and creating bbfs dir:#{$DAILY_TEST_DIR}") end def clone_bbfs_repo + Dir.chdir($DAILY_TEST_DIR) $log_file.puts("\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}") $log_file.puts("-------------------------------------------------------------------") execute_command("git clone #{BBFS_GIT_REPO}") $log_file.puts("\nDone cloning bbfs from git repo:#{BBFS_GIT_REPO}") + Dir.chdir($BBFS_DIR) end # Create all needed Gems for tests (Bundler and Rake) def unit_test_create_gems $log_file.puts("\n\nStart install bundler gems") $log_file.puts("-------------------------------------------------------------------") - Dir.chdir(BBFS_DIR) execute_command('gem install bundler') execute_command('bundle install') $log_file.puts("\nDone install bundler gems") @@ -99,9 +101,9 @@ def unit_test_create_gems def unit_test_prepare_prev_inout_paths $log_file.puts("\n\nUnit test: Start prepare prev inout paths") $log_file.puts("-------------------------------------------------------------------") - ::FileUtils.remove_dir(UNIT_TEST_OUT_DIR, true) # true will force delete - ::FileUtils.mkdir_p(UNIT_TEST_OUT_DIR) - $log_file.puts(" Cleared and Created out path:#{UNIT_TEST_OUT_DIR}") + #::FileUtils.remove_dir($UNIT_TEST_OUT_DIR, true) # true will force delete + ::FileUtils.mkdir_p($UNIT_TEST_OUT_DIR) + $log_file.puts(" Cleared and Created out path:#{$UNIT_TEST_OUT_DIR}") $log_file.puts("\nUnit test: Done prepare prev inout paths") end @@ -110,7 +112,7 @@ def unit_test_execute $log_file.puts("\n\nStart unit test execution") $log_file.puts("-------------------------------------------------------------------") rake_output = execute_command("rake", false) - File.open(UNIT_TEST_OUT_FILE,'w') { |file| + File.open($UNIT_TEST_OUT_FILE,'w') { |file| file.puts(rake_output) } rake_output @@ -156,21 +158,20 @@ def unit_test_generate_report(report) mail_body =< e puts("\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}") $log_file.puts("\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}") From d1293ae9cbd4c7b3bbeb5d90849e0d40e9134db7 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 22:40:16 +0200 Subject: [PATCH 16/20] fixed time format for file name --- bin/daily_tests.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 4c280c8..9142150 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -74,7 +74,7 @@ def prepare_daily_test_dirs puts("\n\nStart preparing daily test dir:#{$DAILY_TEST_DIR}") puts("-------------------------------------------------------------------") #::FileUtils.remove_dir($DAILY_TEST_DIR, true) # true will force delete - ::FileUtils.mkdir_p($DAILY_TEST_DIR) unless File.exist($DAILY_TEST_DIR) + ::FileUtils.mkdir_p($DAILY_TEST_DIR) unless File.exist?($DAILY_TEST_DIR) ::FileUtils.mkdir_p($DAILY_TEST_LOG_DIR) puts("\nDone removing and creating bbfs dir:#{$DAILY_TEST_DIR}") end @@ -201,7 +201,7 @@ def unit_test #start at midnight time_now = Time.now puts("Wake at #{time_now} and Start Daily test execution") - update_dirs(time_now) + update_dirs("#{time_now.year}_#{time_now.month}_#{time_now.day}") prepare_daily_test_dirs # this will use puts to console unit_test } From ec53da43156d027579f6ce40ede7ccce5f1cae53 Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 22:54:48 +0200 Subject: [PATCH 17/20] support many executions in 1 day. This will make different dirs --- bin/daily_tests.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 9142150..183e30e 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -40,7 +40,7 @@ def execute_command(command, raise_error=true) chomped_line = line.chomp $log_file.puts(" #{chomped_line}") } - raise("Error occurred in command:#{command}") if command_res.match(/fatal|fail|error|aborted/i) if raise_error + raise("Error occurred in command:#{command}\nCommand log:#{command_res}") if command_res.match(/fatal|fail|error|aborted/i) if raise_error command_res end @@ -76,7 +76,7 @@ def prepare_daily_test_dirs #::FileUtils.remove_dir($DAILY_TEST_DIR, true) # true will force delete ::FileUtils.mkdir_p($DAILY_TEST_DIR) unless File.exist?($DAILY_TEST_DIR) ::FileUtils.mkdir_p($DAILY_TEST_LOG_DIR) - puts("\nDone removing and creating bbfs dir:#{$DAILY_TEST_DIR}") + puts("\nDone preparing daily test dir:#{$DAILY_TEST_DIR}") end def clone_bbfs_repo @@ -196,12 +196,20 @@ def unit_test seconds_from_midnight = current_seconds + current_minutes * 60 + current_hour * 3600 seconds_till_midnight = 24*3600 - seconds_from_midnight puts("Time is:#{time_now}. sleeping till midnight: #{seconds_till_midnight}[S]") - sleep(seconds_till_midnight) + sleep(seconds_till_midnight+0.1) #start at midnight time_now = Time.now puts("Wake at #{time_now} and Start Daily test execution") - update_dirs("#{time_now.year}_#{time_now.month}_#{time_now.day}") + exec_index = 1 + while exec_index < 99999 + dir_time_format = "#{time_now.year}_#{time_now.month}_#{time_now.day}.exec_#{exec_index}" + trial_file = File.join('/tmp','daily_tests', dir_time_format) + break unless File.exist?(trial_file) + exec_index += 1 + end + + update_dirs(trial_file) prepare_daily_test_dirs # this will use puts to console unit_test } From a7f7f66c960bb746721af03f347bb002c3f14b4f Mon Sep 17 00:00:00 2001 From: yarondbb Date: Wed, 11 Dec 2013 23:03:36 +0200 Subject: [PATCH 18/20] fix dirs path issue --- bin/daily_tests.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 183e30e..4e17734 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -56,12 +56,8 @@ def uninstall_all_gems $log_file.puts("\nDone uninstall all gems") end -def update_dirs(time) - unless Gem::win_platform? - $DAILY_TEST_DIR = File.join('/tmp','daily_tests', time.to_s) - else - $DAILY_TEST_DIR = File.join(File.expand_path('~'),'daily_tests', time.to_s) #for Windows - end +def update_dirs(base_dir) + $DAILY_TEST_DIR = base_dir $DAILY_TEST_LOG_DIR = File.join($DAILY_TEST_DIR, 'log') $DAILY_TEST_LOG_FILE = File.join($DAILY_TEST_LOG_DIR, 'daily_test.log') $BBFS_DIR = File.join($DAILY_TEST_DIR, 'bbfs') @@ -201,10 +197,15 @@ def unit_test #start at midnight time_now = Time.now puts("Wake at #{time_now} and Start Daily test execution") + unless Gem::win_platform? + basic_dir = File.join('/tmp','daily_tests') + else + basic_dir = File.join(File.expand_path('~'),'daily_tests') #for Windows + end exec_index = 1 while exec_index < 99999 dir_time_format = "#{time_now.year}_#{time_now.month}_#{time_now.day}.exec_#{exec_index}" - trial_file = File.join('/tmp','daily_tests', dir_time_format) + trial_file = File.join(basic_dir, dir_time_format) break unless File.exist?(trial_file) exec_index += 1 end From 6935661cb4c16d416a9c5e1383e97037555e908d Mon Sep 17 00:00:00 2001 From: yarondbb Date: Mon, 16 Dec 2013 17:37:37 +0200 Subject: [PATCH 19/20] . --- bin/daily_tests.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 4e17734..65aeca9 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -196,7 +196,7 @@ def unit_test #start at midnight time_now = Time.now - puts("Wake at #{time_now} and Start Daily test execution") + puts("\nWake at #{time_now} and Start Daily test execution") unless Gem::win_platform? basic_dir = File.join('/tmp','daily_tests') else From 23eb75ae8257891e15965a5d40d3575aa45b3285 Mon Sep 17 00:00:00 2001 From: AlexeyNemytov Date: Sat, 4 Jan 2014 15:50:18 +0200 Subject: [PATCH 20/20] 1. ADD SERVER NAME TO LOG AND COMMAND LINE 2. ADD IIMIDIATE RUN COMMAND NOT TO WAIT FOR SLEEP 3. MKDIR FOR BBFS DIR IF NOT EXIST --- bin/daily_tests.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/daily_tests.rb b/bin/daily_tests.rb index 65aeca9..5b8232d 100644 --- a/bin/daily_tests.rb +++ b/bin/daily_tests.rb @@ -21,6 +21,7 @@ FROM_EMAIL = ARGV[0] FROM_EMAIL_PASSWORD = ARGV[1] TO_EMAIL = ARGV[2] +RUN_CMD = ARGV[3] # MIDNIGHT ; RUN or any other input $log_file = nil # will be initialized later @@ -77,6 +78,7 @@ def prepare_daily_test_dirs def clone_bbfs_repo Dir.chdir($DAILY_TEST_DIR) + ::FileUtils.mkdir_p($BBFS_DIR)unless File.exist?($BBFS_DIR) $log_file.puts("\n\nStart cloning bbfs from git repo:#{BBFS_GIT_REPO}") $log_file.puts("-------------------------------------------------------------------") execute_command("git clone #{BBFS_GIT_REPO}") @@ -165,9 +167,13 @@ def unit_test_generate_report(report) def unit_test + # init log $log_file = File.open($DAILY_TEST_LOG_FILE, 'w') + $log_file.puts("Working server name: #{$DAILY_TEST_SERVER}") + puts("\n Working server name: #{$DAILY_TEST_SERVER}") puts("\nRest of log can be found in: #{$DAILY_TEST_LOG_FILE}") + # from now on log file will be used by methods clone_bbfs_repo @@ -182,7 +188,10 @@ def unit_test end begin + # Working server name + $DAILY_TEST_SERVER =`hostname`.strip puts("Start Daily tests") + puts("\n Working server name: #{$DAILY_TEST_SERVER}") loop { time_now = Time.now current_hour = time_now.hour @@ -192,7 +201,7 @@ def unit_test seconds_from_midnight = current_seconds + current_minutes * 60 + current_hour * 3600 seconds_till_midnight = 24*3600 - seconds_from_midnight puts("Time is:#{time_now}. sleeping till midnight: #{seconds_till_midnight}[S]") - sleep(seconds_till_midnight+0.1) + sleep(seconds_till_midnight+0.1) if RUN_CMD == 'MIDNIGHT' #start at midnight time_now = Time.now @@ -217,5 +226,6 @@ def unit_test rescue => e puts("\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}") $log_file.puts("\nError caught. Msg:#{e.message}\nBack trace:#{e.backtrace}") + $log_file.puts("Working server name: #{$DAILY_TEST_SERVER}") $log_file.close end