def test_cow_vm_conf_disk(self): """ When a VM configuration disk is actually COW format report it correctly """ with fake_file_env() as env: vol = make_volume(env, VM_CONF_SIZE, md_fmt='cow', real_fmt='cow') self.assertFalse(workarounds.invalid_vm_conf_disk(vol))
def test_bad_format_other_size(self): """ When the volume size does not match the VM configuration disk size then the workaround will not be activated even when the formats don't match """ size = 2 * VM_CONF_SIZE with fake_file_env() as env: vol = make_volume(env, size, md_fmt='cow', real_fmt='raw') self.assertFalse(workarounds.invalid_vm_conf_disk(vol))
def test_bad_format_vm_conf_disk(self): """ When the volume size matches the VM configuration disk size and the source volume reports COW even though qemuimg reports RAW then we expect the workaround to report both volumes as RAW. """ with fake_file_env() as env: vol = make_volume(env, VM_CONF_SIZE, md_fmt='cow', real_fmt='raw') self.assertTrue(workarounds.invalid_vm_conf_disk(vol))
def _interImagesCopy(self, destDom, srcSdUUID, imgUUID, chains): srcLeafVol = chains['srcChain'][-1] dstLeafVol = chains['dstChain'][-1] try: # Prepare the whole chains before the copy srcLeafVol.prepare(rw=False) dstLeafVol.prepare(rw=True, chainrw=True, setrw=True) except Exception: self.log.error("Unexpected error", exc_info=True) # teardown volumes self.__cleanupMove(srcLeafVol, dstLeafVol) raise try: for srcVol in chains['srcChain']: # Do the actual copy try: dstVol = destDom.produceVolume(imgUUID=imgUUID, volUUID=srcVol.volUUID) if workarounds.invalid_vm_conf_disk(srcVol): srcFormat = dstFormat = qemuimg.FORMAT.RAW else: srcFormat = sc.fmt2str(srcVol.getFormat()) dstFormat = sc.fmt2str(dstVol.getFormat()) parentVol = dstVol.getParentVolume() if parentVol is not None: backing = volume.getBackingVolumePath( imgUUID, parentVol.volUUID) backingFormat = sc.fmt2str(parentVol.getFormat()) else: backing = None backingFormat = None if (destDom.supportsSparseness and dstVol.getType() == sc.PREALLOCATED_VOL): preallocation = qemuimg.PREALLOCATION.FALLOC else: preallocation = None operation = qemuimg.convert( srcVol.getVolumePath(), dstVol.getVolumePath(), srcFormat=srcFormat, dstFormat=dstFormat, dstQcow2Compat=destDom.qcow2_compat(), backing=backing, backingFormat=backingFormat, preallocation=preallocation, unordered_writes=destDom.recommends_unordered_writes( dstVol.getFormat()), create=not destDom.is_block(), ) with utils.stopwatch("Copy volume %s" % srcVol.volUUID): self._run_qemuimg_operation(operation) except ActionStopped: raise except se.StorageException: self.log.error("Unexpected error", exc_info=True) raise except Exception: self.log.error( "Copy image error: image=%s, src domain=%s," " dst domain=%s", imgUUID, srcSdUUID, destDom.sdUUID, exc_info=True) raise se.CopyImageError() finally: # teardown volumes self.__cleanupMove(srcLeafVol, dstLeafVol)
def is_invalid_vm_conf_disk(self): return workarounds.invalid_vm_conf_disk(self.volume)
def _interImagesCopy(self, destDom, srcSdUUID, imgUUID, chains): srcLeafVol = chains['srcChain'][-1] dstLeafVol = chains['dstChain'][-1] try: # Prepare the whole chains before the copy srcLeafVol.prepare(rw=False) dstLeafVol.prepare(rw=True, chainrw=True, setrw=True) except Exception: self.log.error("Unexpected error", exc_info=True) # teardown volumes self.__cleanupMove(srcLeafVol, dstLeafVol) raise try: for srcVol in chains['srcChain']: # Do the actual copy try: dstVol = destDom.produceVolume(imgUUID=imgUUID, volUUID=srcVol.volUUID) if workarounds.invalid_vm_conf_disk(srcVol): srcFormat = dstFormat = qemuimg.FORMAT.RAW else: srcFormat = sc.fmt2str(srcVol.getFormat()) dstFormat = sc.fmt2str(dstVol.getFormat()) parentVol = dstVol.getParentVolume() if parentVol is not None: backing = volume.getBackingVolumePath( imgUUID, parentVol.volUUID) backingFormat = sc.fmt2str(parentVol.getFormat()) else: backing = None backingFormat = None operation = qemuimg.convert( srcVol.getVolumePath(), dstVol.getVolumePath(), srcFormat=srcFormat, dstFormat=dstFormat, dstQcow2Compat=destDom.qcow2_compat(), backing=backing, backingFormat=backingFormat, unordered_writes=destDom.recommends_unordered_writes( dstVol.getFormat()), create=dstVol.requires_create(), target_is_zero=dstVol.zero_initialized(), ) with utils.stopwatch("Copy volume {}".format( srcVol.volUUID), level=logging.INFO, log=self.log): self._run_qemuimg_operation(operation) except ActionStopped: raise except se.StorageException: self.log.error("Unexpected error", exc_info=True) raise except Exception: self.log.error( "Copy image error: image=%s, src domain=%s," " dst domain=%s", imgUUID, srcSdUUID, destDom.sdUUID, exc_info=True) raise se.CopyImageError() finally: # teardown volumes self.__cleanupMove(srcLeafVol, dstLeafVol)