Ejemplo n.º 1
0
 def testEmptyDir(self):
     """
     Test if method can delete an empty dir.
     """
     with namedTemporaryDir() as baseDir:
         dirty = os.path.join(baseDir, 'dirty')
         os.mkdir(dirty)
         fileUtils.cleanupdir(dirty)
         self.assertFalse(os.path.lexists(dirty))
Ejemplo n.º 2
0
 def testEmptyDir(self):
     """
     Test if method can delete an empty dir.
     """
     with namedTemporaryDir() as baseDir:
         dirty = os.path.join(baseDir, 'dirty')
         os.mkdir(dirty)
         fileUtils.cleanupdir(dirty)
         self.assertFalse(os.path.lexists(dirty))
Ejemplo n.º 3
0
 def create_image_rollback(cls, task, image_dir):
     """
     Remove empty image folder
     """
     cls.log.info("create image rollback (image_dir=%s)", image_dir)
     if os.path.exists(image_dir):
         if not len(os.listdir(image_dir)):
             fileUtils.cleanupdir(image_dir)
         else:
             cls.log.error("create image rollback: Cannot remove dirty "
                           "image (image_dir=%s)",
                           image_dir)
Ejemplo n.º 4
0
    def testDirWithUndeletableFiles(self):
        """
        See that the method handles correctly a situation where it is given a
        dir it can't clean.
        """
        baseDir = "/proc/misc"  # This can't be deleted

        # Try and fail to clean it
        fileUtils.cleanupdir(baseDir, ignoreErrors=True)
        self.assertTrue(os.path.lexists(baseDir))

        self.assertRaises(RuntimeError, fileUtils.cleanupdir, baseDir, False)
        self.assertTrue(os.path.lexists(baseDir))
Ejemplo n.º 5
0
Archivo: sd.py Proyecto: oVirt/vdsm
 def create_image_rollback(cls, task, image_dir):
     """
     Remove empty image folder
     """
     cls.log.info("create image rollback (image_dir=%s)", image_dir)
     if os.path.exists(image_dir):
         if not len(os.listdir(image_dir)):
             cls.log.info("Removing image directory %r", image_dir)
             fileUtils.cleanupdir(image_dir)
         else:
             cls.log.error("create image rollback: Cannot remove dirty "
                           "image (image_dir=%s)",
                           image_dir)
Ejemplo n.º 6
0
    def testDirWithUndeletableFiles(self):
        """
        See that the method handles correctly a situation where it is given a
        dir it can't clean.
        """
        baseDir = "/proc/misc"  # This can't be deleted

        # Try and fail to clean it
        fileUtils.cleanupdir(baseDir, ignoreErrors=True)
        self.assertTrue(os.path.lexists(baseDir))

        self.assertRaises(RuntimeError, fileUtils.cleanupdir,
                          baseDir, False)
        self.assertTrue(os.path.lexists(baseDir))
Ejemplo n.º 7
0
    def testFullDir(self):
        """
        Test if method can clean a dir it should be able to.
        """
        with namedTemporaryDir() as baseDir:
            # Populate dir
            dirty = os.path.join(baseDir, 'dirty')
            os.mkdir(dirty)
            numOfFilesToCreate = 50
            for i in range(numOfFilesToCreate):
                tempfile.mkstemp(dir=dirty)

            # clean it
            fileUtils.cleanupdir(dirty)

            self.assertFalse(os.path.lexists(dirty))
Ejemplo n.º 8
0
    def testFullDir(self):
        """
        Test if method can clean a dir it should be able to.
        """
        with namedTemporaryDir() as baseDir:
            # Populate dir
            dirty = os.path.join(baseDir, 'dirty')
            os.mkdir(dirty)
            numOfFilesToCreate = 50
            for i in range(numOfFilesToCreate):
                tempfile.mkstemp(dir=dirty)

            # clean it
            fileUtils.cleanupdir(dirty)

            self.assertFalse(os.path.lexists(dirty))
Ejemplo n.º 9
0
    def createVolumeRollback(cls, taskObj, repoPath, sdUUID, imgUUID, volUUID,
                             imageDir):
        cls.log.info("createVolumeRollback: repoPath=%s sdUUID=%s imgUUID=%s "
                     "volUUID=%s imageDir=%s" %
                     (repoPath, sdUUID, imgUUID, volUUID, imageDir))
        vol = sdCache.produce(sdUUID).produceVolume(imgUUID, volUUID)
        pvol = vol.getParentVolume()
        # Remove volume
        vol.delete(postZero=False, force=True)
        if len(cls.getImageVolumes(repoPath, sdUUID, imgUUID)):
            # Don't remove the image folder itself
            return

        if not pvol or pvol.isShared():
            # Remove image folder with all leftovers
            if os.path.exists(imageDir):
                fileUtils.cleanupdir(imageDir)
Ejemplo n.º 10
0
    def createVolumeRollback(cls, taskObj, repoPath,
                             sdUUID, imgUUID, volUUID, imageDir):
        cls.log.info("createVolumeRollback: repoPath=%s sdUUID=%s imgUUID=%s "
                     "volUUID=%s imageDir=%s" %
                     (repoPath, sdUUID, imgUUID, volUUID, imageDir))
        vol = sdCache.produce(sdUUID).produceVolume(imgUUID, volUUID)
        pvol = vol.getParentVolume()
        # Remove volume
        vol.delete(postZero=False, force=True, discard=False)
        if len(cls.getImageVolumes(repoPath, sdUUID, imgUUID)):
            # Don't remove the image folder itself
            return

        if not pvol or pvol.isShared():
            # Remove image folder with all leftovers
            if os.path.exists(imageDir):
                fileUtils.cleanupdir(imageDir)
Ejemplo n.º 11
0
 def testNotExistingDir(self):
     """
     See that method doesn't throw a fit if given a non existing dir
     """
     fileUtils.cleanupdir(os.path.join("I", " DONT", "EXIST"))
Ejemplo n.º 12
0
 def testNotExistingDir(self):
     """
     See that method doesn't throw a fit if given a non existing dir
     """
     fileUtils.cleanupdir(os.path.join("I", " DONT", "EXIST"))