Adam Litke has uploaded a new change for review. Change subject: Use Volume.operation in SDM.copy_data ......................................................................
Use Volume.operation in SDM.copy_data Change-Id: I574cea3387ab5b99368e0317aed73683d398a596 Signed-off-by: Adam Litke <[email protected]> --- M tests/storage_sdm_copy_data_test.py M vdsm/storage/sdm/api/copy_data.py 2 files changed, 56 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/64478/1 diff --git a/tests/storage_sdm_copy_data_test.py b/tests/storage_sdm_copy_data_test.py index c0ec533..fef85cc 100644 --- a/tests/storage_sdm_copy_data_test.py +++ b/tests/storage_sdm_copy_data_test.py @@ -221,7 +221,50 @@ # Qemu pads the file to a 1k boundary with null bytes self.assertTrue(f.read().startswith(vm_conf_data)) + @permutations(( + ('file', jobs.STATUS.DONE), + ('file', jobs.STATUS.FAILED), + ('block', jobs.STATUS.DONE), + ('block', jobs.STATUS.FAILED), + )) + def test_volume_operation(self, env_type, final_status): + if final_status == jobs.STATUS.DONE: + cmd = ['/bin/true'] + final_legality = sc.LEGAL_VOL + else: + cmd = ['/bin/false'] + final_legality = sc.ILLEGAL_VOL + job_id = str(uuid.uuid4()) + fmt = sc.RAW_FORMAT + with self.get_vols(env_type, fmt, fmt) as (src_chain, dst_chain): + src_vol = src_chain[0] + dst_vol = dst_chain[0] + self.assertEqual(sc.LEGAL_VOL, dst_vol.getLegality()) + source = dict(endpoint_type='div', sd_id=src_vol.sdUUID, + img_id=src_vol.imgUUID, vol_id=src_vol.volUUID) + dest = dict(endpoint_type='div', sd_id=dst_vol.sdUUID, + img_id=dst_vol.imgUUID, vol_id=dst_vol.volUUID) + fake_convert = FakeQemuConvertChecker(src_vol, dst_vol, cmd) + with MonkeyPatchScope([(qemuimg, 'convert', fake_convert)]): + job = storage.sdm.api.copy_data.Job(job_id, 0, source, dest) + job.run() + wait_for_job(job) + self.assertEqual(final_status, job.status) + self.assertEqual(final_legality, dst_vol.getLegality()) + # TODO: Missing tests: # Copy between 2 different domains # Abort before copy # Abort during copy + + +class FakeQemuConvertChecker(object): + def __init__(self, src_vol, dst_vol, command): + self.src_vol = src_vol + self.dst_vol = dst_vol + self.command = command + + def __call__(self, *args, **kwargs): + assert sc.LEGAL_VOL == self.src_vol.getLegality() + assert sc.ILLEGAL_VOL == self.dst_vol.getLegality() + return qemuimg.QemuImgOperation(self.command) diff --git a/vdsm/storage/sdm/api/copy_data.py b/vdsm/storage/sdm/api/copy_data.py index d55e651..dc97248 100644 --- a/vdsm/storage/sdm/api/copy_data.py +++ b/vdsm/storage/sdm/api/copy_data.py @@ -73,14 +73,15 @@ src_format = self._source.qemu_format dst_format = self._dest.qemu_format - self._operation = qemuimg.convert( - self._source.path, - self._dest.path, - srcFormat=src_format, - dstFormat=dst_format, - backing=self._dest.backing_path, - backingFormat=self._dest.backing_qemu_format) - self._operation.wait_for_completion() + with self._dest.volume_operation(): + self._operation = qemuimg.convert( + self._source.path, + self._dest.path, + srcFormat=src_format, + dstFormat=dst_format, + backing=self._dest.backing_path, + backingFormat=self._dest.backing_qemu_format) + self._operation.wait_for_completion() def _create_endpoint(params, host_id, writable): @@ -141,6 +142,10 @@ return None return sc.fmt2str(parent_vol.getFormat()) + @property + def volume_operation(self): + return self._vol.operation + @contextmanager def prepare(self): dom = sdCache.produce_manifest(self.sd_id) -- To view, visit https://gerrit.ovirt.org/64478 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I574cea3387ab5b99368e0317aed73683d398a596 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam Litke <[email protected]> _______________________________________________ vdsm-patches mailing list -- [email protected] To unsubscribe send an email to [email protected]
