add sync files method to just sync rpms
authorjingui.ren <jingui.ren@samsung.com>
Fri, 1 Feb 2019 09:42:30 +0000 (17:42 +0800)
committerjingui.ren <jingui.ren@samsung.com>
Fri, 1 Feb 2019 09:42:30 +0000 (17:42 +0800)
Change-Id: I3164821abd60d448c8abab2407fdc5973dcaa8cf

tools/worker.py

index e51da3fb913823b103f4a0676580262c87c0fe47..5ce0aaf86f4f8dcc8a2c22959461de376630fee0 100755 (executable)
@@ -7,12 +7,15 @@ import Queue
 import time
 import threading
 import multiprocessing
+import socket
 from multiprocessing import Process, cpu_count
 from kafka import KafkaConsumer
 from kafka import KafkaProducer
 
 class GbsBuild(object):
        errorRule = re.compile(r"some packages failed to be built")
+       ips = ['109.123.100.182','109.123.100.139','109.123.100.72']
+       cpus = [8,4,4]
        def __init__(self,packageName, id):
                super(GbsBuild, self).__init__()
                self.sourcePath = "/home/scm/renjg/workspace"
@@ -22,6 +25,8 @@ class GbsBuild(object):
                self.gbsRoot = "/home/scm/GBS-ROOT"
                self.packageName = packageName
                self.threadId = id
+               self.result = "/home/scm/GBS-ROOT-%d/local/results" % id
+               self.localip = socket.gethostbyname(socket.gethostname())
        def build(self):
                os.system("cd %s" % (self.sourcePath))
                os.system("mkdir -p %s" % self.logPath)
@@ -29,9 +34,30 @@ class GbsBuild(object):
                if GbsBuild.errorRule.findall(result):
                        print "%s build error \n log file is: %s/%s.log" % (self.packageName, self.logPath, self.packageName)
                        return "Fail"
-               os.system("scp -r %s renjg@109.123.123.6:/home/renjg/GBS-ROOT/local/repos/unified_standard/" % (self.gbsRoot+"-"+str(self.threadId)+"/local/repos/unified_standard/armv7l/"))
-               print "%s package in process %d ,build done, copy done" % (self.packageName, self.threadId)
+               #os.system("scp -r %s renjg@109.123.123.6:/home/renjg/GBS-ROOT/local/repos/unified_standard/" % (self.gbsRoot+"-"+str(self.threadId)+"/local/repos/unified_standard/armv7l/"))
+               print "%s package in process %d ,build done" % (self.packageName, self.threadId)
                return "Success"
+       def syncResult(self):
+               buildFiles = []
+               with open(self.result, "r") as f:
+                       buildFiles.append(f.readline)
+               os.system("rm -rf %s" % self.result)
+               if not buildFiles:
+                       return
+               for ip, cpunumber in zip(GbsBuild.ips, GbsBuild.cpus):
+                       if ip == self.localip:
+                               for i in xrange(cpunumber):
+                                       if i == self.threadId:
+                                               continue
+                                       else:
+                                               print "copy to %s GBS-ROOT-%d" % (ip, i)
+                                               for file in buildFiles:
+                                                       os.popen("cp %s /home/scm/GBS-ROOT-%d/local/repos/unified_standard/armv7l/RPMS/" % (file, i))
+                       else:
+                               for i in xrange(cpunumber):
+                                       print "copy to %s GBS-ROOT-%d" % (ip, i)
+                                       for file in buildFiles:
+                                               os.popen("scp %s samsung@%s:/home/scm/GBS-ROOT-%d/local/repos/unified_standard/armv7l/RPMS/" % (file, ip, i))
 
 class Consumer(Process):
        def __init__(self, threadId, partition = 0):
@@ -74,6 +100,8 @@ class Consumer(Process):
                                else:
                                        print "send fail"
                        self.messageHandler.close()
+                       gbsbuild.syncResult()
+                       print "sync done"
 
 class LargeConsumer(Process):
        def __init__(self, threadId, partition = 0):
@@ -114,6 +142,8 @@ class LargeConsumer(Process):
                                else:
                                        print "send fail"
                        self.messageHandler.close()
+                       gbsbuild.syncResult()
+                       print "sync done"
 
 class WorkerPool(object):
        capcaticy = cpu_count()