From 72bc25744bf2d97e4ec773e3efca780e366ea763 Mon Sep 17 00:00:00 2001 From: donghee yang Date: Fri, 29 Mar 2013 16:34:25 +0900 Subject: [PATCH] [Title] Refactored "build-cli" to use JobLog.monitor --- build-cli | 124 +++++++----------- .../build-server.basic1/build-cli-31.testcase | 31 +++++ test/build-server.basic1/testsuite | 2 + 3 files changed, 82 insertions(+), 75 deletions(-) create mode 100644 test/build-server.basic1/build-cli-31.testcase diff --git a/build-cli b/build-cli index 746ae95..47186af 100755 --- a/build-cli +++ b/build-cli @@ -224,57 +224,36 @@ begin client.terminate if not client.nil? end + if not result then exit(-1) end + # Query log in case sync if result and option[:async].eql? "NO" then begin - client = BuildCommClient.create( addr[0], addr[1], nil, 0 ) - if client.nil? then - puts "ERROR: Can't query log, Connection to server failed!" - exit 1 - end - - client.send "LOG|#{job_id}" - result = client.read_lines do |line| - if line.strip.start_with?("=JOB_STATUS") then - data = line.strip.split(",") - job_status = data[1] - job_error = data[2] + result = JobLog.monitor(addr[0], addr[1], job_id) do |line| + category, level, contents = JobLog.parse_log(line) + if level < Log::LV_USER then next end + + if category == "INFO" then + puts "Info: #{contents}" + elsif category == "WARN" then + puts "Warn: #{contents}" + elsif category == "ERROR" then + puts "Error: #{contents}" else - # print log - category, level, contents = JobLog.parse_log(line) - if level < Log::LV_USER then next end - - if category == "INFO" then - puts "Info: #{contents}" - elsif category == "WARN" then - puts "Warn: #{contents}" - elsif category == "ERROR" then - puts "Error: #{contents}" - else - next - end + next end end - - if not result then - puts "ERROR: Can't query log, Communication failed! #{client.get_error_msg()}" - end - - # Check job status - if not job_status.eql? "FINISHED" then - result = false - end - client.terminate + rescue BuildServerException => e + puts e.err_message() + result = false rescue => e puts "ERROR: #{e}" result = false - client.terminate end end - if not result then - exit 1 - end + if not result then exit(1) end + when "query" result = Utils.parse_server_addr(option[:domain]) if result.nil? then @@ -324,16 +303,7 @@ begin query_job_list( result[0], result[1] ) when "query-log" - output = option[:output] - if output.nil? then - log = STDOUT - else - if File.exist? output - raise RuntimeError, "The output file is already exist." - end - log = File.open(output, "w") - end - + result = false addr = Utils.parse_server_addr(option[:domain]) if addr.nil? then puts "Server address is incorrect. (#{option[:domain]})" @@ -341,38 +311,39 @@ begin puts " :" exit 1 end + output = option[:output] - client = BuildCommClient.create( addr[0], addr[1], nil, 0 ) - if client.nil? then - raise RuntimeError, "The output file is already exist." - end + begin + if output.nil? then + log = STDOUT + else + if File.exist? output + raise RuntimeError, "The output file is already exist." + end + log = File.open(output, "w") + end - client.send "LOG|#{option[:job].strip}" - result = client.read_lines do |line| - if line.strip.start_with?("=JOB_STATUS") then - data = line.strip.split(",") - job_status = data[1] - job_error = data[2] - next + result = JobLog.monitor(addr[0], addr[1], option[:job].strip) do |line| + log.puts line + end + if result and not output.nil? then + log.puts "=LOG_END" + end + rescue BuildServerException => e + log.puts e.err_message() + result = false + rescue => e + puts "ERROR: #{e}" + result = false + ensure + if not output.nil? then + log.close if not log.nil? end - # print log - log.puts line - end - - if not output.nil? then - log.puts "=LOG_END" end if not result then - puts "ERROR: Communication failed! #{client.get_error_msg()}" - client.terminate - log.close - if not output.nil? then - FileUtils.rm output - end - exit 1 - else - client.terminate + FileUtils.rm output if not output.nil? + exit(1) end when "cancel" @@ -512,6 +483,9 @@ begin rescue BuildServerException => e puts e.err_message() result = false + rescue => e + puts "ERROR: #{e}" + result = false end if not result then exit(-1) end diff --git a/test/build-server.basic1/build-cli-31.testcase b/test/build-server.basic1/build-cli-31.testcase new file mode 100644 index 0000000..a37f1e0 --- /dev/null +++ b/test/build-server.basic1/build-cli-31.testcase @@ -0,0 +1,31 @@ +#PRE-EXEC +echo "query-log" +#EXEC +../../build-cli query-log -d 127.0.0.1:2223 -j 1 | grep {2} | cut -d '}' -f2 +#POST-EXEC +#EXPECT +Added new job +Initializing job... +Checking package version ... +Invoking a thread for building Job +New Job +hecking build dependency ... +Checking install dependency ... +Started to build this job... +JobBuilder +ownloding client is initializing... +Installing dependent packages... +Downloading dependent source packages... +Make clean... +Make build... +Make install... +eneratiing pkginfo.manifest... +Zipping... +Creating package file ... a_0.0.1_ubuntu-32.zip +Checking reverse build dependency ... +Uploading ... +Upload succeeded. Sync local pkg-server again... +Snapshot: +Job is completed! +Job is FINISHED successfully! +Updating the source info for project "testa" diff --git a/test/build-server.basic1/testsuite b/test/build-server.basic1/testsuite index 478f804..52ceaa4 100644 --- a/test/build-server.basic1/testsuite +++ b/test/build-server.basic1/testsuite @@ -28,3 +28,5 @@ build-cli-27.testcase build-cli-28.testcase build-cli-29.testcase build-cli-30.testcase +build-cli-31.testcase +build-cli-32.testcase -- 2.34.1