summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafi Khardalian <rafi@metacloud.com>2013-02-10 06:05:59 +0000
committerRafi Khardalian <rafi@metacloud.com>2013-02-10 08:20:44 +0000
commit65ba31366c2c13ca70342200865b7b5f6624f2e3 (patch)
tree0c3954913a26138601db4bde53e0ae7ad7efe92c
parentf9c4cd90a94516ec05acbb62b13b48af646fa218 (diff)
Properly write non-raw LVM images on creation
Fixes bug 1075333 When force_raw_images=False and libvirt_images_type=lvm were set together, selecting anything other than a RAW image would result in an unbootable instance. This is because the downloaded image was being directly dd'd onto the new LVM root, which will obviously not work for any format other than RAW. Simple change to use qemu-img to read from the image (letting it decide the format) and write to the LVM root as raw. Change-Id: I36494e6d0671c07f7511c10ef886c8cf84c18df7
-rw-r--r--nova/tests/test_imagebackend.py8
-rwxr-xr-x[-rw-r--r--]nova/virt/images.py4
-rwxr-xr-xnova/virt/libvirt/imagebackend.py3
3 files changed, 7 insertions, 8 deletions
diff --git a/nova/tests/test_imagebackend.py b/nova/tests/test_imagebackend.py
index 76fd1d5b6..87e51819d 100644
--- a/nova/tests/test_imagebackend.py
+++ b/nova/tests/test_imagebackend.py
@@ -241,8 +241,8 @@ class LvmTestCase(_ImageTestCase, test.TestCase):
sparse=sparse)
self.disk.get_disk_size(self.TEMPLATE_PATH
).AndReturn(self.TEMPLATE_SIZE)
- cmd = ('dd', 'if=%s' % self.TEMPLATE_PATH,
- 'of=%s' % self.PATH, 'bs=4M')
+ cmd = ('qemu-img', 'convert', '-O', 'raw', self.TEMPLATE_PATH,
+ self.PATH)
self.utils.execute(*cmd, run_as_root=True)
self.mox.ReplayAll()
@@ -271,8 +271,8 @@ class LvmTestCase(_ImageTestCase, test.TestCase):
self.SIZE, sparse=sparse)
self.disk.get_disk_size(self.TEMPLATE_PATH
).AndReturn(self.TEMPLATE_SIZE)
- cmd = ('dd', 'if=%s' % self.TEMPLATE_PATH,
- 'of=%s' % self.PATH, 'bs=4M')
+ cmd = ('qemu-img', 'convert', '-O', 'raw', self.TEMPLATE_PATH,
+ self.PATH)
self.utils.execute(*cmd, run_as_root=True)
self.disk.resize2fs(self.PATH, run_as_root=True)
self.mox.ReplayAll()
diff --git a/nova/virt/images.py b/nova/virt/images.py
index 018badecf..a5c960486 100644..100755
--- a/nova/virt/images.py
+++ b/nova/virt/images.py
@@ -184,10 +184,10 @@ def qemu_img_info(path):
return QemuImgInfo(out)
-def convert_image(source, dest, out_format):
+def convert_image(source, dest, out_format, run_as_root=False):
"""Convert image to other format."""
cmd = ('qemu-img', 'convert', '-O', out_format, source, dest)
- utils.execute(*cmd)
+ utils.execute(*cmd, run_as_root=run_as_root)
def fetch(context, image_href, path, _user_id, _project_id):
diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py
index 74148a866..7e7175865 100755
--- a/nova/virt/libvirt/imagebackend.py
+++ b/nova/virt/libvirt/imagebackend.py
@@ -248,8 +248,7 @@ class Lvm(Image):
size = size if resize else base_size
libvirt_utils.create_lvm_image(self.vg, self.lv,
size, sparse=self.sparse)
- cmd = ('dd', 'if=%s' % base, 'of=%s' % self.path, 'bs=4M')
- utils.execute(*cmd, run_as_root=True)
+ images.convert_image(base, self.path, 'raw', run_as_root=True)
if resize:
disk.resize2fs(self.path, run_as_root=True)