예제 #1
0
 def test_special_volumes(self, size, loop_device, zero_method):
     # Zero size bytes
     blockdev.zero(loop_device.path, size=size)
     with io.open(loop_device.backing_file, "rb") as f:
         # Verify that size bytes were zeroed
         data = f.read(size)
         assert data == b"\0" * size
예제 #2
0
파일: blockdev_test.py 프로젝트: nirs/vdsm
 def test_entire_device(self, loop_device, zero_method):
     # Zero the entire device
     blockdev.zero(loop_device.path)
     # Check that it contains zeros
     with io.open(loop_device.backing_file, "rb") as f:
         data = f.read()
         assert data == b"\0" * FILE_SIZE
예제 #3
0
파일: blockdev_test.py 프로젝트: nirs/vdsm
 def test_special_volumes(self, size, loop_device, zero_method):
     # Zero size bytes
     blockdev.zero(loop_device.path, size=size)
     with io.open(loop_device.backing_file, "rb") as f:
         # Verify that size bytes were zeroed
         data = f.read(size)
         assert data == b"\0" * size
예제 #4
0
 def test_entire_device(self, loop_device, zero_method):
     # Zero the entire device
     blockdev.zero(loop_device.path)
     # Check that it contains zeros
     with io.open(loop_device.backing_file, "rb") as f:
         data = f.read()
         assert data == b"\0" * FILE_SIZE
예제 #5
0
파일: blockdev_test.py 프로젝트: nirs/vdsm
 def test_size(self, loop_device, zero_method):
     # Zero the first DEFAULT_BLOCK_SIZE
     blockdev.zero(loop_device.path, size=DEFAULT_BLOCK_SIZE)
     with io.open(loop_device.backing_file, "rb") as f:
         # Verify that the first DEFAULT_BLOCK_SIZE is zeroed
         data = f.read(DEFAULT_BLOCK_SIZE)
         assert data == b"\0" * DEFAULT_BLOCK_SIZE
         # And the rest was not modified
         data = f.read(DEFAULT_BLOCK_SIZE)
         assert data == b"x" * DEFAULT_BLOCK_SIZE
예제 #6
0
 def test_size(self, loop_device, zero_method):
     # Zero the first DEFAULT_BLOCK_SIZE
     blockdev.zero(loop_device.path, size=DEFAULT_BLOCK_SIZE)
     with io.open(loop_device.backing_file, "rb") as f:
         # Verify that the first DEFAULT_BLOCK_SIZE is zeroed
         data = f.read(DEFAULT_BLOCK_SIZE)
         assert data == b"\0" * DEFAULT_BLOCK_SIZE
         # And the rest was not modified
         data = f.read(DEFAULT_BLOCK_SIZE)
         assert data == b"x" * DEFAULT_BLOCK_SIZE
예제 #7
0
 def test_entire_device(self):
     with namedTemporaryDir() as tmpdir:
         # Prepare device poisoned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * SIZE)
         # Zero the entire device
         blockdev.zero(path)
         # Check that it contains zeros
         with io.open(path, "rb") as f:
             data = f.read()
             self.assertEqual(data, b"\0" * SIZE, "data was not zeroed")
예제 #8
0
 def test_special_volumes(self, size):
     with namedTemporaryDir() as tmpdir:
         # Prepare device posioned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * size)
         # Zero size bytes
         blockdev.zero(path, size=size)
         with io.open(path, "rb") as f:
             # Verify that size bytes were zeroed
             data = f.read(size)
             self.assertEqual(data, b"\0" * size, "data was not zeroed")
예제 #9
0
 def test_entire_device(self):
     with namedTemporaryDir() as tmpdir:
         # Prepare device poisoned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * SIZE)
         # Zero the entire device
         blockdev.zero(path)
         # Check that it contains zeros
         with io.open(path, "rb") as f:
             data = f.read()
             self.assertEqual(data, b"\0" * SIZE, "data was not zeroed")
예제 #10
0
 def test_special_volumes(self, size):
     with namedTemporaryDir() as tmpdir:
         # Prepare device posioned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * size)
         # Zero size bytes
         blockdev.zero(path, size=size)
         with io.open(path, "rb") as f:
             # Verify that size bytes were zeroed
             data = f.read(size)
             self.assertEqual(data, b"\0" * size, "data was not zeroed")
예제 #11
0
    def test_size(self, loop_device):
        # Write some data to the device.
        with directio.open(loop_device.path, "r+") as f:
            f.write(DATA * 2)

        # Zero bytes at the start of the device.
        blockdev.zero(loop_device.path, size=len(ZERO))

        # Verify that the area was zeroed.
        with directio.open(loop_device.path) as f:
            data = f.read(len(ZERO))
            assert data == ZERO
            data = f.read(len(DATA))
            assert data == DATA
예제 #12
0
파일: blockdev_test.py 프로젝트: oVirt/vdsm
    def test_special_volumes(self, size, loop_device):
        # Write some data to the device.
        with directio.open(loop_device.path, "r+") as f:
            f.write(b"x" * size * 2)

        # Zero size bytes
        blockdev.zero(loop_device.path, size=size)

        # Verify that size bytes were zeroed and the rest not modified.
        with directio.open(loop_device.path) as f:
            data = f.read(size)
            assert data == b"\0" * size
            data = f.read(size)
            assert data == b"x" * size
예제 #13
0
파일: blockdev_test.py 프로젝트: oVirt/vdsm
    def test_size(self, loop_device):
        # Write some data to the device.
        with directio.open(loop_device.path, "r+") as f:
            f.write(DATA * 2)

        # Zero bytes at the start of the device.
        blockdev.zero(loop_device.path, size=len(ZERO))

        # Verify that the area was zeroed.
        with directio.open(loop_device.path) as f:
            data = f.read(len(ZERO))
            assert data == ZERO
            data = f.read(len(DATA))
            assert data == DATA
예제 #14
0
 def test_abort(self, tmpdir):
     # Prepare device poisoned with "x"
     path = str(tmpdir.join("file"))
     with io.open(path, "wb") as f:
         f.write(b"x" * FILE_SIZE)
     # Create a task that will be aborted immediately
     task = AbortingTask()
     # The operation should be stopped
     with pytest.raises(exception.ActionStopped):
         blockdev.zero(path, size=FILE_SIZE, task=task)
     # And the file should not be zeroed
     with io.open(path, "rb") as f:
         data = f.read(FILE_SIZE)
         assert data == b"x" * FILE_SIZE
예제 #15
0
파일: blockdev_test.py 프로젝트: nirs/vdsm
 def test_abort(self, tmpdir):
     # Prepare device poisoned with "x"
     path = str(tmpdir.join("file"))
     with io.open(path, "wb") as f:
         f.write(b"x" * FILE_SIZE)
     # Create a task that will be aborted immediately
     task = AbortingTask()
     # The operation should be stopped
     with pytest.raises(exception.ActionStopped):
         blockdev.zero(path, size=FILE_SIZE, task=task)
     # And the file should not be zeroed
     with io.open(path, "rb") as f:
         data = f.read(FILE_SIZE)
         assert data == b"x" * FILE_SIZE
예제 #16
0
    def test_special_volumes(self, size, loop_device):
        # Write some data to the device.
        with directio.open(loop_device.path, "r+") as f:
            f.write(b"x" * size * 2)

        # Zero size bytes
        blockdev.zero(loop_device.path, size=size)

        # Verify that size bytes were zeroed and the rest not modified.
        with directio.open(loop_device.path) as f:
            data = f.read(size)
            assert data == b"\0" * size
            data = f.read(size)
            assert data == b"x" * size
예제 #17
0
 def test_abort(self):
     with namedTemporaryDir() as tmpdir:
         # Prepare device poisoned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * SIZE)
         # Create a task that will be aborted immediately
         task = AbortingTask()
         # The operation should be stopped
         with self.assertRaises(exception.ActionStopped):
             blockdev.zero(path, size=SIZE, task=task)
         # And the file should not be zeroed
         with io.open(path, "rb") as f:
             data = f.read(SIZE)
             self.assertEqual(data, b"x" * SIZE, "data was modified")
예제 #18
0
 def test_size(self):
     with namedTemporaryDir() as tmpdir:
         # Prepare device poisoned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * SIZE * 2)
         # Zero the first 1Mib
         blockdev.zero(path, size=SIZE)
         with io.open(path, "rb") as f:
             # Verify that the first 1MiB is zeroed
             data = f.read(SIZE)
             self.assertEqual(data, b"\0" * SIZE, "data was not zeroed")
             # And the rest was not modified
             data = f.read(SIZE)
             self.assertEqual(data, b"x" * SIZE, "data was modified")
예제 #19
0
 def test_abort(self):
     with namedTemporaryDir() as tmpdir:
         # Prepare device poisoned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * SIZE)
         # Create a task that will be aborted immediately
         task = AbortingTask()
         # The operation should be stopped
         with self.assertRaises(exception.ActionStopped):
             blockdev.zero(path, size=SIZE, task=task)
         # And the file should not be zeroed
         with io.open(path, "rb") as f:
             data = f.read(SIZE)
             self.assertEqual(data, b"x" * SIZE, "data was modified")
예제 #20
0
 def test_size(self):
     with namedTemporaryDir() as tmpdir:
         # Prepare device poisoned with "x"
         path = os.path.join(tmpdir, "file")
         with io.open(path, "wb") as f:
             f.write(b"x" * SIZE * 2)
         # Zero the first 1Mib
         blockdev.zero(path, size=SIZE)
         with io.open(path, "rb") as f:
             # Verify that the first 1MiB is zeroed
             data = f.read(SIZE)
             self.assertEqual(data, b"\0" * SIZE, "data was not zeroed")
             # And the rest was not modified
             data = f.read(SIZE)
             self.assertEqual(data, b"x" * SIZE, "data was modified")
예제 #21
0
    def test_entire_device(self, loop_device):
        # Write some data to the device.
        with directio.open(loop_device.path, "r+") as f:
            f.write(DATA)
            f.seek(FILE_SIZE - len(DATA))
            f.write(DATA)

        # Zero the entire device
        blockdev.zero(loop_device.path)

        # Verify that parts with data were zeroed.
        with directio.open(loop_device.path) as f:
            data = f.read(len(ZERO))
            assert data == ZERO
            f.seek(FILE_SIZE - len(ZERO))
            data = f.read(len(ZERO))
            assert data == ZERO
예제 #22
0
파일: blockdev_test.py 프로젝트: oVirt/vdsm
    def test_entire_device(self, loop_device):
        # Write some data to the device.
        with directio.open(loop_device.path, "r+") as f:
            f.write(DATA)
            f.seek(FILE_SIZE - len(DATA))
            f.write(DATA)

        # Zero the entire device
        blockdev.zero(loop_device.path)

        # Verify that parts with data were zeroed.
        with directio.open(loop_device.path) as f:
            data = f.read(len(ZERO))
            assert data == ZERO
            f.seek(FILE_SIZE - len(ZERO))
            data = f.read(len(ZERO))
            assert data == ZERO
예제 #23
0
파일: blockVolume.py 프로젝트: minqf/vdsm
    def delete(self, postZero, force, discard):
        """ Delete volume
            'postZero' - zeroing file before deletion
            'force' is required to remove shared and internal volumes
            'discard' - discard lv before deletion
        """
        self.log.info("Request to delete LV %s of image %s in VG %s ",
                      self.volUUID, self.imgUUID, self.sdUUID)

        vol_path = self.getVolumePath()

        # On block storage domains we store a volume's parent UUID in two
        # places: 1) in the domain's metadata LV, and 2) in a LV tag attached
        # to the volume LV itself.  The LV tag is more efficient to access
        # than the domain metadata but it may only be updated by the SPM.
        #
        # This means that after a live merge completes the domain metadata LV
        # will be updated but the LV tag will not.  We can detect this case
        # here and fix the LV tag since this is an SPM verb.
        #
        # File domains do not have this complexity because the metadata is
        # stored in only one place and that metadata is updated by the HSM
        # host when the live merge finishes.
        sync = False
        for childID in self.getChildren():
            child = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                childID)
            metaParent = child.getParentMeta()
            tagParent = child.getParentTag()
            if metaParent != tagParent:
                self.log.debug(
                    "Updating stale PUUID LV tag from %s to %s for "
                    "volume %s", tagParent, metaParent, child.volUUID)
                child.setParentTag(metaParent)
                sync = True
        if sync:
            self.recheckIfLeaf()

        if not force:
            self.validateDelete()

        # Mark volume as illegal before deleting
        self.setLegality(sc.ILLEGAL_VOL)

        if postZero or discard:
            self.prepare(justme=True,
                         rw=True,
                         chainrw=force,
                         setrw=True,
                         force=True)
            try:
                if postZero:
                    blockdev.zero(vol_path, task=vars.task)

                if discard:
                    blockdev.discard(vol_path)
            finally:
                self.teardown(self.sdUUID, self.volUUID, justme=True)

        # try to cleanup as much as possible
        eFound = se.CannotDeleteVolume(self.volUUID)
        puuid = None
        try:
            # We need to blank parent record in our metadata
            # for parent to become leaf successfully.
            puuid = self.getParent()
            self.setParent(sc.BLANK_UUID)
            if puuid and puuid != sc.BLANK_UUID:
                pvol = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                   puuid)
                pvol.recheckIfLeaf()
        except Exception as e:
            eFound = e
            self.log.warning("cannot finalize parent volume %s",
                             puuid,
                             exc_info=True)

        # Basically, we want to mark the volume _remove_me at the beginning of
        # the delete; however, with the current delete logic, if marking the
        # volume fails, and the deleted volume is a leaf, we end up with a
        # chain with a valid leaf volume.
        # The ultimate solution of volume deletion requires changes in
        # image.syncVolumeChain to disconnect the volume from the chain,
        # and probably there mark it as _remove_me.
        manifest = sdCache.produce_manifest(self.sdUUID)
        manifest.markForDelVols(self.sdUUID, self.imgUUID, [self.volUUID],
                                sc.REMOVED_IMAGE_PREFIX)

        try:
            lvm.removeLVs(self.sdUUID, (self.volUUID, ))
        except se.CannotRemoveLogicalVolume as e:
            self.log.exception(
                "Failed to delete volume %s/%s. The "
                "logical volume must be removed manually.", self.sdUUID,
                self.volUUID)

        try:
            self.log.info("Unlinking %s", vol_path)
            os.unlink(vol_path)
            return True
        except Exception as e:
            eFound = e
            self.log.error("cannot delete volume's %s/%s link path: %s",
                           self.sdUUID,
                           self.volUUID,
                           vol_path,
                           exc_info=True)

        raise eFound
예제 #24
0
파일: blockVolume.py 프로젝트: EdDev/vdsm
    def delete(self, postZero, force, discard):
        """ Delete volume
            'postZero' - zeroing file before deletion
            'force' is required to remove shared and internal volumes
            'discard' - discard lv before deletion
        """
        self.log.info("Request to delete LV %s of image %s in VG %s ",
                      self.volUUID, self.imgUUID, self.sdUUID)

        vol_path = self.getVolumePath()
        offs = self.getMetaOffset()

        # On block storage domains we store a volume's parent UUID in two
        # places: 1) in the domain's metadata LV, and 2) in a LV tag attached
        # to the volume LV itself.  The LV tag is more efficient to access
        # than the domain metadata but it may only be updated by the SPM.
        #
        # This means that after a live merge completes the domain metadata LV
        # will be updated but the LV tag will not.  We can detect this case
        # here and fix the LV tag since this is an SPM verb.
        #
        # File domains do not have this complexity because the metadata is
        # stored in only one place and that metadata is updated by the HSM
        # host when the live merge finishes.
        sync = False
        for childID in self.getChildren():
            child = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                childID)
            metaParent = child.getParentMeta()
            tagParent = child.getParentTag()
            if metaParent != tagParent:
                self.log.debug("Updating stale PUUID LV tag from %s to %s for "
                               "volume %s", tagParent, metaParent,
                               child.volUUID)
                child.setParentTag(metaParent)
                sync = True
        if sync:
            self.recheckIfLeaf()

        if not force:
            self.validateDelete()

        # Mark volume as illegal before deleting
        self.setLegality(sc.ILLEGAL_VOL)

        discard_needed = discard or blockdev.discard_enabled()
        if postZero or discard_needed:
            self.prepare(justme=True, rw=True, chainrw=force, setrw=True,
                         force=True)
            try:
                if postZero:
                    blockdev.zero(vol_path, task=vars.task)

                if discard_needed:
                    blockdev.discard(vol_path)
            finally:
                self.teardown(self.sdUUID, self.volUUID, justme=True)

        # try to cleanup as much as possible
        eFound = se.CannotDeleteVolume(self.volUUID)
        puuid = None
        try:
            # We need to blank parent record in our metadata
            # for parent to become leaf successfully.
            puuid = self.getParent()
            self.setParent(sc.BLANK_UUID)
            if puuid and puuid != sc.BLANK_UUID:
                pvol = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                   puuid)
                pvol.recheckIfLeaf()
        except Exception as e:
            eFound = e
            self.log.warning("cannot finalize parent volume %s", puuid,
                             exc_info=True)

        try:
            try:
                lvm.removeLVs(self.sdUUID, self.volUUID)
            except se.CannotRemoveLogicalVolume:
                # At this point LV is already marked as illegal, we will
                # try to cleanup whatever we can...
                pass

            self.removeMetadata([self.sdUUID, offs])
        except Exception as e:
            eFound = e
            self.log.error("cannot remove volume %s/%s", self.sdUUID,
                           self.volUUID, exc_info=True)

        try:
            self.log.debug("Unlinking %s", vol_path)
            os.unlink(vol_path)
            return True
        except Exception as e:
            eFound = e
            self.log.error("cannot delete volume's %s/%s link path: %s",
                           self.sdUUID, self.volUUID, vol_path, exc_info=True)

        raise eFound
예제 #25
0
파일: blockVolume.py 프로젝트: nirs/vdsm
    def delete(self, postZero, force, discard):
        """ Delete volume
            'postZero' - zeroing file before deletion
            'force' is required to remove shared and internal volumes
            'discard' - discard lv before deletion
        """
        self.log.info("Request to delete LV %s of image %s in VG %s ",
                      self.volUUID, self.imgUUID, self.sdUUID)

        vol_path = self.getVolumePath()
        slot = self.getMetaSlot()

        # On block storage domains we store a volume's parent UUID in two
        # places: 1) in the domain's metadata LV, and 2) in a LV tag attached
        # to the volume LV itself.  The LV tag is more efficient to access
        # than the domain metadata but it may only be updated by the SPM.
        #
        # This means that after a live merge completes the domain metadata LV
        # will be updated but the LV tag will not.  We can detect this case
        # here and fix the LV tag since this is an SPM verb.
        #
        # File domains do not have this complexity because the metadata is
        # stored in only one place and that metadata is updated by the HSM
        # host when the live merge finishes.
        sync = False
        for childID in self.getChildren():
            child = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                childID)
            metaParent = child.getParentMeta()
            tagParent = child.getParentTag()
            if metaParent != tagParent:
                self.log.debug("Updating stale PUUID LV tag from %s to %s for "
                               "volume %s", tagParent, metaParent,
                               child.volUUID)
                child.setParentTag(metaParent)
                sync = True
        if sync:
            self.recheckIfLeaf()

        if not force:
            self.validateDelete()

        # Mark volume as illegal before deleting
        self.setLegality(sc.ILLEGAL_VOL)

        if postZero or discard:
            self.prepare(justme=True, rw=True, chainrw=force, setrw=True,
                         force=True)
            try:
                if postZero:
                    blockdev.zero(vol_path, task=vars.task)

                if discard:
                    blockdev.discard(vol_path)
            finally:
                self.teardown(self.sdUUID, self.volUUID, justme=True)

        # try to cleanup as much as possible
        eFound = se.CannotDeleteVolume(self.volUUID)
        puuid = None
        try:
            # We need to blank parent record in our metadata
            # for parent to become leaf successfully.
            puuid = self.getParent()
            self.setParent(sc.BLANK_UUID)
            if puuid and puuid != sc.BLANK_UUID:
                pvol = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                   puuid)
                pvol.recheckIfLeaf()
        except Exception as e:
            eFound = e
            self.log.warning("cannot finalize parent volume %s", puuid,
                             exc_info=True)

        # Basically, we want to mark the volume _remove_me at the beginning of
        # the delete; however, with the current delete logic, if marking the
        # volume fails, and the deleted volume is a leaf, we end up with a
        # chain with a valid leaf volume.
        # The ultimate solution of volume deletion requires changes in
        # image.syncVolumeChain to disconnect the volume from the chain,
        # and probably there mark it as _remove_me.
        manifest = sdCache.produce_manifest(self.sdUUID)
        manifest.markForDelVols(self.sdUUID, self.imgUUID, [self.volUUID],
                                sc.REMOVED_IMAGE_PREFIX)

        try:
            lvm.removeLVs(self.sdUUID, self.volUUID)
        except se.CannotRemoveLogicalVolume as e:
            self.log.exception("Failed to delete volume %s/%s. The "
                               "logical volume must be removed manually.",
                               self.sdUUID, self.volUUID)
        else:
            # If removing the LV fails, we don't want to remove the
            # metadata. As the volume still exists on the storage, and is
            # accessible, removing the metadata will cause unexpected
            # errors when accessing the metadata that was wiped.  This is a
            # minimal solution for: https://bugzilla.redhat.com/1574631
            try:
                self.removeMetadata([self.sdUUID, slot])
            except se.VolumeMetadataWriteError as e:
                eFound = e
                self.log.exception("Failed to delete volume %s/%s metadata.",
                                   self.sdUUID, self.volUUID)

        try:
            self.log.info("Unlinking %s", vol_path)
            os.unlink(vol_path)
            return True
        except Exception as e:
            eFound = e
            self.log.error("cannot delete volume's %s/%s link path: %s",
                           self.sdUUID, self.volUUID, vol_path, exc_info=True)

        raise eFound
예제 #26
0
 def test_unaligned_size(self, size):
     with self.assertRaises(se.InvalidParameterException):
         blockdev.zero("/no/such/path", size=size)
예제 #27
0
    def delete(self, postZero, force, discard):
        """ Delete volume
            'postZero' - zeroing file before deletion
            'force' is required to remove shared and internal volumes
            'discard' - discard lv before deletion
        """
        self.log.info("Request to delete LV %s of image %s in VG %s ",
                      self.volUUID, self.imgUUID, self.sdUUID)

        vol_path = self.getVolumePath()
        offs = self.getMetaOffset()

        # On block storage domains we store a volume's parent UUID in two
        # places: 1) in the domain's metadata LV, and 2) in a LV tag attached
        # to the volume LV itself.  The LV tag is more efficient to access
        # than the domain metadata but it may only be updated by the SPM.
        #
        # This means that after a live merge completes the domain metadata LV
        # will be updated but the LV tag will not.  We can detect this case
        # here and fix the LV tag since this is an SPM verb.
        #
        # File domains do not have this complexity because the metadata is
        # stored in only one place and that metadata is updated by the HSM
        # host when the live merge finishes.
        sync = False
        for childID in self.getChildren():
            child = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                childID)
            metaParent = child.getParentMeta()
            tagParent = child.getParentTag()
            if metaParent != tagParent:
                self.log.debug("Updating stale PUUID LV tag from %s to %s for "
                               "volume %s", tagParent, metaParent,
                               child.volUUID)
                child.setParentTag(metaParent)
                sync = True
        if sync:
            self.recheckIfLeaf()

        if not force:
            self.validateDelete()

        # Mark volume as illegal before deleting
        self.setLegality(sc.ILLEGAL_VOL)

        if postZero or discard:
            self.prepare(justme=True, rw=True, chainrw=force, setrw=True,
                         force=True)
            try:
                if postZero:
                    blockdev.zero(vol_path, task=vars.task)

                if discard:
                    blockdev.discard(vol_path)
            finally:
                self.teardown(self.sdUUID, self.volUUID, justme=True)

        # try to cleanup as much as possible
        eFound = se.CannotDeleteVolume(self.volUUID)
        puuid = None
        try:
            # We need to blank parent record in our metadata
            # for parent to become leaf successfully.
            puuid = self.getParent()
            self.setParent(sc.BLANK_UUID)
            if puuid and puuid != sc.BLANK_UUID:
                pvol = BlockVolume(self.repoPath, self.sdUUID, self.imgUUID,
                                   puuid)
                pvol.recheckIfLeaf()
        except Exception as e:
            eFound = e
            self.log.warning("cannot finalize parent volume %s", puuid,
                             exc_info=True)

        try:
            try:
                lvm.removeLVs(self.sdUUID, self.volUUID)
            except se.CannotRemoveLogicalVolume:
                # At this point LV is already marked as illegal, we will
                # try to cleanup whatever we can...
                pass

            self.removeMetadata([self.sdUUID, offs])
        except Exception as e:
            eFound = e
            self.log.error("cannot remove volume %s/%s", self.sdUUID,
                           self.volUUID, exc_info=True)

        try:
            self.log.debug("Unlinking %s", vol_path)
            os.unlink(vol_path)
            return True
        except Exception as e:
            eFound = e
            self.log.error("cannot delete volume's %s/%s link path: %s",
                           self.sdUUID, self.volUUID, vol_path, exc_info=True)

        raise eFound
예제 #28
0
 def test_unaligned_size(self, size):
     with pytest.raises(se.InvalidParameterException):
         blockdev.zero("/no/such/path", size=size)