Change-Id: I8249c644c3f2c23e284672fe117f86a075fd793a
Reviewed-on: http://photon-jenkins.eng.vmware.com/39
Tested-by: jenkins-photon <wangnan2015@hotmail.com>
Reviewed-by: Touseef Liaqat <tliaqat@vmware.com>
| ... | ... |
@@ -313,15 +313,12 @@ clean: clean-install clean-chroot |
| 313 | 313 |
clean-install: |
| 314 | 314 |
@echo "Cleaning installer working directory..." |
| 315 | 315 |
@if [ -d $(PHOTON_STAGE)/photon_iso ]; then \ |
| 316 |
- cd $(PHOTON_INSTALLER_DIR) && \ |
|
| 317 |
- $(PHOTON_INSTALLER_DIR)/mk-unmount-disk.sh -w $(PHOTON_STAGE)/photon_iso && \ |
|
| 318 |
- $(RMDIR) $(PHOTON_STAGE)/photon_iso; \ |
|
| 316 |
+ $(PHOTON_CHROOT_CLEANER) $(PHOTON_STAGE)/photon_iso; \ |
|
| 319 | 317 |
fi |
| 320 | 318 |
|
| 321 | 319 |
clean-chroot: |
| 322 | 320 |
@echo "Cleaning chroot path..." |
| 323 | 321 |
@if [ -d $(PHOTON_CHROOT_PATH) ]; then \ |
| 324 |
- cd $(PHOTON_PKG_BUILDER_DIR) && \ |
|
| 325 | 322 |
$(PHOTON_CHROOT_CLEANER) $(PHOTON_CHROOT_PATH); \ |
| 326 | 323 |
fi |
| 327 | 324 |
|
| ... | ... |
@@ -42,7 +42,7 @@ PHOTON_BINTRAY_CONFIG?=$(PHOTON_PKG_BUILDER_DIR)/pullsources.conf |
| 42 | 42 |
PHOTON_PULL_PUBLISH_RPMS=$(PHOTON_PULL_PUBLISH_RPMS_DIR)/pullpublishrpms.sh |
| 43 | 43 |
PHOTON_CLOUD_IMAGE_BUILDER=$(PHOTON_CLOUD_IMAGE_BUILDER_DIR)/cloud-image-build.sh |
| 44 | 44 |
|
| 45 |
-PHOTON_CHROOT_CLEANER=$(PHOTON_PKG_BUILDER_DIR)/cleanup-build-root.sh |
|
| 45 |
+PHOTON_CHROOT_CLEANER=$(PHOTON_PKG_BUILDER_DIR)/clean-up-chroot.py |
|
| 46 | 46 |
PHOTON_RPMS_DIR_NOARCH=$(PHOTON_RPMS_DIR)/noarch |
| 47 | 47 |
PHOTON_RPMS_DIR_X86_64=$(PHOTON_RPMS_DIR)/x86_64 |
| 48 | 48 |
PHOTON_UPDATED_RPMS_DIR_NOARCH?=$(PHOTON_UPDATED_RPMS_DIR)/noarch |
| ... | ... |
@@ -33,7 +33,7 @@ class ChrootUtils(object): |
| 33 | 33 |
# need to add timeout for this step |
| 34 | 34 |
# http://stackoverflow.com/questions/1191374/subprocess-with-timeout |
| 35 | 35 |
cmdUtils=CommandUtils() |
| 36 |
- returnVal=cmdUtils.runCommandInShell("./cleanup-build-root.sh "+chrootID)
|
|
| 36 |
+ returnVal=cmdUtils.runCommandInShell("./clean-up-chroot.py "+chrootID)
|
|
| 37 | 37 |
if not returnVal: |
| 38 | 38 |
self.logger.error("Unable to destroy chroot:"+ chrootID +".Unknown error.")
|
| 39 | 39 |
return False |
| ... | ... |
@@ -44,4 +44,4 @@ class ChrootUtils(object): |
| 44 | 44 |
return False |
| 45 | 45 |
self.logger.info("Successfully destroyed chroot:"+chrootID)
|
| 46 | 46 |
return True |
| 47 |
- |
|
| 48 | 47 |
\ No newline at end of file |
| 48 |
+ |
| 49 | 49 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,79 @@ |
| 0 |
+#!/usr/bin/env python |
|
| 1 |
+import subprocess |
|
| 2 |
+import sys |
|
| 3 |
+ |
|
| 4 |
+def cleanUpChroot(chrootPath): |
|
| 5 |
+ returnVal,listmountpoints=findmountpoints(chrootPath) |
|
| 6 |
+ |
|
| 7 |
+ if not returnVal: |
|
| 8 |
+ return False |
|
| 9 |
+ |
|
| 10 |
+ sortmountpoints(listmountpoints, chrootPath) |
|
| 11 |
+ |
|
| 12 |
+ print listmountpoints |
|
| 13 |
+ |
|
| 14 |
+ if not unmountmountpoints(listmountpoints): |
|
| 15 |
+ return False |
|
| 16 |
+ |
|
| 17 |
+ if not removeAllFilesFromChroot(chrootPath): |
|
| 18 |
+ return False |
|
| 19 |
+ |
|
| 20 |
+ return True |
|
| 21 |
+ |
|
| 22 |
+def removeAllFilesFromChroot(chrootPath): |
|
| 23 |
+ cmd="rm -rf "+chrootPath+"/*" |
|
| 24 |
+ process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
| 25 |
+ retval = process.wait() |
|
| 26 |
+ if retval!=0: |
|
| 27 |
+ print "Unable to remove files from chroot "+chrootPath |
|
| 28 |
+ return False |
|
| 29 |
+ return True |
|
| 30 |
+ |
|
| 31 |
+def unmountmountpoints(listmountpoints): |
|
| 32 |
+ if listmountpoints is None: |
|
| 33 |
+ return True |
|
| 34 |
+ result=True |
|
| 35 |
+ for mountpoint in listmountpoints: |
|
| 36 |
+ cmd="umount "+mountpoint |
|
| 37 |
+ process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
| 38 |
+ retval = process.wait() |
|
| 39 |
+ if retval!=0: |
|
| 40 |
+ result = False |
|
| 41 |
+ print "Unable to unmount "+mountpoint |
|
| 42 |
+ break |
|
| 43 |
+ if not result: |
|
| 44 |
+ print "Unable to unmount all mounts. Unable to clean up the chroot" |
|
| 45 |
+ return False |
|
| 46 |
+ return True |
|
| 47 |
+ |
|
| 48 |
+def findmountpoints(chrootPath): |
|
| 49 |
+ cmd="mount | grep "+chrootPath+" | cut -d' ' -s -f3" |
|
| 50 |
+ process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
|
|
| 51 |
+ retval = process.wait() |
|
| 52 |
+ if retval!=0: |
|
| 53 |
+ print "Unable to find mountpoints in chroot" |
|
| 54 |
+ return False,None |
|
| 55 |
+ mountpoints=process.communicate()[0] |
|
| 56 |
+ mountpoints= mountpoints.replace("\n"," ").strip()
|
|
| 57 |
+ if mountpoints == "": |
|
| 58 |
+ print "No mount points found" |
|
| 59 |
+ return True,None |
|
| 60 |
+ listmountpoints=mountpoints.split(" ")
|
|
| 61 |
+ return True,listmountpoints |
|
| 62 |
+ |
|
| 63 |
+def sortmountpoints(listmountpoints,chrootPath): |
|
| 64 |
+ if listmountpoints is None: |
|
| 65 |
+ return True |
|
| 66 |
+ sortedmountpoints=listmountpoints |
|
| 67 |
+ sorted(sortedmountpoints) |
|
| 68 |
+ sortedmountpoints.reverse() |
|
| 69 |
+ |
|
| 70 |
+def main(): |
|
| 71 |
+ if len(sys.argv) < 2: |
|
| 72 |
+ print "Usage: ./clean-up-chroot.py <chrootpath>" |
|
| 73 |
+ return False |
|
| 74 |
+ return cleanUpChroot(sys.argv[1]) |
|
| 75 |
+ |
|
| 76 |
+if __name__=="__main__": |
|
| 77 |
+ main() |
|
| 78 |
+ |