Skip to content

Commit

Permalink
Fixing make clean script
Browse files Browse the repository at this point in the history
Change-Id: I8249c644c3f2c23e284672fe117f86a075fd793a
Reviewed-on: http://photon-jenkins.eng.vmware.com/39
Tested-by: jenkins-photon <[email protected]>
Reviewed-by: Touseef Liaqat <[email protected]>
  • Loading branch information
dthaluru authored and Touseef Liaqat committed Oct 7, 2015
1 parent b4e77fc commit a802553
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion support/make/makedefs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions support/package-builder/ChrootUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,4 +44,4 @@ def destroyChroot(self,chrootID):
return False
self.logger.info("Successfully destroyed chroot:"+chrootID)
return True


79 changes: 79 additions & 0 deletions support/package-builder/clean-up-chroot.py
Original file line number Diff line number Diff line change
@@ -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 <chrootpath>"
return False
return cleanUpChroot(sys.argv[1])

if __name__=="__main__":
main()

0 comments on commit a802553

Please sign in to comment.