[Title] Refactored "build-cli" to use JobLog.monitor
authordonghee yang <donghee.yang@samsung.com>
Fri, 29 Mar 2013 07:34:25 +0000 (16:34 +0900)
committerdonghee yang <donghee.yang@samsung.com>
Fri, 29 Mar 2013 07:34:25 +0000 (16:34 +0900)
build-cli
test/build-server.basic1/build-cli-31.testcase [new file with mode: 0644]
test/build-server.basic1/testsuite

index 746ae950792896f4029785f3cb08d40a179260e0..47186af50b03c8735c8f53a41f60714c8baeadbe 100755 (executable)
--- 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 " <ip>:<port>"
                        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 (file)
index 0000000..a37f1e0
--- /dev/null
@@ -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"
index 478f8048951eb6d578a27b1814a707a04e9043e6..52ceaa4d9dfd9b204d90815fbd0f9f772b34077c 100644 (file)
@@ -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