diff --git a/Makefile b/Makefile index 41b6d55fbd..bf4ad48aa0 100644 --- a/Makefile +++ b/Makefile @@ -313,15 +313,12 @@ clean: clean-install clean-chroot clean-install: @echo "Cleaning installer working directory..." @if [ -d $(PHOTON_STAGE)/photon_iso ]; then \ - cd $(PHOTON_INSTALLER_DIR) && \ - $(PHOTON_INSTALLER_DIR)/mk-unmount-disk.sh -w $(PHOTON_STAGE)/photon_iso && \ - $(RMDIR) $(PHOTON_STAGE)/photon_iso; \ + $(PHOTON_CHROOT_CLEANER) $(PHOTON_STAGE)/photon_iso; \ fi clean-chroot: @echo "Cleaning chroot path..." @if [ -d $(PHOTON_CHROOT_PATH) ]; then \ - cd $(PHOTON_PKG_BUILDER_DIR) && \ $(PHOTON_CHROOT_CLEANER) $(PHOTON_CHROOT_PATH); \ fi diff --git a/support/make/makedefs.mk b/support/make/makedefs.mk index 585f38e21e..266d72f685 100644 --- a/support/make/makedefs.mk +++ b/support/make/makedefs.mk @@ -42,7 +42,7 @@ PHOTON_BINTRAY_CONFIG?=$(PHOTON_PKG_BUILDER_DIR)/pullsources.conf PHOTON_PULL_PUBLISH_RPMS=$(PHOTON_PULL_PUBLISH_RPMS_DIR)/pullpublishrpms.sh PHOTON_CLOUD_IMAGE_BUILDER=$(PHOTON_CLOUD_IMAGE_BUILDER_DIR)/cloud-image-build.sh -PHOTON_CHROOT_CLEANER=$(PHOTON_PKG_BUILDER_DIR)/cleanup-build-root.sh +PHOTON_CHROOT_CLEANER=$(PHOTON_PKG_BUILDER_DIR)/clean-up-chroot.py PHOTON_RPMS_DIR_NOARCH=$(PHOTON_RPMS_DIR)/noarch PHOTON_RPMS_DIR_X86_64=$(PHOTON_RPMS_DIR)/x86_64 PHOTON_UPDATED_RPMS_DIR_NOARCH?=$(PHOTON_UPDATED_RPMS_DIR)/noarch diff --git a/support/package-builder/ChrootUtils.py b/support/package-builder/ChrootUtils.py index 486de4faa8..ec800b77b3 100644 --- a/support/package-builder/ChrootUtils.py +++ b/support/package-builder/ChrootUtils.py @@ -33,7 +33,7 @@ def destroyChroot(self,chrootID): # need to add timeout for this step # http://stackoverflow.com/questions/1191374/subprocess-with-timeout cmdUtils=CommandUtils() - returnVal=cmdUtils.runCommandInShell("./cleanup-build-root.sh "+chrootID) + returnVal=cmdUtils.runCommandInShell("./clean-up-chroot.py "+chrootID) if not returnVal: self.logger.error("Unable to destroy chroot:"+ chrootID +".Unknown error.") return False @@ -44,4 +44,4 @@ def destroyChroot(self,chrootID): return False self.logger.info("Successfully destroyed chroot:"+chrootID) return True - \ No newline at end of file + diff --git a/support/package-builder/clean-up-chroot.py b/support/package-builder/clean-up-chroot.py new file mode 100755 index 0000000000..e2687312af --- /dev/null +++ b/support/package-builder/clean-up-chroot.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +import subprocess +import sys + +def cleanUpChroot(chrootPath): + returnVal,listmountpoints=findmountpoints(chrootPath) + + if not returnVal: + return False + + sortmountpoints(listmountpoints, chrootPath) + + print listmountpoints + + if not unmountmountpoints(listmountpoints): + return False + + if not removeAllFilesFromChroot(chrootPath): + return False + + return True + +def removeAllFilesFromChroot(chrootPath): + cmd="rm -rf "+chrootPath+"/*" + process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + retval = process.wait() + if retval!=0: + print "Unable to remove files from chroot "+chrootPath + return False + return True + +def unmountmountpoints(listmountpoints): + if listmountpoints is None: + return True + result=True + for mountpoint in listmountpoints: + cmd="umount "+mountpoint + process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + retval = process.wait() + if retval!=0: + result = False + print "Unable to unmount "+mountpoint + break + if not result: + print "Unable to unmount all mounts. Unable to clean up the chroot" + return False + return True + +def findmountpoints(chrootPath): + cmd="mount | grep "+chrootPath+" | cut -d' ' -s -f3" + process = subprocess.Popen("%s" %cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) + retval = process.wait() + if retval!=0: + print "Unable to find mountpoints in chroot" + return False,None + mountpoints=process.communicate()[0] + mountpoints= mountpoints.replace("\n"," ").strip() + if mountpoints == "": + print "No mount points found" + return True,None + listmountpoints=mountpoints.split(" ") + return True,listmountpoints + +def sortmountpoints(listmountpoints,chrootPath): + if listmountpoints is None: + return True + sortedmountpoints=listmountpoints + sorted(sortedmountpoints) + sortedmountpoints.reverse() + +def main(): + if len(sys.argv) < 2: + print "Usage: ./clean-up-chroot.py " + return False + return cleanUpChroot(sys.argv[1]) + +if __name__=="__main__": + main() +