Adam Litke has uploaded a new change for review.

Change subject: storage: Use mismatched_vm_conf_disk workaround in copy_data
......................................................................

storage: Use mismatched_vm_conf_disk workaround in copy_data

SDM.copy_data needs to apply the same workaround when interpreting
volume format information for VM configuration disks.  Resolve this TODO
and add a test for it.

Change-Id: Iecfd3e0fd5923e9a333379ab21e01c9b12def78c
Signed-off-by: Adam Litke <ali...@redhat.com>
---
M tests/storage_sdm_copy_data_test.py
M vdsm/storage/sdm/api/copy_data.py
2 files changed, 43 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/31/64231/1

diff --git a/tests/storage_sdm_copy_data_test.py 
b/tests/storage_sdm_copy_data_test.py
index 6d7342b..77b5bbc 100644
--- a/tests/storage_sdm_copy_data_test.py
+++ b/tests/storage_sdm_copy_data_test.py
@@ -24,7 +24,7 @@
 
 from monkeypatch import MonkeyPatchScope
 from storagefakelib import FakeResourceManager
-from storagetestlib import fake_env
+from storagetestlib import fake_env, fake_file_env
 from storagetestlib import make_qemu_chain, write_qemu_chain, verify_qemu_chain
 from storagetestlib import ChainVerificationError
 from testlib import VdsmTestCase, expandPermutations, permutations
@@ -38,6 +38,7 @@
 
 from storage import blockVolume, sd, volume
 from storage import resourceManager
+from storage import workarounds
 
 import storage.sdm.api.copy_data
 
@@ -188,6 +189,39 @@
                                  sorted(guarded.context.locks))
             verify_qemu_chain(dst_chain)
 
+    def test_bad_vm_configuration_volume(self):
+        """
+        When copying a volume containing VM configuration information the
+        volume format may be set incorrectly due to an old bug.  Check that the
+        workaround we have in place allows the copy to proceed without error.
+        """
+        src_img_id = str(uuid.uuid4())
+        src_vol_id = str(uuid.uuid4())
+        dst_img_id = str(uuid.uuid4())
+        dst_vol_id = str(uuid.uuid4())
+        job_id = str(uuid.uuid4())
+        size = workarounds.VM_CONF_SIZE_BLK * sc.BLOCK_SIZE
+        with fake_file_env() as env:
+            env.make_volume(size, src_img_id, src_vol_id,
+                            vol_format=sc.COW_FORMAT)
+            env.make_volume(size, dst_img_id, dst_vol_id,
+                            vol_format=sc.RAW_FORMAT)
+            src_vol = env.sd_manifest.produceVolume(src_img_id, src_vol_id)
+            dst_vol = env.sd_manifest.produceVolume(dst_img_id, dst_vol_id)
+            qemuimg.create(src_vol.getVolumePath(), size, qemuimg.FORMAT.RAW)
+            with MonkeyPatchScope([
+                (guarded, 'context', fake_guarded_context()),
+                (storage.sdm.api.copy_data, 'sdCache', env.sdcache),
+            ]):
+                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)
+                job = storage.sdm.api.copy_data.Job(job_id, 0, source, dest)
+                job.run()
+                wait_for_job(job)
+                self.assertEqual(jobs.STATUS.DONE, job.status)
+
     # TODO: Missing tests:
     # Copy between 2 different domains
     # Abort before copy
diff --git a/vdsm/storage/sdm/api/copy_data.py 
b/vdsm/storage/sdm/api/copy_data.py
index 0a1cdb6..c078439 100644
--- a/vdsm/storage/sdm/api/copy_data.py
+++ b/vdsm/storage/sdm/api/copy_data.py
@@ -31,6 +31,7 @@
 from storage import resourceManager as rm
 from storage import sd
 from storage import volume
+from storage import workarounds
 from storage.sdc import sdCache
 
 from . import base
@@ -94,6 +95,7 @@
         self._host_id = host_id
         self._writable = writable
         self._vol = None
+        self._qemu_format = None
 
     @property
     def locks(self):
@@ -113,8 +115,12 @@
 
     @property
     def qemu_format(self):
-        # TODO: Use Image._detect_format to handle broken VM md images.
-        return sc.fmt2str(self._vol.getFormat())
+        if not self._qemu_format:
+            if workarounds.mismatched_vm_conf_disk(self._vol):
+                self._qemu_format = qemuimg.FORMAT.RAW
+            else:
+                self._qemu_format = sc.fmt2str(self._vol.getFormat())
+        return self._qemu_format
 
     @property
     def backing_path(self):


-- 
To view, visit https://gerrit.ovirt.org/64231
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecfd3e0fd5923e9a333379ab21e01c9b12def78c
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Adam Litke <ali...@redhat.com>
_______________________________________________
vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org
To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org

Reply via email to