Browse code

Removing lock from chroot utils

Divya Thaluru authored on 2015/06/02 23:41:03
Showing 4 changed files
... ...
@@ -103,7 +103,20 @@ class ChrootUtils(object):
103 103
         ChrootUtils.lockForTrackingChroots.release()           
104 104
         return True,chrootID
105 105
     
106
+    def createChroot1(self,chrootID):
107
+        # need to add timeout for this step
108
+        # http://stackoverflow.com/questions/1191374/subprocess-with-timeout
109
+        process = subprocess.Popen("mkdir -p "+chrootID,shell=True,stdout=subprocess.PIPE)
110
+        retval = process.wait()
111
+        
112
+        if retval != 0:
113
+            self.logger.error("Unable to create chroot:"+ chrootID +".Unknown error.")
114
+            return False,None
115
+        
116
+        return True,chrootID
117
+    
106 118
     def destroyChroot(self,chrootID):
119
+        '''
107 120
         validChroot = True
108 121
         ChrootUtils.lockForTrackingChroots.acquire()
109 122
         if chrootID not in ChrootUtils.activeChroots:
... ...
@@ -114,7 +127,7 @@ class ChrootUtils(object):
114 114
         if not validChroot:
115 115
             self.logger.error("Given chroot:"+chrootID+" is not a valid chroot. It is not created by ChrootUtils.")
116 116
             return False
117
-
117
+        '''
118 118
         # need to add timeout for this step
119 119
         # http://stackoverflow.com/questions/1191374/subprocess-with-timeout
120 120
         process = subprocess.Popen("./cleanup-build-root.sh "+chrootID,shell=True,stdout=subprocess.PIPE)
... ...
@@ -36,6 +36,21 @@ class PackageBuilder(object):
36 36
             raise e
37 37
         return chrootID
38 38
     
39
+    def prepareBuildRoot1(self,chrootID):
40
+        #chrootID=None
41
+        try:
42
+            chrUtils = ChrootUtils(self.logName,self.logPath)
43
+            returnVal,chrootID = chrUtils.createChroot1(chrootID)
44
+            if not returnVal:
45
+                raise Exception("Unable to prepare build root")
46
+            tUtils=ToolChainUtils(self.logName,self.logPath)
47
+            tUtils.installToolChain(chrootID)
48
+        except Exception as e:
49
+            if chrootID is not None:
50
+                chrUtils.destroyChroot(chrootID)
51
+            raise e
52
+        return chrootID
53
+    
39 54
     def findPackageNameFromRPMFile(self,rpmfile):
40 55
         rpmfile=os.path.basename(rpmfile)
41 56
         releaseindex=rpmfile.rfind("-")
... ...
@@ -70,9 +85,9 @@ class PackageBuilder(object):
70 70
     def buildPackage(self,package):
71 71
         #should initialize a logger based on package name
72 72
         chrUtils = ChrootUtils(self.logName,self.logPath)
73
-        chrootID=None
73
+        chrootID="build-"+package
74 74
         try:
75
-            chrootID = self.prepareBuildRoot()
75
+            chrootID = self.prepareBuildRoot1(chrootID)
76 76
             destLogPath=constants.logPath+"/build-"+package
77 77
             if not os.path.isdir(destLogPath):
78 78
                 cmdUtils = CommandUtils()
... ...
@@ -202,7 +202,7 @@ class PackageManager(object):
202 202
         Scheduler.setParams(self.sortedPackageList, self.listOfPackagesAlreadyBuilt)
203 203
         Scheduler.setEvent(statusEvent)
204 204
         
205
-        numWorkerThreads=self.calculatePossibleNumWorkerThreads()
205
+        numWorkerThreads=8#self.calculatePossibleNumWorkerThreads()
206 206
         if numWorkerThreads == 0:
207 207
             return False
208 208
          
... ...
@@ -70,9 +70,11 @@ class Scheduler(object):
70 70
     
71 71
     @staticmethod
72 72
     def getNextPackageToBuild():
73
+        Scheduler.logger.info("Waiting to acquire scheduler lock")
73 74
         Scheduler.lock.acquire()
74 75
         
75 76
         if Scheduler.stopScheduling:
77
+            Scheduler.logger.info("Released scheduler lock")
76 78
             Scheduler.lock.release()
77 79
             return None
78 80
         
... ...
@@ -85,6 +87,7 @@ class Scheduler(object):
85 85
             Scheduler.listOfPackagesNextToBuild=listOfPackagesNextToBuild
86 86
             
87 87
         if len(Scheduler.listOfPackagesNextToBuild) == 0:
88
+            Scheduler.logger.info("Released scheduler lock")
88 89
             Scheduler.lock.release()
89 90
             return None
90 91
         
... ...
@@ -92,6 +95,7 @@ class Scheduler(object):
92 92
         
93 93
         if len(Scheduler.listOfPackagesNextToBuild) > 0:
94 94
             ThreadPool.activateWorkerThreads(len(Scheduler.listOfPackagesNextToBuild))
95
+        Scheduler.logger.info("Released scheduler lock")
95 96
         Scheduler.lock.release()
96 97
         Scheduler.listOfPackagesCurrentlyBuilding.append(package)
97 98
         Scheduler.listOfPackagesToBuild.remove(package)